use of org.activiti.bpmn.model.UserTask in project Activiti by Activiti.
the class BaseBpmnJsonConverter method convertJsonToFormProperties.
protected void convertJsonToFormProperties(JsonNode objectNode, BaseElement element) {
JsonNode formPropertiesNode = getProperty(PROPERTY_FORM_PROPERTIES, objectNode);
if (formPropertiesNode != null) {
formPropertiesNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(formPropertiesNode);
JsonNode propertiesArray = formPropertiesNode.get("formProperties");
if (propertiesArray != null) {
for (JsonNode formNode : propertiesArray) {
JsonNode formIdNode = formNode.get(PROPERTY_FORM_ID);
if (formIdNode != null && StringUtils.isNotEmpty(formIdNode.asText())) {
FormProperty formProperty = new FormProperty();
formProperty.setId(formIdNode.asText());
formProperty.setName(getValueAsString(PROPERTY_FORM_NAME, formNode));
formProperty.setType(getValueAsString(PROPERTY_FORM_TYPE, formNode));
formProperty.setExpression(getValueAsString(PROPERTY_FORM_EXPRESSION, formNode));
formProperty.setVariable(getValueAsString(PROPERTY_FORM_VARIABLE, formNode));
if ("date".equalsIgnoreCase(formProperty.getType())) {
formProperty.setDatePattern(getValueAsString(PROPERTY_FORM_DATE_PATTERN, formNode));
} else if ("enum".equalsIgnoreCase(formProperty.getType())) {
JsonNode enumValuesNode = formNode.get(PROPERTY_FORM_ENUM_VALUES);
if (enumValuesNode != null) {
List<FormValue> formValueList = new ArrayList<FormValue>();
for (JsonNode enumNode : enumValuesNode) {
if (enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID) != null && enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID).isNull() == false && enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME) != null && enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME).isNull() == false) {
FormValue formValue = new FormValue();
formValue.setId(enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID).asText());
formValue.setName(enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME).asText());
formValueList.add(formValue);
} else if (enumNode.get("value") != null && enumNode.get("value").isNull() == false) {
FormValue formValue = new FormValue();
formValue.setId(enumNode.get("value").asText());
formValue.setName(enumNode.get("value").asText());
formValueList.add(formValue);
}
}
formProperty.setFormValues(formValueList);
}
}
formProperty.setRequired(getValueAsBoolean(PROPERTY_FORM_REQUIRED, formNode));
formProperty.setReadable(getValueAsBoolean(PROPERTY_FORM_READABLE, formNode));
formProperty.setWriteable(getValueAsBoolean(PROPERTY_FORM_WRITABLE, formNode));
if (element instanceof StartEvent) {
((StartEvent) element).getFormProperties().add(formProperty);
} else if (element instanceof UserTask) {
((UserTask) element).getFormProperties().add(formProperty);
}
}
}
}
}
}
use of org.activiti.bpmn.model.UserTask in project Activiti by Activiti.
the class UserTaskJsonConverter method convertElementToJson.
@Override
protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
UserTask userTask = (UserTask) baseElement;
String assignee = userTask.getAssignee();
String owner = userTask.getOwner();
if (StringUtils.isNotEmpty(assignee) || StringUtils.isNotEmpty(owner) || CollectionUtils.isNotEmpty(userTask.getCandidateUsers()) || CollectionUtils.isNotEmpty(userTask.getCandidateGroups())) {
ObjectNode assignmentNode = objectMapper.createObjectNode();
ObjectNode assignmentValuesNode = objectMapper.createObjectNode();
if (StringUtils.isNotEmpty(assignee)) {
assignmentValuesNode.put(PROPERTY_USERTASK_ASSIGNEE, assignee);
}
if (StringUtils.isNotEmpty(owner)) {
assignmentValuesNode.put(PROPERTY_USERTASK_OWNER, owner);
}
if (CollectionUtils.isNotEmpty(userTask.getCandidateUsers())) {
ArrayNode candidateArrayNode = objectMapper.createArrayNode();
for (String candidateUser : userTask.getCandidateUsers()) {
ObjectNode candidateNode = objectMapper.createObjectNode();
candidateNode.put("value", candidateUser);
candidateArrayNode.add(candidateNode);
}
assignmentValuesNode.put(PROPERTY_USERTASK_CANDIDATE_USERS, candidateArrayNode);
}
if (CollectionUtils.isNotEmpty(userTask.getCandidateGroups())) {
ArrayNode candidateArrayNode = objectMapper.createArrayNode();
for (String candidateGroup : userTask.getCandidateGroups()) {
ObjectNode candidateNode = objectMapper.createObjectNode();
candidateNode.put("value", candidateGroup);
candidateArrayNode.add(candidateNode);
}
assignmentValuesNode.put(PROPERTY_USERTASK_CANDIDATE_GROUPS, candidateArrayNode);
}
assignmentNode.put("assignment", assignmentValuesNode);
propertiesNode.put(PROPERTY_USERTASK_ASSIGNMENT, assignmentNode);
}
if (userTask.getPriority() != null) {
setPropertyValue(PROPERTY_USERTASK_PRIORITY, userTask.getPriority().toString(), propertiesNode);
}
if (StringUtils.isNotEmpty(userTask.getFormKey())) {
setPropertyValue(PROPERTY_FORMKEY, userTask.getFormKey(), propertiesNode);
}
setPropertyValue(PROPERTY_USERTASK_DUEDATE, userTask.getDueDate(), propertiesNode);
setPropertyValue(PROPERTY_USERTASK_CATEGORY, userTask.getCategory(), propertiesNode);
addFormProperties(userTask.getFormProperties(), propertiesNode);
}
use of org.activiti.bpmn.model.UserTask in project Activiti by Activiti.
the class BpmnJsonConverterUtil method parseListeners.
protected static void parseListeners(JsonNode listenersNode, BaseElement element, boolean isTaskListener) {
if (listenersNode == null)
return;
listenersNode = validateIfNodeIsTextual(listenersNode);
for (JsonNode listenerNode : listenersNode) {
listenerNode = validateIfNodeIsTextual(listenerNode);
JsonNode eventNode = listenerNode.get(PROPERTY_LISTENER_EVENT);
if (eventNode != null && eventNode.isNull() == false && StringUtils.isNotEmpty(eventNode.asText())) {
ActivitiListener listener = new ActivitiListener();
listener.setEvent(eventNode.asText());
if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode))) {
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
listener.setImplementation(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode));
} else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode))) {
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
listener.setImplementation(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode));
} else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode))) {
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
listener.setImplementation(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode));
}
JsonNode fieldsNode = listenerNode.get(PROPERTY_LISTENER_FIELDS);
if (fieldsNode != null) {
for (JsonNode fieldNode : fieldsNode) {
JsonNode nameNode = fieldNode.get(PROPERTY_FIELD_NAME);
if (nameNode != null && nameNode.isNull() == false && StringUtils.isNotEmpty(nameNode.asText())) {
FieldExtension fieldExtension = new FieldExtension();
fieldExtension.setFieldName(nameNode.asText());
fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING_VALUE, fieldNode));
if (StringUtils.isEmpty(fieldExtension.getStringValue())) {
fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING, fieldNode));
}
if (StringUtils.isEmpty(fieldExtension.getStringValue())) {
fieldExtension.setExpression(getValueAsString(PROPERTY_FIELD_EXPRESSION, fieldNode));
}
listener.getFieldExtensions().add(fieldExtension);
}
}
}
if (element instanceof Process) {
((Process) element).getExecutionListeners().add(listener);
} else if (element instanceof SequenceFlow) {
((SequenceFlow) element).getExecutionListeners().add(listener);
} else if (element instanceof UserTask) {
if (isTaskListener) {
((UserTask) element).getTaskListeners().add(listener);
} else {
((UserTask) element).getExecutionListeners().add(listener);
}
} else if (element instanceof FlowElement) {
((FlowElement) element).getExecutionListeners().add(listener);
}
}
}
}
use of org.activiti.bpmn.model.UserTask 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.UserTask in project Activiti by Activiti.
the class ValuedDataObjectConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("start1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof StartEvent);
assertEquals("start1", flowElement.getId());
// verify the main process data objects
List<ValuedDataObject> dataObjects = model.getProcess(null).getDataObjects();
assertEquals(7, dataObjects.size());
Map<String, ValuedDataObject> objectMap = new HashMap<String, ValuedDataObject>();
for (ValuedDataObject valueObj : dataObjects) {
objectMap.put(valueObj.getId(), valueObj);
}
ValuedDataObject dataObj = objectMap.get("dObj1");
assertEquals("dObj1", dataObj.getId());
assertEquals("StringTest", dataObj.getName());
assertEquals("xsd:string", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof String);
assertEquals("Testing1&2&3", dataObj.getValue());
dataObj = objectMap.get("dObj2");
assertEquals("dObj2", dataObj.getId());
assertEquals("BooleanTest", dataObj.getName());
assertEquals("xsd:boolean", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Boolean);
assertEquals(new Boolean(true), dataObj.getValue());
dataObj = objectMap.get("dObj3");
assertEquals("dObj3", dataObj.getId());
assertEquals("DateTest", dataObj.getName());
assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Date);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
assertEquals("2013-09-16T11:23:00", sdf.format(dataObj.getValue()));
dataObj = objectMap.get("dObj4");
assertEquals("dObj4", dataObj.getId());
assertEquals("DoubleTest", dataObj.getName());
assertEquals("xsd:double", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Double);
assertEquals(new Double(123456789), dataObj.getValue());
dataObj = objectMap.get("dObj5");
assertEquals("dObj5", dataObj.getId());
assertEquals("IntegerTest", dataObj.getName());
assertEquals("xsd:int", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Integer);
assertEquals(new Integer(123), dataObj.getValue());
dataObj = objectMap.get("dObj6");
assertEquals("dObj6", dataObj.getId());
assertEquals("LongTest", dataObj.getName());
assertEquals("xsd:long", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Long);
assertEquals(new Long(-123456), dataObj.getValue());
assertEquals(1, dataObj.getExtensionElements().size());
List<ExtensionElement> testValues = dataObj.getExtensionElements().get("testvalue");
assertNotNull(testValues);
assertEquals(1, testValues.size());
assertEquals("testvalue", testValues.get(0).getName());
assertEquals("test", testValues.get(0).getElementText());
dataObj = objectMap.get("NoData");
assertEquals("NoData", dataObj.getId());
assertEquals("NoData", dataObj.getName());
assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
assertNull(dataObj.getValue());
flowElement = model.getMainProcess().getFlowElement("userTask1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof UserTask);
assertEquals("userTask1", flowElement.getId());
UserTask userTask = (UserTask) flowElement;
assertEquals("kermit", userTask.getAssignee());
flowElement = model.getMainProcess().getFlowElement("subprocess1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof SubProcess);
assertEquals("subprocess1", flowElement.getId());
SubProcess subProcess = (SubProcess) flowElement;
assertEquals(11, subProcess.getFlowElements().size());
// verify the sub process data objects
dataObjects = subProcess.getDataObjects();
assertEquals(6, dataObjects.size());
objectMap = new HashMap<String, ValuedDataObject>();
for (ValuedDataObject valueObj : dataObjects) {
objectMap.put(valueObj.getId(), valueObj);
}
dataObj = objectMap.get("dObj7");
assertEquals("dObj7", dataObj.getId());
assertEquals("StringSubTest", dataObj.getName());
assertEquals("xsd:string", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof String);
assertEquals("Testing456", dataObj.getValue());
dataObj = objectMap.get("dObj8");
assertEquals("dObj8", dataObj.getId());
assertEquals("BooleanSubTest", dataObj.getName());
assertEquals("xsd:boolean", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Boolean);
assertEquals(new Boolean(false), dataObj.getValue());
dataObj = objectMap.get("dObj9");
assertEquals("dObj9", dataObj.getId());
assertEquals("DateSubTest", dataObj.getName());
assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Date);
assertEquals("2013-11-11T22:00:00", sdf.format(dataObj.getValue()));
dataObj = objectMap.get("dObj10");
assertEquals("dObj10", dataObj.getId());
assertEquals("DoubleSubTest", dataObj.getName());
assertEquals("xsd:double", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Double);
assertEquals(new Double(678912345), dataObj.getValue());
dataObj = objectMap.get("dObj11");
assertEquals("dObj11", dataObj.getId());
assertEquals("IntegerSubTest", dataObj.getName());
assertEquals("xsd:int", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Integer);
assertEquals(new Integer(45), dataObj.getValue());
dataObj = objectMap.get("dObj12");
assertEquals("dObj12", dataObj.getId());
assertEquals("LongSubTest", dataObj.getName());
assertEquals("xsd:long", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Long);
assertEquals(new Long(456123), dataObj.getValue());
}
Aggregations