Search in sources :

Example 1 with ExecutionSummary

use of org.alfresco.service.cmr.action.ExecutionSummary in project alfresco-remote-api by Alfresco.

the class AbstractExecuteActionWebscript method buildModel.

protected Map<String, Object> buildModel(RunningActionModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
    try {
        // Have the action to run be identified
        Action action = identifyAction(req, status, cache);
        if (action == null) {
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "No Runnable Action found with the supplied details");
        }
        // Ask for it to be run in the background
        // It will be available to execute once the webscript finishes
        actionService.executeAction(action, null, false, true);
        // Return the details if we can
        ExecutionSummary summary = getSummaryFromAction(action);
        if (summary == null) {
            throw new WebScriptException(Status.STATUS_EXPECTATION_FAILED, "Action failed to be added to the pending queue");
        }
        return modelBuilder.buildSimpleModel(summary);
    } catch (Exception e) {
        // Transaction broke
        throw new RuntimeException(e);
    }
}
Also used : Action(org.alfresco.service.cmr.action.Action) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ExecutionSummary(org.alfresco.service.cmr.action.ExecutionSummary) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Example 2 with ExecutionSummary

use of org.alfresco.service.cmr.action.ExecutionSummary in project alfresco-remote-api by Alfresco.

the class RunningActionDelete method buildModel.

@Override
protected Map<String, Object> buildModel(RunningActionModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
    // Which action did they ask for?
    String actionTrackingId = req.getServiceMatch().getTemplateVars().get("action_tracking_id");
    // Check it exists
    ExecutionSummary action = getSummaryFromKey(actionTrackingId);
    if (action == null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "No Running Action found with that tracking id");
    }
    ExecutionDetails details = actionTrackingService.getExecutionDetails(action);
    if (details == null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "No Running Action found with that tracking id");
    }
    // Request the cancel
    actionTrackingService.requestActionCancellation(action);
    // Report it as having been cancelled
    status.setCode(Status.STATUS_NO_CONTENT);
    status.setMessage("Action cancellation requested");
    status.setRedirect(true);
    return null;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ExecutionSummary(org.alfresco.service.cmr.action.ExecutionSummary) ExecutionDetails(org.alfresco.service.cmr.action.ExecutionDetails)

Example 3 with ExecutionSummary

use of org.alfresco.service.cmr.action.ExecutionSummary in project alfresco-remote-api by Alfresco.

the class RunningActionGet method buildModel.

@Override
protected Map<String, Object> buildModel(RunningActionModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
    // Which action did they ask for?
    String actionTrackingId = req.getServiceMatch().getTemplateVars().get("action_tracking_id");
    ExecutionSummary action = getSummaryFromKey(actionTrackingId);
    // Get the details, if we can
    Map<String, Object> model = modelBuilder.buildSimpleModel(action);
    if (model == null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "No Running Action found with that tracking id");
    }
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ExecutionSummary(org.alfresco.service.cmr.action.ExecutionSummary)

Example 4 with ExecutionSummary

use of org.alfresco.service.cmr.action.ExecutionSummary in project alfresco-remote-api by Alfresco.

the class ReplicationModelBuilder method buildSimpleList.

/**
 * Build a model containing a list of simple definitions for the given
 *  list of Replication Definitions.
 */
protected Map<String, Object> buildSimpleList(List<ReplicationDefinition> replicationDefinitions, Comparator<Map<String, Object>> sorter) {
    List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
    // have some Replication Definitions to render
    if (replicationDefinitions.size() > 0) {
        List<ExecutionSummary> executing = actionTrackingService.getExecutingActions(replicationDefinitions.get(0).getActionDefinitionName());
        for (ReplicationDefinition rd : replicationDefinitions) {
            // Get the executing detail(s) for this definition
            ExecutionDetails details = getExecutionDetails(rd, executing);
            // Set the core details
            Map<String, Object> rdm = new HashMap<String, Object>();
            rdm.put(DEFINITION_NAME, rd.getReplicationName());
            rdm.put(DEFINITION_ENABLED, rd.isEnabled());
            // 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);
        }
    }
    // Sort the entries
    if (sorter != null) {
        Collections.sort(models, sorter);
    }
    // Finish up
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(MODEL_DATA_LIST, models);
    return model;
}
Also used : ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExecutionSummary(org.alfresco.service.cmr.action.ExecutionSummary) ExecutionDetails(org.alfresco.service.cmr.action.ExecutionDetails) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ExecutionSummary

use of org.alfresco.service.cmr.action.ExecutionSummary in project alfresco-remote-api by Alfresco.

the class ReplicationModelBuilder method getExecutionDetails.

/**
 * For the given Replication Definition, and list of executing
 *  actions (which may or may not be only for this definition),
 *  return a single execution details.
 *
 * Returns null if no copies of the definition are executing.
 * Returns a predictable instance if more than one copy is
 *  executing.
 */
private ExecutionDetails getExecutionDetails(ReplicationDefinition replicationDefinition, List<ExecutionSummary> executing) {
    // Figure out which of the running actions are us
    List<ExecutionSummary> ours = new ArrayList<ExecutionSummary>();
    for (ExecutionSummary es : executing) {
        if (es.getActionType().equals(replicationDefinition.getActionDefinitionName()) && es.getActionId().equals(replicationDefinition.getId())) {
            ours.add(es);
        }
    }
    // Do we have anything running at the moment
    if (ours.size() == 0) {
        // Not executing at the moment
        return null;
    }
    // We have at least one copy running
    ExecutionSummary es;
    if (executing.size() == 1) {
        // Only one copy, life is simple
        es = ours.get(0);
    } else {
        // More than one copy runing, joy
        // Go for the lowest execution instance id, so
        // we're predictable
        es = ours.get(0);
        for (ExecutionSummary e : ours) {
            if (e.getExecutionInstance() < es.getExecutionInstance()) {
                es = e;
            }
        }
    }
    // Grab the details
    return actionTrackingService.getExecutionDetails(es);
}
Also used : ArrayList(java.util.ArrayList) ExecutionSummary(org.alfresco.service.cmr.action.ExecutionSummary)

Aggregations

ExecutionSummary (org.alfresco.service.cmr.action.ExecutionSummary)10 ArrayList (java.util.ArrayList)3 ExecutionDetails (org.alfresco.service.cmr.action.ExecutionDetails)3 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)3 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Action (org.alfresco.service.cmr.action.Action)2 UserTransaction (javax.transaction.UserTransaction)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1