use of org.activiti.workflow.simple.alfresco.conversion.script.PropertyReference in project Activiti by Activiti.
the class AlfrescoReferencePropertyConverter method addFieldReference.
protected void addFieldReference(Form form, String formSet, ReferencePropertyDefinition definition, M2Type contentType, WorkflowDefinitionConversion conversion) {
if (form.isStartForm()) {
throw new AlfrescoSimpleWorkflowException("Field references cannot be used on start-forms");
}
// Check if model contains an aspect for the property
String propertyName = getPropertyName(definition, conversion);
// Add property-reference to the context to be validated
PropertyReference reference = new PropertyReference(definition.getName());
AlfrescoConversionUtil.getPropertyReferences(conversion).add(reference);
// Add aspect to content-type
contentType.getMandatoryAspects().add(propertyName);
// Add read-only field to form
form.getFormFieldVisibility().addShowFieldElement(propertyName);
FormField field = new FormField();
form.getFormAppearance().addFormAppearanceElement(field);
field.setId(propertyName);
field.setLabelId(definition.getName());
field.setSet(formSet);
field.setControl(new FormFieldControl(AlfrescoConversionConstants.FORM_READONLY_TEMPLATE));
}
use of org.activiti.workflow.simple.alfresco.conversion.script.PropertyReference in project Activiti by Activiti.
the class AlfrescoHumanStepDefinitionConverter method resolveUserPropertyReferences.
protected List<String> resolveUserPropertyReferences(List<String> list, String namespacePrefix, WorkflowDefinitionConversion conversion) {
if (list != null) {
List<String> result = new ArrayList<String>();
PropertyReference propertyReference = null;
for (String string : list) {
if (PropertyReference.isPropertyReference(string)) {
propertyReference = PropertyReference.createReference(string);
result.add(propertyReference.getUsernameReferenceExpression(namespacePrefix));
// Add reference to be validated
AlfrescoConversionUtil.getPropertyReferences(conversion).add(propertyReference);
} else {
result.add(string);
}
}
return result;
}
return null;
}
use of org.activiti.workflow.simple.alfresco.conversion.script.PropertyReference in project Activiti by Activiti.
the class AlfrescoHumanStepDefinitionConverter method resolveGroupPropertyReferences.
protected List<String> resolveGroupPropertyReferences(List<String> list, String namespacePrefix, WorkflowDefinitionConversion conversion) {
if (list != null) {
List<String> result = new ArrayList<String>();
PropertyReference propertyReference = null;
for (String string : list) {
if (PropertyReference.isPropertyReference(string)) {
propertyReference = PropertyReference.createReference(string);
result.add(propertyReference.getGroupReferenceExpression(namespacePrefix));
// Add reference to be validated
AlfrescoConversionUtil.getPropertyReferences(conversion).add(propertyReference);
} else {
result.add(string);
}
}
return result;
}
return null;
}
use of org.activiti.workflow.simple.alfresco.conversion.script.PropertyReference 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;
}
use of org.activiti.workflow.simple.alfresco.conversion.script.PropertyReference 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);
}
}
}
Aggregations