use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry in project kie-wb-common by kiegroup.
the class ContextEntryPropertyConverter method dmnFromWB.
public static JSITContextEntry dmnFromWB(final ContextEntry wb, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
final JSITContextEntry result = new JSITContextEntry();
final JSITInformationItem variable = InformationItemPropertyConverter.dmnFromWB(wb.getVariable());
JSITExpression expression = ExpressionPropertyConverter.dmnFromWB(wb.getExpression(), componentWidthsConsumer);
if (Objects.isNull(expression)) {
final JSITLiteralExpression mockLiteralExpression = new JSITLiteralExpression();
mockLiteralExpression.setText(ContextEntry.DEFAULT_EXPRESSION_VALUE);
expression = getWrappedJSITLiteralExpression(mockLiteralExpression, "dmn", "literalExpression");
}
result.setVariable(variable);
result.setExpression(expression);
return result;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry in project kie-wb-common by kiegroup.
the class ContextEntryPropertyConverter method wbFromDMN.
public static ContextEntry wbFromDMN(final JSITContextEntry dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
final InformationItem variable = InformationItemPropertyConverter.wbFromDMN(dmn.getVariable());
Expression expression = null;
final JSITExpression jsiWrapped = dmn.getExpression();
if (Objects.nonNull(jsiWrapped)) {
final JSITExpression jsiExpression = Js.uncheckedCast(JsUtils.getUnwrappedElement(jsiWrapped));
expression = ExpressionPropertyConverter.wbFromDMN(jsiExpression, Js.uncheckedCast(dmn), hasComponentWidthsConsumer);
}
final ContextEntry result = new ContextEntry();
if (Objects.nonNull(variable)) {
variable.setParent(result);
result.setVariable(variable);
}
if (Objects.nonNull(expression)) {
expression.setParent(result);
result.setExpression(expression);
}
return result;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry 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.JSITContextEntry 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