Search in sources :

Example 6 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException 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 7 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException 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 8 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException 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 9 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.

the class RunningActionsPost method identifyAction.

@Override
protected Action identifyAction(WebScriptRequest req, Status status, Cache cache) {
    // Which action did they ask for?
    String nodeRef = req.getParameter("nodeRef");
    if (nodeRef == null) {
        try {
            JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
            if (!json.has("nodeRef")) {
                throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not find required 'nodeRef' parameter");
            }
            nodeRef = json.getString("nodeRef");
        } catch (IOException iox) {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from request.", iox);
        } catch (JSONException je) {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from request.", je);
        }
    }
    // Does it exist in the repo?
    NodeRef actionNodeRef = new NodeRef(nodeRef);
    if (!nodeService.exists(actionNodeRef)) {
        return null;
    }
    // Load the specified action
    Action action = runtimeActionService.createAction(actionNodeRef);
    return action;
}
Also used : JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Action(org.alfresco.service.cmr.action.Action) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 10 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.

the class TemplatesWebScript method executeImpl.

/* (non-Javadoc)
     * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
     */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
    String path = "/";
    String templatePattern = "*.ftl";
    // process extension
    // optional
    String p = req.getExtensionPath();
    if ((p != null) && (p.length() > 0)) {
        int idx = p.lastIndexOf("/");
        if (idx != -1) {
            path = p.substring(0, idx);
            templatePattern = p.substring(idx + 1) + ".ftl";
        }
    }
    Set<String> templatePaths = new HashSet<String>();
    for (Store apiStore : searchPath.getStores()) {
        try {
            for (String templatePath : apiStore.getDocumentPaths(path, false, templatePattern)) {
                templatePaths.add(templatePath);
            }
        } catch (IOException e) {
            throw new WebScriptException("Failed to search for templates from store " + apiStore, e);
        }
    }
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("paths", templatePaths);
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) Store(org.springframework.extensions.webscripts.Store) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

WebScriptException (org.springframework.extensions.webscripts.WebScriptException)204 HashMap (java.util.HashMap)94 NodeRef (org.alfresco.service.cmr.repository.NodeRef)67 IOException (java.io.IOException)60 JSONException (org.json.JSONException)48 JSONObject (org.json.JSONObject)44 ArrayList (java.util.ArrayList)32 QName (org.alfresco.service.namespace.QName)31 JSONTokener (org.json.JSONTokener)29 JSONObject (org.json.simple.JSONObject)25 JSONArray (org.json.JSONArray)18 Map (java.util.Map)12 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)11 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)11 StoreRef (org.alfresco.service.cmr.repository.StoreRef)10 File (java.io.File)9 Date (java.util.Date)8 JSONParser (org.json.simple.parser.JSONParser)8 Serializable (java.io.Serializable)7 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)7