Search in sources :

Example 6 with HasVariable

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

the class DecisionTableEditorDefinitionEnricher method getOutputClauseTypeRef.

private Optional<QName> getOutputClauseTypeRef(final HasVariable hasVariable) {
    final IsInformationItem variable = hasVariable.getVariable();
    if (Objects.nonNull(variable)) {
        return Optional.ofNullable(variable.getTypeRef());
    }
    final DMNModelInstrumentedBase base = hasVariable.asDMNModelInstrumentedBase().getParent();
    final DMNModelInstrumentedBase parent = base.getParent();
    if (parent instanceof HasTypeRef) {
        return Optional.ofNullable(((HasTypeRef) parent).getTypeRef());
    }
    if (parent instanceof HasVariable) {
        return getOutputClauseTypeRef((HasVariable) parent);
    }
    return Optional.empty();
}
Also used : HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) 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)

Example 7 with HasVariable

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

the class PropertiesPanelNotifierTest method testNotifyVariables.

@Test
public void testNotifyVariables() {
    final Node node = mock(Node.class);
    final HasVariable hasVariable = mock(HasVariable.class);
    final IsInformationItem informationItem = mock(IsInformationItem.class);
    when(hasVariable.getVariable()).thenReturn(informationItem);
    doNothing().when(notifier).notifyOutdatedElement(any(), any());
    notifier.notifyVariables(node, hasVariable);
    verify(notifier).notifyOutdatedElement(node, informationItem);
}
Also used : HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) Node(org.kie.workbench.common.stunner.core.graph.Node) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) Test(org.junit.Test)

Example 8 with HasVariable

use of org.kie.workbench.common.dmn.api.definition.HasVariable 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 9 with HasVariable

use of org.kie.workbench.common.dmn.api.definition.HasVariable 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 10 with HasVariable

use of org.kie.workbench.common.dmn.api.definition.HasVariable 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)

Aggregations

HasVariable (org.kie.workbench.common.dmn.api.definition.HasVariable)12 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 HasName (org.kie.workbench.common.dmn.api.definition.HasName)3 DMNModelInstrumentedBase (org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase)3 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)3 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)3 HasTypeRef (org.kie.workbench.common.dmn.api.definition.HasTypeRef)2 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)2 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)2 DMNElement (org.kie.workbench.common.dmn.api.definition.model.DMNElement)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 View (org.kie.workbench.common.stunner.core.graph.content.view.View)2 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)1 HasText (org.kie.workbench.common.dmn.api.definition.HasText)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 DynamicReadOnly (org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly)1