Search in sources :

Example 1 with WorkflowException

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();
}
Also used : StringTokenizer(java.util.StringTokenizer) WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) WorkflowException(org.alfresco.service.cmr.workflow.WorkflowException) OutputStream(java.io.OutputStream) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 2 with WorkflowException

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);
    }
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) HashMap(java.util.HashMap) WorkflowException(org.alfresco.service.cmr.workflow.WorkflowException) JSONException(org.json.JSONException) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) IOException(java.io.IOException) JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.JSONObject)

Aggregations

WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 StringTokenizer (java.util.StringTokenizer)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 WorkflowService (org.alfresco.service.cmr.workflow.WorkflowService)1 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 JSONTokener (org.json.JSONTokener)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1