use of org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement in project kie-wb-common by kiegroup.
the class BusinessKnowledgeModelConverter method dmnFromNode.
@Override
public org.kie.dmn.model.api.BusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) {
final BusinessKnowledgeModel source = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node);
final org.kie.dmn.model.api.BusinessKnowledgeModel result = new org.kie.dmn.model.v1_2.TBusinessKnowledgeModel();
result.setId(source.getId().getValue());
result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
result.setName(source.getName().getValue());
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result);
final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
if (variable != null) {
variable.setParent(result);
}
result.setVariable(variable);
final org.kie.dmn.model.api.FunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB(source.getEncapsulatedLogic(), componentWidthsConsumer);
final FunctionDefinition wbFunctionDefinition = source.getEncapsulatedLogic();
if (Objects.nonNull(wbFunctionDefinition)) {
final String uuid = wbFunctionDefinition.getId().getValue();
if (Objects.nonNull(uuid)) {
final ComponentWidths componentWidths = new ComponentWidths();
componentWidths.setDmnElementRef(new QName(uuid));
componentWidths.setWidths(new ArrayList<>(source.getEncapsulatedLogic().getComponentWidths()));
componentWidthsConsumer.accept(componentWidths);
}
}
if (functionDefinition != null) {
functionDefinition.setParent(result);
}
result.setEncapsulatedLogic(functionDefinition);
// DMN spec table 2: Requirements connection rules
final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
final Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
final View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) view.getDefinition();
if (drgElement instanceof BusinessKnowledgeModel) {
final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
result.getKnowledgeRequirement().add(iReq);
} else if (drgElement instanceof KnowledgeSource) {
final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredAuthority(ri);
result.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof DecisionService) {
if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
result.getKnowledgeRequirement().add(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement in project kie-wb-common by kiegroup.
the class DecisionConverter method dmnFromNode.
@Override
@SuppressWarnings("unchecked")
public JSITDecision dmnFromNode(final Node<View<Decision>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
final Decision source = (Decision) DefinitionUtils.getElementDefinition(node);
final JSITDecision d = new JSITDecision();
d.setId(source.getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
description.ifPresent(d::setDescription);
d.setName(source.getName().getValue());
final JSITInformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
d.setVariable(variable);
final JSITExpression expression = ExpressionPropertyConverter.dmnFromWB(source.getExpression(), componentWidthsConsumer);
d.setExpression(expression);
final String question = QuestionPropertyConverter.dmnFromWB(source.getQuestion());
if (!StringUtils.isEmpty(question)) {
d.setQuestion(question);
}
final String allowedAnswers = AllowedAnswersPropertyConverter.dmnFromWB(source.getAllowedAnswers());
if (!StringUtils.isEmpty(allowedAnswers)) {
d.setAllowedAnswers(allowedAnswers);
}
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(d.getInformationRequirement())) {
d.setInformationRequirement(new ArrayList<>());
}
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(d.getKnowledgeRequirement())) {
d.setKnowledgeRequirement(new ArrayList<>());
}
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(d.getAuthorityRequirement())) {
d.setAuthorityRequirement(new ArrayList<>());
}
// DMN spec table 2: Requirements connection rules
final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
final Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
final View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) view.getDefinition();
if (drgElement instanceof Decision) {
final JSITInformationRequirement iReq = new JSITInformationRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredDecision(ri);
d.addInformationRequirement(iReq);
} else if (drgElement instanceof BusinessKnowledgeModel) {
final JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
d.addKnowledgeRequirement(iReq);
} else if (drgElement instanceof KnowledgeSource) {
final JSITAuthorityRequirement iReq = new JSITAuthorityRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredAuthority(ri);
d.addAuthorityRequirement(iReq);
} else if (drgElement instanceof InputData) {
final JSITInformationRequirement iReq = new JSITInformationRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredInput(ri);
d.addInformationRequirement(iReq);
} else if (drgElement instanceof DecisionService) {
if (e.getContent() instanceof Child) {
// Stunner relationship of this Decision be encapsulated by the DecisionService, not managed here.
} else if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
final JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
d.addKnowledgeRequirement(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, d);
return d;
}
use of org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement in project kie-wb-common by kiegroup.
the class DecisionServiceConverter method dmnFromNode.
@Override
@SuppressWarnings("unchecked")
public JSITDecisionService dmnFromNode(final Node<View<DecisionService>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
final DecisionService source = (DecisionService) DefinitionUtils.getElementDefinition(node);
final JSITDecisionService ds = new JSITDecisionService();
ds.setId(source.getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
description.ifPresent(ds::setDescription);
ds.setName(source.getName().getValue());
final JSITInformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
ds.setVariable(variable);
final List<JSITDMNElementReference> existing_outputDecision = source.getOutputDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<JSITDMNElementReference> existing_encapsulatedDecision = source.getEncapsulatedDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<JSITDMNElementReference> existing_inputDecision = source.getInputDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<JSITDMNElementReference> existing_inputData = source.getInputData().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<JSITDMNElementReference> candidate_outputDecision = new ArrayList<>();
final List<JSITDMNElementReference> candidate_encapsulatedDecision = new ArrayList<>();
final List<JSITDMNElementReference> candidate_inputDecision = new ArrayList<>();
final List<JSITDMNElementReference> candidate_inputData = new ArrayList<>();
final HashSet<InputData> reqInputs = new HashSet();
final HashSet<Decision> reqDecisions = new HashSet();
// DMN spec table 2: Requirements connection rules
final List<Edge<?, ?>> outEdges = (List<Edge<?, ?>>) node.getOutEdges();
for (Edge<?, ?> e : outEdges) {
if (e.getContent() instanceof Child) {
@SuppressWarnings("unchecked") final Node<View<?>, ?> targetNode = e.getTargetNode();
final View<?> targetNodeView = targetNode.getContent();
if (targetNodeView.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) targetNodeView.getDefinition();
if (drgElement instanceof Decision) {
final Decision decision = (Decision) drgElement;
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref("#" + decision.getId().getValue());
if (isOutputDecision(targetNode.getContent(), node.getContent())) {
candidate_outputDecision.add(ri);
} else {
candidate_encapsulatedDecision.add(ri);
final List<Node> all = diagramsSession.getNodesFromAllDiagramsWithContentId(drgElement.getContentDefinitionId());
for (final Node other : all) {
if (!Objects.equals(other, targetNode)) {
inspectDecisionForDSReqs(other, reqInputs, reqDecisions);
}
}
}
inspectDecisionForDSReqs(targetNode, reqInputs, reqDecisions);
} else {
throw new UnsupportedOperationException("wrong model definition: a DecisionService is expected to encapsulate only Decision");
}
}
} else if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
// this was taken care by the receiving Decision or BKM.
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
reqInputs.stream().sorted(Comparator.comparing(x -> x.getName().getValue())).map(x -> {
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref("#" + x.getId().getValue());
return ri;
}).forEach(ri -> candidate_inputData.add(Js.uncheckedCast(ri)));
reqDecisions.stream().sorted(Comparator.comparing(x -> x.getName().getValue())).map(x -> {
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref("#" + x.getId().getValue());
return ri;
}).forEach(rs -> candidate_inputDecision.add(Js.uncheckedCast(rs)));
for (int i = 0; i < candidate_outputDecision.size(); i++) {
final JSITDMNElementReference er = Js.uncheckedCast(candidate_outputDecision.get(i));
candidate_inputDecision.removeIf(x -> x.getHref().equals(er.getHref()));
}
for (int i = 0; i < candidate_encapsulatedDecision.size(); i++) {
final JSITDMNElementReference er = Js.uncheckedCast(candidate_encapsulatedDecision.get(i));
candidate_inputDecision.removeIf(x -> x.getHref().equals(er.getHref()));
}
ds.setInputData(reconcileExistingAndCandidate(existing_inputData, candidate_inputData));
ds.setInputDecision(reconcileExistingAndCandidate(existing_inputDecision, candidate_inputDecision));
ds.setEncapsulatedDecision(reconcileExistingAndCandidate(existing_encapsulatedDecision, candidate_encapsulatedDecision));
ds.setOutputDecision(reconcileExistingAndCandidate(existing_outputDecision, candidate_outputDecision));
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, ds);
return ds;
}
use of org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement in project kie-wb-common by kiegroup.
the class BusinessKnowledgeModelConverter method dmnFromNode.
@Override
@SuppressWarnings("unchecked")
public JSITBusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
final BusinessKnowledgeModel source = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node);
final JSITBusinessKnowledgeModel result = new JSITBusinessKnowledgeModel();
result.setId(source.getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
description.ifPresent(result::setDescription);
result.setName(source.getName().getValue());
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(result.getKnowledgeRequirement())) {
result.setKnowledgeRequirement(new ArrayList<>());
}
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(result.getAuthorityRequirement())) {
result.setAuthorityRequirement(new ArrayList<>());
}
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result);
final JSITInformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
result.setVariable(variable);
final JSITFunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB(source.getEncapsulatedLogic(), componentWidthsConsumer);
final FunctionDefinition wbFunctionDefinition = source.getEncapsulatedLogic();
if (Objects.nonNull(wbFunctionDefinition)) {
final String uuid = wbFunctionDefinition.getId().getValue();
if (Objects.nonNull(uuid)) {
final JSITComponentWidths componentWidths = new JSITComponentWidths();
componentWidths.setDmnElementRef(uuid);
source.getEncapsulatedLogic().getComponentWidths().stream().filter(Objects::nonNull).forEach(w -> componentWidths.addWidth(new Float(w)));
componentWidthsConsumer.accept(componentWidths);
}
}
result.setEncapsulatedLogic(functionDefinition);
// DMN spec table 2: Requirements connection rules
final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
final Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
final View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) view.getDefinition();
if (drgElement instanceof BusinessKnowledgeModel) {
final JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
result.addKnowledgeRequirement(iReq);
} else if (drgElement instanceof KnowledgeSource) {
final JSITAuthorityRequirement iReq = new JSITAuthorityRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredAuthority(ri);
result.addAuthorityRequirement(iReq);
} else if (drgElement instanceof DecisionService) {
if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
final JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
result.addKnowledgeRequirement(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement in project kie-wb-common by kiegroup.
the class DecisionConverter method dmnFromNode.
@Override
public org.kie.dmn.model.api.Decision dmnFromNode(final Node<View<Decision>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) {
final Decision source = (Decision) DefinitionUtils.getElementDefinition(node);
final org.kie.dmn.model.api.Decision d = new org.kie.dmn.model.v1_2.TDecision();
d.setId(source.getId().getValue());
d.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
d.setName(source.getName().getValue());
final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
if (variable != null) {
variable.setParent(d);
}
d.setVariable(variable);
final org.kie.dmn.model.api.Expression expression = ExpressionPropertyConverter.dmnFromWB(source.getExpression(), componentWidthsConsumer);
if (expression != null) {
expression.setParent(d);
}
d.setExpression(expression);
d.setQuestion(QuestionPropertyConverter.dmnFromWB(source.getQuestion()));
d.setAllowedAnswers(AllowedAnswersPropertyConverter.dmnFromWB(source.getAllowedAnswers()));
// DMN spec table 2: Requirements connection rules
final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
final Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
final View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) view.getDefinition();
if (drgElement instanceof Decision) {
final org.kie.dmn.model.api.InformationRequirement iReq = new org.kie.dmn.model.v1_2.TInformationRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredDecision(ri);
d.getInformationRequirement().add(iReq);
} else if (drgElement instanceof BusinessKnowledgeModel) {
final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
d.getKnowledgeRequirement().add(iReq);
} else if (drgElement instanceof KnowledgeSource) {
final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredAuthority(ri);
d.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof InputData) {
final org.kie.dmn.model.api.InformationRequirement iReq = new org.kie.dmn.model.v1_2.TInformationRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredInput(ri);
d.getInformationRequirement().add(iReq);
} else if (drgElement instanceof DecisionService) {
if (e.getContent() instanceof Child) {
// Stunner relationship of this Decision be encapsulated by the DecisionService, not managed here.
} else if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
d.getKnowledgeRequirement().add(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, d);
return d;
}
Aggregations