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);
}
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);
}
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();
}
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;
}
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());
}
}
Aggregations