Search in sources :

Example 1 with InputData

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

the class XStreamMarshaller method newXStream.

private XStream newXStream() {
    XStream xStream = createTrustingXStream(staxDriver, Definitions.class.getClassLoader());
    xStream.alias("artifact", Artifact.class);
    xStream.alias("definitions", Definitions.class);
    xStream.alias("inputData", InputData.class);
    xStream.alias("decision", Decision.class);
    xStream.alias("variable", InformationItem.class);
    xStream.alias("informationRequirement", InformationRequirement.class);
    xStream.alias("requiredInput", DMNElementReference.class);
    xStream.alias("literalExpression", LiteralExpression.class);
    // TODO will need to remove dups and find missing element not captured?
    xStream.alias("DMNElement", DMNElement.class);
    xStream.alias("allowedValues", UnaryTests.class);
    xStream.alias("artifact", Artifact.class);
    xStream.alias("association", Association.class);
    xStream.alias("authorityRequirement", AuthorityRequirement.class);
    xStream.alias("authorityRequirement", AuthorityRequirement.class);
    xStream.alias("authorityRequirement", AuthorityRequirement.class);
    xStream.alias("binding", Binding.class);
    xStream.alias("businessContextElement", BusinessContextElement.class);
    xStream.alias("businessKnowledgeModel", BusinessKnowledgeModel.class);
    xStream.alias("column", InformationItem.class);
    xStream.alias("context", Context.class);
    xStream.alias("contextEntry", ContextEntry.class);
    xStream.alias("decision", Decision.class);
    xStream.alias("decisionMade", DMNElementReference.class);
    xStream.alias("decisionMaker", DMNElementReference.class);
    xStream.alias("decisionOwned", DMNElementReference.class);
    xStream.alias("decisionOwner", DMNElementReference.class);
    xStream.alias("decisionService", DecisionService.class);
    xStream.alias("decisionTable", DecisionTable.class);
    xStream.alias("defaultOutputEntry", LiteralExpression.class);
    xStream.alias("definitions", Definitions.class);
    xStream.alias("drgElement", DMNElementReference.class);
    // xStream.alias("drgElement", DRGElement.class ); ambiguity, also referring to top-level xsd element just under xsd root.
    xStream.alias("elementCollection", ElementCollection.class);
    xStream.alias("elementCollection", ElementCollection.class);
    xStream.alias("encapsulatedDecision", DMNElementReference.class);
    xStream.alias("encapsulatedLogic", FunctionDefinition.class);
    xStream.alias("expression", Expression.class);
    xStream.alias("formalParameter", InformationItem.class);
    xStream.alias("functionDefinition", FunctionDefinition.class);
    xStream.alias("impactedPerformanceIndicator", DMNElementReference.class);
    xStream.alias("impactingDecision", DMNElementReference.class);
    xStream.alias("import", Import.class);
    xStream.alias("import", Import.class);
    // TODO where?
    xStream.alias("importedElement", String.class);
    xStream.alias("importedValues", ImportedValues.class);
    xStream.alias("informationItem", InformationItem.class);
    xStream.alias("informationRequirement", InformationRequirement.class);
    xStream.alias("input", InputClause.class);
    xStream.alias("inputData", DMNElementReference.class);
    xStream.alias("inputData", InputData.class);
    xStream.alias("inputDecision", DMNElementReference.class);
    xStream.alias("inputEntry", UnaryTests.class);
    xStream.alias("inputExpression", LiteralExpression.class);
    xStream.alias("inputValues", UnaryTests.class);
    xStream.alias("invocation", Invocation.class);
    xStream.alias("itemComponent", ItemDefinition.class);
    xStream.alias("itemDefinition", ItemDefinition.class);
    xStream.alias("itemDefinition", ItemDefinition.class);
    xStream.alias("knowledgeRequirement", KnowledgeRequirement.class);
    xStream.alias("knowledgeRequirement", KnowledgeRequirement.class);
    xStream.alias("knowledgeSource", KnowledgeSource.class);
    xStream.alias("literalExpression", LiteralExpression.class);
    xStream.alias("namedElement", NamedElement.class);
    xStream.alias("organizationUnit", OrganizationUnit.class);
    xStream.alias("output", OutputClause.class);
    xStream.alias("outputDecision", DMNElementReference.class);
    xStream.alias("outputEntry", LiteralExpression.class);
    xStream.alias("outputValues", UnaryTests.class);
    xStream.alias("owner", DMNElementReference.class);
    xStream.alias("parameter", InformationItem.class);
    xStream.alias("performanceIndicator", PerformanceIndicator.class);
    xStream.alias("relation", Relation.class);
    xStream.alias("requiredAuthority", DMNElementReference.class);
    xStream.alias("requiredDecision", DMNElementReference.class);
    xStream.alias("requiredDecision", DMNElementReference.class);
    xStream.alias("requiredInput", DMNElementReference.class);
    xStream.alias("requiredInput", DMNElementReference.class);
    xStream.alias("requiredKnowledge", DMNElementReference.class);
    xStream.alias("rule", DecisionRule.class);
    xStream.alias("sourceRef", DMNElementReference.class);
    xStream.alias("supportedObjective", DMNElementReference.class);
    xStream.alias("targetRef", DMNElementReference.class);
    xStream.alias("textAnnotation", TextAnnotation.class);
    // TODO where?
    xStream.alias("type", String.class);
    xStream.alias("typeRef", QName.class);
    xStream.alias("usingProcess", DMNElementReference.class);
    xStream.alias("usingTask", DMNElementReference.class);
    xStream.alias("variable", InformationItem.class);
    xStream.alias("variable", InformationItem.class);
    xStream.alias("variable", InformationItem.class);
    xStream.alias("variable", InformationItem.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.List.class);
    xStream.alias("list", org.kie.dmn.model.v1_1.List.class);
    xStream.alias("extensionElements", DMNElement.ExtensionElements.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 : DMNElement(org.kie.dmn.model.v1_1.DMNElement) XStream(com.thoughtworks.xstream.XStream) XStreamUtils.createTrustingXStream(org.kie.soup.commons.xstream.XStreamUtils.createTrustingXStream) Definitions(org.kie.dmn.model.v1_1.Definitions) DMNExtensionRegister(org.kie.dmn.api.marshalling.v1_1.DMNExtensionRegister)

Example 2 with InputData

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

the class DMNXMLLoaderTest method testLoadingDefinitions.

@Test
public void testLoadingDefinitions() {
    final DMNMarshaller DMNMarshaller = DMNMarshallerFactory.newDefaultMarshaller();
    final InputStream is = this.getClass().getResourceAsStream("0001-input-data-string.dmn");
    final InputStreamReader isr = new InputStreamReader(is);
    final Definitions def = DMNMarshaller.unmarshal(isr);
    assertThat(def, not(nullValue()));
    assertThat(def.getName(), is("0001-input-data-string"));
    assertThat(def.getId(), is("_0001-input-data-string"));
    assertThat(def.getNamespace(), is("https://github.com/agilepro/dmn-tck"));
    assertThat(def.getDrgElement().size(), is(2));
    assertThat(def.getDrgElement().get(0), is(instanceOf(Decision.class)));
    Decision dec = (Decision) def.getDrgElement().get(0);
    assertThat(dec.getName(), is("Greeting Message"));
    assertThat(dec.getId(), is("d_GreetingMessage"));
    assertThat(dec.getVariable().getName(), is("Greeting Message"));
    assertThat(dec.getVariable().getTypeRef().getPrefix(), is("feel"));
    assertThat(dec.getVariable().getTypeRef().getLocalPart(), is("string"));
    assertThat(dec.getVariable().getTypeRef().getNamespaceURI(), is(XMLConstants.NULL_NS_URI));
    assertThat(dec.getInformationRequirement().size(), is(1));
    assertThat(dec.getInformationRequirement().get(0).getRequiredInput().getHref(), is("#i_FullName"));
    assertThat(dec.getExpression(), is(instanceOf(LiteralExpression.class)));
    LiteralExpression le = (LiteralExpression) dec.getExpression();
    assertThat(le.getText(), is("\"Hello \" + Full Name"));
    InputData idata = (InputData) def.getDrgElement().get(1);
    assertThat(idata.getId(), is("i_FullName"));
    assertThat(idata.getName(), is("Full Name"));
    assertThat(idata.getVariable().getName(), is("Full Name"));
    assertThat(idata.getVariable().getTypeRef().getPrefix(), is("feel"));
    assertThat(idata.getVariable().getTypeRef().getLocalPart(), is("string"));
    assertThat(idata.getVariable().getTypeRef().getNamespaceURI(), is(XMLConstants.NULL_NS_URI));
}
Also used : DMNMarshaller(org.kie.dmn.api.marshalling.v1_1.DMNMarshaller) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Definitions(org.kie.dmn.model.v1_1.Definitions) LiteralExpression(org.kie.dmn.model.v1_1.LiteralExpression) InputData(org.kie.dmn.model.v1_1.InputData) Decision(org.kie.dmn.model.v1_1.Decision) Test(org.junit.Test)

Example 3 with InputData

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

the class DMNExtensionRegisterTest method testUsingKModuleProperty_WrongClasses.

@Test
public void testUsingKModuleProperty_WrongClasses() {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    KieModuleModel kmm = ks.newKieModuleModel();
    kmm.setConfigurationProperty("org.kie.dmn.profiles.FirstNameLastNameProfile", "foo");
    kfs.writeKModuleXML(kmm.toXML());
    kfs.write(ks.getResources().newClassPathResource("0001-input-data-string-with-extensions.dmn", this.getClass()));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results results = kieBuilder.getResults();
    LOG.info("buildAll() completed.");
    results.getMessages(Level.WARNING).forEach(e -> LOG.warn("{}", e));
    assertTrue(results.getMessages(Level.WARNING).size() > 0);
    final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0001-input-data-string");
    assertThat(dmnModel, notNullValue());
    assertThat(formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    assertEquals(3, dmnModel.getDefinitions().getDrgElement().size());
    InputData inputData1 = (InputData) dmnModel.getDefinitions().getDrgElement().get(1);
    assertEquals("First Name", inputData1.getName());
    DMNElement.ExtensionElements id1elements = inputData1.getExtensionElements();
    assertTrue(id1elements != null);
    assertEquals(0, id1elements.getAny().size());
    InputData inputData2 = (InputData) dmnModel.getDefinitions().getDrgElement().get(2);
    assertEquals("Last Name", inputData2.getName());
    DMNElement.ExtensionElements id2elements = inputData2.getExtensionElements();
    assertTrue(id2elements != null);
    assertEquals(0, id2elements.getAny().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DMNElement(org.kie.dmn.model.v1_1.DMNElement) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InputData(org.kie.dmn.model.v1_1.InputData) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 4 with InputData

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

the class DMNExtensionRegisterTest method testUsingKModuleProperty.

@Test
public void testUsingKModuleProperty() {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    KieModuleModel kmm = ks.newKieModuleModel();
    kmm.setConfigurationProperty("org.kie.dmn.profiles.FirstNameLastNameProfile", FirstNameLastNameProfile.class.getCanonicalName());
    kfs.writeKModuleXML(kmm.toXML());
    kfs.write(ks.getResources().newClassPathResource("0001-input-data-string-with-extensions.dmn", this.getClass()));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results results = kieBuilder.getResults();
    LOG.info("buildAll() completed.");
    results.getMessages(Level.WARNING).forEach(e -> LOG.warn("{}", e));
    assertTrue(results.getMessages(Level.WARNING).size() == 0);
    final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0001-input-data-string");
    assertThat(dmnModel, notNullValue());
    assertThat(formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    assertEquals(3, dmnModel.getDefinitions().getDrgElement().size());
    InputData inputData1 = (InputData) dmnModel.getDefinitions().getDrgElement().get(1);
    assertEquals("First Name", inputData1.getName());
    DMNElement.ExtensionElements id1elements = inputData1.getExtensionElements();
    assertTrue(id1elements != null);
    assertEquals(1, id1elements.getAny().size());
    FirstNameDescription firstNameDescription = (FirstNameDescription) id1elements.getAny().get(0);
    assertTrue(firstNameDescription.getContent().equals("First name in latin characters"));
    InputData inputData2 = (InputData) dmnModel.getDefinitions().getDrgElement().get(2);
    assertEquals("Last Name", inputData2.getName());
    DMNElement.ExtensionElements id2elements = inputData2.getExtensionElements();
    assertTrue(id2elements != null);
    assertEquals(1, id2elements.getAny().size());
    LastNameDescription lastNameDescription = (LastNameDescription) id2elements.getAny().get(0);
    assertTrue(lastNameDescription.getContent().equals("Last name in latin characters"));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Results(org.kie.api.builder.Results) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DMNElement(org.kie.dmn.model.v1_1.DMNElement) KieBuilder(org.kie.api.builder.KieBuilder) InputData(org.kie.dmn.model.v1_1.InputData) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 5 with InputData

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

the class DMNMarshaller method ddExtAugmentStunner.

private void ddExtAugmentStunner(Optional<org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram> dmnDDDiagram, Node currentNode) {
    if (!dmnDDDiagram.isPresent()) {
        return;
    }
    Stream<DMNShape> drgShapeStream = dmnDDDiagram.get().getAny().stream().filter(DMNShape.class::isInstance).map(DMNShape.class::cast);
    View content = (View) currentNode.getContent();
    if (content.getDefinition() instanceof Decision) {
        Decision d = (Decision) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), content.getBounds().getUpperLeft(), d.getDimensionsSet(), content.getBounds().getLowerRight(), d.getBackgroundSet(), d::setFontSet);
    } else if (content.getDefinition() instanceof InputData) {
        InputData d = (InputData) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), content.getBounds().getUpperLeft(), d.getDimensionsSet(), content.getBounds().getLowerRight(), d.getBackgroundSet(), d::setFontSet);
    } else if (content.getDefinition() instanceof BusinessKnowledgeModel) {
        BusinessKnowledgeModel d = (BusinessKnowledgeModel) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), content.getBounds().getUpperLeft(), d.getDimensionsSet(), content.getBounds().getLowerRight(), d.getBackgroundSet(), d::setFontSet);
    } else if (content.getDefinition() instanceof KnowledgeSource) {
        KnowledgeSource d = (KnowledgeSource) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), content.getBounds().getUpperLeft(), d.getDimensionsSet(), content.getBounds().getLowerRight(), d.getBackgroundSet(), d::setFontSet);
    } else if (content.getDefinition() instanceof TextAnnotation) {
        TextAnnotation d = (TextAnnotation) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), content.getBounds().getUpperLeft(), d.getDimensionsSet(), content.getBounds().getLowerRight(), d.getBackgroundSet(), d::setFontSet);
    }
}
Also used : DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Bound(org.kie.workbench.common.stunner.core.graph.content.Bounds.Bound) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) InputData(org.kie.workbench.common.dmn.api.definition.v1_1.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision)

Aggregations

InputData (org.kie.dmn.model.v1_1.InputData)7 InputData (org.kie.workbench.common.dmn.api.definition.v1_1.InputData)7 Test (org.junit.Test)5 DMNElement (org.kie.dmn.model.v1_1.DMNElement)4 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)4 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource)4 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 DMNModel (org.kie.dmn.api.core.DMNModel)3 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)3 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)3 List (java.util.List)2 KieServices (org.kie.api.KieServices)2 KieBuilder (org.kie.api.builder.KieBuilder)2 KieFileSystem (org.kie.api.builder.KieFileSystem)2 Results (org.kie.api.builder.Results)2 KieModuleModel (org.kie.api.builder.model.KieModuleModel)2 KieContainer (org.kie.api.runtime.KieContainer)2 Definitions (org.kie.dmn.model.v1_1.Definitions)2 DRGElement (org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement)2 TextAnnotation (org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation)2