use of org.alfresco.service.cmr.workflow.WorkflowException in project acs-community-packaging by Alfresco.
the class WorkflowDefinitionImageServlet method doGet.
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// retrieve workflow definition id
String uri = request.getRequestURI();
uri = uri.substring(request.getContextPath().length());
StringTokenizer t = new StringTokenizer(uri, "/");
if (t.countTokens() != 2) {
throw new WorkflowException("Workflow Definition Image servlet does not contain workflow definition id : " + uri);
}
// skip servlet name
t.nextToken();
String workflowDefinitionId = t.nextToken();
// retrieve workflow definition image
WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
WorkflowService workflowService = (WorkflowService) wc.getBean(ServiceRegistry.WORKFLOW_SERVICE.getLocalName());
byte[] definitionImage = workflowService.getDefinitionImage(workflowDefinitionId);
// stream out through response
OutputStream out = response.getOutputStream();
out.write(definitionImage);
out.flush();
}
use of org.alfresco.service.cmr.workflow.WorkflowException in project alfresco-remote-api by Alfresco.
the class TaskInstancePut method buildModel.
@Override
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
Map<String, String> params = req.getServiceMatch().getTemplateVars();
// getting task id from request parameters
String taskId = params.get("task_instance_id");
JSONObject json = null;
try {
WorkflowTask workflowTask = workflowService.getTaskById(taskId);
String currentUser = authenticationService.getCurrentUserName();
// read request json
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// update task properties
workflowTask = workflowService.updateTask(taskId, parseTaskProperties(json, workflowTask), null, null);
// task was not found -> return 404
if (workflowTask == null) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Failed to find workflow task with id: " + taskId);
}
// build the model for ftl
Map<String, Object> model = new HashMap<String, Object>();
model.put("workflowTask", modelBuilder.buildDetailed(workflowTask));
return model;
} 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);
} catch (AccessDeniedException ade) {
throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "Failed to update workflow task with id: " + taskId, ade);
} catch (WorkflowException we) {
throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "Failed to update workflow task with id: " + taskId, we);
}
}
Aggregations