Search in sources :

Example 6 with IsInformationItem

use of org.kie.workbench.common.dmn.api.definition.model.IsInformationItem in project kie-wb-common by kiegroup.

the class DMNIncludedNodeFactory method withNamespace.

private DRGElement withNamespace(final DRGElement drgElement, final IncludedModel includeModel) {
    final String modelName = includeModel.getModelName();
    drgElement.setName(new Name(modelName + "." + drgElement.getName().getValue()));
    drgElement.setAllowOnlyVisualChange(true);
    if (drgElement instanceof HasVariable) {
        final HasVariable hasVariable = (HasVariable) drgElement;
        final IsInformationItem variable = hasVariable.getVariable();
        final QName qName = variable.getTypeRef();
        if (qName != null && !isBuiltInType(qName.getLocalPart())) {
            final QName typeRef = new QName(qName.getNamespaceURI(), modelName + "." + qName.getLocalPart(), qName.getPrefix());
            setVariable(hasVariable, variable, typeRef);
        }
    }
    return drgElement;
}
Also used : HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 7 with IsInformationItem

use of org.kie.workbench.common.dmn.api.definition.model.IsInformationItem in project kie-wb-common by kiegroup.

the class DMNIncludedModelHandler method updateDRGElementsVariableAndId.

private void updateDRGElementsVariableAndId(final String oldModelName, final String newModelName) {
    dmnGraphUtils.getModelDRGElements().forEach(drgElement -> {
        final Id oldId = drgElement.getId();
        if (oldId.getValue().startsWith(oldModelName)) {
            final String newId = oldId.getValue().replaceAll("^" + oldModelName, newModelName);
            drgElement.setId(new Id(newId));
        }
        if (drgElement instanceof HasVariable) {
            final HasVariable hasVariable = (HasVariable) drgElement;
            final IsInformationItem variable = hasVariable.getVariable();
            final QName typeRef = variable.getTypeRef();
            final String oldType = typeRef.getLocalPart();
            if (oldType.startsWith(oldModelName)) {
                final String newType = oldType.replaceAll("^" + oldModelName, newModelName);
                variable.setTypeRef(new QName(typeRef.getNamespaceURI(), newType, typeRef.getPrefix()));
            }
        }
    });
}
Also used : HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 8 with IsInformationItem

use of org.kie.workbench.common.dmn.api.definition.model.IsInformationItem in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricher method getOutputClauseName.

private Optional<String> getOutputClauseName(final HasVariable hasVariable) {
    final IsInformationItem variable = hasVariable.getVariable();
    if (variable instanceof InformationItem) {
        return Optional.ofNullable((variable).getName().getValue());
    }
    final DMNModelInstrumentedBase base = hasVariable.asDMNModelInstrumentedBase().getParent();
    final DMNModelInstrumentedBase parent = base.getParent();
    if (parent instanceof HasName) {
        return Optional.ofNullable(((HasName) parent).getName().getValue());
    }
    if (parent instanceof HasVariable) {
        return getOutputClauseName((HasVariable) parent);
    }
    return Optional.empty();
}
Also used : HasName(org.kie.workbench.common.dmn.api.definition.HasName) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem)

Example 9 with IsInformationItem

use of org.kie.workbench.common.dmn.api.definition.model.IsInformationItem in project kie-wb-common by kiegroup.

the class DMNIncludedNodeFactoryTest method testDrgElementWithNamespace.

@Test
public void testDrgElementWithNamespace() {
    final DRGElement drgElement = mock(DRGElement.class, withSettings().extraInterfaces(HasVariable.class));
    final IncludedModel includedModel = mock(IncludedModel.class);
    final DMNIncludedNodeFactory factory = mock(DMNIncludedNodeFactory.class);
    final Id elementId = mock(Id.class);
    final String theId = "theId";
    final String theName = "theName";
    final String tType = "tType";
    final String namespaceUri = "namespaceUri";
    final String prefix = "prefix";
    final String modelName = "Model Name";
    final Name elementName = mock(Name.class);
    final IsInformationItem informationItem = mock(IsInformationItem.class);
    final QName qName = mock(QName.class);
    final Name createdName = mock(Name.class);
    final QName typeRef = mock(QName.class);
    when(includedModel.getModelName()).thenReturn(modelName);
    when(elementId.getValue()).thenReturn(theId);
    when(elementName.getValue()).thenReturn(theName);
    when(drgElement.getName()).thenReturn(elementName);
    when(drgElement.getId()).thenReturn(elementId);
    when(((HasVariable) drgElement).getVariable()).thenReturn(informationItem);
    when(qName.getLocalPart()).thenReturn(tType);
    when(informationItem.getTypeRef()).thenReturn(qName);
    when(qName.getPrefix()).thenReturn(prefix);
    when(qName.getNamespaceURI()).thenReturn(namespaceUri);
    when(factory.createName(drgElement, modelName)).thenReturn(createdName);
    when(factory.createTypeRef(modelName, qName)).thenReturn(typeRef);
    doCallRealMethod().when(factory).drgElementWithNamespace(drgElement, includedModel);
    factory.drgElementWithNamespace(drgElement, includedModel);
    verify(drgElement).setName(createdName);
    verify(drgElement).setAllowOnlyVisualChange(true);
    verify(factory).setVariable((HasVariable) drgElement, informationItem, typeRef);
}
Also used : HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Aggregations

HasVariable (org.kie.workbench.common.dmn.api.definition.HasVariable)9 IsInformationItem (org.kie.workbench.common.dmn.api.definition.model.IsInformationItem)9 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)4 Test (org.junit.Test)3 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)3 DMNModelInstrumentedBase (org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)2 HasName (org.kie.workbench.common.dmn.api.definition.HasName)1 HasText (org.kie.workbench.common.dmn.api.definition.HasText)1 HasTypeRef (org.kie.workbench.common.dmn.api.definition.HasTypeRef)1 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)1 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)1 DMNElement (org.kie.workbench.common.dmn.api.definition.model.DMNElement)1 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)1 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)1 IncludedModel (org.kie.workbench.common.dmn.api.editors.included.IncludedModel)1 Element (org.kie.workbench.common.stunner.core.graph.Element)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1