Search in sources :

Example 1 with WorkflowTask

use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.

the class TaskInfoBean method sendTaskResources.

/**
 * Returns the resource list for the workflow task identified by the 'taskId'
 * parameter found in the ExternalContext.
 * <p>
 * The result is the formatted HTML to show on the client.
 */
public void sendTaskResources() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    ResponseWriter out = context.getResponseWriter();
    String taskId = (String) context.getExternalContext().getRequestParameterMap().get("taskId");
    if (taskId == null || taskId.length() == 0) {
        throw new IllegalArgumentException("'taskId' parameter is missing");
    }
    WorkflowTask task = this.getWorkflowService().getTaskById(taskId);
    if (task != null) {
        Repository.getServiceRegistry(context).getTemplateService().processTemplate("/alfresco/templates/client/task_resource_panel.ftl", getModel(task), out);
    } else {
        out.write("<span class='errorMessage'>Task could not be found.</span>");
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ResponseWriter(javax.faces.context.ResponseWriter) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Example 2 with WorkflowTask

use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.

the class CCCheckoutFileDialog method checkoutFile.

/**
 * Action called upon completion of the Check Out file page
 */
public String checkoutFile(FacesContext context, String outcome) {
    boolean checkoutSuccessful = false;
    final Node node = property.getDocument();
    if (node != null) {
        try {
            if (logger.isDebugEnabled())
                logger.debug("Trying to checkout content node Id: " + node.getId());
            // checkout the node content to create a working copy
            if (logger.isDebugEnabled()) {
                logger.debug("Checkout copy location: " + property.getCopyLocation());
                logger.debug("Selected Space Id: " + property.getSelectedSpaceId());
            }
            NodeRef workingCopyRef = null;
            if (property.getCopyLocation().equals(CCProperties.COPYLOCATION_OTHER) && property.getSelectedSpaceId() != null) {
                // checkout to a arbituary parent Space
                NodeRef destRef = property.getSelectedSpaceId();
                ChildAssociationRef childAssocRef = getNodeService().getPrimaryParent(destRef);
                workingCopyRef = property.getVersionOperationsService().checkout(node.getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, childAssocRef.getQName());
            } else {
                // checkout the content to the current space
                workingCopyRef = property.getVersionOperationsService().checkout(node.getNodeRef());
                // in the resources panel in the manage task dialog
                if (property.isWorkflowAction() && property.getWorkflowTaskId() != null && (property.getWorkflowTaskId().equals("null") == false)) {
                    WorkflowTask task = property.getWorkflowService().getTaskById(property.getWorkflowTaskId());
                    if (task != null) {
                        NodeRef workflowPackage = (NodeRef) task.properties.get(WorkflowModel.ASSOC_PACKAGE);
                        if (workflowPackage != null) {
                            getNodeService().addChild(workflowPackage, workingCopyRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName((String) getNodeService().getProperty(workingCopyRef, ContentModel.PROP_NAME))));
                            if (logger.isDebugEnabled())
                                logger.debug("Added working copy to workflow package: " + workflowPackage);
                        }
                    }
                }
            }
            // set the working copy Node instance
            Node workingCopy = new Node(workingCopyRef);
            property.setWorkingDocument(workingCopy);
            // create content URL to the content download servlet with ID
            // and expected filename
            // the myfile part will be ignored by the servlet but gives the
            // browser a hint
            String url = DownloadContentServlet.generateDownloadURL(workingCopyRef, workingCopy.getName());
            workingCopy.getProperties().put("url", url);
            workingCopy.getProperties().put("fileType32", FileTypeImageUtils.getFileTypeImage(workingCopy.getName(), false));
            // mark as successful
            checkoutSuccessful = true;
        } catch (Throwable err) {
            Utils.addErrorMessage(Application.getMessage(context, MSG_ERROR_CHECKOUT) + err.getMessage(), err);
            ReportedException.throwIfNecessary(err);
        }
    } else {
        logger.warn("WARNING: checkoutFile called without a current Document!");
    }
    // determine which page to show next if the checkout was successful.
    if (checkoutSuccessful) {
        // already disappeared!
        if (getNodeService().exists(property.getWorkingDocument().getNodeRef())) {
            // go to the page that allows the user to download the content
            // for editing
            // "checkoutFileLink";
            outcome = "dialog:checkoutFileLink";
        // //checkout-file-link.jsp
        // currentAction = Action.CHECKOUT_FILE_LINK;
        } else {
            // show a page telling the user that the content has already
            // been checked in
            // "workingCopyMissing";
            outcome = "dialog:workingCopyMissing";
        // //
        // working-copy-missing.jsp
        // currentAction = Action.WORKING_COPY_MISSING;
        }
    }
    return outcome;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Node(org.alfresco.web.bean.repository.Node) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 3 with WorkflowTask

use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.

the class WorkflowUtil method isTaskEditable.

public static boolean isTaskEditable(String taskId, ServletContext sc) {
    if (taskId == null || taskId.isEmpty()) {
        return false;
    }
    ServiceRegistry serviceRegistry = Repository.getServiceRegistry(sc);
    String username = serviceRegistry.getAuthenticationService().getCurrentUserName();
    WorkflowService workflowService = serviceRegistry.getWorkflowService();
    WorkflowTask task = workflowService.getTaskById(taskId);
    return workflowService.isTaskEditable(task, username);
}
Also used : WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Example 4 with WorkflowTask

use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.

the class StartWorkflowWizard method finishImpl.

@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    if (logger.isDebugEnabled())
        logger.debug("Starting workflow: " + this.selectedWorkflow);
    // prepare the parameters from the current state of the property sheet
    Map<QName, Serializable> params = WorkflowUtil.prepareTaskParams(this.startTaskNode);
    if (logger.isDebugEnabled())
        logger.debug("Starting workflow with parameters: " + params);
    // create a workflow package for the attached items and add them
    NodeRef workflowPackage = this.getWorkflowService().createPackage(null);
    params.put(WorkflowModel.ASSOC_PACKAGE, workflowPackage);
    for (String addedItem : this.packageItemsToAdd) {
        NodeRef addedNodeRef = new NodeRef(addedItem);
        // MNT-11522. fix bug. add behavior filter for add items in workflow package.
        try {
            this.getBehaviourFilter().disableBehaviour(addedNodeRef, ContentModel.ASPECT_AUDITABLE);
            this.getUnprotectedNodeService().addChild(workflowPackage, addedNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName((String) this.getNodeService().getProperty(addedNodeRef, ContentModel.PROP_NAME))));
        } finally {
            this.getBehaviourFilter().enableBehaviour(addedNodeRef, ContentModel.ASPECT_AUDITABLE);
        }
    }
    // setup the context for the workflow (this is the space the workflow was launched from)
    Node workflowContext = this.navigator.getCurrentNode();
    if (workflowContext != null) {
        params.put(WorkflowModel.PROP_CONTEXT, (Serializable) workflowContext.getNodeRef());
    }
    // start the workflow to get access to the start task
    WorkflowPath path = this.getWorkflowService().startWorkflow(this.selectedWorkflow, params);
    if (path != null) {
        // extract the start task
        List<WorkflowTask> tasks = this.getWorkflowService().getTasksForWorkflowPath(path.id);
        if (tasks.size() == 1) {
            WorkflowTask startTask = tasks.get(0);
            if (logger.isDebugEnabled())
                logger.debug("Found start task:" + startTask);
            if (startTask.state == WorkflowTaskState.IN_PROGRESS) {
                // end the start task to trigger the first 'proper'
                // task in the workflow
                this.getWorkflowService().endTask(startTask.id, null);
            }
        }
        if (logger.isDebugEnabled())
            logger.debug("Started workflow: " + this.selectedWorkflow);
    }
    return outcome;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) TransientNode(org.alfresco.web.bean.repository.TransientNode) MapNode(org.alfresco.web.bean.repository.MapNode) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Example 5 with WorkflowTask

use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.

the class WorkflowBean method getTasksCompleted.

/**
 * Returns a list of nodes representing the completed tasks the
 * current user has.
 *
 * @return List of completed tasks
 */
public List<Node> getTasksCompleted() {
    if (this.completedTasks == null) {
        // get the current username
        FacesContext context = FacesContext.getCurrentInstance();
        User user = Application.getCurrentUser(context);
        String userName = user.getUserName();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            // get the current in progress tasks for the current user
            ClientConfigElement clientConfig = (ClientConfigElement) Application.getConfigService(context).getGlobalConfig().getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID);
            WorkflowTaskQuery query = new WorkflowTaskQuery();
            query.setActive(null);
            query.setActorId(userName);
            query.setTaskState(WorkflowTaskState.COMPLETED);
            query.setLimit(clientConfig.getTasksCompletedMaxResults());
            List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
            // create a list of transient nodes to represent
            this.completedTasks = new ArrayList<Node>(tasks.size());
            for (WorkflowTask task : tasks) {
                Node node = createTask(task);
                this.completedTasks.add(node);
                if (logger.isDebugEnabled())
                    logger.debug("Added completed task: " + node);
            }
            // commit the changes
            tx.commit();
        } catch (Throwable e) {
            // rollback the transaction
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception ex) {
            }
            Utils.addErrorMessage("Failed to get completed tasks: " + e.toString(), e);
        }
    }
    return this.completedTasks;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) User(org.alfresco.web.bean.repository.User) Node(org.alfresco.web.bean.repository.Node) TransientNode(org.alfresco.web.bean.repository.TransientNode) TransientMapNode(org.alfresco.web.bean.repository.TransientMapNode) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) ClientConfigElement(org.alfresco.web.config.ClientConfigElement) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Aggregations

WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)37 Serializable (java.io.Serializable)22 HashMap (java.util.HashMap)21 QName (org.alfresco.service.namespace.QName)20 Date (java.util.Date)15 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)15 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)14 JSONObject (org.json.JSONObject)11 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)11 FacesContext (javax.faces.context.FacesContext)10 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)10 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)8 UserTransaction (javax.transaction.UserTransaction)7 JSONArray (org.json.JSONArray)7 Calendar (java.util.Calendar)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 WorkflowTaskQuery (org.alfresco.service.cmr.workflow.WorkflowTaskQuery)6 Node (org.alfresco.web.bean.repository.Node)6 User (org.alfresco.web.bean.repository.User)6 TransientNode (org.alfresco.web.bean.repository.TransientNode)5