Search in sources :

Example 1 with HasVariable

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

the class ObserverBuilderControlTest method testUpdateVariableFromDefinition.

@Test
@SuppressWarnings("unchecked")
public void testUpdateVariableFromDefinition() {
    final Element element = mock(Element.class);
    final View elementContent = mock(View.class);
    final HasVariable newHasVariable = mock(HasVariable.class);
    final HasVariable hasVariable = mock(HasVariable.class);
    final IsInformationItem isInformationItem = mock(IsInformationItem.class);
    when(element.getContent()).thenReturn(elementContent);
    when(elementContent.getDefinition()).thenReturn(newHasVariable);
    when(hasVariable.getVariable()).thenReturn(isInformationItem);
    observerBuilderControl.updateElementFromDefinition(element, hasVariable);
    verify(newHasVariable).setVariable(isInformationItem);
}
Also used : HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) Element(org.kie.workbench.common.stunner.core.graph.Element) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 2 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 3 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 4 with HasVariable

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

the class TypeRefUtils method getTypeRefOfExpression.

public static <E extends Expression> HasTypeRef getTypeRefOfExpression(final E expression, final HasExpression hasExpression) {
    HasTypeRef hasTypeRef = expression;
    final DMNModelInstrumentedBase base = hasExpression.asDMNModelInstrumentedBase();
    if (base instanceof HasVariable) {
        final HasVariable hasVariable = (HasVariable) base;
        hasTypeRef = hasVariable.getVariable();
    }
    return hasTypeRef;
}
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)

Example 5 with HasVariable

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

the class ObserverBuilderControl method updateElementFromDefinition.

@Override
@SuppressWarnings("unchecked")
protected void updateElementFromDefinition(final Element element, final Object definition) {
    final Object content = element.getContent();
    if (!(content instanceof View)) {
        return;
    }
    final Object newDefinition = ((View) content).getDefinition();
    if (newDefinition instanceof HasName && definition instanceof HasName) {
        ((HasName) newDefinition).getName().setValue(((HasName) definition).getName().getValue());
    }
    if (newDefinition instanceof DynamicReadOnly && definition instanceof DynamicReadOnly) {
        ((DynamicReadOnly) newDefinition).setAllowOnlyVisualChange(((DynamicReadOnly) definition).isAllowOnlyVisualChange());
    }
    if (newDefinition instanceof HasVariable && definition instanceof HasVariable) {
        ((HasVariable) newDefinition).setVariable(((HasVariable) definition).getVariable());
    }
    if (newDefinition instanceof BusinessKnowledgeModel && definition instanceof BusinessKnowledgeModel) {
        ((BusinessKnowledgeModel) newDefinition).setEncapsulatedLogic(((BusinessKnowledgeModel) definition).getEncapsulatedLogic());
    }
    if (newDefinition instanceof HasExpression && definition instanceof HasExpression) {
        ((HasExpression) newDefinition).setExpression(((HasExpression) definition).getExpression());
    }
    if (newDefinition instanceof DMNElement && definition instanceof DMNElement) {
        final DMNElement dmnElement = (DMNElement) definition;
        if (!StringUtils.isEmpty(dmnElement.getId().getValue())) {
            ((DMNElement) newDefinition).getId().setValue(dmnElement.getId().getValue());
        }
    }
    final Optional<DMNDiagramElement> currentDMNDiagramElement = getDMNDiagramsSession().getCurrentDMNDiagramElement();
    if (currentDMNDiagramElement.isPresent() && newDefinition instanceof HasContentDefinitionId) {
        ((HasContentDefinitionId) newDefinition).setDiagramId(currentDMNDiagramElement.get().getId().getValue());
    }
}
Also used : DynamicReadOnly(org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasContentDefinitionId(org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId) HasName(org.kie.workbench.common.dmn.api.definition.HasName) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

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