use of org.eclipse.bpmn2.Monitoring in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallDefinitions.
protected void marshallDefinitions(Definitions def, JsonGenerator generator, String preProcessingData) throws JsonGenerationException, IOException {
try {
generator.writeStartObject();
generator.writeObjectField("resourceId", def.getId());
/**
* "properties":{"name":"",
* "documentation":"",
* "auditing":"",
* "monitoring":"",
* "executable":"true",
* "package":"com.sample",
* "vardefs":"a,b,c,d",
* "lanes" : "a,b,c",
* "id":"",
* "version":"",
* "author":"",
* "language":"",
* "namespaces":"",
* "targetnamespace":"",
* "expressionlanguage":"",
* "typelanguage":"",
* "creationdate":"",
* "modificationdate":""
* }
*/
Map<String, Object> props = new LinkedHashMap<String, Object>();
props.put(NAMESPACES, "");
// props.put("targetnamespace", def.getTargetNamespace());
props.put(TARGETNAMESPACE, "http://www.omg.org/bpmn20");
props.put(TYPELANGUAGE, def.getTypeLanguage());
props.put(NAME, StringEscapeUtils.unescapeXml(def.getName()));
props.put(ID, def.getId());
props.put(EXPRESSIONLANGUAGE, def.getExpressionLanguage());
// backwards compat for BZ 1048191
putDocumentationProperty(def, props);
for (RootElement rootElement : def.getRootElements()) {
if (rootElement instanceof Process) {
// have to wait for process node to finish properties and stencil marshalling
props.put(EXECUTABLE, ((Process) rootElement).isIsExecutable() + "");
props.put(ID, rootElement.getId());
if (rootElement.getDocumentation() != null && rootElement.getDocumentation().size() > 0) {
props.put(DOCUMENTATION, rootElement.getDocumentation().get(0).getText());
}
Process pr = (Process) rootElement;
if (pr.getName() != null && pr.getName().length() > 0) {
props.put(PROCESSN, StringEscapeUtils.unescapeXml(((Process) rootElement).getName()));
}
List<Property> processProperties = ((Process) rootElement).getProperties();
if (processProperties != null && processProperties.size() > 0) {
String propVal = "";
for (int i = 0; i < processProperties.size(); i++) {
Property p = processProperties.get(i);
String pKPI = Utils.getMetaDataValue(p.getExtensionValues(), "customKPI");
propVal += p.getId();
// check the structureRef value
if (p.getItemSubjectRef() != null && p.getItemSubjectRef().getStructureRef() != null) {
propVal += ":" + p.getItemSubjectRef().getStructureRef();
}
if (pKPI != null && pKPI.length() > 0) {
propVal += ":" + pKPI;
}
if (i != processProperties.size() - 1) {
propVal += ",";
}
}
props.put("vardefs", propVal);
}
// packageName and version and adHoc are jbpm-specific extension attribute
Iterator<FeatureMap.Entry> iter = ((Process) rootElement).getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("packageName")) {
props.put(PACKAGE, entry.getValue());
}
if (entry.getEStructuralFeature().getName().equals("version")) {
props.put(VERSION, entry.getValue());
}
if (entry.getEStructuralFeature().getName().equals("adHoc")) {
props.put(ADHOCPROCESS, entry.getValue());
}
}
// process imports, custom description and globals extension elements
String allImports = "";
if ((rootElement).getExtensionValues() != null && (rootElement).getExtensionValues().size() > 0) {
String importsStr = "";
String globalsStr = "";
for (ExtensionAttributeValue extattrval : rootElement.getExtensionValues()) {
FeatureMap extensionElements = extattrval.getValue();
@SuppressWarnings("unchecked") List<ImportType> importExtensions = (List<ImportType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, true);
@SuppressWarnings("unchecked") List<GlobalType> globalExtensions = (List<GlobalType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, true);
List<MetaDataType> metadataExtensions = (List<MetaDataType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__META_DATA, true);
for (ImportType importType : importExtensions) {
importsStr += importType.getName();
importsStr += "|default,";
}
for (GlobalType globalType : globalExtensions) {
globalsStr += (globalType.getIdentifier() + ":" + globalType.getType());
globalsStr += ",";
}
for (MetaDataType metaType : metadataExtensions) {
props.put("customdescription", metaType.getMetaValue());
}
}
allImports += importsStr;
if (globalsStr.length() > 0) {
if (globalsStr.endsWith(",")) {
globalsStr = globalsStr.substring(0, globalsStr.length() - 1);
}
props.put(GLOBALS, globalsStr);
}
}
// definitions imports (wsdl)
List<org.eclipse.bpmn2.Import> wsdlImports = def.getImports();
if (wsdlImports != null) {
for (org.eclipse.bpmn2.Import imp : wsdlImports) {
allImports += imp.getLocation() + "|" + imp.getNamespace() + "|wsdl,";
}
}
if (allImports.endsWith(",")) {
allImports = allImports.substring(0, allImports.length() - 1);
}
props.put(IMPORTS, allImports);
// simulation
if (_simulationScenario != null && _simulationScenario.getScenarioParameters() != null) {
props.put(CURRENCY, _simulationScenario.getScenarioParameters().getBaseCurrencyUnit() == null ? "" : _simulationScenario.getScenarioParameters().getBaseCurrencyUnit());
props.put(TIMEUNIT, _simulationScenario.getScenarioParameters().getBaseTimeUnit().getName());
}
marshallProperties(props, generator);
marshallStencil("BPMNDiagram", generator);
linkSequenceFlows(((Process) rootElement).getFlowElements());
marshallProcess((Process) rootElement, def, generator, preProcessingData);
} else if (rootElement instanceof Interface) {
// TODO
} else if (rootElement instanceof ItemDefinition) {
// TODO
} else if (rootElement instanceof Resource) {
// TODO
} else if (rootElement instanceof Error) {
// TODO
} else if (rootElement instanceof Message) {
// TODO
} else if (rootElement instanceof Signal) {
// TODO
} else if (rootElement instanceof Escalation) {
// TODO
} else if (rootElement instanceof Collaboration) {
} else {
_logger.warn("Unknown root element " + rootElement + ". This element will not be parsed.");
}
}
generator.writeObjectFieldStart("stencilset");
generator.writeObjectField("url", this.profile.getStencilSetURL());
generator.writeObjectField("namespace", this.profile.getStencilSetNamespaceURL());
generator.writeEndObject();
generator.writeArrayFieldStart("ssextensions");
generator.writeObject(this.profile.getStencilSetExtensionURL());
generator.writeEndArray();
generator.writeEndObject();
} finally {
_diagramElements.clear();
}
}
use of org.eclipse.bpmn2.Monitoring in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyProcessProperties.
protected void applyProcessProperties(Process process, Map<String, String> properties) {
if (properties.get("processn") != null) {
process.setName(StringEscapeUtils.escapeXml(properties.get("processn")));
} else {
process.setName("");
}
if (properties.get("auditing") != null && !"".equals(properties.get("auditing"))) {
Auditing audit = Bpmn2Factory.eINSTANCE.createAuditing();
audit.getDocumentation().add(createDocumentation(properties.get("auditing")));
process.setAuditing(audit);
}
process.setProcessType(ProcessType.getByName(properties.get("processtype")));
process.setIsClosed(Boolean.parseBoolean(properties.get("isclosed")));
process.setIsExecutable(Boolean.parseBoolean(properties.get("executable")));
// get the drools-specific extension packageName attribute to Process if defined
if (properties.get("package") != null && properties.get("package").length() > 0) {
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "packageName", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("package"));
process.getAnyAttribute().add(extensionEntry);
}
// add version attrbute to process
if (properties.get("version") != null && properties.get("version").length() > 0) {
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "version", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("version"));
process.getAnyAttribute().add(extensionEntry);
}
if (properties.get("monitoring") != null && !"".equals(properties.get("monitoring"))) {
Monitoring monitoring = Bpmn2Factory.eINSTANCE.createMonitoring();
monitoring.getDocumentation().add(createDocumentation(properties.get("monitoring")));
process.setMonitoring(monitoring);
}
// import extension elements
if (properties.get("imports") != null && properties.get("imports").length() > 0) {
String[] allImports = properties.get("imports").split(",\\s*");
for (String importStr : allImports) {
String[] importParts = importStr.split("\\|\\s*");
// sample 'com.sample.Myclass|default,location|namespace|wsdl
if (importParts.length == 2 || importParts.length == 3) {
if (importParts[1] != null && importParts[1].equals("default")) {
ImportType importType = DroolsFactory.eINSTANCE.createImportType();
importType.setName(importParts[0]);
if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
process.getExtensionValues().add(extensionElement);
}
FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, importType);
process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
} else {
Import imp = Bpmn2Factory.eINSTANCE.createImport();
imp.setImportType("http://schemas.xmlsoap.org/wsdl/");
imp.setLocation(importParts[0]);
imp.setNamespace(importParts[1]);
_wsdlImports.add(imp);
}
} else {
// just default (support legacy)
ImportType importType = DroolsFactory.eINSTANCE.createImportType();
importType.setName(importStr);
if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
process.getExtensionValues().add(extensionElement);
}
FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, importType);
process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
}
}
}
// globals extension elements
if (properties.get("globals") != null && properties.get("globals").length() > 0) {
String[] allGlobals = properties.get("globals").split(",\\s*");
for (String globalStr : allGlobals) {
// identifier:type
String[] globalParts = globalStr.split(":\\s*");
if (globalParts.length == 2) {
GlobalType globalType = DroolsFactory.eINSTANCE.createGlobalType();
globalType.setIdentifier(globalParts[0]);
globalType.setType(globalParts[1]);
if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
process.getExtensionValues().add(extensionElement);
}
FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, globalType);
process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
} else if (globalParts.length == 1) {
GlobalType globalType = DroolsFactory.eINSTANCE.createGlobalType();
globalType.setIdentifier(globalParts[0]);
globalType.setType("Object");
if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
process.getExtensionValues().add(extensionElement);
}
FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, globalType);
process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
}
}
}
// simulation properties
if (properties.get("timeunit") != null && properties.get("timeunit").length() > 0) {
_simulationScenarioParameters.setBaseTimeUnit(TimeUnit.getByName(properties.get("timeunit")));
}
if (properties.get("currency") != null && properties.get("currency").length() > 0) {
_simulationScenarioParameters.setBaseCurrencyUnit(properties.get("currency"));
}
}
use of org.eclipse.bpmn2.Monitoring in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyEventProperties.
protected void applyEventProperties(Event event, Map<String, String> properties) {
if (properties.get("name") != null) {
event.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " "));
// add unescaped and untouched name value as extension element as well
Utils.setMetaDataExtensionValue(event, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n")));
} else {
event.setName("");
}
if (properties.get("auditing") != null && !"".equals(properties.get("auditing"))) {
Auditing audit = Bpmn2Factory.eINSTANCE.createAuditing();
audit.getDocumentation().add(createDocumentation(properties.get("auditing")));
event.setAuditing(audit);
}
if (properties.get("monitoring") != null && !"".equals(properties.get("monitoring"))) {
Monitoring monitoring = Bpmn2Factory.eINSTANCE.createMonitoring();
monitoring.getDocumentation().add(createDocumentation(properties.get("monitoring")));
event.setMonitoring(monitoring);
}
}
use of org.eclipse.bpmn2.Monitoring in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applySequenceFlowProperties.
protected void applySequenceFlowProperties(SequenceFlow sequenceFlow, Map<String, String> properties) {
// sequence flow name is options
if (properties.get("name") != null && !"".equals(properties.get("name"))) {
sequenceFlow.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " "));
// add unescaped and untouched name value as extension eleent as well
Utils.setMetaDataExtensionValue(sequenceFlow, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n")));
}
if (properties.get("bgcolor") != null && properties.get("bgcolor").length() > 0) {
if (!(_elementColors.containsKey(sequenceFlow.getId()))) {
List<String> colorsList = new ArrayList<String>();
colorsList.add("bgcolor:" + properties.get("bgcolor"));
_elementColors.put(sequenceFlow.getId(), colorsList);
} else {
_elementColors.get(sequenceFlow.getId()).add("bgcolor:" + properties.get("bgcolor"));
}
}
if (properties.get("bordercolor") != null && properties.get("bordercolor").length() > 0) {
if (!(_elementColors.containsKey(sequenceFlow.getId()))) {
List<String> colorsList = new ArrayList<String>();
colorsList.add("bordercolor:" + properties.get("bordercolor"));
_elementColors.put(sequenceFlow.getId(), colorsList);
} else {
_elementColors.get(sequenceFlow.getId()).add("bordercolor:" + properties.get("bordercolor"));
}
}
if (properties.get("fontsize") != null && properties.get("fontsize").length() > 0) {
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "fontsize", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("fontsize"));
sequenceFlow.getAnyAttribute().add(extensionEntry);
}
if (properties.get("fontcolor") != null && properties.get("fontcolor").length() > 0) {
if (!(_elementColors.containsKey(sequenceFlow.getId()))) {
List<String> colorsList = new ArrayList<String>();
colorsList.add("fontcolor:" + properties.get("fontcolor"));
_elementColors.put(sequenceFlow.getId(), colorsList);
} else {
_elementColors.get(sequenceFlow.getId()).add("fontcolor:" + properties.get("fontcolor"));
}
}
// Custom extended auto connection property for Stunner.
String sourceConnAutoPropertyName = Bpmn2OryxManager.MAGNET_AUTO_CONNECTION + Bpmn2OryxManager.SOURCE;
String sourceConnAutoRaw = properties.get(sourceConnAutoPropertyName);
if (null != sourceConnAutoRaw && Boolean.TRUE.equals(Boolean.parseBoolean(sourceConnAutoRaw))) {
Utils.setMetaDataExtensionValue(sequenceFlow, sourceConnAutoPropertyName, Boolean.toString(true));
}
String targetConnAutoPropertyName = Bpmn2OryxManager.MAGNET_AUTO_CONNECTION + Bpmn2OryxManager.TARGET;
String targetConnAutoRaw = properties.get(targetConnAutoPropertyName);
if (null != targetConnAutoRaw && Boolean.TRUE.equals(Boolean.parseBoolean(targetConnAutoRaw))) {
Utils.setMetaDataExtensionValue(sequenceFlow, targetConnAutoPropertyName, Boolean.toString(true));
}
if (properties.get("isselectable") != null && properties.get("isselectable").length() > 0) {
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "selectable", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("isselectable"));
sequenceFlow.getAnyAttribute().add(extensionEntry);
}
if (properties.get("auditing") != null && !"".equals(properties.get("auditing"))) {
Auditing audit = Bpmn2Factory.eINSTANCE.createAuditing();
audit.getDocumentation().add(createDocumentation(properties.get("auditing")));
sequenceFlow.setAuditing(audit);
}
applySequenceFlowCondition(sequenceFlow, properties);
if (properties.get("priority") != null && !"".equals(properties.get("priority"))) {
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl priorityElement = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "priority", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(priorityElement, properties.get("priority"));
sequenceFlow.getAnyAttribute().add(extensionEntry);
}
if (properties.get("monitoring") != null && !"".equals(properties.get("monitoring"))) {
Monitoring monitoring = Bpmn2Factory.eINSTANCE.createMonitoring();
monitoring.getDocumentation().add(createDocumentation(properties.get("monitoring")));
sequenceFlow.setMonitoring(monitoring);
}
sequenceFlow.setIsImmediate(Boolean.parseBoolean(properties.get("isimmediate")));
// simulation properties
if (properties.get("probability") != null && properties.get("probability").length() > 0) {
ControlParameters controlParams = BpsimFactory.eINSTANCE.createControlParameters();
Parameter probParam = BpsimFactory.eINSTANCE.createParameter();
FloatingParameterType probParamValueParam = BpsimFactory.eINSTANCE.createFloatingParameterType();
DecimalFormat twoDForm = new DecimalFormat("#.##");
probParamValueParam.setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("probability")))));
probParam.getParameterValue().add(probParamValueParam);
controlParams.setProbability(probParam);
if (_simulationElementParameters.containsKey(sequenceFlow.getId())) {
_simulationElementParameters.get(sequenceFlow.getId()).add(controlParams);
} else {
List<EObject> values = new ArrayList<EObject>();
values.add(controlParams);
_simulationElementParameters.put(sequenceFlow.getId(), values);
}
}
}
Aggregations