From ce1f57c3b981320505b1536a59727e0103693b24 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 26 Aug 2010 13:36:37 +0000 Subject: [PATCH] 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 --- .../replication-definition.lib.ftl | 8 +++- .../AbstractReplicationWebscript.java | 48 +++++++++++++++++++ .../replication/ReplicationDefinitionPut.java | 3 ++ .../ReplicationDefinitionsPost.java | 3 ++ .../replication/ReplicationModelBuilder.java | 19 ++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.lib.ftl index 37c931af2f..47529af1d1 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.lib.ftl @@ -35,7 +35,13 @@ "transferLocalReport": <#if replicationDefinition.transferLocalReport??>"${replicationDefinition.transferLocalReport.nodeRef}"<#else>null, "transferRemoteReport": <#if replicationDefinition.transferRemoteReport??>"${replicationDefinition.transferRemoteReport.nodeRef}"<#else>null, "enabled": ${replicationDefinition.enabled?string}, - "targetName": <#if replicationDefinition.targetName??>"${replicationDefinition.targetName}"<#else>null + "targetName": <#if replicationDefinition.targetName??>"${replicationDefinition.targetName}"<#else>null, + "schedule": <#if replicationDefinition.scheduleEnabled> + { + "start": "${replicationDefinition.scheduleStart}", + "intervalPeriod": <#if replicationDefinition.scheduleIntervalPeriod??>"${replicationDefinition.scheduleIntervalPeriod}"<#else>null, + "intervalCount": <#if replicationDefinition.scheduleIntervalCount??>${replicationDefinition.scheduleIntervalCount}<#else>null + }<#else>null } diff --git a/source/java/org/alfresco/repo/web/scripts/replication/AbstractReplicationWebscript.java b/source/java/org/alfresco/repo/web/scripts/replication/AbstractReplicationWebscript.java index 2fb26c7554..856146b66d 100644 --- a/source/java/org/alfresco/repo/web/scripts/replication/AbstractReplicationWebscript.java +++ b/source/java/org/alfresco/repo/web/scripts/replication/AbstractReplicationWebscript.java @@ -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 buildModel( ReplicationModelBuilder modelBuilder, WebScriptRequest req, diff --git a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionPut.java b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionPut.java index 1327e9d0cd..a75d98baf6 100644 --- a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionPut.java +++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionPut.java @@ -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) { diff --git a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionsPost.java b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionsPost.java index 266be95845..a2d1708ed6 100644 --- a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionsPost.java +++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionsPost.java @@ -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) { diff --git a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java index c693d5398f..3c33f0b8b0 100644 --- a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java +++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java @@ -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);