use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project drools by kiegroup.
the class DMNCompilerImpl method buildTypeDef.
private DMNType buildTypeDef(DMNCompilerContext ctx, DMNFEELHelper feel, DMNModelImpl dmnModel, DMNNode node, ItemDefinition itemDef, boolean topLevel) {
BaseDMNTypeImpl type = null;
if (itemDef.getTypeRef() != null) {
// this is a reference to an existing type, so resolve the reference
type = (BaseDMNTypeImpl) resolveTypeRef(dmnModel, node, itemDef, itemDef, itemDef.getTypeRef());
if (type != null) {
UnaryTests allowedValuesStr = itemDef.getAllowedValues();
// or if it changes the metadata for the base type
if (topLevel || allowedValuesStr != null || itemDef.isIsCollection() != type.isCollection()) {
// we have to clone this type definition into a new one
BaseDMNTypeImpl baseType = type;
type = type.clone();
type.setBaseType(baseType);
type.setNamespace(dmnModel.getNamespace());
type.setName(itemDef.getName());
type.setAllowedValues(null);
if (allowedValuesStr != null) {
List<UnaryTest> av = feel.evaluateUnaryTests(ctx, allowedValuesStr.getText(), dmnModel, itemDef, Msg.ERR_COMPILING_ALLOWED_VALUES_LIST_ON_ITEM_DEF, allowedValuesStr.getText(), node.getName());
type.setAllowedValues(av);
}
if (itemDef.isIsCollection()) {
type.setCollection(itemDef.isIsCollection());
}
}
if (topLevel) {
DMNType registered = dmnModel.getTypeRegistry().registerType(type);
if (registered != type) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, itemDef, dmnModel, null, null, Msg.DUPLICATED_ITEM_DEFINITION, itemDef.getName());
}
}
}
} else {
// this is a composite type
DMNCompilerHelper.checkVariableName(dmnModel, itemDef, itemDef.getName());
CompositeTypeImpl compType = new CompositeTypeImpl(dmnModel.getNamespace(), itemDef.getName(), itemDef.getId(), itemDef.isIsCollection());
for (ItemDefinition fieldDef : itemDef.getItemComponent()) {
DMNCompilerHelper.checkVariableName(dmnModel, fieldDef, fieldDef.getName());
DMNType fieldType = buildTypeDef(ctx, feel, dmnModel, node, fieldDef, false);
fieldType = fieldType != null ? fieldType : DMNTypeRegistry.UNKNOWN;
compType.addField(fieldDef.getName(), fieldType);
}
type = compType;
if (topLevel) {
DMNType registered = dmnModel.getTypeRegistry().registerType(type);
if (registered != type) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, itemDef, dmnModel, null, null, Msg.DUPLICATED_ITEM_DEFINITION, itemDef.getName());
}
}
}
return type;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project kie-wb-common by kiegroup.
the class DefinitionsConverter method wbFromDMN.
public static Definitions wbFromDMN(final org.kie.dmn.model.v1_1.Definitions dmn) {
if (dmn == null) {
return null;
}
Id id = new Id(dmn.getId());
Name name = new Name(dmn.getName());
String namespace = dmn.getNamespace();
Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
Definitions result = new Definitions();
result.setId(id);
result.setName(name);
result.setNamespace(namespace);
result.setDescription(description);
result.getNsContext().putAll(dmn.getNsContext());
for (org.kie.dmn.model.v1_1.ItemDefinition itemDef : dmn.getItemDefinition()) {
ItemDefinition itemDefConvered = ItemDefinitionPropertyConverter.wbFromDMN(itemDef);
result.getItemDefinition().add(itemDefConvered);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project kie-wb-common by kiegroup.
the class InputAssignmentWriter method typedefInput.
private ItemDefinition typedefInput(VariableDeclaration decl) {
ItemDefinition typeDef = bpmn2.createItemDefinition();
typeDef.setId(Ids.dataInputItem(parentId, decl.getIdentifier()));
typeDef.setStructureRef(decl.getType());
return typeDef;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition 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.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitAssociationsIoSpec.
public void revisitAssociationsIoSpec(Definitions def) {
List<RootElement> rootElements = def.getRootElements();
List<ItemDefinition> toAddItemDefinitions = new ArrayList<ItemDefinition>();
for (RootElement root : rootElements) {
if (root instanceof Process) {
setItemDefinitionsForActivitiesIoSpec((Process) root, def, toAddItemDefinitions);
}
}
for (ItemDefinition itemDef : toAddItemDefinitions) {
def.getRootElements().add(itemDef);
}
}
Aggregations