Search in sources :

Example 61 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class AlfrescoReviewStepConverter method createProcessArtifact.

@Override
protected FlowElement createProcessArtifact(AlfrescoReviewStepDefinition stepDefinition, WorkflowDefinitionConversion conversion) {
    FlowElement lastElement;
    M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
    String namespacePrefix = model.getNamespaces().get(0).getPrefix();
    String id = stepDefinition.getId();
    if (id == null) {
        id = AlfrescoConversionUtil.getValidIdString(stepDefinition.getName());
    }
    // Break down the review into separate steps and convert those instead
    HumanStepDefinition reviewTask = new HumanStepDefinition();
    reviewTask.setName(stepDefinition.getName());
    reviewTask.setDescription("Review task");
    // Clone the review-form and add custom transitions property
    FormDefinition finalForm = null;
    if (stepDefinition.getForm() != null) {
        finalForm = stepDefinition.getForm().clone();
    } else {
        finalForm = new FormDefinition();
    }
    finalForm.addFormProperty(createTransitionsProperty());
    reviewTask.setForm(finalForm);
    // Assignment
    if (stepDefinition.getAssignmentType() == HumanStepAssignmentType.USER) {
        reviewTask.setAssignee(new PropertyReference(stepDefinition.getAssignmentPropertyName()).getPlaceholder());
    }
    // Add a script-task that initializes the correct variables for the review
    ScriptServiceTaskBuilder builder = new ScriptServiceTaskBuilder();
    builder.setExecutionVariable(getCountVariableName(id, namespacePrefix), "0");
    String requiredCount = null;
    if (stepDefinition.getRequiredApprovalCount() != null) {
        if (PropertyReference.isPropertyReference(stepDefinition.getRequiredApprovalCount())) {
            PropertyReference reference = PropertyReference.createReference(stepDefinition.getRequiredApprovalCount());
            requiredCount = reference.getVariableReference(namespacePrefix);
            AlfrescoConversionUtil.getPropertyReferences(conversion).add(reference);
        } else {
            // No reference, use explicit value
            requiredCount = stepDefinition.getRequiredApprovalCount();
        }
    } else {
        requiredCount = "1";
    }
    builder.setExecutionVariable(getRequiredCountVariableName(id, namespacePrefix), requiredCount);
    ServiceTask serviceTask = builder.build();
    serviceTask.setName("Review initialization");
    serviceTask.setId(conversion.getUniqueNumberedId(ConversionConstants.SERVICE_TASK_ID_PREFIX));
    addFlowElement(conversion, serviceTask, true);
    // Create the actual element
    UserTask userTask = (UserTask) conversion.getConversionFactory().getStepConverterFor(reviewTask).convertStepDefinition(reviewTask, conversion);
    lastElement = userTask;
    M2Type userTaskType = model.getType(userTask.getFormKey());
    // Update parent, since we use an "outcome" for this task
    userTaskType.setParentName(AlfrescoConversionConstants.OUTCOME_BASE_FORM_TYPE);
    // Add script to the complete-task listener to update approval count (if needed)
    ScriptTaskListenerBuilder listenerBuilder = AlfrescoConversionUtil.getScriptTaskListenerBuilder(conversion, userTask.getId(), AlfrescoConversionConstants.TASK_LISTENER_EVENT_COMPLETE);
    String approverCount = getCountVariableName(id, namespacePrefix);
    listenerBuilder.addLine("if(task.getVariableLocal('" + getTransitionProperty(userTaskType, namespacePrefix) + "') == '" + AlfrescoConversionConstants.TRANSITION_APPROVE + "') {");
    listenerBuilder.addLine("execution.setVariable('" + approverCount + "', " + approverCount + " + 1);");
    listenerBuilder.addLine("}");
    if (stepDefinition.getAssignmentType() == HumanStepAssignmentType.USERS) {
        String assignmentVariableName = id + "Assignee";
        // Add the assignee-property to the content-model
        M2ClassAssociation reviewAssignee = new M2ClassAssociation();
        M2AssociationTarget target = new M2AssociationTarget();
        target.setClassName(AlfrescoConversionConstants.CONTENT_TYPE_PEOPLE);
        target.setMandatory(true);
        target.setMany(false);
        M2AssociationSource source = new M2AssociationSource();
        source.setMany(false);
        source.setMandatory(true);
        reviewAssignee.setName(AlfrescoConversionUtil.getQualifiedName(namespacePrefix, assignmentVariableName));
        reviewAssignee.setTarget(target);
        reviewAssignee.setSource(source);
        userTaskType.getAssociations().add(reviewAssignee);
        userTask.setAssignee(new PropertyReference(assignmentVariableName).getUsernameReferenceExpression(namespacePrefix));
        // Finally, add the multi-instance characteristics to the userTask
        MultiInstanceLoopCharacteristics mi = new MultiInstanceLoopCharacteristics();
        mi.setCompletionCondition(getCompletionCondition(id, namespacePrefix));
        mi.setElementVariable(new PropertyReference(assignmentVariableName).getVariableReference(namespacePrefix));
        PropertyReference reference = null;
        if (PropertyReference.isPropertyReference(stepDefinition.getAssignmentPropertyName())) {
            reference = PropertyReference.createReference(stepDefinition.getAssignmentPropertyName());
        } else {
            reference = new PropertyReference(stepDefinition.getAssignmentPropertyName());
        }
        mi.setInputDataItem(reference.getVariableReference(namespacePrefix));
        AlfrescoConversionUtil.getPropertyReferences(conversion).add(reference);
        mi.setSequential(false);
        userTask.setLoopCharacteristics(mi);
    }
    if (stepDefinition.getRejectionSteps() != null) {
        // Create choice-step
        ChoiceStepsDefinition choice = new ChoiceStepsDefinition();
        choice.setId(id + "choice");
        // Add rejection steps to the choice
        ListConditionStepDefinition<ChoiceStepsDefinition> rejectStepList = new ListConditionStepDefinition<ChoiceStepsDefinition>();
        rejectStepList.setName("Rejected");
        for (StepDefinition child : stepDefinition.getRejectionSteps()) {
            rejectStepList.addStep(child);
        }
        // Add end-process step to reject path, if needed
        if (stepDefinition.isEndProcessOnReject()) {
            rejectStepList.addStep(new AlfrescoEndProcessStepDefinition());
        }
        // Make choice condition based on review outcome
        ConditionDefinition condition = new ConditionDefinition();
        condition.setLeftOperand(getCountVariableName(id, namespacePrefix));
        condition.setOperator("<");
        condition.setRightOperand(getRequiredCountVariableName(id, namespacePrefix));
        rejectStepList.setConditions(Arrays.asList(condition));
        choice.addStepList(rejectStepList);
        // Add default (empty) choice for approval AFTER the review-one
        ListConditionStepDefinition<ChoiceStepsDefinition> defaultStepList = new ListConditionStepDefinition<ChoiceStepsDefinition>();
        defaultStepList.setName("Approved");
        choice.addStepList(defaultStepList);
        // Convert the choice-step
        lastElement = (FlowElement) conversion.getConversionFactory().getStepConverterFor(choice).convertStepDefinition(choice, conversion);
    }
    return lastElement;
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) ListConditionStepDefinition(org.activiti.workflow.simple.definition.ListConditionStepDefinition) M2Model(org.activiti.workflow.simple.alfresco.model.M2Model) ChoiceStepsDefinition(org.activiti.workflow.simple.definition.ChoiceStepsDefinition) UserTask(org.activiti.bpmn.model.UserTask) PropertyReference(org.activiti.workflow.simple.alfresco.conversion.script.PropertyReference) M2AssociationTarget(org.activiti.workflow.simple.alfresco.model.M2AssociationTarget) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) M2Type(org.activiti.workflow.simple.alfresco.model.M2Type) AlfrescoEndProcessStepDefinition(org.activiti.workflow.simple.alfresco.step.AlfrescoEndProcessStepDefinition) MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) FlowElement(org.activiti.bpmn.model.FlowElement) ScriptServiceTaskBuilder(org.activiti.workflow.simple.alfresco.conversion.script.ScriptServiceTaskBuilder) M2AssociationSource(org.activiti.workflow.simple.alfresco.model.M2AssociationSource) StepDefinition(org.activiti.workflow.simple.definition.StepDefinition) AlfrescoEndProcessStepDefinition(org.activiti.workflow.simple.alfresco.step.AlfrescoEndProcessStepDefinition) ListConditionStepDefinition(org.activiti.workflow.simple.definition.ListConditionStepDefinition) AlfrescoReviewStepDefinition(org.activiti.workflow.simple.alfresco.step.AlfrescoReviewStepDefinition) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) ConditionDefinition(org.activiti.workflow.simple.definition.ConditionDefinition) ScriptTaskListenerBuilder(org.activiti.workflow.simple.alfresco.conversion.script.ScriptTaskListenerBuilder) M2ClassAssociation(org.activiti.workflow.simple.alfresco.model.M2ClassAssociation)

Example 62 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class InitializeAlfrescoModelsConversionListener method afterStepsConversion.

@Override
public void afterStepsConversion(WorkflowDefinitionConversion conversion) {
    M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
    M2Namespace modelNamespace = model.getNamespaces().get(0);
    for (FlowElement flowElement : conversion.getProcess().getFlowElements()) {
        if (flowElement instanceof StartEvent) {
            StartEvent startEvent = (StartEvent) flowElement;
            if (startEvent.getFormKey() == null) {
                Module module = AlfrescoConversionUtil.getExtension(conversion).getModules().get(0);
                Configuration detailsForm = module.addConfiguration(EVALUATOR_STRING_COMPARE, MessageFormat.format(EVALUATOR_CONDITION_ACTIVITI, conversion.getProcess().getId()));
                // is available
                if (conversion.getWorkflowDefinition().getStartFormDefinition() != null && !conversion.getWorkflowDefinition().getStartFormDefinition().getFormGroups().isEmpty()) {
                    // Create the content model for the start-task
                    M2Type type = new M2Type();
                    model.getTypes().add(type);
                    type.setName(AlfrescoConversionUtil.getQualifiedName(modelNamespace.getPrefix(), AlfrescoConversionConstants.START_TASK_SIMPLE_NAME));
                    type.setParentName(AlfrescoConversionConstants.DEFAULT_START_FORM_TYPE);
                    // Create a form-config for the start-task
                    Module shareModule = AlfrescoConversionUtil.getExtension(conversion).getModules().get(0);
                    Configuration configuration = shareModule.addConfiguration(AlfrescoConversionConstants.EVALUATOR_TASK_TYPE, type.getName());
                    Form formConfig = configuration.createForm();
                    formConfig.setStartForm(true);
                    // Populate model and form based on FormDefinition
                    formCreator.createForm(type, formConfig, conversion.getWorkflowDefinition().getStartFormDefinition(), conversion);
                    // Use the same form-config for the workflow details
                    detailsForm.addForm(formConfig);
                    // Set formKey on start-event, referencing type
                    startEvent.setFormKey(type.getName());
                } else {
                    // Revert to the default start-form
                    startEvent.setFormKey(DEFAULT_START_FORM_TYPE);
                    // Also add form-config to the share-module for workflow detail screen, based on the default form
                    populateDefaultDetailFormConfig(detailsForm);
                }
            }
        }
    }
    // Check all elements that can contain PropertyReferences or need additional builders invoked
    List<PropertyReference> references = AlfrescoConversionUtil.getPropertyReferences(conversion);
    for (FlowElement element : conversion.getProcess().getFlowElements()) {
        if (element instanceof SequenceFlow) {
            resolvePropertyRefrencesInSequenceFlow((SequenceFlow) element, modelNamespace, references);
        } else if (element instanceof IntermediateCatchEvent) {
            resolvePropertyRefrencesInCatchEvent((IntermediateCatchEvent) element, modelNamespace, references);
        } else if (element instanceof ServiceTask) {
            resolvePropertyRefrencesInServiceTask((ServiceTask) element, modelNamespace, references);
        } else if (element instanceof UserTask) {
            addScriptListenersToUserTask((UserTask) element, conversion);
        }
    }
    // Check if all property-references reference a valid property
    if (references != null && !references.isEmpty()) {
        for (PropertyReference reference : references) {
            reference.validate(model);
        }
    }
}
Also used : M2Namespace(org.activiti.workflow.simple.alfresco.model.M2Namespace) ServiceTask(org.activiti.bpmn.model.ServiceTask) Configuration(org.activiti.workflow.simple.alfresco.model.config.Configuration) Form(org.activiti.workflow.simple.alfresco.model.config.Form) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) M2Model(org.activiti.workflow.simple.alfresco.model.M2Model) IntermediateCatchEvent(org.activiti.bpmn.model.IntermediateCatchEvent) UserTask(org.activiti.bpmn.model.UserTask) PropertyReference(org.activiti.workflow.simple.alfresco.conversion.script.PropertyReference) M2Type(org.activiti.workflow.simple.alfresco.model.M2Type) FlowElement(org.activiti.bpmn.model.FlowElement) StartEvent(org.activiti.bpmn.model.StartEvent) Module(org.activiti.workflow.simple.alfresco.model.config.Module)

Example 63 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class ParallelStepsDefinitionConverter method createProcessArtifact.

protected ParallelGateway createProcessArtifact(ParallelStepsDefinition parallelStepsDefinition, WorkflowDefinitionConversion conversion) {
    // First parallel gateway
    ParallelGateway forkGateway = createParallelGateway(conversion);
    // Sequence flow from last activity to first gateway
    addSequenceFlow(conversion, conversion.getLastActivityId(), forkGateway.getId());
    conversion.setLastActivityId(forkGateway.getId());
    // Convert all other steps, disabling activity id updates which makes all 
    // generated steps have a sequence flow to the first gateway
    WorkflowDefinitionConversionFactory conversionFactory = conversion.getConversionFactory();
    List<FlowElement> endElements = new ArrayList<FlowElement>();
    for (ListStepDefinition<ParallelStepsDefinition> stepListDefinition : parallelStepsDefinition.getStepList()) {
        for (int i = 0; i < stepListDefinition.getSteps().size(); i++) {
            if (i == 0) {
                conversion.setSequenceflowGenerationEnabled(false);
            } else {
                conversion.setSequenceflowGenerationEnabled(true);
            }
            StepDefinition step = stepListDefinition.getSteps().get(i);
            FlowElement flowElement = (FlowElement) conversionFactory.getStepConverterFor(step).convertStepDefinition(step, conversion);
            if (i == 0) {
                addSequenceFlow(conversion, forkGateway.getId(), flowElement.getId());
            }
            if ((i + 1) == stepListDefinition.getSteps().size()) {
                endElements.add(flowElement);
            }
        }
    }
    conversion.setSequenceflowGenerationEnabled(false);
    // Second parallel gateway
    ParallelGateway joinGateway = createParallelGateway(conversion);
    conversion.setLastActivityId(joinGateway.getId());
    conversion.setSequenceflowGenerationEnabled(true);
    // Create sequence flow from all generated steps to the second gateway
    for (FlowElement endElement : endElements) {
        addSequenceFlow(conversion, endElement.getId(), joinGateway.getId());
    }
    return forkGateway;
}
Also used : ParallelGateway(org.activiti.bpmn.model.ParallelGateway) WorkflowDefinitionConversionFactory(org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayList(java.util.ArrayList) ParallelStepsDefinition(org.activiti.workflow.simple.definition.ParallelStepsDefinition) ListStepDefinition(org.activiti.workflow.simple.definition.ListStepDefinition) StepDefinition(org.activiti.workflow.simple.definition.StepDefinition)

Example 64 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class WorkflowDefinitionConversionTest method testEmptyWorkflowDefinitionConversion.

/**
	 * Check if all required artifacts are created when converting an empty workflow-definition.
	 */
@Test
public void testEmptyWorkflowDefinitionConversion() {
    WorkflowDefinition definition = new WorkflowDefinition();
    definition.setDescription("This is the description");
    definition.setId("workflowdefinition");
    definition.setName("My workflow definition");
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
    conversion.convert();
    BpmnModel bpmnModel = conversion.getBpmnModel();
    assertNotNull(bpmnModel);
    Process process = bpmnModel.getMainProcess();
    assertNotNull(process);
    assertEquals("This is the description", process.getDocumentation());
    assertEquals("My workflow definition", process.getName());
    assertEquals("workflowdefinition", process.getId());
    // Default start-task key should be used, as no custom startform-config is present
    boolean startTaskFound = false;
    for (FlowElement element : process.getFlowElements()) {
        if (element instanceof StartEvent) {
            assertEquals("bpm:startTask", ((StartEvent) element).getFormKey());
            startTaskFound = true;
        }
    }
    assertTrue(startTaskFound);
    // Check presence of content-model
    M2Model contentModel = AlfrescoConversionUtil.getContentModel(conversion);
    assertNotNull(contentModel);
    // Check presence of form-config and default workflow-details
    Module module = AlfrescoConversionUtil.getExtension(conversion).getModules().get(0);
    assertNotNull(module);
    assertEquals(1L, module.getConfigurations().size());
    Configuration config = module.getConfigurations().get(0);
    assertEquals(1L, config.getForms().size());
    assertEquals("activiti$workflowdefinition", config.getCondition());
    assertEquals(AlfrescoConversionConstants.EVALUATOR_STRING_COMPARE, config.getEvaluator());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) Configuration(org.activiti.workflow.simple.alfresco.model.config.Configuration) FlowElement(org.activiti.bpmn.model.FlowElement) M2Model(org.activiti.workflow.simple.alfresco.model.M2Model) StartEvent(org.activiti.bpmn.model.StartEvent) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Process(org.activiti.bpmn.model.Process) Module(org.activiti.workflow.simple.alfresco.model.config.Module) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 65 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class WorkflowDefinitionConversionTest method testConvertEmailStep.

@Test
public void testConvertEmailStep() throws Exception {
    WorkflowDefinition definition = new WorkflowDefinition();
    AlfrescoEmailStepDefinition emailStep = new AlfrescoEmailStepDefinition();
    emailStep.setTo("fred");
    emailStep.setSubject("jos");
    definition.addStep(emailStep);
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
    conversion.convert();
    // Process should contain a single service-task
    ServiceTask task = null;
    for (FlowElement element : conversion.getProcess().getFlowElements()) {
        if (element instanceof ServiceTask) {
            if (task != null) {
                Assert.fail("More than one service-task found");
            }
            task = (ServiceTask) element;
        }
    }
    assertNotNull(task);
    assertEquals(AlfrescoConversionConstants.CLASSNAME_SCRIPT_DELEGATE, task.getImplementation());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ServiceTask(org.activiti.bpmn.model.ServiceTask) AlfrescoEmailStepDefinition(org.activiti.workflow.simple.alfresco.step.AlfrescoEmailStepDefinition) FlowElement(org.activiti.bpmn.model.FlowElement) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Aggregations

FlowElement (org.activiti.bpmn.model.FlowElement)77 SubProcess (org.activiti.bpmn.model.SubProcess)27 UserTask (org.activiti.bpmn.model.UserTask)26 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)24 StartEvent (org.activiti.bpmn.model.StartEvent)14 Process (org.activiti.bpmn.model.Process)13 ArrayList (java.util.ArrayList)11 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)11 HashMap (java.util.HashMap)9 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)9 Activity (org.activiti.bpmn.model.Activity)9 ServiceTask (org.activiti.bpmn.model.ServiceTask)9 Gateway (org.activiti.bpmn.model.Gateway)8 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)7 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)7 Artifact (org.activiti.bpmn.model.Artifact)6 FlowNode (org.activiti.bpmn.model.FlowNode)6 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)6 BpmnModel (org.activiti.bpmn.model.BpmnModel)5 EventDefinition (org.activiti.bpmn.model.EventDefinition)5