Search in sources :

Example 6 with List

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

the class ExpressionPropertyConverter method dmnFromWB.

public static JSITExpression dmnFromWB(final Expression wb, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    if (Objects.isNull(wb)) {
        return null;
    }
    final String uuid = wb.getId().getValue();
    if (Objects.nonNull(uuid)) {
        final JSITComponentWidths componentWidths = new JSITComponentWidths();
        componentWidths.setDmnElementRef(uuid);
        wb.getComponentWidths().stream().filter(Objects::nonNull).forEach(w -> componentWidths.addWidth(new Float(w)));
        componentWidthsConsumer.accept(componentWidths);
    }
    if (wb instanceof IsLiteralExpression) {
        final JSITLiteralExpression unwrappedJSITLiteralExpression = LiteralExpressionPropertyConverter.dmnFromWB((IsLiteralExpression) wb);
        final JSITLiteralExpression wrappedJSITLiteralExpression = getWrappedJSITLiteralExpression(unwrappedJSITLiteralExpression, "dmn", "literalExpression");
        return wrappedJSITLiteralExpression;
    } else if (wb instanceof Context) {
        final JSITContext unwrappedJSITContext = ContextPropertyConverter.dmnFromWB((Context) wb, componentWidthsConsumer);
        final JSITContext wrappedJSITContext = getWrappedJSITContext(unwrappedJSITContext, "dmn", "context");
        return wrappedJSITContext;
    } else if (wb instanceof Relation) {
        final JSITRelation unwrappedJSITRelation = RelationPropertyConverter.dmnFromWB((Relation) wb, componentWidthsConsumer);
        final JSITRelation wrappedJSITRelation = getWrappedJSITRelation(unwrappedJSITRelation, "dmn", "relation");
        return wrappedJSITRelation;
    } else if (wb instanceof List) {
        final JSITList unwrappedJSITList = ListPropertyConverter.dmnFromWB((List) wb, componentWidthsConsumer);
        final JSITList wrappedJSITList = getWrappedJSITList(unwrappedJSITList, "dmn", "list");
        return wrappedJSITList;
    } else if (wb instanceof Invocation) {
        final JSITInvocation unwrappedJSITInvocation = InvocationPropertyConverter.dmnFromWB((Invocation) wb, componentWidthsConsumer);
        final JSITInvocation wrappedJSITInvocation = getWrappedJSITInvocation(unwrappedJSITInvocation, "dmn", "invocation");
        return wrappedJSITInvocation;
    } else if (wb instanceof FunctionDefinition) {
        final JSITFunctionDefinition unwrappedJSITFunctionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB((FunctionDefinition) wb, componentWidthsConsumer);
        final JSITFunctionDefinition wrappedJSITFunctionDefinition = getWrappedJSITFunctionDefinition(unwrappedJSITFunctionDefinition, "dmn", "functionDefinition");
        return wrappedJSITFunctionDefinition;
    } else if (wb instanceof DecisionTable) {
        final JSITDecisionTable unwrappedJSITDecisionTable = DecisionTablePropertyConverter.dmnFromWB((DecisionTable) wb);
        final JSITDecisionTable wrappedJSITDecisionTable = getWrappedJSITDecisionTable(unwrappedJSITDecisionTable, "dmn", "decisionTable");
        return wrappedJSITDecisionTable;
    }
    return null;
}
Also used : JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) WrapperUtils.getWrappedJSITContext(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) WrapperUtils.getWrappedJSITFunctionDefinition(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITFunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) JSITRelation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation) WrapperUtils.getWrappedJSITRelation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITRelation) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) WrapperUtils.getWrappedJSITList(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITList) WrapperUtils.getWrappedJSITInvocation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITInvocation) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) WrapperUtils.getWrappedJSITLiteralExpression(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITLiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) WrapperUtils.getWrappedJSITDecisionTable(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITDecisionTable) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) JSITRelation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation) WrapperUtils.getWrappedJSITRelation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITRelation) JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) WrapperUtils.getWrappedJSITContext(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITContext) List(org.kie.workbench.common.dmn.api.definition.model.List) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) WrapperUtils.getWrappedJSITList(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITList) WrapperUtils.getWrappedJSITInvocation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITInvocation) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) WrapperUtils.getWrappedJSITFunctionDefinition(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITFunctionDefinition) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) JSITComponentWidths(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentWidths) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) WrapperUtils.getWrappedJSITDecisionTable(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITDecisionTable)

Example 7 with List

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

the class ExpressionPropertyConverter method wbFromDMN.

public static Expression wbFromDMN(final JSITExpression dmn, final JSITExpression parent, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    if (JSITLiteralExpression.instanceOf(dmn)) {
        final JSITLiteralExpression jsiExpression = Js.uncheckedCast(dmn);
        final LiteralExpression e = LiteralExpressionPropertyConverter.wbFromDMN(jsiExpression);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITContext.instanceOf(dmn)) {
        final JSITContext jsiExpression = Js.uncheckedCast(dmn);
        final Context e = ContextPropertyConverter.wbFromDMN(jsiExpression, parent, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITRelation.instanceOf(dmn)) {
        final JSITRelation jsiExpression = Js.uncheckedCast(dmn);
        final Relation e = RelationPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITList.instanceOf(dmn)) {
        final JSITList jsiExpression = Js.uncheckedCast(dmn);
        final List e = ListPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITInvocation.instanceOf(dmn)) {
        final JSITInvocation jsiExpression = Js.uncheckedCast(dmn);
        final Invocation e = InvocationPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITFunctionDefinition.instanceOf(dmn)) {
        final JSITFunctionDefinition jsiExpression = Js.uncheckedCast(dmn);
        final FunctionDefinition e = FunctionDefinitionPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITDecisionTable.instanceOf(dmn)) {
        final JSITDecisionTable jsiExpression = Js.uncheckedCast(dmn);
        final DecisionTable e = DecisionTablePropertyConverter.wbFromDMN(jsiExpression);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    }
    return null;
}
Also used : JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) WrapperUtils.getWrappedJSITContext(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) WrapperUtils.getWrappedJSITFunctionDefinition(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITFunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) JSITRelation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation) WrapperUtils.getWrappedJSITRelation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITRelation) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) WrapperUtils.getWrappedJSITList(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITList) WrapperUtils.getWrappedJSITInvocation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITInvocation) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) WrapperUtils.getWrappedJSITLiteralExpression(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITLiteralExpression) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) WrapperUtils.getWrappedJSITLiteralExpression(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITLiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) WrapperUtils.getWrappedJSITDecisionTable(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITDecisionTable) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) JSITRelation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation) WrapperUtils.getWrappedJSITRelation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITRelation) JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) WrapperUtils.getWrappedJSITContext(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITContext) List(org.kie.workbench.common.dmn.api.definition.model.List) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) WrapperUtils.getWrappedJSITList(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITList) WrapperUtils.getWrappedJSITInvocation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITInvocation) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) WrapperUtils.getWrappedJSITFunctionDefinition(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITFunctionDefinition) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) WrapperUtils.getWrappedJSITDecisionTable(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITDecisionTable)

Example 8 with List

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

the class AddListRowCommandTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    this.list = new List();
    this.hasExpression = HasExpression.wrap(list, new LiteralExpression());
    this.uiModel = new BaseGridData();
    this.uiModelRow = new BaseGridRow();
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiExpressionEditorColumn);
    when(gridWidget.getModel()).thenReturn(uiModel);
    when(handler.getRuleManager()).thenReturn(ruleManager);
    when(uiRowNumberColumn.getIndex()).thenReturn(0);
    when(uiExpressionEditorColumn.getIndex()).thenReturn(1);
    this.uiModel.setCellValue(0, EXPRESSION_COLUMN_INDEX, new ExpressionCellValue(Optional.of(literalExpressionEditor)));
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    when(literalExpressionEditor.getParentInformation()).thenReturn(parent);
    when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(new LiteralExpression()));
    when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
    this.uiModelMapper = spy(new ListUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(list), () -> false, () -> expressionEditorDefinitions, listSelector, 0));
}
Also used : ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) Optional(java.util.Optional) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) ListUIModelMapper(org.kie.workbench.common.dmn.client.editors.expressions.types.list.ListUIModelMapper) List(org.kie.workbench.common.dmn.api.definition.model.List) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Before(org.junit.Before)

Example 9 with List

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

the class DeleteListRowCommandTest method setup.

@Before
public void setup() {
    this.list = new List();
    this.uiModel = new BaseGridData();
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiExpressionEditorColumn);
    this.uiModel.appendRow(new BaseGridRow());
    this.list.getExpression().add(HasExpression.wrap(list, new LiteralExpression()));
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiExpressionEditorColumn).getIndex();
}
Also used : BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) List(org.kie.workbench.common.dmn.api.definition.model.List) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Before(org.junit.Before)

Example 10 with List

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

the class AddRelationColumnCommandTest method testGraphCommandExecuteWithExistingColumn_InsertBefore.

@Test
public void testGraphCommandExecuteWithExistingColumn_InsertBefore() {
    final InformationItem existingInformationItem = new InformationItem();
    relation.getColumn().add(existingInformationItem);
    final List row = new List();
    relation.getRow().add(row);
    final LiteralExpression existingLiteralExpression = new LiteralExpression();
    row.getExpression().add(0, HasExpression.wrap(row, existingLiteralExpression));
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    assertEquals(2, relation.getColumn().size());
    assertEquals(informationItem, relation.getColumn().get(0));
    assertEquals(RelationDefaultValueUtilities.PREFIX + "1", informationItem.getName().getValue());
    assertEquals(existingInformationItem, relation.getColumn().get(1));
    assertEquals(1, relation.getRow().size());
    assertEquals(2, relation.getRow().get(0).getExpression().size());
    assertTrue(relation.getRow().get(0).getExpression().get(0).getExpression() instanceof LiteralExpression);
    assertEquals(existingLiteralExpression, relation.getRow().get(0).getExpression().get(1).getExpression());
    assertEquals(relation, informationItem.getParent());
    assertEquals(relation.getRow().get(0), relation.getRow().get(0).getExpression().get(0).getExpression().getParent());
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) List(org.kie.workbench.common.dmn.api.definition.model.List) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Aggregations

List (org.kie.workbench.common.dmn.api.definition.model.List)39 Test (org.junit.Test)22 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)21 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)13 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)10 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)10 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)9 Relation (org.kie.workbench.common.dmn.api.definition.model.Relation)9 ArrayList (java.util.ArrayList)7 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)7 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)7 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)7 Before (org.junit.Before)6 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)5 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)4 Context (org.kie.workbench.common.dmn.api.definition.model.Context)4 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)4 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)4 Invocation (org.kie.workbench.common.dmn.api.definition.model.Invocation)4 IsLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression)4