diff --git a/source/java/org/alfresco/repo/web/scripts/action/AbstractActionWebscript.java b/source/java/org/alfresco/repo/web/scripts/action/AbstractActionWebscript.java new file mode 100644 index 0000000000..75367ed276 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/action/AbstractActionWebscript.java @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.web.scripts.action; + +import java.util.Map; + +import org.alfresco.repo.action.ActionTrackingServiceImpl; +import org.alfresco.repo.action.RuntimeActionService; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.action.ActionTrackingService; +import org.alfresco.service.cmr.action.ExecutionSummary; +import org.alfresco.service.cmr.repository.NodeService; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.DeclarativeWebScript; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * @author Nick Burch + * @since 3.4 + */ +public abstract class AbstractActionWebscript extends DeclarativeWebScript +{ + protected NodeService nodeService; + protected ActionService actionService; + protected RuntimeActionService runtimeActionService; + protected ActionTrackingService actionTrackingService; + + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + public void setActionService(ActionService actionService) + { + this.actionService = actionService; + } + + public void setRuntimeActionService(RuntimeActionService runtimeActionService) + { + this.runtimeActionService = runtimeActionService; + } + + public void setActionTrackingService(ActionTrackingService actionTrackingService) + { + this.actionTrackingService = actionTrackingService; + } + + @Override + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) + { + RunningActionModelBuilder modelBuilder = new RunningActionModelBuilder( + nodeService, actionService, actionTrackingService + ); + return buildModel(modelBuilder, req, status, cache); + } + + protected abstract Map buildModel( + RunningActionModelBuilder modelBuilder, + WebScriptRequest req, + Status status, Cache cache + ); + + + /** + * Takes a running action ID, and returns an + * ExecutionSummary object for it. Note - doesn't + * check to see if the object exists in the + * cache though! + */ + public static ExecutionSummary getSummaryFromKey(String key) + { + return WrappedActionTrackingService.getSummaryFromKey(key); + } + + /** + * Returns the running action ID for the given + * ExecutionSummary + */ + public static String getRunningId(ExecutionSummary summary) + { + return WrappedActionTrackingService.getRunningId(summary); + } + + /** + * So we can get at protected methods, which we need as + * we use the same naming scheme as the cache in the + * interests of simplicity. + */ + private static class WrappedActionTrackingService extends ActionTrackingServiceImpl + { + private static String getRunningId(ExecutionSummary summary) + { + return ActionTrackingServiceImpl.generateCacheKey(summary); + } + + private static ExecutionSummary getSummaryFromKey(String key) + { + return ActionTrackingServiceImpl.buildExecutionSummary(key); + } + } +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/action/RunningActionModelBuilder.java b/source/java/org/alfresco/repo/web/scripts/action/RunningActionModelBuilder.java new file mode 100644 index 0000000000..440dc6bfef --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/action/RunningActionModelBuilder.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.web.scripts.action; + +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.action.ActionTrackingService; +import org.alfresco.service.cmr.repository.NodeService; + +/** + * Builds up models for running actions + * + * @author Nick Burch + * @since 3.4 + */ +public class RunningActionModelBuilder +{ + protected static final String MODEL_DATA_ITEM = "runningAction"; + protected static final String MODEL_DATA_LIST = "runningActions"; + + + protected NodeService nodeService; + protected ActionService actionService; + protected ActionTrackingService actionTrackingService; + + public RunningActionModelBuilder(NodeService nodeService, ActionService actionService, + ActionTrackingService actionTrackingService) + { + this.nodeService = nodeService; + this.actionService = actionService; + this.actionTrackingService = actionTrackingService; + } +} \ No newline at end of file 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 5fcfc8e9de..63f1c85b8e 100644 --- a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java +++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.alfresco.repo.web.scripts.action.AbstractActionWebscript; import org.alfresco.service.cmr.action.ActionTrackingService; import org.alfresco.service.cmr.action.ExecutionDetails; import org.alfresco.service.cmr.action.ExecutionSummary; @@ -47,10 +48,18 @@ public class ReplicationModelBuilder protected static final String MODEL_DATA_LIST = "replicationDefinitions"; protected static final String DEFINITION_NAME = "name"; + protected static final String DEFINITION_DESCRIPTION = "description"; protected static final String DEFINITION_STATUS = "status"; protected static final String DEFINITION_STARTED_AT = "startedAt"; protected static final String DEFINITION_ENDED_AT = "endedAt"; + protected static final String DEFINITION_FAILURE_MESSAGE = "failureMessage"; + protected static final String DEFINITION_RUNNING_ACTION_ID = "runningActionId"; + protected static final String DEFINITION_PAYLOAD = "payload"; + protected static final String DEFINITION_TRANSFER_LOCAL_REPORT = "transferLocalReport"; + protected static final String DEFINITION_TRANSFER_REMOTE_REPORT = "transferRemoteReport"; + protected static final String DEFINITION_CANCEL_REQUESTED = "cancelRequested"; protected static final String DEFINITION_ENABLED = "enabled"; + protected static final String DEFINITION_TARGET_NAME = "targetName"; protected NodeService nodeService; protected ReplicationService replicationService; @@ -144,9 +153,11 @@ public class ReplicationModelBuilder rdm.put(DEFINITION_NAME, rd.getReplicationName()); rdm.put(DEFINITION_ENABLED, rd.isEnabled()); - // Do the status - end date isn't needed + // Do the status setStatus(rd, details, rdm); + // In the summary form, we don't need end time or details rdm.remove(DEFINITION_ENDED_AT); + rdm.remove(DEFINITION_RUNNING_ACTION_ID); // Add to the list of finished models models.add(rdm); @@ -174,10 +185,15 @@ public class ReplicationModelBuilder // Set the core details rdm.put(DEFINITION_NAME, rd.getReplicationName()); + rdm.put(DEFINITION_DESCRIPTION, rd.getDescription()); + rdm.put(DEFINITION_FAILURE_MESSAGE, rd.getExecutionFailureMessage()); + rdm.put(DEFINITION_TRANSFER_LOCAL_REPORT, rd.getLocalTransferReport()); + rdm.put(DEFINITION_TRANSFER_REMOTE_REPORT, rd.getRemoteTransferReport()); rdm.put(DEFINITION_ENABLED, rd.isEnabled()); - // TODO + rdm.put(DEFINITION_TARGET_NAME, rd.getTargetName()); // Do the status + // Includes start+end times, and running action details setStatus(rd, rdm); // Expand out the payload details @@ -237,6 +253,9 @@ public class ReplicationModelBuilder model.put(DEFINITION_ENDED_AT, null); } + // It isn't running + model.put(DEFINITION_RUNNING_ACTION_ID, null); + return; } @@ -248,6 +267,8 @@ public class ReplicationModelBuilder } model.put(DEFINITION_STARTED_AT, ISO8601DateFormat.format(details.getStartedAt())); model.put(DEFINITION_ENDED_AT, null); + model.put(DEFINITION_RUNNING_ACTION_ID, + AbstractActionWebscript.getRunningId(details.getExecutionSummary())); } /** diff --git a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java index 96c5c0596d..ec2cd7e2c0 100644 --- a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java @@ -100,6 +100,21 @@ public class ReplicationRestApiTest extends BaseWebScriptTest assertEquals("/api/replication-definition/Test1", jsonRD.get("details")); + // Ensure we didn't get any unexpected data back, + // only the keys we should have done + JSONArray keys = jsonRD.names(); + for(int i=0; i