From 49d99c469c6bfc9dbeafd74ec974ee140ed6af95 Mon Sep 17 00:00:00 2001 From: Maciej Swiderski Date: Wed, 28 Mar 2012 16:50:02 +0200 Subject: [PATCH] JBPM-3575 - deadline support for user task nodes --- .../bpmn2/impl/Bpmn2JsonMarshaller.java | 162 ++++++ .../bpmn2/impl/Bpmn2JsonUnmarshaller.java | 512 +++++++++++++++++- .../bpmn2.0jbpm/stencildata/bpmn2.0jbpm.orig | 121 ++++- 3 files changed, 788 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jbpm/designer/bpmn2/impl/Bpmn2JsonMarshaller.java b/src/main/java/org/jbpm/designer/bpmn2/impl/Bpmn2JsonMarshaller.java index 9ac6c5766..044e9a8f0 100644 --- a/src/main/java/org/jbpm/designer/bpmn2/impl/Bpmn2JsonMarshaller.java +++ b/src/main/java/org/jbpm/designer/bpmn2/impl/Bpmn2JsonMarshaller.java @@ -139,6 +139,21 @@ public class Bpmn2JsonMarshaller { public static final String defaultBgColor_Activities = "#b1c2d6"; public static final String defaultBgColor_Events = "#ffffff"; + private static final String COMPONENT_SEPARATOR = "\\^"; + private static final String ELEMENT_SEPARATOR = "@"; + private static final String ATTRIBUTES_SEPARATOR = "\\|"; + private static final String ATTRIBUTES_ELEMENTS_SEPARATOR = ","; + private static final String KEY_VALUE_SEPARATOR = ":"; + private static final String[] KNOWN_KEYS = { "users", "groups", "from", + "tousers", "togroups", "replyto", "subject", "body" }; + + private static final String reasignmentItemTemplate = + "{\"reassignmentType\":\"{type}\",\"reassignmentToUsers\":\"{users}\",\"reassignmentToGroups\":\"{groups}\",\"reassignmentExpiresAt\":\"{expires}\"}"; + private static final String notificationItemTemplate = + "{\"notificationType\":\"{type}\",\"notificationToUsers\":\"{tousers}\",\"notificationToGroup\":\"{togroups}\"," + + "\"notificationExpiresAt\":\"{expires}\",\"notificationSubject\":\"{subject}\",\"notificationBody\":\"{body}\"," + + "\"notificationFrom\":\"{from}\",\"notificationReplyTo\":\"{replyto}\"}"; + private Map _diagramElements = new HashMap(); private Map _diagramAssociations = new HashMap(); private static final Logger _logger = Logger.getLogger(Bpmn2JsonMarshaller.class); @@ -1179,6 +1194,7 @@ protected void marshallTask(Task task, BPMNPlane plane, JsonGenerator generator, sb.setLength(sb.length() - 1); } properties.put("actors", sb.toString()); + } else if (task instanceof SendTask) { taskType = "Send"; SendTask st = (SendTask) task; @@ -1211,6 +1227,10 @@ protected void marshallTask(Task task, BPMNPlane plane, JsonGenerator generator, // data inputs DataInput groupDataInput = null; + DataInput reassignNotStartedDataInput = null; + DataInput reassignNotCompletedDataInput = null; + DataInput notifyNotStartedDataInput = null; + DataInput notifyNotCompletedDataInput = null; if(task.getIoSpecification() != null) { List inputSetList = task.getIoSpecification().getInputSets(); StringBuilder dataInBuffer = new StringBuilder(); @@ -1228,6 +1248,22 @@ protected void marshallTask(Task task, BPMNPlane plane, JsonGenerator generator, if(dataIn.getName() != null && dataIn.getName().equals("GroupId")) { groupDataInput = dataIn; } + + if(dataIn.getName() != null && dataIn.getName().equals("NotStartedReassign")) { + reassignNotStartedDataInput = dataIn; + } + + if(dataIn.getName() != null && dataIn.getName().equals("NotCompletedReassign")) { + reassignNotCompletedDataInput = dataIn; + } + + if(dataIn.getName() != null && dataIn.getName().equals("NotStartedNotify")) { + notifyNotStartedDataInput = dataIn; + } + + if(dataIn.getName() != null && dataIn.getName().equals("NotCompletedNotify")) { + notifyNotCompletedDataInput = dataIn; + } } } if(dataInBuffer.length() > 0) { @@ -1262,6 +1298,11 @@ protected void marshallTask(Task task, BPMNPlane plane, JsonGenerator generator, List outputAssociations = task.getDataOutputAssociations(); List uniDirectionalAssociations = new ArrayList(); //List biDirectionalAssociations = new ArrayList(); + StringBuffer reassignments = new StringBuffer(); + int reassignCounter = 0; + + StringBuffer notifications = new StringBuffer(); + int notifyCounter = 0; for(DataInputAssociation datain : inputAssociations) { String lhsAssociation = ""; @@ -1310,6 +1351,59 @@ protected void marshallTask(Task task, BPMNPlane plane, JsonGenerator generator, ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody().equals(groupDataInput.getId())) { properties.put("groupid", ((FormalExpression) datain.getAssignment().get(0).getFrom()).getBody()); } + + if (reassignNotStartedDataInput != null && datain.getAssignment().get(0).getTo() != null && + ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody() != null && + ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody().equals(reassignNotStartedDataInput.getId())) { + + if (reassignments.length() > 0) { + reassignments.append(","); + } + String[] value = buildComplexEditorJsonString(((FormalExpression) datain.getAssignment().get(0).getFrom()).getBody(), "not-started", reasignmentItemTemplate); + if (value != null && value.length == 2) { + reassignments.append(value[0]); + reassignCounter += Integer.parseInt(value[1]); + } + } + if (reassignNotCompletedDataInput != null && datain.getAssignment().get(0).getTo() != null && + ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody() != null && + ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody().equals(reassignNotCompletedDataInput.getId())) { + if (reassignments.length() > 0) { + reassignments.append(","); + } + String[] value = buildComplexEditorJsonString(((FormalExpression) datain.getAssignment().get(0).getFrom()).getBody(), "not-completed", reasignmentItemTemplate); + if (value != null && value.length == 2) { + reassignments.append(value[0]); + reassignCounter += Integer.parseInt(value[1]); + } + } + + if (notifyNotStartedDataInput != null && datain.getAssignment().get(0).getTo() != null && + ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody() != null && + ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody().equals(notifyNotStartedDataInput.getId())) { + + if (notifications.length() > 0) { + notifications.append(","); + } + String[] value = buildComplexEditorJsonString(((FormalExpression) datain.getAssignment().get(0).getFrom()).getBody(), "not-started", notificationItemTemplate); + if (value != null && value.length == 2) { + notifications.append(value[0]); + notifyCounter += Integer.parseInt(value[1]); + } + } + if (notifyNotCompletedDataInput != null && datain.getAssignment().get(0).getTo() != null && + ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody() != null && + ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody().equals(notifyNotCompletedDataInput.getId())) { + if (notifications.length() > 0) { + notifications.append(","); + } + String[] value = buildComplexEditorJsonString(((FormalExpression) datain.getAssignment().get(0).getFrom()).getBody(), "not-completed", notificationItemTemplate); + if (value != null && value.length == 2) { + notifications.append(value[0]); + notifyCounter += Integer.parseInt(value[1]); + } + } + } } // else if(isBiDirectional) { @@ -1323,7 +1417,15 @@ protected void marshallTask(Task task, BPMNPlane plane, JsonGenerator generator, uniDirectionalAssociations.add(lhsAssociation + "," + rhsAssociation); } } + if (reassignCounter > 0) { + String value = buildWrapInJsonString(reassignments.toString(), reassignCounter + ""); + properties.put("reassignments", value); + } + if (notifyCounter > 0) { + String value = buildWrapInJsonString(notifications.toString(), notifyCounter + ""); + properties.put("notifications", value); + } for(DataOutputAssociation dataout : outputAssociations) { if(dataout.getSourceRef().size() > 0) { String lhsAssociation = ((DataOutput) dataout.getSourceRef().get(0)).getName(); @@ -2248,4 +2350,64 @@ private boolean isCustomElement(String taskType, String preProcessingData) { return false; } + private String[] buildComplexEditorJsonString(String reassignmentString, String type, String itemTemplate) { + + + if (reassignmentString == null) { + + return null; + } + + int counter = 0; + StringBuffer items = new StringBuffer(); + String[] components = reassignmentString.split(COMPONENT_SEPARATOR); + + for (String component : components) { + if (items.length() > 0) { + items.append(","); + } + counter++; + + String[] elements = component.split(ELEMENT_SEPARATOR); + String actionComponent = elements[0].substring(1, elements[0].length()-1); + String expireComponents = elements[1].substring(1, elements[1].length()-1); + + String item = itemTemplate.replaceAll("\\{expires\\}", expireComponents); + item = item.replaceAll("\\{type\\}", type); + String[] attributes = actionComponent.split(ATTRIBUTES_SEPARATOR); + + for (String attribute : attributes) { + for (String knownKey : KNOWN_KEYS) { + + if (attribute.startsWith(knownKey)) { + String value = null; + try { + + value = attribute.substring(knownKey.length() + KEY_VALUE_SEPARATOR.length()); + } catch (IndexOutOfBoundsException e) { + + value = ""; + + } + item = item.replaceAll("\\{"+knownKey+"\\}", value); + } + } + } + items.append(item); + } + String[] result = {items.toString(), counter+""}; + return result; + + } + + private String buildWrapInJsonString(String reassignmentString, String counter) { + String jsonTemplate = "{\"totalCount\":{0},\"items\":[{1}]}"; + + String jsonString = jsonTemplate.replaceAll("\\{0\\}", counter); + jsonString = jsonString.replaceAll("\\{1\\}", reassignmentString); + + return jsonString; + + } + } diff --git a/src/main/java/org/jbpm/designer/bpmn2/impl/Bpmn2JsonUnmarshaller.java b/src/main/java/org/jbpm/designer/bpmn2/impl/Bpmn2JsonUnmarshaller.java index 3bb7cb625..76c1490cf 100644 --- a/src/main/java/org/jbpm/designer/bpmn2/impl/Bpmn2JsonUnmarshaller.java +++ b/src/main/java/org/jbpm/designer/bpmn2/impl/Bpmn2JsonUnmarshaller.java @@ -175,6 +175,22 @@ public class Bpmn2JsonUnmarshaller { private Map _messages = new HashMap(); private Map _itemDefinitions = new HashMap(); + public static final String reassignmentExpressionTemplate = "[users:{0}|groups:{1}]@[{2}]"; + public static final String reassignmentExpiresAtKey = "reassignmentExpiresAt"; + public static final String reassignmentTypeKey = "reassignmentType"; + public static final String reassignmentToUsersKey = "reassignmentToUsers"; + public static final String reassignmentToGroupsKey = "reassignmentToGroups"; + + public static final String notificationExpressionTemplate = "[from:{0}|tousers:{1}|togroups:{2}|replyto:{3}|subject:{4}|body:{5}]@[{6}]"; + public static final String notificationExpiresAtKey = "notificationExpiresAt"; + public static final String notificationTypeKey = "notificationType"; + public static final String notificationToUsersKey = "notificationToUsers"; + public static final String notificationToGroupsKey = "notificationToGroup"; + public static final String notificationSubjectKey = "notificationSubject"; + public static final String notificationBodyKey = "notificationBody"; + public static final String notificationFromKey = "notificationFrom"; + public static final String notificationReplyToKey = "notificationReplyTo"; + public Bpmn2JsonUnmarshaller() { _helpers = new ArrayList(); DroolsPackageImpl.init(); @@ -3572,8 +3588,437 @@ protected void applyUserTaskProperties(UserTask task, Map proper task.getDataInputAssociations().add(dia); } } + + if(properties.get("reassignmentExpiresAt") != null && properties.get("reassignmentExpiresAt").length() > 0) { + + + if(task.getIoSpecification() == null) { + InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification(); + task.setIoSpecification(iospec); + } + List dataInputs = task.getIoSpecification().getDataInputs(); + boolean foundReassignNotStartedInput = false; + boolean foundReassignNotCompletedInput = false; + DataInput foundInputS = null; + DataInput foundInputC = null; + for(DataInput din : dataInputs) { + if(din.getName().equals("NotStartedReassign")) { + foundReassignNotStartedInput = true; + foundInputS = din; + + } else if(din.getName().equals("NotCompletedReassign")) { + foundReassignNotCompletedInput = true; + foundInputC = din; + } + if (foundReassignNotStartedInput && foundReassignNotCompletedInput) { + break; + } + } + + String reassignmentExpressionNotStarted = buildReassignmentExpression(properties, 0); + String reassignmentExpressionNotCompleted = buildReassignmentExpression(properties, 1); + + + // process not started reassignments + if(!foundReassignNotStartedInput) { + DataInput d = Bpmn2Factory.eINSTANCE.createDataInput(); + d.setId(task.getId() + "_" + "NotStartedReassign" + "Input"); + d.setName("NotStartedReassign"); + task.getIoSpecification().getDataInputs().add(d); + foundInputS = d; + + if(task.getIoSpecification().getInputSets() == null || task.getIoSpecification().getInputSets().size() < 1) { + InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet(); + task.getIoSpecification().getInputSets().add(inset); + } + task.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(d); + } + boolean foundReassignNotStartedAssociation = false; + List inputAssociations = task.getDataInputAssociations(); + for(DataInputAssociation da : inputAssociations) { + if(da.getTargetRef().getId().equals(foundInputS.getId())) { + foundReassignNotStartedAssociation = true; + + ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(reassignmentExpressionNotStarted); + } + } + + if(!foundReassignNotStartedAssociation) { + DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation(); + dia.setTargetRef(foundInputS); + + Assignment a = Bpmn2Factory.eINSTANCE.createAssignment(); + FormalExpression reassignNotStartedFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression(); + + reassignNotStartedFromExpression.setBody(reassignmentExpressionNotStarted); + + FormalExpression reassignNotStartedToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression(); + reassignNotStartedToExpression.setBody(foundInputS.getId()); + + a.setFrom(reassignNotStartedFromExpression); + a.setTo(reassignNotStartedToExpression); + + dia.getAssignment().add(a); + task.getDataInputAssociations().add(dia); + } + + // process not completed reassignments + if(!foundReassignNotCompletedInput) { + DataInput d = Bpmn2Factory.eINSTANCE.createDataInput(); + d.setId(task.getId() + "_" + "NotCompletedReassign" + "Input"); + d.setName("NotCompletedReassign"); + task.getIoSpecification().getDataInputs().add(d); + foundInputC = d; + + if(task.getIoSpecification().getInputSets() == null || task.getIoSpecification().getInputSets().size() < 1) { + InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet(); + task.getIoSpecification().getInputSets().add(inset); + } + task.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(d); + } + boolean foundReassignNotCompletedAssociation = false; + inputAssociations = task.getDataInputAssociations(); + for(DataInputAssociation da : inputAssociations) { + if(da.getTargetRef().getId().equals(foundInputC.getId())) { + foundReassignNotCompletedAssociation = true; + + ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(reassignmentExpressionNotCompleted); + } + } + + if(!foundReassignNotCompletedAssociation) { + DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation(); + dia.setTargetRef(foundInputC); + + Assignment a = Bpmn2Factory.eINSTANCE.createAssignment(); + FormalExpression reassignNotCompletedFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression(); + + reassignNotCompletedFromExpression.setBody(reassignmentExpressionNotCompleted); + + FormalExpression reassignNotCompletedToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression(); + reassignNotCompletedToExpression.setBody(foundInputC.getId()); + + a.setFrom(reassignNotCompletedFromExpression); + a.setTo(reassignNotCompletedToExpression); + + dia.getAssignment().add(a); + task.getDataInputAssociations().add(dia); + } + + + } else { + // reset since there is no reassignment + if (task.getIoSpecification() != null) { + List dataInputs = task.getIoSpecification().getDataInputs(); + + boolean foundReassignNotStartedInput = false; + boolean foundReassignNotCompletedInput = false; + DataInput notStartedfoundInput = null; + DataInput notCompletedfoundInput = null; + for(DataInput din : dataInputs) { + if(din.getName().equals("NotStartedReassign")) { + foundReassignNotStartedInput = true; + notStartedfoundInput = din; + + } else if(din.getName().equals("NotCompletedReassign")) { + foundReassignNotCompletedInput = true; + notCompletedfoundInput = din; + + } + + if (foundReassignNotStartedInput && foundReassignNotCompletedInput) { + break; + } + } + List inputAssociations = task.getDataInputAssociations(); + if (foundReassignNotStartedInput) { + for(DataInputAssociation da : inputAssociations) { + if(da.getTargetRef().getId().equals(notStartedfoundInput.getId())) { + + ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(""); + } + } + } + + if (foundReassignNotCompletedInput) { + for(DataInputAssociation da : inputAssociations) { + if(da.getTargetRef().getId().equals(notCompletedfoundInput.getId())) { + + ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(""); + } + } + } + + } + } + + if(properties.get("notificationExpiresAt") != null && properties.get("notificationExpiresAt").length() > 0) { + System.out.println("notifications are defined as follows " + properties.get("notificationExpiresAt")); + System.out.println("notifications are defined as follows " + properties.get("notificationType")); + System.out.println("notifications are defined as follows " + properties.get("notificationToUsers")); + System.out.println("notifications are defined as follows " + properties.get("notificationToGroup")); + System.out.println("notifications are defined as follows " + properties.get("notificationSubject")); + System.out.println("notifications are defined as follows " + properties.get("notificationBody")); + + if(task.getIoSpecification() == null) { + InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification(); + task.setIoSpecification(iospec); + } + List dataInputs = task.getIoSpecification().getDataInputs(); + boolean foundNotifyNotStartedInput = false; + boolean foundNotifyNotCompletedInput = false; + DataInput foundInputS = null; + DataInput foundInputC = null; + for(DataInput din : dataInputs) { + if(din.getName().equals("NotStartedNotify")) { + foundNotifyNotStartedInput = true; + foundInputS = din; + + } else if(din.getName().equals("NotCompletedNotify")) { + foundNotifyNotCompletedInput = true; + foundInputC = din; + } + if (foundNotifyNotStartedInput && foundNotifyNotCompletedInput) { + break; + } + } + + String notificationExpressionNotStarted = buildNotificationExpression(properties, 0); + String notificationExpressionNotCompleted = buildNotificationExpression(properties, 1); + + + // process not started reassignments + if(!foundNotifyNotStartedInput) { + DataInput d = Bpmn2Factory.eINSTANCE.createDataInput(); + d.setId(task.getId() + "_" + "NotStartedNotify" + "Input"); + d.setName("NotStartedNotify"); + task.getIoSpecification().getDataInputs().add(d); + foundInputS = d; + + if(task.getIoSpecification().getInputSets() == null || task.getIoSpecification().getInputSets().size() < 1) { + InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet(); + task.getIoSpecification().getInputSets().add(inset); + } + task.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(d); + } + boolean foundNotifyNotStartedAssociation = false; + List inputAssociations = task.getDataInputAssociations(); + for(DataInputAssociation da : inputAssociations) { + if(da.getTargetRef().getId().equals(foundInputS.getId())) { + foundNotifyNotStartedAssociation = true; + + ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(notificationExpressionNotStarted); + } + } + + if(!foundNotifyNotStartedAssociation) { + DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation(); + dia.setTargetRef(foundInputS); + + Assignment a = Bpmn2Factory.eINSTANCE.createAssignment(); + FormalExpression notifyNotStartedFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression(); + + notifyNotStartedFromExpression.setBody(notificationExpressionNotStarted); + + FormalExpression notifyNotStartedToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression(); + notifyNotStartedToExpression.setBody(foundInputS.getId()); + + a.setFrom(notifyNotStartedFromExpression); + a.setTo(notifyNotStartedToExpression); + + dia.getAssignment().add(a); + task.getDataInputAssociations().add(dia); + } + + // process not completed reassignments + if(!foundNotifyNotCompletedInput) { + DataInput d = Bpmn2Factory.eINSTANCE.createDataInput(); + d.setId(task.getId() + "_" + "NotCompletedNotify" + "Input"); + d.setName("NotCompletedNotify"); + task.getIoSpecification().getDataInputs().add(d); + foundInputC = d; + + if(task.getIoSpecification().getInputSets() == null || task.getIoSpecification().getInputSets().size() < 1) { + InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet(); + task.getIoSpecification().getInputSets().add(inset); + } + task.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(d); + } + boolean foundNotifyNotCompletedAssociation = false; + inputAssociations = task.getDataInputAssociations(); + for(DataInputAssociation da : inputAssociations) { + if(da.getTargetRef().getId().equals(foundInputC.getId())) { + foundNotifyNotCompletedAssociation = true; + + ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(notificationExpressionNotCompleted); + } + } + + if(!foundNotifyNotCompletedAssociation) { + DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation(); + dia.setTargetRef(foundInputC); + + Assignment a = Bpmn2Factory.eINSTANCE.createAssignment(); + FormalExpression notifyNotCompletedFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression(); + + notifyNotCompletedFromExpression.setBody(notificationExpressionNotCompleted); + + FormalExpression notifyNotCompletedToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression(); + notifyNotCompletedToExpression.setBody(foundInputC.getId()); + + a.setFrom(notifyNotCompletedFromExpression); + a.setTo(notifyNotCompletedToExpression); + + dia.getAssignment().add(a); + task.getDataInputAssociations().add(dia); + } + + + } else { + // reset since there is no reassignment + if (task.getIoSpecification() != null) { + List dataInputs = task.getIoSpecification().getDataInputs(); + + boolean foundNotifyNotStartedInput = false; + boolean foundNotifyNotCompletedInput = false; + DataInput notStartedfoundInput = null; + DataInput notCompletedfoundInput = null; + for(DataInput din : dataInputs) { + if(din.getName().equals("NotStartedNotify")) { + foundNotifyNotStartedInput = true; + notStartedfoundInput = din; + + } else if(din.getName().equals("NotCompletedNotify")) { + foundNotifyNotCompletedInput = true; + notCompletedfoundInput = din; + + } + + if (foundNotifyNotStartedInput && foundNotifyNotCompletedInput) { + break; + } + } + List inputAssociations = task.getDataInputAssociations(); + if (foundNotifyNotStartedInput) { + for(DataInputAssociation da : inputAssociations) { + if(da.getTargetRef().getId().equals(notStartedfoundInput.getId())) { + + ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(""); + } + } + } + + if (foundNotifyNotCompletedInput) { + for(DataInputAssociation da : inputAssociations) { + if(da.getTargetRef().getId().equals(notCompletedfoundInput.getId())) { + + ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(""); + } + } + } + + } + } + } + + private String buildReassignmentExpression(Map properties, int type) { + //[users:john|groups:sales]@[4h] + + StringBuffer expressions = new StringBuffer(); + + if (type == 0 && "not-started".equalsIgnoreCase(properties.get(reassignmentTypeKey))) { + + expressions.append(processReassignTemplate(reassignmentExpressionTemplate, properties, "")); + } else if (type == 1 && "not-completed".equalsIgnoreCase(properties.get(reassignmentTypeKey))) { + expressions.append(processReassignTemplate(reassignmentExpressionTemplate, properties, "")); + } + // process indexed properties + for (int index = 1; index < 100; index++) { + if (properties.get(reassignmentExpiresAtKey+index) != null) { + + if (type == 0 && "not-started".equalsIgnoreCase(properties.get(reassignmentTypeKey+index))) { + if (expressions.length() > 0) { + expressions.append("^"); + } + expressions.append(processReassignTemplate(reassignmentExpressionTemplate, properties, index+"")); + } else if (type == 1 && "not-completed".equalsIgnoreCase(properties.get(reassignmentTypeKey+index))) { + if (expressions.length() > 0) { + expressions.append("^"); + } + expressions.append(processReassignTemplate(reassignmentExpressionTemplate, properties, index+"")); + } + } else { + break; + } + + } + + return expressions.toString(); + } + + private String buildNotificationExpression(Map properties, int type) { + //[from:mike|tousers:john,mary|togroups:sales,hr|replyto:mike|subject:Test of notification|body:And here is the body]@[4h]" + + StringBuffer expressions = new StringBuffer(); + + if (type == 0 && "not-started".equalsIgnoreCase(properties.get(notificationTypeKey))) { + + expressions.append(processNotifyTemplate(notificationExpressionTemplate, properties, "")); + } else if (type == 1 && "not-completed".equalsIgnoreCase(properties.get(notificationTypeKey))) { + expressions.append(processNotifyTemplate(notificationExpressionTemplate, properties, "")); + } + // process indexed properties + for (int index = 1; index < 100; index++) { + if (properties.get(notificationExpiresAtKey+index) != null) { + + if (type == 0 && "not-started".equalsIgnoreCase(properties.get(notificationTypeKey+index))) { + if (expressions.length() > 0) { + expressions.append("^"); + } + expressions.append(processNotifyTemplate(notificationExpressionTemplate, properties, index+"")); + } else if (type == 1 && "not-completed".equalsIgnoreCase(properties.get(notificationTypeKey+index))) { + if (expressions.length() > 0) { + expressions.append("^"); + } + expressions.append(processNotifyTemplate(notificationExpressionTemplate, properties, index+"")); + } + } else { + break; + } + + } + + return expressions.toString(); + } + + private String processReassignTemplate(String expressionTemplate, Map properties, String index) { + String expression = expressionTemplate.replaceAll("\\{0\\}", properties.get(reassignmentToUsersKey+index)); + expression = expression.replaceAll("\\{1\\}", properties.get(reassignmentToGroupsKey+index)); + expression = expression.replaceAll("\\{2\\}", properties.get(reassignmentExpiresAtKey+index)); + + return expression; + } + + private String processNotifyTemplate(String expressionTemplate, Map properties, String index) { + String expression = expressionTemplate.replaceAll("\\{0\\}", defaultValue(properties.get(notificationFromKey+index), "")); + expression = expression.replaceAll("\\{1\\}", defaultValue(properties.get(notificationToUsersKey+index), "")); + expression = expression.replaceAll("\\{2\\}", defaultValue(properties.get(notificationToGroupsKey+index), "")); + expression = expression.replaceAll("\\{3\\}", defaultValue(properties.get(notificationReplyToKey+index), "")); + expression = expression.replaceAll("\\{4\\}", defaultValue(properties.get(notificationSubjectKey+index), "")); + expression = expression.replaceAll("\\{5\\}", defaultValue(properties.get(notificationBodyKey+index), "")); + expression = expression.replaceAll("\\{6\\}", defaultValue(properties.get(notificationExpiresAtKey+index), "")); + + return expression; } + private String defaultValue(String value, String defaultValue) { + if (value == null) { + return defaultValue; + } + + return value; + } + protected void applyGatewayProperties(Gateway gateway, Map properties) { if(properties.get("name") != null && properties.get("name").length() > 0) { gateway.setName(properties.get("name")); @@ -3640,11 +4085,12 @@ protected void applySequenceFlowProperties(SequenceFlow sequenceFlow, Map unmarshallProperties(JsonParser parser) throws JsonParseException, IOException { Map properties = new HashMap(); - while (parser.nextToken() != JsonToken.END_OBJECT) { - String fieldname = parser.getCurrentName(); - parser.nextToken(); - properties.put(fieldname, parser.getText()); - } +// while (parser.nextToken() != JsonToken.END_OBJECT) { +// String fieldname = parser.getCurrentName(); +// parser.nextToken(); +// properties.put(fieldname, parser.getText()); +// } + parseObject(parser, properties, 0); return properties; } @@ -3673,5 +4119,61 @@ protected BaseElement createBaseElement(String stencil, String taskType, boolean protected String wrapInCDATABlock(String value) { return ""; } + + private void parseObject(JsonParser parser, Map properties, int counter) throws JsonParseException, IOException { + JsonToken token = parser.nextToken(); + int index = counter; + while (token != JsonToken.END_OBJECT && token != null) { + String fieldname = null; + if (token == JsonToken.FIELD_NAME) { + fieldname = parser.getCurrentName(); + token = parser.nextToken(); + } + + if (token == JsonToken.VALUE_STRING || token == JsonToken.VALUE_NUMBER_INT) { + + if (index > 0) { + properties.put(fieldname + index, parser.getText()); + } else { + properties.put(fieldname, parser.getText()); + } + } else if (token == JsonToken.START_ARRAY) { + parseArray(parser, properties, index); + + } else if (token == JsonToken.START_OBJECT) { + parseObject(parser, properties, index); + + } + token = parser.nextToken(); + } + } + + private void parseArray(JsonParser parser, Map properties, int counter) throws JsonParseException, IOException { + JsonToken token = parser.nextToken(); + String fieldname = null; + int index = counter; + while (token != JsonToken.END_ARRAY && token != null) { + + if (token == JsonToken.FIELD_NAME) { + fieldname = parser.getCurrentName(); + token = parser.nextToken(); + } + if (token == JsonToken.VALUE_STRING || token == JsonToken.VALUE_NUMBER_INT) { + if (index > 0) { + properties.put(fieldname + index, parser.getText()); + } else { + properties.put(fieldname, parser.getText()); + } + } else if (token == JsonToken.START_ARRAY) { + parseArray(parser, properties, index); + + } else if (token == JsonToken.START_OBJECT) { + + parseObject(parser, properties, index); + index++; + } + token = parser.nextToken(); + } + } } diff --git a/src/main/webapp/stencilsets/bpmn2.0jbpm/stencildata/bpmn2.0jbpm.orig b/src/main/webapp/stencilsets/bpmn2.0jbpm/stencildata/bpmn2.0jbpm.orig index a2d52689e..4e0ae90b5 100644 --- a/src/main/webapp/stencilsets/bpmn2.0jbpm/stencildata/bpmn2.0jbpm.orig +++ b/src/main/webapp/stencilsets/bpmn2.0jbpm/stencildata/bpmn2.0jbpm.orig @@ -136,7 +136,18 @@ "optional":true, "length":"", "wrapLines":true - } + }, + { + "id":"htdeadline", + "type":"Htdeadline", + "title":"Htdeadline", + "value":"", + "description":"Reasignment", + "readonly":false, + "optional":true, + "length":"", + "wrapLines":true + } /**, { "id":"outputset", @@ -2568,7 +2579,113 @@ "description":"Group id value.", "readonly":false, "optional":true - } + }, + { + "id":"reassignments", + "type":"Complex", + "title":"Reassignments", + "value":"", + "description":"", + "readonly":false, + "optional":true, + "complexItems": [ + { + "id":"reassignmentType", + "name":"Trigger when", + "type":"String", + "value":"", + "width":100, + "optional":false + }, + { + "id":"reassignmentToUsers", + "name":"To users", + "type":"String", + "value":"", + "width":100, + "optional":true + }, + { + "id":"reassignmentToGroups", + "name":"To Groups", + "type":"String", + "value":"", + "width":100, + "optional":true + } + , + { + "id":"reassignmentExpiresAt", + "name":"Expires At", + "type":"String", + "value":"", + "width":100, + "optional":false + } + ] + }, + { + "id":"notifications", + "type":"Complex", + "title":"Notifications", + "value":"", + "description":"", + "readonly":false, + "optional":true, + "complexItems": [ + { + "id":"notificationType", + "name":"Trigger when", + "type":"String", + "value":"", + "width":100, + "optional":false + }, + { + "id":"notificationToUsers", + "name":"To Users", + "type":"String", + "value":"", + "width":100, + "optional":true + }, + { + "id":"notificationToGroup", + "name":"To Groups", + "type":"String", + "value":"", + "width":100, + "optional":true + } + , + { + "id":"notificationExpiresAt", + "name":"Expires At", + "type":"String", + "value":"", + "width":100, + "optional":false + } + , + { + "id":"notificationSubject", + "name":"Subject", + "type":"String", + "value":"", + "width":100, + "optional":true + } + , + { + "id":"notificationBody", + "name":"Body", + "type":"String", + "value":"", + "width":100, + "optional":true + } + ] + } ] },