Search in sources :

Example 36 with WorkflowInstance

use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.

the class ScriptNode method getActiveWorkflows.

// ------------------------------------------------------------------------------
// Workflow methods
/**
 * Get active workflow instances this node belongs to
 *
 * @return the active workflow instances this node belongs to
 */
public Scriptable getActiveWorkflows() {
    if (this.activeWorkflows == null) {
        WorkflowService workflowService = this.services.getWorkflowService();
        List<WorkflowInstance> workflowInstances = workflowService.getWorkflowsForContent(this.nodeRef, true);
        Object[] jsWorkflowInstances = new Object[workflowInstances.size()];
        int index = 0;
        for (WorkflowInstance workflowInstance : workflowInstances) {
            jsWorkflowInstances[index++] = new JscriptWorkflowInstance(workflowInstance, this.services, this.scope);
        }
        this.activeWorkflows = Context.getCurrentContext().newArray(this.scope, jsWorkflowInstances);
    }
    return this.activeWorkflows;
}
Also used : JscriptWorkflowInstance(org.alfresco.repo.workflow.jscript.JscriptWorkflowInstance) WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) JSONObject(org.json.JSONObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) JscriptWorkflowInstance(org.alfresco.repo.workflow.jscript.JscriptWorkflowInstance)

Example 37 with WorkflowInstance

use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.

the class ActivitiWorkflowEngine method getWorkflowsInternal.

@SuppressWarnings("unchecked")
private List<WorkflowInstance> getWorkflowsInternal(WorkflowInstanceQuery workflowInstanceQuery, boolean isActive, int maxItems, int skipCount) {
    // MNT-9074 My Tasks fails to render if tasks quantity is excessive
    HistoricProcessInstanceQuery query = createQuery(workflowInstanceQuery, isActive);
    LinkedList<WorkflowInstance> results = new LinkedList<WorkflowInstance>();
    List<HistoricProcessInstance> completedInstances;
    if (maxItems > 0) {
        completedInstances = query.orderByProcessInstanceDuration().desc().listPage(skipCount, maxItems);
    } else {
        completedInstances = query.list();
    }
    List<WorkflowInstance> completedResults = typeConverter.doSpecialTenantFilterAndSafeConvert(completedInstances, new Function<HistoricProcessInstance, String>() {

        public String apply(HistoricProcessInstance historicProcessInstance) {
            ProcessDefinition procDef = activitiUtil.getProcessDefinition(historicProcessInstance.getProcessDefinitionId());
            return procDef.getKey();
        }
    });
    results.addAll(completedResults);
    return results;
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ReadOnlyProcessDefinition(org.activiti.engine.impl.pvm.ReadOnlyProcessDefinition) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) LinkedList(java.util.LinkedList)

Example 38 with WorkflowInstance

use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.

the class WorkflowObjectFactory method createInstance.

public WorkflowInstance createInstance(String id, WorkflowDefinition definition, Map<String, Object> variables, boolean isActive, Date startDate, Date endDate) {
    String actualId = buildGlobalId(id);
    String description = (String) getVariable(variables, WorkflowModel.PROP_WORKFLOW_DESCRIPTION);
    NodeRef initiator = null;
    ScriptNode initiatorSN = (ScriptNode) getVariable(variables, WorkflowConstants.PROP_INITIATOR);
    if (initiatorSN != null) {
        initiator = initiatorSN.getNodeRef();
    }
    NodeRef context = getNodeVariable(variables, WorkflowModel.PROP_CONTEXT);
    NodeRef workflowPackage = getNodeVariable(variables, WorkflowModel.ASSOC_PACKAGE);
    WorkflowInstance workflowInstance = new WorkflowInstance(actualId, definition, description, initiator, workflowPackage, context, isActive, startDate, endDate);
    workflowInstance.priority = (Integer) getVariable(variables, WorkflowModel.PROP_WORKFLOW_PRIORITY);
    Date dueDate = (Date) getVariable(variables, WorkflowModel.PROP_WORKFLOW_DUE_DATE);
    if (dueDate != null) {
        workflowInstance.dueDate = dueDate;
    }
    return workflowInstance;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ScriptNode(org.alfresco.repo.jscript.ScriptNode) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Date(java.util.Date)

Example 39 with WorkflowInstance

use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.

the class WorkflowServiceImpl method deleteWorkflow.

/*
     * (non-Javadoc)
     * @see
     * org.alfresco.service.cmr.workflow.WorkflowService#deleteWorkflow(java
     * .lang.String)
     */
public WorkflowInstance deleteWorkflow(String workflowId) {
    String engineId = BPMEngineRegistry.getEngineId(workflowId);
    WorkflowComponent component = getWorkflowComponent(engineId);
    WorkflowInstance instance = component.deleteWorkflow(workflowId);
    // NOTE: Delete workflow package after deleting workflow, so it's still
    // available
    // in process-end events of workflow definition
    workflowPackageComponent.deletePackage(instance.getWorkflowPackage());
    return instance;
}
Also used : WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance)

Example 40 with WorkflowInstance

use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.

the class WorkflowServiceImpl method updateTask.

/*
     * (non-Javadoc)
     * @see
     * org.alfresco.service.cmr.workflow.WorkflowService#updateTask(java.lang
     * .String, java.util.Map, java.util.Map, java.util.Map)
     */
public WorkflowTask updateTask(String taskId, Map<QName, Serializable> properties, Map<QName, List<NodeRef>> add, Map<QName, List<NodeRef>> remove) {
    String engineId = BPMEngineRegistry.getEngineId(taskId);
    TaskComponent component = getTaskComponent(engineId);
    // get the current assignee before updating the task
    String originalAsignee = (String) component.getTaskById(taskId).getProperties().get(ContentModel.PROP_OWNER);
    WorkflowTask task = component.updateTask(taskId, properties, add, remove);
    if (add != null && add.containsKey(WorkflowModel.ASSOC_PACKAGE)) {
        WorkflowInstance instance = task.getPath().getInstance();
        workflowPackageComponent.setWorkflowForPackage(instance);
    }
    // Get the 'new' assignee
    String assignee = (String) properties.get(ContentModel.PROP_OWNER);
    if (assignee != null && assignee.length() != 0) {
        // if the assignee has changed get the start task
        if (!assignee.equals(originalAsignee)) {
            String instanceId = task.getPath().getInstance().getId();
            WorkflowTask startTask = component.getStartTask(instanceId);
            if (startTask != null) {
                // Get the email notification flag
                Boolean sendEMailNotification = (Boolean) startTask.getProperties().get(WorkflowModel.PROP_SEND_EMAIL_NOTIFICATIONS);
                if (Boolean.TRUE.equals(sendEMailNotification) == true) {
                    // calculate task type label
                    String workflowDefId = task.getPath().getInstance().getDefinition().getName();
                    if (workflowDefId.indexOf('$') != -1 && (workflowDefId.indexOf('$') < workflowDefId.length() - 1)) {
                        workflowDefId = workflowDefId.substring(workflowDefId.indexOf('$') + 1);
                    }
                    // Send the notification
                    workflowNotificationUtils.sendWorkflowAssignedNotificationEMail(taskId, null, assignee, false);
                }
            }
        }
    }
    return task;
}
Also used : WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance)

Aggregations

WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)56 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)26 HashMap (java.util.HashMap)22 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)19 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)16 QName (org.alfresco.service.namespace.QName)16 Serializable (java.io.Serializable)15 Date (java.util.Date)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)15 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)13 Test (org.junit.Test)13 Map (java.util.Map)11 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 ArrayList (java.util.ArrayList)9 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)7 WorkflowNode (org.alfresco.service.cmr.workflow.WorkflowNode)5 Execution (org.activiti.engine.runtime.Execution)4 List (java.util.List)3 ActivitiException (org.activiti.engine.ActivitiException)3 MimetypeMap (org.alfresco.repo.content.MimetypeMap)3