Search in sources :

Example 6 with JSITKnowledgeSource

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeSource in project kie-wb-common by kiegroup.

the class KnowledgeSourceConverter method dmnFromNode.

@Override
@SuppressWarnings("unchecked")
public JSITKnowledgeSource dmnFromNode(final Node<View<KnowledgeSource>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    final KnowledgeSource source = (KnowledgeSource) DefinitionUtils.getElementDefinition(node);
    final JSITKnowledgeSource result = new JSITKnowledgeSource();
    result.setId(source.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
    description.ifPresent(result::setDescription);
    result.setName(source.getName().getValue());
    result.setType(source.getType().getValue());
    result.setLocationURI(source.getLocationURI().getValue());
    result.setAuthorityRequirement(new ArrayList<>());
    DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result);
    // 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 JSITAuthorityRequirement iReq = new JSITAuthorityRequirement();
                    iReq.setId(getRawId(e.getUUID()));
                    final JSITDMNElementReference ri = new JSITDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredDecision(ri);
                    result.addAuthorityRequirement(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 InputData) {
                    final JSITAuthorityRequirement iReq = new JSITAuthorityRequirement();
                    iReq.setId(getRawId(e.getUUID()));
                    final JSITDMNElementReference ri = new JSITDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredInput(ri);
                    result.addAuthorityRequirement(iReq);
                } else {
                    throw new UnsupportedOperationException("wrong model definition.");
                }
            }
        }
    }
    return result;
}
Also used : JSITKnowledgeSource(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeSource) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) JSITKnowledgeSource(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeSource) JSITAuthorityRequirement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAuthorityRequirement) ArrayList(java.util.ArrayList) List(java.util.List) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Aggregations

JSITKnowledgeSource (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeSource)6 ArrayList (java.util.ArrayList)3 JSITAuthorityRequirement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAuthorityRequirement)3 JSITBusinessKnowledgeModel (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBusinessKnowledgeModel)3 JSITDecision (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision)3 View (org.kie.workbench.common.stunner.core.graph.content.view.View)3 List (java.util.List)2 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 JSITDMNElementReference (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference)2 JSITInformationRequirement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationRequirement)2 JSITKnowledgeRequirement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeRequirement)2 BindableAdapterUtils.getDefinitionId (org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId)2 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 Test (org.junit.Test)1 Association (org.kie.workbench.common.dmn.api.definition.model.Association)1 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)1 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)1