use of org.activiti.workflow.simple.definition.HumanStepDefinition in project Activiti by Activiti.
the class TaskTable method getSteps.
public List<HumanStepDefinition> getSteps() {
List<HumanStepDefinition> steps = new ArrayList<HumanStepDefinition>();
for (Object itemId : getItemIds()) {
Item item = getItem(itemId);
HumanStepDefinition humanStepDefinition = new HumanStepDefinition();
String name = (String) item.getItemProperty(ID_NAME).getValue();
if (name != null && name.length() > 0) {
humanStepDefinition.setName(name);
}
String assignee = (String) ((ComboBox) item.getItemProperty(ID_ASSIGNEE).getValue()).getValue();
if (assignee != null && assignee.length() > 0) {
humanStepDefinition.setAssignee(assignee);
}
String groups = (String) ((ComboBox) item.getItemProperty("groups").getValue()).getValue();
List<String> candidateGroups = new ArrayList<String>();
if (groups != null && groups.length() > 0) {
for (String group : groups.split(",")) {
candidateGroups.add(group.trim());
}
}
humanStepDefinition.setCandidateGroups(candidateGroups);
String description = (String) ((TextField) item.getItemProperty(ID_DESCRIPTION).getValue()).getValue();
if (description != null && description.length() > 0) {
humanStepDefinition.setDescription(description);
}
humanStepDefinition.setStartsWithPrevious((boolean) ((CheckBox) item.getItemProperty(ID_START_WITH_PREVIOUS).getValue()).booleanValue());
FormDefinition formDefinition = taskFormModel.getForm(itemId);
humanStepDefinition.setForm(formDefinition);
steps.add(humanStepDefinition);
}
return steps;
}
use of org.activiti.workflow.simple.definition.HumanStepDefinition in project Activiti by Activiti.
the class SimpleTableEditor method loadTaskRows.
protected void loadTaskRows(StepDefinitionContainer<?> container, TaskTable taskTable) {
for (StepDefinition stepDefinition : container.getSteps()) {
if (stepDefinition instanceof HumanStepDefinition) {
HumanStepDefinition humanStepDefinition = (HumanStepDefinition) stepDefinition;
taskTable.addTaskRow(humanStepDefinition);
} else if (stepDefinition instanceof StepDefinitionContainer<?>) {
loadTaskRows((StepDefinitionContainer<?>) stepDefinition, taskTable);
}
}
}
use of org.activiti.workflow.simple.definition.HumanStepDefinition in project Activiti by Activiti.
the class SimpleTableEditor method createWorkflow.
protected WorkflowDefinition createWorkflow() {
WorkflowDefinition workflow = new WorkflowDefinition();
workflow.setName((String) nameField.getValue());
String description = (String) descriptionField.getValue();
if (description != null && description.length() > 0) {
workflow.setDescription(description);
}
List<HumanStepDefinition> steps = taskTable.getSteps();
for (int i = 0; i < steps.size(); i++) {
HumanStepDefinition currentStep = steps.get(i);
// Check if we have a parallel block
int nextIndex = i + 1;
ParallelStepsDefinition parallelStepsDefinition = null;
while (nextIndex < steps.size() && steps.get(nextIndex).isStartsWithPrevious()) {
if (parallelStepsDefinition == null) {
parallelStepsDefinition = new ParallelStepsDefinition();
ListStepDefinition<ParallelStepsDefinition> listStepDef = new ListStepDefinition<ParallelStepsDefinition>();
listStepDef.addStep(currentStep);
parallelStepsDefinition.addStepList(listStepDef);
}
ListStepDefinition<ParallelStepsDefinition> listStepDef = new ListStepDefinition<ParallelStepsDefinition>();
listStepDef.addStep(steps.get(nextIndex));
parallelStepsDefinition.addStepList(listStepDef);
nextIndex++;
}
if (parallelStepsDefinition != null) {
workflow.addStep(parallelStepsDefinition);
i = nextIndex - 1;
} else {
workflow.addStep(currentStep);
}
}
return workflow;
}
use of org.activiti.workflow.simple.definition.HumanStepDefinition 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.definition.HumanStepDefinition in project Activiti by Activiti.
the class WorkflowDefinitionConversionTest method testHumanStepBasicFormField.
/**
* Test basic form-fields (text, number, date, list, ...)
*/
@Test
public void testHumanStepBasicFormField() 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
TextPropertyDefinition textProperty = new TextPropertyDefinition();
textProperty.setName("text");
textProperty.setMandatory(true);
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
M2Property property = getPropertyFromType("text", type);
assertEquals("d:text", property.getPropertyType());
assertEquals(Boolean.TRUE, property.getMandatory().isMandatory());
}
Aggregations