use of org.kie.dmn.model.api.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();
final 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()));
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
final Results results = kieBuilder.getResults();
LOG.info("buildAll() completed.");
results.getMessages(Level.WARNING).forEach(e -> LOG.warn("{}", e));
assertEquals(0, results.getMessages(Level.WARNING).size());
final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
final DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
final 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());
final InputData inputData1 = (InputData) dmnModel.getDefinitions().getDrgElement().get(1);
assertEquals("First Name", inputData1.getName());
final DMNElement.ExtensionElements id1elements = inputData1.getExtensionElements();
assertNotNull(id1elements);
assertEquals(1, id1elements.getAny().size());
final FirstNameDescription firstNameDescription = (FirstNameDescription) id1elements.getAny().get(0);
assertEquals("First name in latin characters", firstNameDescription.getContent());
final InputData inputData2 = (InputData) dmnModel.getDefinitions().getDrgElement().get(2);
assertEquals("Last Name", inputData2.getName());
final DMNElement.ExtensionElements id2elements = inputData2.getExtensionElements();
assertNotNull(id2elements);
assertEquals(1, id2elements.getAny().size());
final LastNameDescription lastNameDescription = (LastNameDescription) id2elements.getAny().get(0);
assertEquals("Last name in latin characters", lastNameDescription.getContent());
}
use of org.kie.dmn.model.api.InputData in project drools by kiegroup.
the class DefinitionsConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Definitions def = (Definitions) parent;
for (Import i : def.getImport()) {
writeChildrenNode(writer, context, i, IMPORT);
}
for (ItemDefinition id : def.getItemDefinition()) {
writeChildrenNode(writer, context, id, ITEM_DEFINITION);
}
for (DRGElement e : def.getDrgElement()) {
String nodeName = DRG_ELEMENT;
if (e instanceof BusinessKnowledgeModel) {
nodeName = "businessKnowledgeModel";
} else if (e instanceof Decision) {
nodeName = "decision";
} else if (e instanceof InputData) {
nodeName = "inputData";
} else if (e instanceof KnowledgeSource) {
nodeName = "knowledgeSource";
} else if (e instanceof DecisionService) {
nodeName = "decisionService";
}
writeChildrenNode(writer, context, e, nodeName);
}
for (Artifact a : def.getArtifact()) {
String nodeName = ARTIFACT;
if (a instanceof Association) {
nodeName = "association";
} else if (a instanceof TextAnnotation) {
nodeName = "textAnnotation";
} else if (a instanceof Group) {
nodeName = "group";
}
writeChildrenNode(writer, context, a, nodeName);
}
for (ElementCollection ec : def.getElementCollection()) {
writeChildrenNode(writer, context, ec, ELEMENT_COLLECTION);
}
for (BusinessContextElement bce : def.getBusinessContextElement()) {
String nodeName = BUSINESS_CONTEXT_ELEMENT;
if (bce instanceof OrganizationUnit) {
nodeName = "organizationUnit";
} else if (bce instanceof PerformanceIndicator) {
nodeName = "performanceIndicator";
}
writeChildrenNode(writer, context, bce, nodeName);
}
if (def.getDMNDI() != null) {
writeChildrenNode(writer, context, def.getDMNDI(), "DMNDI");
}
}
use of org.kie.dmn.model.api.InputData in project drools by kiegroup.
the class InputDataConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
InputData id = (InputData) parent;
if (id.getVariable() != null) {
writeChildrenNode(writer, context, id.getVariable(), VARIABLE);
}
}
use of org.kie.dmn.model.api.InputData in project drools by kiegroup.
the class InputDataConverter method assignChildElement.
@Override
protected void assignChildElement(Object parent, String nodeName, Object child) {
super.assignChildElement(parent, nodeName, child);
InputData id = (InputData) parent;
if (VARIABLE.equals(nodeName)) {
id.setVariable((InformationItem) child);
} else {
super.assignChildElement(parent, nodeName, child);
}
}
use of org.kie.dmn.model.api.InputData in project drools by kiegroup.
the class XLS2DMNParser method appendInputData.
private void appendInputData(Definitions definitions, Map<String, DTHeaderInfo> headerInfos) {
Set<String> usedRI = new LinkedHashSet<>();
for (DTHeaderInfo hi : headerInfos.values()) {
for (String ri : hi.getRequiredInput()) {
if (!usedRI.contains(ri)) {
InputData id = new TInputData();
id.setName(ri);
id.setId("id_" + CodegenStringUtil.escapeIdentifier(ri));
InformationItem variable = new TInformationItem();
variable.setName(ri);
variable.setId("idvar_" + CodegenStringUtil.escapeIdentifier(ri));
variable.setTypeRef(new QName("Any"));
id.setVariable(variable);
definitions.getDrgElement().add(id);
}
usedRI.add(ri);
}
}
}
Aggregations