Search in sources :

Example 1 with DMNElement

use of org.kie.dmn.model.v1_1.DMNElement in project drools by kiegroup.

the class XStreamMarshaller method newXStream.

private XStream newXStream() {
    XStream xStream = XStreamUtils.createNonTrustingXStream(staxDriver, Definitions.class.getClassLoader(), DMNXStream::from);
    xStream.addPermission(new TypeHierarchyPermission(QName.class));
    xStream.addPermission(new TypeHierarchyPermission(KieDMNModelInstrumentedBase.class));
    xStream.alias("artifact", TArtifact.class);
    xStream.alias("definitions", TDefinitions.class);
    xStream.alias("inputData", TInputData.class);
    xStream.alias("decision", TDecision.class);
    xStream.alias("variable", TInformationItem.class);
    xStream.alias("informationRequirement", TInformationRequirement.class);
    xStream.alias("requiredInput", TDMNElementReference.class);
    xStream.alias("literalExpression", TLiteralExpression.class);
    // TODO will need to remove dups and find missing element not captured?
    xStream.alias("DMNElement", TDMNElement.class);
    xStream.alias("allowedValues", TUnaryTests.class);
    xStream.alias("artifact", TArtifact.class);
    xStream.alias("association", TAssociation.class);
    xStream.alias("authorityRequirement", TAuthorityRequirement.class);
    xStream.alias("authorityRequirement", TAuthorityRequirement.class);
    xStream.alias("authorityRequirement", TAuthorityRequirement.class);
    xStream.alias("binding", TBinding.class);
    xStream.alias("businessContextElement", TBusinessContextElement.class);
    xStream.alias("businessKnowledgeModel", TBusinessKnowledgeModel.class);
    xStream.alias("column", TInformationItem.class);
    xStream.alias("context", TContext.class);
    xStream.alias("contextEntry", TContextEntry.class);
    xStream.alias("decision", TDecision.class);
    xStream.alias("decisionMade", TDMNElementReference.class);
    xStream.alias("decisionMaker", TDMNElementReference.class);
    xStream.alias("decisionOwned", TDMNElementReference.class);
    xStream.alias("decisionOwner", TDMNElementReference.class);
    xStream.alias("decisionService", TDecisionService.class);
    xStream.alias("decisionTable", TDecisionTable.class);
    xStream.alias("defaultOutputEntry", TLiteralExpression.class);
    xStream.alias("definitions", TDefinitions.class);
    xStream.alias("drgElement", TDMNElementReference.class);
    // xStream.alias("drgElement", DRGElement.class ); ambiguity, also referring to top-level xsd element just under xsd root.
    xStream.alias("elementCollection", TElementCollection.class);
    xStream.alias("elementCollection", TElementCollection.class);
    xStream.alias("encapsulatedDecision", TDMNElementReference.class);
    xStream.alias("encapsulatedLogic", TFunctionDefinition.class);
    xStream.alias("expression", TExpression.class);
    xStream.alias("formalParameter", TInformationItem.class);
    xStream.alias("functionDefinition", TFunctionDefinition.class);
    xStream.alias("impactedPerformanceIndicator", TDMNElementReference.class);
    xStream.alias("impactingDecision", TDMNElementReference.class);
    xStream.alias("import", TImport.class);
    xStream.alias("import", TImport.class);
    // TODO where?
    xStream.alias("importedElement", String.class);
    xStream.alias("importedValues", TImportedValues.class);
    xStream.alias("informationItem", TInformationItem.class);
    xStream.alias("informationRequirement", TInformationRequirement.class);
    xStream.alias("input", TInputClause.class);
    xStream.alias("inputData", TDMNElementReference.class);
    xStream.alias("inputData", TInputData.class);
    xStream.alias("inputDecision", TDMNElementReference.class);
    xStream.alias("inputEntry", TUnaryTests.class);
    xStream.alias("inputExpression", TLiteralExpression.class);
    xStream.alias("inputValues", TUnaryTests.class);
    xStream.alias("invocation", TInvocation.class);
    xStream.alias("itemComponent", TItemDefinition.class);
    xStream.alias("itemDefinition", TItemDefinition.class);
    xStream.alias("itemDefinition", TItemDefinition.class);
    xStream.alias("knowledgeRequirement", TKnowledgeRequirement.class);
    xStream.alias("knowledgeRequirement", TKnowledgeRequirement.class);
    xStream.alias("knowledgeSource", TKnowledgeSource.class);
    xStream.alias("literalExpression", TLiteralExpression.class);
    xStream.alias("namedElement", TNamedElement.class);
    xStream.alias("organizationUnit", TOrganizationUnit.class);
    xStream.alias("output", TOutputClause.class);
    xStream.alias("outputDecision", TDMNElementReference.class);
    xStream.alias("outputEntry", TLiteralExpression.class);
    xStream.alias("outputValues", TUnaryTests.class);
    xStream.alias("owner", TDMNElementReference.class);
    xStream.alias("parameter", TInformationItem.class);
    xStream.alias("performanceIndicator", TPerformanceIndicator.class);
    xStream.alias("relation", TRelation.class);
    xStream.alias("requiredAuthority", TDMNElementReference.class);
    xStream.alias("requiredDecision", TDMNElementReference.class);
    xStream.alias("requiredDecision", TDMNElementReference.class);
    xStream.alias("requiredInput", TDMNElementReference.class);
    xStream.alias("requiredInput", TDMNElementReference.class);
    xStream.alias("requiredKnowledge", TDMNElementReference.class);
    xStream.alias("rule", TDecisionRule.class);
    xStream.alias("sourceRef", TDMNElementReference.class);
    xStream.alias("supportedObjective", TDMNElementReference.class);
    xStream.alias("targetRef", TDMNElementReference.class);
    xStream.alias("textAnnotation", TTextAnnotation.class);
    // TODO where?
    xStream.alias("type", String.class);
    xStream.alias("typeRef", QName.class);
    xStream.alias("usingProcess", TDMNElementReference.class);
    xStream.alias("usingTask", TDMNElementReference.class);
    xStream.alias("variable", TInformationItem.class);
    xStream.alias("variable", TInformationItem.class);
    xStream.alias("variable", TInformationItem.class);
    xStream.alias("variable", TInformationItem.class);
    // xStream.alias("allowedAnswers", xsd:string.class );
    // xStream.alias("description", xsd:string.class );
    // xStream.alias("question", xsd:string.class );
    // xStream.alias("text", xsd:string.class );
    // xStream.alias("text", xsd:string.class );
    // xStream.alias("text", xsd:string.class );
    xStream.alias("row", org.kie.dmn.model.v1_1.TList.class);
    xStream.alias("list", org.kie.dmn.model.v1_1.TList.class);
    xStream.alias("extensionElements", TDMNElement.TExtensionElements.class);
    // Manually imported TEXT = String
    xStream.alias(LiteralExpressionConverter.TEXT, String.class);
    xStream.alias(TextAnnotationConverter.TEXT, String.class);
    xStream.alias(UnaryTestsConverter.TEXT, String.class);
    xStream.alias(DecisionConverter.QUESTION, String.class);
    xStream.alias(DecisionConverter.ALLOWED_ANSWERS, String.class);
    xStream.alias(DMNElementConverter.DESCRIPTION, String.class);
    xStream.registerConverter(new AssociationConverter(xStream));
    xStream.registerConverter(new AuthorityRequirementConverter(xStream));
    xStream.registerConverter(new BindingConverter(xStream));
    xStream.registerConverter(new BusinessKnowledgeModelConverter(xStream));
    xStream.registerConverter(new ContextConverter(xStream));
    xStream.registerConverter(new ContextEntryConverter(xStream));
    xStream.registerConverter(new DecisionConverter(xStream));
    xStream.registerConverter(new DecisionRuleConverter(xStream));
    xStream.registerConverter(new DecisionServiceConverter(xStream));
    xStream.registerConverter(new DecisionTableConverter(xStream));
    xStream.registerConverter(new DefinitionsConverter(xStream));
    xStream.registerConverter(new DMNElementReferenceConverter(xStream));
    xStream.registerConverter(new FunctionDefinitionConverter(xStream));
    xStream.registerConverter(new ImportConverter(xStream));
    xStream.registerConverter(new ImportedValuesConverter(xStream));
    xStream.registerConverter(new InformationItemConverter(xStream));
    xStream.registerConverter(new InformationRequirementConverter(xStream));
    xStream.registerConverter(new InputClauseConverter(xStream));
    xStream.registerConverter(new InputDataConverter(xStream));
    xStream.registerConverter(new InvocationConverter(xStream));
    xStream.registerConverter(new ItemDefinitionConverter(xStream));
    xStream.registerConverter(new KnowledgeRequirementConverter(xStream));
    xStream.registerConverter(new KnowledgeSourceConverter(xStream));
    xStream.registerConverter(new LiteralExpressionConverter(xStream));
    xStream.registerConverter(new OrganizationUnitConverter(xStream));
    xStream.registerConverter(new OutputClauseConverter(xStream));
    xStream.registerConverter(new PerformanceIndicatorConverter(xStream));
    xStream.registerConverter(new RelationConverter(xStream));
    xStream.registerConverter(new TextAnnotationConverter(xStream));
    xStream.registerConverter(new UnaryTestsConverter(xStream));
    xStream.registerConverter(new QNameConverter());
    xStream.registerConverter(new DMNListConverter(xStream));
    xStream.registerConverter(new ElementCollectionConverter(xStream));
    xStream.registerConverter(new ExtensionElementsConverter(xStream, extensionRegisters));
    xStream.ignoreUnknownElements();
    for (DMNExtensionRegister extensionRegister : extensionRegisters) {
        extensionRegister.registerExtensionConverters(xStream);
    }
    return xStream;
}
Also used : KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase) DMNXStream(org.kie.dmn.backend.marshalling.v1x.DMNXStream) TypeHierarchyPermission(com.thoughtworks.xstream.security.TypeHierarchyPermission) XStream(com.thoughtworks.xstream.XStream) DMNXStream(org.kie.dmn.backend.marshalling.v1x.DMNXStream) QName(javax.xml.namespace.QName) TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) TDMNElement(org.kie.dmn.model.v1_1.TDMNElement) DMNExtensionRegister(org.kie.dmn.api.marshalling.DMNExtensionRegister)

Example 2 with DMNElement

use of org.kie.dmn.model.v1_1.DMNElement in project kie-wb-common by kiegroup.

the class DMNMarshaller method marshall.

@Override
public String marshall(final Diagram<Graph, Metadata> diagram) throws IOException {
    Graph<?, Node<View, ?>> g = diagram.getGraph();
    Map<String, org.kie.dmn.model.v1_1.DRGElement> nodes = new HashMap<>();
    Map<String, org.kie.dmn.model.v1_1.TextAnnotation> textAnnotations = new HashMap<>();
    @SuppressWarnings("unchecked") Node<View<DMNDiagram>, ?> dmnDiagramRoot = (Node<View<DMNDiagram>, ?>) findDMNDiagramRoot(g);
    Definitions definitionsStunnerPojo = dmnDiagramRoot.getContent().getDefinition().getDefinitions();
    org.kie.dmn.model.v1_1.Definitions definitions = DefinitionsConverter.dmnFromWB(definitionsStunnerPojo);
    if (definitions.getExtensionElements() == null) {
        definitions.setExtensionElements(new org.kie.dmn.model.v1_1.Definitions.ExtensionElements());
    }
    org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram dmnDDDMNDiagram = new org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram();
    definitions.getExtensionElements().getAny().add(dmnDDDMNDiagram);
    for (Node<?, ?> node : g.nodes()) {
        if (node.getContent() instanceof View<?>) {
            View<?> view = (View<?>) node.getContent();
            if (view.getDefinition() instanceof DRGElement) {
                DRGElement n = (org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement) view.getDefinition();
                nodes.put(n.getId().getValue(), stunnerToDMN(node));
                dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
            } else if (view.getDefinition() instanceof TextAnnotation) {
                TextAnnotation textAnnotation = (TextAnnotation) view.getDefinition();
                textAnnotations.put(textAnnotation.getId().getValue(), textAnnotationConverter.dmnFromNode((Node<View<TextAnnotation>, ?>) node));
                dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
                List<org.kie.dmn.model.v1_1.Association> associations = AssociationConverter.dmnFromWB((Node<View<TextAnnotation>, ?>) node);
                definitions.getArtifact().addAll(associations);
            }
        }
    }
    nodes.values().forEach(definitions.getDrgElement()::add);
    textAnnotations.values().forEach(definitions.getArtifact()::add);
    String marshalled = marshaller.marshal(definitions);
    return marshalled;
}
Also used : HashMap(java.util.HashMap) Node(org.kie.workbench.common.stunner.core.graph.Node) DMNElement(org.kie.workbench.common.dmn.api.definition.v1_1.DMNElement) List(java.util.List) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) Definitions(org.kie.workbench.common.dmn.api.definition.v1_1.Definitions) View(org.kie.workbench.common.stunner.core.graph.content.view.View) DRGElement(org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement)

Aggregations

XStream (com.thoughtworks.xstream.XStream)1 TypeHierarchyPermission (com.thoughtworks.xstream.security.TypeHierarchyPermission)1 HashMap (java.util.HashMap)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 DMNExtensionRegister (org.kie.dmn.api.marshalling.DMNExtensionRegister)1 DMNXStream (org.kie.dmn.backend.marshalling.v1x.DMNXStream)1 Definitions (org.kie.dmn.model.api.Definitions)1 KieDMNModelInstrumentedBase (org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase)1 TDMNElement (org.kie.dmn.model.v1_1.TDMNElement)1 TDefinitions (org.kie.dmn.model.v1_1.TDefinitions)1 DMNDiagram (org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram)1 DMNElement (org.kie.workbench.common.dmn.api.definition.v1_1.DMNElement)1 DRGElement (org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement)1 Definitions (org.kie.workbench.common.dmn.api.definition.v1_1.Definitions)1 TextAnnotation (org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1