use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext 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;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext 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;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext in project kie-wb-common by kiegroup.
the class WrapperUtils method getWrappedJSITContext.
public static JSITContext getWrappedJSITContext(final JSITContext toWrap, final String prefix, final String localPart) {
final JSITContext toReturn = Js.uncheckedCast(JsUtils.getWrappedElement(toWrap));
final JSIName jsiName = JSITContext.getJSIName();
updateJSIName(jsiName, prefix, localPart);
JsUtils.setNameOnWrapped(toReturn, jsiName);
return toReturn;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext in project kie-wb-common by kiegroup.
the class ContextPropertyConverter method wbFromDMN.
public static Context wbFromDMN(final JSITContext dmn, final JSITExpression parent, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
final Context result = new Context(id, description, typeRef);
final List<JSITContextEntry> jsiContextEntries = dmn.getContextEntry();
for (int i = 0; i < jsiContextEntries.size(); i++) {
final JSITContextEntry jsiContextentry = Js.uncheckedCast(jsiContextEntries.get(i));
final ContextEntry ceConverted = ContextEntryPropertyConverter.wbFromDMN(jsiContextentry, hasComponentWidthsConsumer);
if (Objects.nonNull(ceConverted)) {
ceConverted.setParent(result);
result.getContextEntry().add(ceConverted);
}
}
// No need to append a _default_ row if the Context is part of a JAVA or PMML FunctionDefinition
if (JSITFunctionDefinition.instanceOf(parent)) {
final JSITFunctionDefinition functionDefinition = Js.uncheckedCast(parent);
final String sKind = Js.uncheckedCast(functionDefinition.getKind());
final Kind kind = Kind.fromValue(sKind);
if (!Objects.equals(Kind.FEEL, kind)) {
return result;
}
}
// The UI requires a ContextEntry for the _default_ result even if none has been defined
final int contextEntriesCount = result.getContextEntry().size();
if (contextEntriesCount == 0) {
result.getContextEntry().add(new ContextEntry());
} else if (!Objects.isNull(result.getContextEntry().get(contextEntriesCount - 1).getVariable())) {
result.getContextEntry().add(new ContextEntry());
}
return result;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext in project kie-wb-common by kiegroup.
the class ContextPropertyConverter method dmnFromWB.
public static JSITContext dmnFromWB(final Context wb, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
final JSITContext result = new JSITContext();
result.setId(wb.getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
description.ifPresent(result::setDescription);
QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
for (ContextEntry ce : wb.getContextEntry()) {
final JSITContextEntry ceConverted = ContextEntryPropertyConverter.dmnFromWB(ce, componentWidthsConsumer);
result.addContextEntry(ceConverted);
}
// The UI appends a ContextEntry for the _default_ result that may contain an undefined Expression.
// If this is the case then DMN does not require the ContextEntry to be written out to the XML.
// Conversion of ContextEntries will always create a _mock_ LiteralExpression if no Expression has
// been defined therefore remove the last entry from the org.kie.dmn.model if the WB had no Expression.
final int contextEntriesCount = result.getContextEntry().size();
if (contextEntriesCount > 0) {
if (Objects.isNull(wb.getContextEntry().get(contextEntriesCount - 1).getExpression())) {
result.removeContextEntry(contextEntriesCount - 1);
}
}
return result;
}
Aggregations