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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations