提交 05c8a821 编写于 作者: B Bassam Al-Sarori

JSON owner and custom identity links json conversion

added support in modeler
上级 0ddf1f18
......@@ -146,9 +146,15 @@ public interface StencilConstants {
final String PROPERTY_USERTASK_ASSIGNMENT = "usertaskassignment";
final String PROPERTY_USERTASK_ASSIGNMENT_TYPE = "assignment_type";
final String PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION = "resourceassignmentexpr";
final String PROPERTY_USERTASK_OWNER = "owner";
final String PROPERTY_USERTASK_ASSIGNEE = "assignee";
final String PROPERTY_USERTASK_CANDIDATE_USERS = "candidateUsers";
final String PROPERTY_USERTASK_CANDIDATE_GROUPS = "candidateGroups";
final String PROPERTY_USERTASK_CUSTOM_IDENTITY_LINKS = "customidentitylinks";
final String PROPERTY_USERTASK_IDENTITY_TYPE = "identity_type";
final String PROPERTY_USERTASK_IDENTITY_LINK_TYPE = "identity_link_type";
final String PROPERTY_USERTASK_IDENTITY_LINK_EXPRESSION = "identitylinkexpr";
final String PROPERTY_SERVICETASK_CLASS = "servicetaskclass";
final String PROPERTY_SERVICETASK_EXPRESSION = "servicetaskexpression";
......@@ -198,4 +204,4 @@ public interface StencilConstants {
final String PROPERTY_IOPARAMETER_TARGET = "ioparameter_target";
final String PROPERTY_SEQUENCEFLOW_CONDITION = "conditionsequenceflow";
}
}
\ No newline at end of file
......@@ -12,8 +12,12 @@
*/
package org.activiti.editor.language.json.converter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.activiti.bpmn.model.BaseElement;
import org.activiti.bpmn.model.FlowElement;
......@@ -52,14 +56,22 @@ public class UserTaskJsonConverter extends BaseBpmnJsonConverter {
@Override
protected void convertElementToJson(ObjectNode propertiesNode, FlowElement flowElement) {
UserTask userTask = (UserTask) flowElement;
String owner = userTask.getOwner();
String assignee = userTask.getAssignee();
String candidateUsers = convertListToCommaSeparatedString(userTask.getCandidateUsers());
String candidateGroups = convertListToCommaSeparatedString(userTask.getCandidateGroups());
if (StringUtils.isNotEmpty(assignee) || StringUtils.isNotEmpty(candidateUsers) || StringUtils.isNotEmpty(candidateGroups)) {
if (StringUtils.isNotEmpty(owner) || StringUtils.isNotEmpty(assignee) || StringUtils.isNotEmpty(candidateUsers) || StringUtils.isNotEmpty(candidateGroups)) {
ObjectNode assignmentNode = objectMapper.createObjectNode();
ArrayNode itemsNode = objectMapper.createArrayNode();
if (StringUtils.isNotEmpty(owner)) {
ObjectNode assignmentItemNode = objectMapper.createObjectNode();
assignmentItemNode.put(PROPERTY_USERTASK_ASSIGNMENT_TYPE, PROPERTY_USERTASK_OWNER);
assignmentItemNode.put(PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION, owner);
itemsNode.add(assignmentItemNode);
}
if (StringUtils.isNotEmpty(assignee)) {
ObjectNode assignmentItemNode = objectMapper.createObjectNode();
assignmentItemNode.put(PROPERTY_USERTASK_ASSIGNMENT_TYPE, PROPERTY_USERTASK_ASSIGNEE);
......@@ -84,8 +96,37 @@ public class UserTaskJsonConverter extends BaseBpmnJsonConverter {
assignmentNode.put("totalCount", itemsNode.size());
assignmentNode.put(EDITOR_PROPERTIES_GENERAL_ITEMS, itemsNode);
propertiesNode.put(PROPERTY_USERTASK_ASSIGNMENT, assignmentNode);
}
if(userTask.getCustomUserIdentityLinks().size() > 0 || userTask.getCustomGroupIdentityLinks().size() > 0){
ObjectNode customIdentityLinksNode = objectMapper.createObjectNode();
ArrayNode itemsNode = objectMapper.createArrayNode();
for(String linkType : userTask.getCustomUserIdentityLinks().keySet()){
ObjectNode identityItemNode = objectMapper.createObjectNode();
identityItemNode.put(PROPERTY_USERTASK_IDENTITY_TYPE, "user");
identityItemNode.put(PROPERTY_USERTASK_IDENTITY_LINK_TYPE, linkType);
String users = convertListToCommaSeparatedString(new ArrayList<String>(userTask.getCustomUserIdentityLinks().get(linkType)));
identityItemNode.put(PROPERTY_USERTASK_IDENTITY_LINK_EXPRESSION, users);
itemsNode.add(identityItemNode);
}
for(String linkType : userTask.getCustomGroupIdentityLinks().keySet()){
ObjectNode identityItemNode = objectMapper.createObjectNode();
identityItemNode.put(PROPERTY_USERTASK_IDENTITY_TYPE, "group");
identityItemNode.put(PROPERTY_USERTASK_IDENTITY_LINK_TYPE, linkType);
String groups = convertListToCommaSeparatedString(new ArrayList<String>(userTask.getCustomGroupIdentityLinks().get(linkType)));
identityItemNode.put(PROPERTY_USERTASK_IDENTITY_LINK_EXPRESSION, groups);
itemsNode.add(identityItemNode);
}
customIdentityLinksNode.put("totalCount", itemsNode.size());
customIdentityLinksNode.put(EDITOR_PROPERTIES_GENERAL_ITEMS, itemsNode);
propertiesNode.put(PROPERTY_USERTASK_CUSTOM_IDENTITY_LINKS, customIdentityLinksNode);
}
if (userTask.getPriority() != null) {
setPropertyValue(PROPERTY_PRIORITY, userTask.getPriority().toString(), propertiesNode);
}
......@@ -117,6 +158,8 @@ public class UserTaskJsonConverter extends BaseBpmnJsonConverter {
String assignmentType = assignmentItemNode.get(PROPERTY_USERTASK_ASSIGNMENT_TYPE).asText();
if (PROPERTY_USERTASK_ASSIGNEE.equals(assignmentType)) {
task.setAssignee(assignmentItemNode.get(PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION).asText());
} else if (PROPERTY_USERTASK_OWNER.equals(assignmentType)) {
task.setOwner(assignmentItemNode.get(PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION).asText());
} else if (PROPERTY_USERTASK_CANDIDATE_USERS.equals(assignmentType)) {
task.setCandidateUsers(getValueAsList(PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION, assignmentItemNode));
} else if (PROPERTY_USERTASK_CANDIDATE_GROUPS.equals(assignmentType)) {
......@@ -126,7 +169,42 @@ public class UserTaskJsonConverter extends BaseBpmnJsonConverter {
}
}
}
JsonNode customIdentityLinksNode = getProperty(PROPERTY_USERTASK_CUSTOM_IDENTITY_LINKS, elementNode);
if (customIdentityLinksNode != null) {
JsonNode itemsNode = customIdentityLinksNode.get(EDITOR_PROPERTIES_GENERAL_ITEMS);
if (itemsNode != null) {
Iterator<JsonNode> customIdentityLinksIterator = itemsNode.elements();
while (customIdentityLinksIterator.hasNext()) {
JsonNode customIdentityLinksItemNode = customIdentityLinksIterator.next();
if (customIdentityLinksItemNode.get(PROPERTY_USERTASK_IDENTITY_TYPE) != null && customIdentityLinksItemNode.get(PROPERTY_USERTASK_IDENTITY_LINK_TYPE) != null
&& customIdentityLinksItemNode.get(PROPERTY_USERTASK_IDENTITY_LINK_EXPRESSION) != null) {
String identityType = customIdentityLinksItemNode.get(PROPERTY_USERTASK_IDENTITY_TYPE).asText();
String identityLinkType = customIdentityLinksItemNode.get(PROPERTY_USERTASK_IDENTITY_LINK_TYPE).asText();
List<String> identitiesList = getValueAsList(PROPERTY_USERTASK_IDENTITY_LINK_EXPRESSION, customIdentityLinksItemNode);
if ("user".equals(identityType)) {
Set<String> users = task.getCustomUserIdentityLinks().get(identityLinkType);
if(users == null){
users = new HashSet<String>();
task.getCustomUserIdentityLinks().put(identityLinkType, users);
}
users.addAll(identitiesList);
}else if ("group".equals(identityType)) {
Set<String> groups = task.getCustomGroupIdentityLinks().get(identityLinkType);
if(groups == null){
groups = new HashSet<String>();
task.getCustomGroupIdentityLinks().put(identityLinkType, groups);
}
groups.addAll(identitiesList);
}
}
}
}
}
convertJsonToFormProperties(elementNode, task);
return task;
}
}
}
\ No newline at end of file
......@@ -49,7 +49,9 @@ public class UserTaskConverterTest extends AbstractConverterTest {
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"));
......@@ -58,6 +60,15 @@ public class UserTaskConverterTest extends AbstractConverterTest {
assertTrue(userTask.getCandidateGroups().contains("management"));
assertTrue(userTask.getCandidateGroups().contains("sales"));
assertEquals(2, userTask.getCustomUserIdentityLinks().size());
assertEquals(1, userTask.getCustomGroupIdentityLinks().size());
assertTrue(userTask.getCustomUserIdentityLinks().get("bizAdmin").contains("kermit"));
assertTrue(userTask.getCustomGroupIdentityLinks().get("bizAdmin").contains("management"));
assertTrue(userTask.getCustomGroupIdentityLinks().get("bizAdmin").contains("sales"));
assertTrue(userTask.getCustomUserIdentityLinks().get("manager").contains("fozzie"));
assertTrue(userTask.getCustomUserIdentityLinks().get("manager").contains("gonzo"));
List<FormProperty> formProperties = userTask.getFormProperties();
assertEquals(2, formProperties.size());
FormProperty formProperty = formProperties.get(0);
......@@ -102,4 +113,4 @@ public class UserTaskConverterTest extends AbstractConverterTest {
assertNotNull(flow.getSourceRef());
assertNotNull(flow.getTargetRef());
}
}
}
\ No newline at end of file
......@@ -39,6 +39,7 @@
"duedatedefinition" : "2012-11-01",
"exclusivedefinition" : "No",
"formkeydefinition" : "testKey",
"categoryDefinition" : "defaultCategory",
"formproperties" : { "items" : [ { "formproperty_expression" : "${expression}",
"formproperty_id" : "formId",
"formproperty_name" : "formName",
......@@ -62,6 +63,9 @@
"usertaskassignment" : { "items" : [ { "assignment_type" : "assignee",
"resourceassignmentexpr" : "kermit"
},
{ "assignment_type" : "owner",
"resourceassignmentexpr" : "gonzo"
},
{ "assignment_type" : "candidateUsers",
"resourceassignmentexpr" : "kermit,fozzie"
},
......@@ -69,6 +73,21 @@
"resourceassignmentexpr" : "management,sales"
}
],
"totalCount" : 4
},
"customidentitylinks" : { "items" : [ { "identity_type" : "user",
"identity_link_type" : "manager",
"identitylinkexpr" : "fozzie, gonzo"
},
{ "identity_type" : "user",
"identity_link_type" : "bizAdmin",
"identitylinkexpr" : "kermit"
},
{ "identity_type" : "group",
"identity_link_type" : "bizAdmin",
"identitylinkexpr" : "management,sales"
}
],
"totalCount" : 3
}
},
......
......@@ -100,7 +100,15 @@
"value" : "",
"description" : "Priority of the user task.",
"popular" : true
} ]
}, {
"id" : "categoryDefinition",
"type" : "String",
"title" : "Category",
"value" : "",
"description" : "Category of the user task.",
"popular" : true
}
]
}, {
"name" : "usertaskassignment",
"properties" : [ {
......@@ -136,6 +144,12 @@
"title_de" : "PotentialOwner",
"value" : "candidateGroups",
"refToView" : ""
}, {
"id" : "c4",
"title" : "Owner",
"title_de" : "Owner",
"value" : "owner",
"refToView" : ""
} ]
}, {
"id" : "resourceassignmentexpr",
......@@ -150,6 +164,55 @@
} ]
} ]
}, {
"name" : "customidentitylinks",
"properties" : [ {
"id" : "customidentitylinks",
"type" : "Complex",
"title" : "Identity Links",
"value" : "",
"description" : "Custom Assignment definition for the user task",
"popular" : true,
"complexItems" : [ {
"id" : "identity_type",
"name" : "Identity Type",
"type" : "Choice",
"value" : "",
"width" : 80,
"optional" : false,
"items" : [ {
"id" : "c1",
"title" : "User",
"title_de" : "User",
"value" : "user",
"refToView" : ""
}, {
"id" : "c2",
"title" : "Group",
"title_de" : "Group",
"value" : "group",
"refToView" : ""
}]
}, {
"id" : "identity_link_type",
"name" : "Identity Link Type",
"type" : "String",
"description" : "This defines the expression used for the resource assignment.",
"description_de" : "Definiert den Ausdruck, der fr die Zordung von Ressourcen genutzt wird.",
"value" : "",
"width" : 200,
"optional" : true
}, {
"id" : "identitylinkexpr",
"name" : "Resource assignment expression",
"type" : "String",
"description" : "This defines the expression used for the resource assignment.",
"description_de" : "Definiert den Ausdruck, der fr die Zordung von Ressourcen genutzt wird.",
"value" : "",
"width" : 200,
"optional" : true
} ]
} ]
}, {
"name" : "formdefinition",
"properties" : [ {
"id" : "formproperties",
......@@ -1225,7 +1288,7 @@
"view" : "activity/usertask.svg",
"icon" : "activity/list/type.user.png",
"groups" : [ "Activities" ],
"propertyPackages" : [ "elementbase", "baseattributes", "usertaskbase", "usertaskassignment", "formdefinition", "tasklistenersbase", "asynchronousbase", "loopcharacteristics", "activity" ],
"propertyPackages" : [ "elementbase", "baseattributes", "usertaskbase", "usertaskassignment", "customidentitylinks", "formdefinition", "tasklistenersbase", "asynchronousbase", "loopcharacteristics", "activity" ],
"roles" : [ "sequence_start", "Activity", "sequence_end", "ActivitiesMorph", "all" ]
}, {
"type" : "node",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册