use of org.activiti.bpmn.model.FormProperty in project Activiti by Activiti.
the class FormPropertiesConverterTest method validateModel.
private void validateModel(BpmnModel model) {
assertEquals("formPropertiesProcess", model.getMainProcess().getId());
assertEquals("User registration", model.getMainProcess().getName());
assertEquals(true, model.getMainProcess().isExecutable());
FlowElement startFlowElement = model.getMainProcess().getFlowElement("startNode");
assertNotNull(startFlowElement);
assertTrue(startFlowElement instanceof StartEvent);
StartEvent startEvent = (StartEvent) startFlowElement;
for (FormProperty formProperty : startEvent.getFormProperties()) {
assertEquals(true, formProperty.isRequired());
}
FlowElement userFlowElement = model.getMainProcess().getFlowElement("userTask");
assertNotNull(userFlowElement);
assertTrue(userFlowElement instanceof UserTask);
UserTask userTask = (UserTask) userFlowElement;
List<FormProperty> formProperties = userTask.getFormProperties();
assertNotNull(formProperties);
assertEquals("Invalid form properties list: ", 8, formProperties.size());
for (FormProperty formProperty : formProperties) {
if (formProperty.getId().equals("new_property_1")) {
checkFormProperty(formProperty, false, false, false);
} else if (formProperty.getId().equals("new_property_2")) {
checkFormProperty(formProperty, false, false, true);
} else if (formProperty.getId().equals("new_property_3")) {
checkFormProperty(formProperty, false, true, false);
} else if (formProperty.getId().equals("new_property_4")) {
checkFormProperty(formProperty, false, true, true);
} else if (formProperty.getId().equals("new_property_5")) {
checkFormProperty(formProperty, true, false, false);
List<Map<String, Object>> formValues = new ArrayList<Map<String, Object>>();
for (FormValue formValue : formProperty.getFormValues()) {
Map<String, Object> formValueMap = new HashMap<String, Object>();
formValueMap.put("id", formValue.getId());
formValueMap.put("name", formValue.getName());
formValues.add(formValueMap);
}
checkFormPropertyFormValues(formValues);
} else if (formProperty.getId().equals("new_property_6")) {
checkFormProperty(formProperty, true, false, true);
} else if (formProperty.getId().equals("new_property_7")) {
checkFormProperty(formProperty, true, true, false);
} else if (formProperty.getId().equals("new_property_8")) {
checkFormProperty(formProperty, true, true, true);
}
}
}
use of org.activiti.bpmn.model.FormProperty in project Activiti by Activiti.
the class BaseStepDefinitionConverter method convertProperties.
/**
* Converts form properties. Multiple step types can contain forms,
* hence why it it a shared method here.
*/
protected List<FormProperty> convertProperties(FormDefinition formDefinition) {
List<FormProperty> formProperties = new ArrayList<FormProperty>();
for (FormPropertyDefinition propertyDefinition : formDefinition.getFormPropertyDefinitions()) {
FormProperty formProperty = new FormProperty();
formProperties.add(formProperty);
formProperty.setId(propertyDefinition.getName());
formProperty.setName(propertyDefinition.getName());
formProperty.setRequired(propertyDefinition.isMandatory());
String type = null;
if (propertyDefinition instanceof NumberPropertyDefinition) {
type = "long";
} else if (propertyDefinition instanceof DatePropertyDefinition) {
type = "date";
} else if (propertyDefinition instanceof BooleanPropertyDefinition) {
type = "boolean";
} else if (propertyDefinition instanceof ListPropertyDefinition) {
type = "enum";
ListPropertyDefinition listDefinition = (ListPropertyDefinition) propertyDefinition;
if (!listDefinition.getEntries().isEmpty()) {
List<FormValue> formValues = new ArrayList<FormValue>(listDefinition.getEntries().size());
for (ListPropertyEntry entry : listDefinition.getEntries()) {
FormValue formValue = new FormValue();
// We're using same value for id and name for the moment
formValue.setId(entry.getValue());
formValue.setName(entry.getName());
formValues.add(formValue);
}
formProperty.setFormValues(formValues);
}
} else {
// Fallback to simple text
type = "string";
}
formProperty.setType(type);
}
return formProperties;
}
use of org.activiti.bpmn.model.FormProperty in project Activiti by Activiti.
the class FeedbackStepDefinitionConverter method createSelectPeopleUserTask.
protected UserTask createSelectPeopleUserTask(FeedbackStepDefinition feedbackStepDefinition, WorkflowDefinitionConversion conversion, Map<String, BaseElement> processElements) {
UserTask selectPeopleUserTask = new UserTask();
selectPeopleUserTask.setId(conversion.getUniqueNumberedId(ConversionConstants.USER_TASK_ID_PREFIX));
selectPeopleUserTask.setName(getSelectPeopleTaskName());
selectPeopleUserTask.setAssignee(feedbackStepDefinition.getFeedbackInitiator());
addFlowElement(conversion, selectPeopleUserTask, true);
processElements.put(SELECT_PEOPLE_USER_TASK, selectPeopleUserTask);
// TODO: work out form such that it can be used in Activiti Explorer, ie. add correct form properties
// The following is just a a bit of a dummy form property
FormProperty feedbackProvidersProperty = new FormProperty();
feedbackProvidersProperty.setId(VARIABLE_FEEDBACK_PROVIDERS);
feedbackProvidersProperty.setName("Who needs to provide feedback?");
feedbackProvidersProperty.setRequired(true);
// TODO: we need some kind of 'people' property type here
feedbackProvidersProperty.setType("string");
selectPeopleUserTask.setFormProperties(Arrays.asList(feedbackProvidersProperty));
// that injects these variables into the process (instead of having it provided by the end user in a form)
if (feedbackStepDefinition.getFeedbackProviders() != null && !feedbackStepDefinition.getFeedbackProviders().isEmpty()) {
if (selectPeopleUserTask.getTaskListeners() == null) {
selectPeopleUserTask.setTaskListeners(new ArrayList<ActivitiListener>());
}
ActivitiListener taskListener = new ActivitiListener();
taskListener.setEvent("complete");
taskListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
taskListener.setImplementation("org.activiti.engine.impl.bpmn.listener.ScriptTaskListener");
FieldExtension languageField = new FieldExtension();
languageField.setFieldName("language");
languageField.setStringValue("JavaScript");
FieldExtension scriptField = new FieldExtension();
scriptField.setFieldName("script");
StringBuilder script = new StringBuilder();
if (JvmUtil.isJDK8()) {
script.append("load(\"nashorn:mozilla_compat.js\");");
}
script.append("importPackage (java.util); var feedbackProviders = new ArrayList();" + System.getProperty("line.separator"));
for (String feedbackProvider : feedbackStepDefinition.getFeedbackProviders()) {
script.append("feedbackProviders.add('" + feedbackProvider + "');" + System.getProperty("line.separator"));
}
script.append("task.getExecution().setVariable('" + VARIABLE_FEEDBACK_PROVIDERS + "', feedbackProviders);" + System.getProperty("line.separator"));
scriptField.setStringValue(script.toString());
taskListener.setFieldExtensions(Arrays.asList(languageField, scriptField));
selectPeopleUserTask.getTaskListeners().add(taskListener);
}
return selectPeopleUserTask;
}
use of org.activiti.bpmn.model.FormProperty in project Activiti by Activiti.
the class StartEventConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("start");
assertTrue(flowElement instanceof StartEvent);
StartEvent startEvent = (StartEvent) flowElement;
assertEquals("start", startEvent.getId());
assertEquals("startName", startEvent.getName());
assertEquals("startFormKey", startEvent.getFormKey());
assertEquals("startInitiator", startEvent.getInitiator());
assertEquals("startDoc", startEvent.getDocumentation());
List<FormProperty> formProperties = startEvent.getFormProperties();
assertEquals(2, formProperties.size());
FormProperty formProperty = formProperties.get(0);
assertEquals("startFormProp1", formProperty.getId());
assertEquals("startFormProp1", formProperty.getName());
assertEquals("string", formProperty.getType());
formProperty = formProperties.get(1);
assertEquals("startFormProp2", formProperty.getId());
assertEquals("startFormProp2", formProperty.getName());
assertEquals("boolean", formProperty.getType());
}
use of org.activiti.bpmn.model.FormProperty in project Activiti by Activiti.
the class UserTaskConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("usertask");
assertNotNull(flowElement);
assertTrue(flowElement instanceof UserTask);
assertEquals("usertask", flowElement.getId());
UserTask userTask = (UserTask) flowElement;
assertEquals("usertask", userTask.getId());
assertEquals("User task", userTask.getName());
assertEquals("testKey", userTask.getFormKey());
assertEquals("40", userTask.getPriority());
assertEquals("2012-11-01", userTask.getDueDate());
assertEquals("defaultCategory", userTask.getCategory());
assertEquals("gonzo", userTask.getOwner());
assertEquals("kermit", userTask.getAssignee());
assertEquals(2, userTask.getCandidateUsers().size());
assertTrue(userTask.getCandidateUsers().contains("kermit"));
assertTrue(userTask.getCandidateUsers().contains("fozzie"));
assertEquals(2, userTask.getCandidateGroups().size());
assertTrue(userTask.getCandidateGroups().contains("management"));
assertTrue(userTask.getCandidateGroups().contains("sales"));
List<FormProperty> formProperties = userTask.getFormProperties();
assertEquals(2, formProperties.size());
FormProperty formProperty = formProperties.get(0);
assertEquals("formId", formProperty.getId());
assertEquals("formName", formProperty.getName());
assertEquals("string", formProperty.getType());
assertEquals("variable", formProperty.getVariable());
assertEquals("${expression}", formProperty.getExpression());
formProperty = formProperties.get(1);
assertEquals("formId2", formProperty.getId());
assertEquals("anotherName", formProperty.getName());
assertEquals("long", formProperty.getType());
assertTrue(StringUtils.isEmpty(formProperty.getVariable()));
assertTrue(StringUtils.isEmpty(formProperty.getExpression()));
List<ActivitiListener> listeners = userTask.getTaskListeners();
assertEquals(3, listeners.size());
ActivitiListener listener = (ActivitiListener) listeners.get(0);
assertTrue(ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(listener.getImplementationType()));
assertEquals("org.test.TestClass", listener.getImplementation());
assertEquals("create", listener.getEvent());
assertEquals(2, listener.getFieldExtensions().size());
assertEquals("testField", listener.getFieldExtensions().get(0).getFieldName());
assertEquals("test", listener.getFieldExtensions().get(0).getStringValue());
listener = (ActivitiListener) listeners.get(1);
assertTrue(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals(listener.getImplementationType()));
assertEquals("${someExpression}", listener.getImplementation());
assertEquals("assignment", listener.getEvent());
listener = (ActivitiListener) listeners.get(2);
assertTrue(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(listener.getImplementationType()));
assertEquals("${someDelegateExpression}", listener.getImplementation());
assertEquals("complete", listener.getEvent());
flowElement = model.getMainProcess().getFlowElement("start");
assertTrue(flowElement instanceof StartEvent);
StartEvent startEvent = (StartEvent) flowElement;
assertTrue(startEvent.getOutgoingFlows().size() == 1);
flowElement = model.getMainProcess().getFlowElement("flow1");
assertTrue(flowElement instanceof SequenceFlow);
SequenceFlow flow = (SequenceFlow) flowElement;
assertEquals("flow1", flow.getId());
assertNotNull(flow.getSourceRef());
assertNotNull(flow.getTargetRef());
}
Aggregations