Search in sources :

Example 1 with DynamicReadOnly

use of org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly in project kie-wb-common by kiegroup.

the class NoInputNodesInImportedDecisionRuleTest method testEvaluate.

@Test
@SuppressWarnings("unchecked")
public void testEvaluate() {
    final Node source = mock(Node.class);
    final Node target = mock(Node.class);
    final View content = mock(View.class);
    final DynamicReadOnly dynamicReadonly = mock(DynamicReadOnly.class);
    when(dynamicReadonly.isAllowOnlyVisualChange()).thenReturn(true);
    when(content.getDefinition()).thenReturn(dynamicReadonly);
    when(target.getContent()).thenReturn(content);
    when(context.getSource()).thenReturn(Optional.of(source));
    when(context.getTarget()).thenReturn(Optional.of(target));
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    final RuleViolation violation = result.violations().iterator().next();
    assertNotNull(violation);
    assertTrue(violation.getArguments().isPresent());
    assertEquals(1, violation.getArguments().get().length);
    assertEquals(NoInputNodesInImportedDecisionRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
Also used : DynamicReadOnly(org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 2 with DynamicReadOnly

use of org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly in project kie-wb-common by kiegroup.

the class NoInputNodesInImportedDecisionRuleTest method testIsReadOnly.

@Test
@SuppressWarnings("unchecked")
public void testIsReadOnly() {
    final Node target = mock(Node.class);
    final View content = mock(View.class);
    final DynamicReadOnly dynamicReadonly = mock(DynamicReadOnly.class);
    when(dynamicReadonly.isAllowOnlyVisualChange()).thenReturn(true);
    when(content.getDefinition()).thenReturn(dynamicReadonly);
    when(target.getContent()).thenReturn(content);
    when(context.getTarget()).thenReturn(Optional.of(target));
    final boolean actual = check.isReadOnly(Optional.of(target));
    assertTrue(actual);
    verify(check).isReadOnly(any(Optional.class));
}
Also used : DynamicReadOnly(org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly) Optional(java.util.Optional) Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 3 with DynamicReadOnly

use of org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly 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)

Example 4 with DynamicReadOnly

use of org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly in project kie-wb-common by kiegroup.

the class AbstractCanvasInlineTextEditorControlTest method testAllowOnlyVisualChanges.

@Test
public void testAllowOnlyVisualChanges() {
    final Element element = mock(Element.class);
    final Definition definition = mock(Definition.class);
    final DynamicReadOnly dynamicReadOnly = mock(DynamicReadOnly.class);
    when(element.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(dynamicReadOnly);
    boolean actual = control.allowOnlyVisualChanges(element);
    assertFalse(actual);
    when(dynamicReadOnly.isAllowOnlyVisualChange()).thenReturn(true);
    actual = control.allowOnlyVisualChanges(element);
    assertTrue(actual);
}
Also used : DynamicReadOnly(org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly) HTMLElement(org.jboss.errai.common.client.dom.HTMLElement) Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Test(org.junit.Test)

Example 5 with DynamicReadOnly

use of org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly in project kie-wb-common by kiegroup.

the class ObserverBuilderControlTest method testUpdateDynamicReadOnlyFromDefinition.

private void testUpdateDynamicReadOnlyFromDefinition(final boolean expectedDynamicReadOnlyValue) {
    final Element element = mock(Element.class);
    final View elementContent = mock(View.class);
    final DynamicReadOnly newDefinition = mock(DynamicReadOnly.class);
    final DynamicReadOnly definition = mock(DynamicReadOnly.class);
    when(element.getContent()).thenReturn(elementContent);
    when(elementContent.getDefinition()).thenReturn(newDefinition);
    when(definition.isAllowOnlyVisualChange()).thenReturn(expectedDynamicReadOnlyValue);
    observerBuilderControl.updateElementFromDefinition(element, definition);
    verify(newDefinition).setAllowOnlyVisualChange(expectedDynamicReadOnlyValue);
}
Also used : DynamicReadOnly(org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly) 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) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Aggregations

DynamicReadOnly (org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 Test (org.junit.Test)3 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)2 DMNElement (org.kie.workbench.common.dmn.api.definition.model.DMNElement)2 Element (org.kie.workbench.common.stunner.core.graph.Element)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 Optional (java.util.Optional)1 HTMLElement (org.jboss.errai.common.client.dom.HTMLElement)1 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)1 HasName (org.kie.workbench.common.dmn.api.definition.HasName)1 HasVariable (org.kie.workbench.common.dmn.api.definition.HasVariable)1 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)1 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)1 HasContentDefinitionId (org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId)1 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)1 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)1 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)1