mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-4346 & ALF-4348 - More work on schedulable actions, and start to expose this through to the replication service
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22019 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -21,10 +21,12 @@ package org.alfresco.repo.web.scripts.replication;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.action.ActionTrackingService;
|
||||
import org.alfresco.service.cmr.action.scheduled.SchedulableAction.IntervalPeriod;
|
||||
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||
import org.alfresco.service.cmr.replication.ReplicationService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.util.ISO8601DateFormat;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -102,6 +104,52 @@ public abstract class AbstractReplicationWebscript extends DeclarativeWebScript
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the schedule related properties, based on the
|
||||
* JSON, and has these persisted as required.
|
||||
*/
|
||||
protected void updateDefinitionScheduling(ReplicationDefinition replicationDefinition, JSONObject json)
|
||||
throws JSONException
|
||||
{
|
||||
if(json.has("schedule") && !json.isNull("schedule")) {
|
||||
// Turn on scheduling, if not already enabled
|
||||
replicationService.enableScheduling(replicationDefinition);
|
||||
|
||||
// Update the properties
|
||||
JSONObject schedule = json.getJSONObject("schedule");
|
||||
|
||||
if(schedule.has("start") && !schedule.isNull("start")) {
|
||||
replicationDefinition.setScheduleStart(
|
||||
ISO8601DateFormat.parse(schedule.getString("start"))
|
||||
);
|
||||
} else {
|
||||
replicationDefinition.setScheduleStart(null);
|
||||
}
|
||||
|
||||
if(schedule.has("intervalPeriod") && !schedule.isNull("intervalPeriod")) {
|
||||
replicationDefinition.setScheduleIntervalPeriod(
|
||||
IntervalPeriod.valueOf(schedule.getString("intervalPeriod"))
|
||||
);
|
||||
} else {
|
||||
replicationDefinition.setScheduleIntervalPeriod(null);
|
||||
}
|
||||
|
||||
if(schedule.has("intervalCount") && !schedule.isNull("intervalCount")) {
|
||||
replicationDefinition.setScheduleIntervalCount(
|
||||
schedule.getInt("intervalCount")
|
||||
);
|
||||
} else {
|
||||
replicationDefinition.setScheduleIntervalCount(null);
|
||||
}
|
||||
|
||||
// Ensure the scheduling is saved
|
||||
replicationService.saveReplicationDefinition(replicationDefinition);
|
||||
} else {
|
||||
// Disable scheduling
|
||||
replicationService.disableScheduling(replicationDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Map<String, Object> buildModel(
|
||||
ReplicationModelBuilder modelBuilder,
|
||||
WebScriptRequest req,
|
||||
|
@@ -85,6 +85,9 @@ public class ReplicationDefinitionPut extends AbstractReplicationWebscript
|
||||
|
||||
// Save the changes
|
||||
replicationService.saveReplicationDefinition(replicationDefinition);
|
||||
|
||||
// Now do the scheduling
|
||||
updateDefinitionScheduling(replicationDefinition, json);
|
||||
}
|
||||
catch (IOException iox)
|
||||
{
|
||||
|
@@ -72,6 +72,9 @@ public class ReplicationDefinitionsPost extends AbstractReplicationWebscript
|
||||
|
||||
// Save the changes
|
||||
replicationService.saveReplicationDefinition(replicationDefinition);
|
||||
|
||||
// Now do the scheduling
|
||||
updateDefinitionScheduling(replicationDefinition, json);
|
||||
}
|
||||
catch (IOException iox)
|
||||
{
|
||||
|
@@ -60,6 +60,11 @@ public class ReplicationModelBuilder
|
||||
protected static final String DEFINITION_ENABLED = "enabled";
|
||||
protected static final String DEFINITION_TARGET_NAME = "targetName";
|
||||
|
||||
protected static final String DEFINITION_SCHEDULE_ENABLED = "scheduleEnabled";
|
||||
protected static final String DEFINITION_SCHEDULE_START = "scheduleStart";
|
||||
protected static final String DEFINITION_SCHEDULE_PERIOD = "scheduleIntervalPeriod";
|
||||
protected static final String DEFINITION_SCHEDULE_COUNT = "scheduleIntervalCount";
|
||||
|
||||
protected NodeService nodeService;
|
||||
protected ReplicationService replicationService;
|
||||
protected ActionTrackingService actionTrackingService;
|
||||
@@ -191,6 +196,20 @@ public class ReplicationModelBuilder
|
||||
rdm.put(DEFINITION_ENABLED, rd.isEnabled());
|
||||
rdm.put(DEFINITION_TARGET_NAME, rd.getTargetName());
|
||||
|
||||
// Set the scheduling details
|
||||
rdm.put(DEFINITION_SCHEDULE_ENABLED, rd.isSchedulingEnabled());
|
||||
if(rd.isSchedulingEnabled())
|
||||
{
|
||||
rdm.put(DEFINITION_SCHEDULE_START, ISO8601DateFormat.format(rd.getScheduleStart()));
|
||||
|
||||
rdm.put(DEFINITION_SCHEDULE_COUNT, rd.getScheduleIntervalCount());
|
||||
if(rd.getScheduleIntervalPeriod() != null) {
|
||||
rdm.put(DEFINITION_SCHEDULE_PERIOD, rd.getScheduleIntervalPeriod().toString());
|
||||
} else {
|
||||
rdm.put(DEFINITION_SCHEDULE_PERIOD, null);
|
||||
}
|
||||
}
|
||||
|
||||
// Do the status
|
||||
// Includes start+end times, and running action details
|
||||
setStatus(rd, rdm);
|
||||
|
Reference in New Issue
Block a user