use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition in project kie-wb-common by kiegroup.
the class WrapperUtils method getWrappedJSITFunctionDefinition.
public static JSITFunctionDefinition getWrappedJSITFunctionDefinition(final JSITFunctionDefinition toWrap, final String prefix, final String localPart) {
final JSITFunctionDefinition toReturn = Js.uncheckedCast(JsUtils.getWrappedElement(toWrap));
final JSIName jsiName = JSITFunctionDefinition.getJSIName();
updateJSIName(jsiName, prefix, localPart);
JsUtils.setNameOnWrapped(toReturn, jsiName);
return toReturn;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition in project kie-wb-common by kiegroup.
the class FunctionDefinitionPropertyConverter method wbFromDMN.
public static FunctionDefinition wbFromDMN(final JSITFunctionDefinition dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
if (Objects.isNull(dmn)) {
return null;
}
final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
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 FunctionDefinition result = new FunctionDefinition(id, description, typeRef, expression);
if (Objects.nonNull(expression)) {
expression.setParent(result);
}
// JSITFunctionKind is a String JSO so convert into the real type
final String sKind = Js.uncheckedCast(dmn.getKind());
final Kind kind = Kind.fromValue(sKind);
switch(kind) {
case FEEL:
result.setKind(Kind.FEEL);
break;
case JAVA:
result.setKind(Kind.JAVA);
break;
case PMML:
result.setKind(Kind.PMML);
convertPMMLFunctionExpression(result, hasComponentWidthsConsumer);
break;
default:
result.setKind(Kind.FEEL);
break;
}
final List<JSITInformationItem> jsiInformationItems = dmn.getFormalParameter();
for (int i = 0; i < jsiInformationItems.size(); i++) {
final JSITInformationItem jsiInformationItem = Js.uncheckedCast(jsiInformationItems.get(i));
final InformationItem iiConverted = InformationItemPropertyConverter.wbFromDMN(jsiInformationItem);
if (Objects.nonNull(iiConverted)) {
iiConverted.setParent(result);
}
result.getFormalParameter().add(iiConverted);
}
return result;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition 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;
}
Aggregations