Search in sources :

Example 6 with M2Model

use of org.activiti.workflow.simple.alfresco.model.M2Model in project Activiti by Activiti.

the class WorkflowDefinitionConversionTest method testCustomReference.

/**
	 * Test if a custom reference (eg. type=cm:person) is turned into an association on the
	 * model.
	 */
@Test
public void testCustomReference() throws Exception {
    // TODO: finish test once all types are present
    WorkflowDefinition definition = new WorkflowDefinition();
    definition.setId("process");
    HumanStepDefinition humanStep = new HumanStepDefinition();
    humanStep.setId("step1");
    FormDefinition form = new FormDefinition();
    humanStep.setForm(form);
    FormPropertyGroup group = new FormPropertyGroup();
    group.setId("group");
    group.setTitle("My group");
    humanStep.getForm().addFormPropertyGroup(group);
    // Add simple text
    ReferencePropertyDefinition textProperty = new ReferencePropertyDefinition();
    textProperty.setName("person");
    textProperty.setMandatory(true);
    textProperty.setType("cm:person");
    group.addFormProperty(textProperty);
    definition.addStep(humanStep);
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
    conversion.convert();
    // Check content-model
    M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
    assertNotNull(model);
    M2Type type = model.getTypes().get(0);
    assertNotNull(type);
    // Simple text
    M2ClassAssociation association = getAssociationFromType("person", type);
    assertEquals("cm:person", association.getTarget().getClassName());
    assertTrue(association.getTarget().isMandatory());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) M2Type(org.activiti.workflow.simple.alfresco.model.M2Type) ReferencePropertyDefinition(org.activiti.workflow.simple.definition.form.ReferencePropertyDefinition) M2Model(org.activiti.workflow.simple.alfresco.model.M2Model) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) FormPropertyGroup(org.activiti.workflow.simple.definition.form.FormPropertyGroup) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) M2ClassAssociation(org.activiti.workflow.simple.alfresco.model.M2ClassAssociation) Test(org.junit.Test)

Example 7 with M2Model

use of org.activiti.workflow.simple.alfresco.model.M2Model in project Activiti by Activiti.

the class InitializeAlfrescoModelsConversionListener method addContentModel.

protected M2Model addContentModel(WorkflowDefinitionConversion conversion, String processId) {
    // The process ID is used as namespace prefix, to guarantee uniqueness
    // Set general model properties
    M2Model model = new M2Model();
    model.setName(AlfrescoConversionUtil.getQualifiedName(processId, CONTENT_MODEL_UNQUALIFIED_NAME));
    M2Namespace namespace = AlfrescoConversionUtil.createNamespace(processId);
    model.getNamespaces().add(namespace);
    // Import required alfresco models
    model.getImports().add(DICTIONARY_NAMESPACE);
    model.getImports().add(CONTENT_NAMESPACE);
    model.getImports().add(BPM_NAMESPACE);
    // Store model in the conversion artifacts to be accessed later
    AlfrescoConversionUtil.storeContentModel(model, conversion);
    AlfrescoConversionUtil.storeModelNamespacePrefix(namespace.getPrefix(), conversion);
    return model;
}
Also used : M2Namespace(org.activiti.workflow.simple.alfresco.model.M2Namespace) M2Model(org.activiti.workflow.simple.alfresco.model.M2Model)

Example 8 with M2Model

use of org.activiti.workflow.simple.alfresco.model.M2Model in project Activiti by Activiti.

the class AlfrescoBooleanPropertyConverter method convertProperty.

@Override
public void convertProperty(M2Type contentType, String formSet, Form form, FormPropertyDefinition propertyDefinition, WorkflowDefinitionConversion conversion) {
    BooleanPropertyDefinition booleanDefinition = (BooleanPropertyDefinition) propertyDefinition;
    String propertyName = getPropertyName(propertyDefinition, conversion);
    // Add to content model
    M2Property property = new M2Property();
    property.setMandatory(new M2Mandatory(booleanDefinition.isMandatory()));
    property.setName(propertyName);
    property.setPropertyType(AlfrescoConversionConstants.PROPERTY_TYPE_BOOLEAN);
    M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
    M2Aspect aspect = model.getAspect(propertyName);
    if (aspect != null) {
        // do this here
        if (aspect.getProperties().isEmpty()) {
            aspect.getProperties().add(property);
        }
        contentType.getMandatoryAspects().add(propertyName);
    } else {
        contentType.getProperties().add(property);
    }
    // Add form configuration
    form.getFormFieldVisibility().addShowFieldElement(propertyName);
    FormField formField = form.getFormAppearance().addFormField(propertyName, booleanDefinition.getName(), formSet);
    if (!booleanDefinition.isWritable()) {
        // Read-only properties should always be rendered using an info-template
        FormFieldControl control = new FormFieldControl();
        control.setTemplate(AlfrescoConversionConstants.FORM_READONLY_TEMPLATE);
        formField.setControl(control);
    }
    if (!form.isStartForm()) {
        // Add to output properties, if needed
        addOutputProperty(propertyDefinition, propertyName, contentType.getName(), conversion);
    }
}
Also used : BooleanPropertyDefinition(org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition) M2Property(org.activiti.workflow.simple.alfresco.model.M2Property) FormFieldControl(org.activiti.workflow.simple.alfresco.model.config.FormFieldControl) M2Model(org.activiti.workflow.simple.alfresco.model.M2Model) M2Aspect(org.activiti.workflow.simple.alfresco.model.M2Aspect) M2Mandatory(org.activiti.workflow.simple.alfresco.model.M2Mandatory) FormField(org.activiti.workflow.simple.alfresco.model.config.FormField)

Example 9 with M2Model

use of org.activiti.workflow.simple.alfresco.model.M2Model in project Activiti by Activiti.

the class AlfrescoArtifactExporter method writeContentModel.

/**
	 * Write the content model XML in the given conversion to the given stream. 
	 */
public void writeContentModel(OutputStream out, WorkflowDefinitionConversion conversion) throws IOException {
    M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
    try {
        Marshaller marshaller = modelJaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(model, out);
    } catch (JAXBException jaxbe) {
        throw new IOException(jaxbe);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) M2Model(org.activiti.workflow.simple.alfresco.model.M2Model) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException)

Example 10 with M2Model

use of org.activiti.workflow.simple.alfresco.model.M2Model 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)

Aggregations

M2Model (org.activiti.workflow.simple.alfresco.model.M2Model)17 M2Property (org.activiti.workflow.simple.alfresco.model.M2Property)7 FormField (org.activiti.workflow.simple.alfresco.model.config.FormField)7 FormFieldControl (org.activiti.workflow.simple.alfresco.model.config.FormFieldControl)7 M2Aspect (org.activiti.workflow.simple.alfresco.model.M2Aspect)6 M2Mandatory (org.activiti.workflow.simple.alfresco.model.M2Mandatory)6 M2Type (org.activiti.workflow.simple.alfresco.model.M2Type)6 HumanStepDefinition (org.activiti.workflow.simple.definition.HumanStepDefinition)5 PropertyReference (org.activiti.workflow.simple.alfresco.conversion.script.PropertyReference)4 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)4 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)4 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)4 Test (org.junit.Test)4 FlowElement (org.activiti.bpmn.model.FlowElement)3 UserTask (org.activiti.bpmn.model.UserTask)3 M2ClassAssociation (org.activiti.workflow.simple.alfresco.model.M2ClassAssociation)3 M2Namespace (org.activiti.workflow.simple.alfresco.model.M2Namespace)3 Configuration (org.activiti.workflow.simple.alfresco.model.config.Configuration)3 Module (org.activiti.workflow.simple.alfresco.model.config.Module)3 ListPropertyEntry (org.activiti.workflow.simple.definition.form.ListPropertyEntry)3