use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class WorkflowConversionTest method testGroupsForHumanStep.
@Test
public void testGroupsForHumanStep() {
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addHumanStepForGroup("step1", "management", "sales").addHumanStepForGroup("step1", "sales");
activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
// Complete first task
TaskService taskService = activitiRule.getTaskService();
assertEquals(1, taskService.createTaskQuery().taskCandidateGroup("management").count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroup("sales").count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management")).count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management", "sales")).count());
taskService.complete(taskService.createTaskQuery().singleResult().getId());
// Second task is only done by sales
assertEquals(0, taskService.createTaskQuery().taskCandidateGroup("management").count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroup("sales").count());
assertEquals(0, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management")).count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("sales")).count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management", "sales")).count());
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class WorkflowConversionTest method testFeedbackStepWithFixedUsersFeedbackHaltedByInitiator.
@Test
public void testFeedbackStepWithFixedUsersFeedbackHaltedByInitiator() {
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addFeedbackStep("Test feedback", "kermit", Arrays.asList("gonzo", "mispiggy", "fozzie"));
activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
// First, a task should be assigned to kermit to select the people
assertEquals(1, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
Task task = taskService.createTaskQuery().singleResult();
taskService.complete(task.getId());
// Four tasks should be available now
assertEquals(4, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("mispiggy").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("fozzie").count());
// Completing only one feedback task
for (Task feedbackTask : taskService.createTaskQuery().list()) {
if (!feedbackTask.getAssignee().equals("kermit")) {
activitiRule.getTaskService().complete(feedbackTask.getId());
break;
}
}
assertEquals(3, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
// Completing the 'gather feedback' task by kermit should cancel the remaining feedback tasks
activitiRule.getTaskService().complete(activitiRule.getTaskService().createTaskQuery().taskAssignee("kermit").singleResult().getId());
assertEquals(0, taskService.createTaskQuery().count());
assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().count());
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class JsonConverterTest method testHumanStepConversion.
@Test
public void testHumanStepConversion() {
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").addHumanStep("step1", "fred").addHumanStepForGroup("step2", Collections.singletonList("group")).addHumanStepForWorkflowInitiator("step3");
// Add form to last step
HumanStepDefinition stepWithForm = new HumanStepDefinition();
stepWithForm.setName("step4");
stepWithForm.setDescription("Step description");
workflowDefinition.getSteps().add(stepWithForm);
FormDefinition formDefinition = new FormDefinition();
stepWithForm.setForm(formDefinition);
formDefinition.setFormKey("123");
TextPropertyDefinition textProp = new TextPropertyDefinition();
textProp.setMandatory(true);
textProp.setName("textProp");
textProp.setWritable(false);
formDefinition.addFormProperty(textProp);
textProp.getParameters().put("custom-parameter", "This is a test");
NumberPropertyDefinition numberProp = new NumberPropertyDefinition();
numberProp.setMandatory(true);
numberProp.setName("numberProp");
numberProp.setWritable(false);
formDefinition.addFormProperty(numberProp);
ReferencePropertyDefinition reference = new ReferencePropertyDefinition();
reference.setMandatory(true);
reference.setName("referenceProp");
reference.setWritable(false);
reference.setType("referencedType");
formDefinition.addFormProperty(reference);
ListPropertyDefinition itemType = new ListPropertyDefinition();
itemType.setMandatory(true);
itemType.setName("referenceProp");
itemType.setWritable(false);
itemType.addEntry(new ListPropertyEntry("1", "Item 1"));
itemType.addEntry(new ListPropertyEntry("2", "Item 2"));
formDefinition.addFormProperty(itemType);
// Write result to byte-array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(baos);
converter.writeWorkflowDefinition(workflowDefinition, writer);
// Parse definition based on written JSON
WorkflowDefinition parsedDefinition = converter.readWorkflowDefinition(baos.toByteArray());
assertEquals(workflowDefinition.getSteps().size(), parsedDefinition.getSteps().size());
int index = 0;
for (StepDefinition stepDefinition : parsedDefinition.getSteps()) {
assertTrue(stepDefinition instanceof HumanStepDefinition);
HumanStepDefinition humanStep = (HumanStepDefinition) stepDefinition;
HumanStepDefinition originalStep = (HumanStepDefinition) workflowDefinition.getSteps().get(index);
// Check general human-step fields
assertEquals(originalStep.getAssignee(), humanStep.getAssignee());
assertEquals(originalStep.getAssignmentType(), humanStep.getAssignmentType());
assertEquals(originalStep.getCandidateGroups(), humanStep.getCandidateGroups());
assertEquals(originalStep.getCandidateUsers(), humanStep.getCandidateUsers());
assertEquals(originalStep.getName(), humanStep.getName());
assertEquals(originalStep.getDescription(), humanStep.getDescription());
if (originalStep.getForm() != null) {
// Encountered step with form attached to it, should be last step
assertEquals(3, index);
assertEquals("123", humanStep.getForm().getFormKey());
assertEquals(originalStep.getForm().getFormPropertyDefinitions().size(), humanStep.getForm().getFormPropertyDefinitions().size());
// Check form-fields, generic fields
for (int i = 0; i < originalStep.getForm().getFormPropertyDefinitions().size(); i++) {
FormPropertyDefinition origDef = originalStep.getForm().getFormPropertyDefinitions().get(i);
FormPropertyDefinition parsedDef = humanStep.getForm().getFormPropertyDefinitions().get(i);
assertEquals(origDef.getName(), parsedDef.getName());
assertEquals(origDef.isMandatory(), parsedDef.isMandatory());
assertEquals(origDef.isWritable(), parsedDef.isWritable());
assertEquals(origDef.getClass(), parsedDef.getClass());
if (parsedDef instanceof TextPropertyDefinition) {
assertTrue(parsedDef.getParameters() != null);
assertEquals(1L, parsedDef.getParameters().size());
assertEquals("This is a test", parsedDef.getParameters().get("custom-parameter"));
}
if (parsedDef instanceof ListPropertyDefinition) {
ListPropertyDefinition parsed = (ListPropertyDefinition) parsedDef;
assertEquals(2L, parsed.getEntries().size());
}
}
}
index++;
}
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class SimpleTableEditor method save.
protected void save() {
WorkflowDefinition workflowDefinition = createWorkflow();
final ProcessEngineImpl defaultProcessEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
ProcessEngineConfiguration processEngineConfiguration = defaultProcessEngine.getProcessEngineConfiguration();
ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
Model model = null;
if (modelId == null) {
// new process
model = repositoryService.newModel();
} else {
// update existing process
model = repositoryService.getModel(modelId);
}
model.setName(workflowDefinition.getName());
model.setCategory(SimpleTableEditorConstants.TABLE_EDITOR_CATEGORY);
repositoryService.saveModel(model);
// Store model entity
WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
try {
// Write JSON to byte-array and set as editor-source
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ExplorerApp.get().getSimpleWorkflowJsonConverter().writeWorkflowDefinition(workflowDefinition, new OutputStreamWriter(baos));
repositoryService.addModelEditorSource(model.getId(), baos.toByteArray());
// Store process image
// TODO: we should really allow the service to take an inputstream as input. Now we load it into memory ...
repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(diagramGenerator.generateDiagram(conversion.getBpmnModel(), "png", processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader())));
} catch (IOException e) {
logger.warn("Could not generate process image. Image is not stored and will not be shown.", e);
}
ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(model.getId());
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition 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;
}
Aggregations