ALF-4130 - Continue work on replication details fetch webscript

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21566 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2010-08-03 11:47:58 +00:00
parent 90fbffbb58
commit dd5a727408
4 changed files with 208 additions and 2 deletions

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
RunningActionModelBuilder modelBuilder = new RunningActionModelBuilder(
nodeService, actionService, actionTrackingService
);
return buildModel(modelBuilder, req, status, cache);
}
protected abstract Map<String, Object> 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);
}
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.ActionTrackingService;
import org.alfresco.service.cmr.action.ExecutionDetails; import org.alfresco.service.cmr.action.ExecutionDetails;
import org.alfresco.service.cmr.action.ExecutionSummary; 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 MODEL_DATA_LIST = "replicationDefinitions";
protected static final String DEFINITION_NAME = "name"; 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_STATUS = "status";
protected static final String DEFINITION_STARTED_AT = "startedAt"; protected static final String DEFINITION_STARTED_AT = "startedAt";
protected static final String DEFINITION_ENDED_AT = "endedAt"; 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_ENABLED = "enabled";
protected static final String DEFINITION_TARGET_NAME = "targetName";
protected NodeService nodeService; protected NodeService nodeService;
protected ReplicationService replicationService; protected ReplicationService replicationService;
@@ -144,9 +153,11 @@ public class ReplicationModelBuilder
rdm.put(DEFINITION_NAME, rd.getReplicationName()); rdm.put(DEFINITION_NAME, rd.getReplicationName());
rdm.put(DEFINITION_ENABLED, rd.isEnabled()); rdm.put(DEFINITION_ENABLED, rd.isEnabled());
// Do the status - end date isn't needed // Do the status
setStatus(rd, details, rdm); setStatus(rd, details, rdm);
// In the summary form, we don't need end time or details
rdm.remove(DEFINITION_ENDED_AT); rdm.remove(DEFINITION_ENDED_AT);
rdm.remove(DEFINITION_RUNNING_ACTION_ID);
// Add to the list of finished models // Add to the list of finished models
models.add(rdm); models.add(rdm);
@@ -174,10 +185,15 @@ public class ReplicationModelBuilder
// Set the core details // Set the core details
rdm.put(DEFINITION_NAME, rd.getReplicationName()); 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()); rdm.put(DEFINITION_ENABLED, rd.isEnabled());
// TODO rdm.put(DEFINITION_TARGET_NAME, rd.getTargetName());
// Do the status // Do the status
// Includes start+end times, and running action details
setStatus(rd, rdm); setStatus(rd, rdm);
// Expand out the payload details // Expand out the payload details
@@ -237,6 +253,9 @@ public class ReplicationModelBuilder
model.put(DEFINITION_ENDED_AT, null); model.put(DEFINITION_ENDED_AT, null);
} }
// It isn't running
model.put(DEFINITION_RUNNING_ACTION_ID, null);
return; return;
} }
@@ -248,6 +267,8 @@ public class ReplicationModelBuilder
} }
model.put(DEFINITION_STARTED_AT, ISO8601DateFormat.format(details.getStartedAt())); model.put(DEFINITION_STARTED_AT, ISO8601DateFormat.format(details.getStartedAt()));
model.put(DEFINITION_ENDED_AT, null); model.put(DEFINITION_ENDED_AT, null);
model.put(DEFINITION_RUNNING_ACTION_ID,
AbstractActionWebscript.getRunningId(details.getExecutionSummary()));
} }
/** /**

View File

@@ -100,6 +100,21 @@ public class ReplicationRestApiTest extends BaseWebScriptTest
assertEquals("/api/replication-definition/Test1", jsonRD.get("details")); 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<keys.length(); i++) {
String key = keys.getString(0);
if(key.equals("name") || key.equals("status") ||
key.equals("startedAt") || key.equals("enabled") ||
key.equals("details")) {
// All good
} else {
fail("Unexpected key '"+key+"' found in json, raw json is\n" + jsonStr);
}
}
// Change the status to running, and re-check // Change the status to running, and re-check
actionTrackingService.recordActionExecuting(rd); actionTrackingService.recordActionExecuting(rd);
String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate()); String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
@@ -366,6 +381,10 @@ System.err.println(jsonStr);
assertEquals(JSONObject.NULL, json.get("startedAt")); assertEquals(JSONObject.NULL, json.get("startedAt"));
// Ensure we didn't get any unexpected data back
// TODO
// Change the status to running, and re-check // Change the status to running, and re-check
actionTrackingService.recordActionExecuting(rd); actionTrackingService.recordActionExecuting(rd);
String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate()); String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());