use of io.atlasmap.v2.Expression in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallSequenceFlow.
protected void marshallSequenceFlow(SequenceFlow sequenceFlow, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset) throws JsonGenerationException, IOException {
// dont marshal "dangling" sequence flow..better to just omit than fail
if (sequenceFlow.getSourceRef() == null || sequenceFlow.getTargetRef() == null) {
return;
}
Map<String, Object> properties = new LinkedHashMap<String, Object>();
// check null for sequence flow name
if (sequenceFlow.getName() != null && !"".equals(sequenceFlow.getName())) {
properties.put(NAME, StringEscapeUtils.unescapeXml(sequenceFlow.getName()));
} else {
properties.put(NAME, "");
}
// overwrite name if elementname extension element is present
String elementName = Utils.getMetaDataValue(sequenceFlow.getExtensionValues(), "elementname");
if (elementName != null) {
properties.put(NAME, elementName);
}
putDocumentationProperty(sequenceFlow, properties);
if (sequenceFlow.isIsImmediate()) {
properties.put(ISIMMEDIATE, "true");
} else {
properties.put(ISIMMEDIATE, "false");
}
Expression conditionExpression = sequenceFlow.getConditionExpression();
if (conditionExpression instanceof FormalExpression) {
setConditionExpressionProperties((FormalExpression) conditionExpression, properties, "mvel");
}
boolean foundBgColor = false;
boolean foundBrColor = false;
boolean foundFontColor = false;
boolean foundSelectable = false;
Iterator<FeatureMap.Entry> iter = sequenceFlow.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("priority")) {
String priorityStr = String.valueOf(entry.getValue());
if (priorityStr != null) {
try {
Integer priorityInt = Integer.parseInt(priorityStr);
if (priorityInt >= 1) {
properties.put(PRIORITY, entry.getValue());
} else {
_logger.error("Priority must be equal or greater than 1.");
}
} catch (NumberFormatException e) {
_logger.error("Priority must be a number.");
}
}
}
if (entry.getEStructuralFeature().getName().equals("background-color") || entry.getEStructuralFeature().getName().equals("bgcolor")) {
properties.put(BGCOLOR, entry.getValue());
foundBgColor = true;
}
if (entry.getEStructuralFeature().getName().equals("border-color") || entry.getEStructuralFeature().getName().equals("bordercolor")) {
properties.put(BORDERCOLOR, entry.getValue());
foundBrColor = true;
}
if (entry.getEStructuralFeature().getName().equals("fontsize")) {
properties.put(FONTSIZE, entry.getValue());
foundBrColor = true;
}
if (entry.getEStructuralFeature().getName().equals("color") || entry.getEStructuralFeature().getName().equals("fontcolor")) {
properties.put(FONTCOLOR, entry.getValue());
foundFontColor = true;
}
if (entry.getEStructuralFeature().getName().equals("selectable")) {
properties.put(ISSELECTABLE, entry.getValue());
foundSelectable = true;
}
}
if (!foundBgColor) {
properties.put(BGCOLOR, defaultSequenceflowColor);
}
if (!foundBrColor) {
properties.put(BORDERCOLOR, defaultSequenceflowColor);
}
if (!foundFontColor) {
properties.put(FONTCOLOR, defaultSequenceflowColor);
}
if (!foundSelectable) {
properties.put(ISSELECTABLE, "true");
}
// simulation properties
setSimulationProperties(sequenceFlow.getId(), properties);
// Custom attributes for Stunner's connectors - source/target auto connection flag.
String sourcePropertyName = Bpmn2OryxManager.MAGNET_AUTO_CONNECTION + Bpmn2OryxManager.SOURCE;
String sourceConnectorAuto = Utils.getMetaDataValue(sequenceFlow.getExtensionValues(), sourcePropertyName);
if (sourceConnectorAuto != null && sourceConnectorAuto.trim().length() > 0) {
properties.put(sourcePropertyName, sourceConnectorAuto);
}
String targetPropertyName = Bpmn2OryxManager.MAGNET_AUTO_CONNECTION + Bpmn2OryxManager.TARGET;
String targetConnectorAuto = Utils.getMetaDataValue(sequenceFlow.getExtensionValues(), targetPropertyName);
if (targetConnectorAuto != null && targetConnectorAuto.trim().length() > 0) {
properties.put(targetPropertyName, targetConnectorAuto);
}
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
generator.writeObjectField("id", "SequenceFlow");
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
generator.writeStartObject();
generator.writeObjectField("resourceId", sequenceFlow.getTargetRef().getId());
generator.writeEndObject();
generator.writeEndArray();
Bounds sourceBounds = ((BPMNShape) findDiagramElement(plane, sequenceFlow.getSourceRef())).getBounds();
Bounds targetBounds = ((BPMNShape) findDiagramElement(plane, sequenceFlow.getTargetRef())).getBounds();
generator.writeArrayFieldStart("dockers");
List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, sequenceFlow)).getWaypoint();
if (waypoints.size() > 1) {
Point waypoint = waypoints.get(0);
writeWaypointObject(generator, waypoint.getX() - sourceBounds.getX(), waypoint.getY() - sourceBounds.getY());
} else {
writeWaypointObject(generator, sourceBounds.getWidth() / 2, sourceBounds.getHeight() / 2);
}
for (int i = 1; i < waypoints.size() - 1; i++) {
Point waypoint = waypoints.get(i);
writeWaypointObject(generator, waypoint.getX(), waypoint.getY());
}
if (waypoints.size() > 1) {
Point waypoint = waypoints.get(waypoints.size() - 1);
writeWaypointObject(generator, waypoint.getX() - targetBounds.getX(), waypoint.getY() - targetBounds.getY());
} else {
writeWaypointObject(generator, targetBounds.getWidth() / 2, targetBounds.getHeight() / 2);
}
generator.writeEndArray();
}
use of io.atlasmap.v2.Expression in project kie-wb-common by kiegroup.
the class InvocationPropertyConverter method wbFromDMN.
public static Invocation wbFromDMN(final org.kie.dmn.model.v1_1.Invocation dmn) {
if (dmn == null) {
return null;
}
Id id = new Id(dmn.getId());
Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
Invocation result = new Invocation();
result.setId(id);
result.setDescription(description);
result.setTypeRef(typeRef);
Expression convertedExpression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression());
result.setExpression(convertedExpression);
for (org.kie.dmn.model.v1_1.Binding b : dmn.getBinding()) {
Binding bConverted = BindingPropertyConverter.wbFromDMN(b);
result.getBinding().add(bConverted);
}
return result;
}
use of io.atlasmap.v2.Expression in project kie-wb-common by kiegroup.
the class ListPropertyConverter method wbFromDMN.
public static List wbFromDMN(final org.kie.dmn.model.v1_1.List dmn) {
Id id = new Id(dmn.getId());
Description description = new Description(dmn.getDescription());
QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
java.util.List<Expression> expression = new ArrayList<>();
for (org.kie.dmn.model.v1_1.Expression e : dmn.getExpression()) {
Expression eConverted = ExpressionPropertyConverter.wbFromDMN(e);
expression.add(eConverted);
}
List result = new List(id, description, typeRef, expression);
return result;
}
use of io.atlasmap.v2.Expression in project kie-wb-common by kiegroup.
the class ListPropertyConverter method dmnFromWB.
public static org.kie.dmn.model.v1_1.List dmnFromWB(final List wb) {
org.kie.dmn.model.v1_1.List result = new org.kie.dmn.model.v1_1.List();
result.setId(wb.getId().getValue());
result.setDescription(wb.getDescription().getValue());
QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
for (Expression e : wb.getExpression()) {
org.kie.dmn.model.v1_1.Expression eConverted = ExpressionPropertyConverter.dmnFromWB(e);
result.getExpression().add(eConverted);
}
return result;
}
use of io.atlasmap.v2.Expression in project drools by kiegroup.
the class DMNEvaluatorCompiler method compileFunctionDefinition.
private DMNExpressionEvaluator compileFunctionDefinition(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, String functionName, FunctionDefinition expression) {
FunctionDefinition funcDef = expression;
String kindStr = funcDef.getAdditionalAttributes().get(FunctionDefinition.KIND_QNAME);
FunctionDefinition.Kind kind = kindStr != null ? FunctionDefinition.Kind.determineFromString(kindStr) : FunctionDefinition.Kind.FEEL;
if (kind == null) {
// unknown function kind
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, funcDef, model, null, null, Msg.FUNC_DEF_INVALID_KIND, kindStr, node.getIdentifierString());
return new DMNFunctionDefinitionEvaluator(node.getName(), funcDef);
} else if (kind.equals(FunctionDefinition.Kind.FEEL)) {
ctx.enterFrame();
try {
DMNFunctionDefinitionEvaluator func = new DMNFunctionDefinitionEvaluator(node.getName(), funcDef);
for (InformationItem p : funcDef.getFormalParameter()) {
DMNCompilerHelper.checkVariableName(model, p, p.getName());
DMNType dmnType = compiler.resolveTypeRef(model, node, p, p, p.getTypeRef());
func.addParameter(p.getName(), dmnType);
ctx.setVariable(p.getName(), dmnType);
}
DMNExpressionEvaluator eval = compileExpression(ctx, model, node, functionName, funcDef.getExpression());
if (eval instanceof DMNLiteralExpressionEvaluator && ((DMNLiteralExpressionEvaluator) eval).isFunctionDefinition()) {
// we need to resolve the function and eliminate the indirection
CompiledExpression fexpr = ((DMNLiteralExpressionEvaluator) eval).getExpression();
FEELFunction feelFunction = feel.evaluateFunctionDef(ctx, fexpr, model, funcDef, Msg.FUNC_DEF_COMPILATION_ERR, functionName, node.getIdentifierString());
DMNInvocationEvaluator invoker = new DMNInvocationEvaluator(node.getName(), node.getSource(), functionName, new Invocation(), (fctx, fname) -> feelFunction, // feel can be null as anyway is hardcoded to `feelFunction`
null);
for (InformationItem p : funcDef.getFormalParameter()) {
invoker.addParameter(p.getName(), func.getParameterType(p.getName()), (em, dr) -> new EvaluatorResultImpl(dr.getContext().get(p.getName()), EvaluatorResult.ResultType.SUCCESS));
}
eval = invoker;
}
func.setEvaluator(eval);
return func;
} finally {
ctx.exitFrame();
}
} else if (kind.equals(FunctionDefinition.Kind.JAVA)) {
if (funcDef.getExpression() instanceof Context) {
// proceed
Context context = (Context) funcDef.getExpression();
String clazz = null;
String method = null;
for (ContextEntry ce : context.getContextEntry()) {
if (ce.getVariable() != null && ce.getVariable().getName() != null && ce.getExpression() != null && ce.getExpression() instanceof LiteralExpression) {
if (ce.getVariable().getName().equals("class")) {
clazz = stripQuotes(((LiteralExpression) ce.getExpression()).getText().trim());
} else if (ce.getVariable().getName().equals("method signature")) {
method = stripQuotes(((LiteralExpression) ce.getExpression()).getText().trim());
}
}
}
if (clazz != null && method != null) {
String params = funcDef.getFormalParameter().stream().map(p -> p.getName()).collect(Collectors.joining(","));
String expr = String.format("function(%s) external { java: { class: \"%s\", method signature: \"%s\" }}", params, clazz, method);
try {
FEELFunction feelFunction = feel.evaluateFunctionDef(ctx, expr, model, funcDef, Msg.FUNC_DEF_COMPILATION_ERR, functionName, node.getIdentifierString());
if (feelFunction != null) {
((BaseFEELFunction) feelFunction).setName(functionName);
}
DMNInvocationEvaluator invoker = new DMNInvocationEvaluator(node.getName(), node.getSource(), functionName, new Invocation(), (fctx, fname) -> feelFunction, // feel can be null as anyway is hardcoded to `feelFunction`
null);
DMNFunctionDefinitionEvaluator func = new DMNFunctionDefinitionEvaluator(node.getName(), funcDef);
for (InformationItem p : funcDef.getFormalParameter()) {
DMNCompilerHelper.checkVariableName(model, p, p.getName());
DMNType dmnType = compiler.resolveTypeRef(model, node, p, p, p.getTypeRef());
func.addParameter(p.getName(), dmnType);
invoker.addParameter(p.getName(), dmnType, (em, dr) -> new EvaluatorResultImpl(dr.getContext().get(p.getName()), EvaluatorResult.ResultType.SUCCESS));
}
func.setEvaluator(invoker);
return func;
} catch (Throwable e) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, expression, model, e, null, Msg.FUNC_DEF_COMPILATION_ERR, functionName, node.getIdentifierString(), "Exception raised: " + e.getClass().getSimpleName());
}
} else {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, expression, model, null, null, Msg.FUNC_DEF_MISSING_ENTRY, functionName, node.getIdentifierString());
}
} else {
// error, java function definitions require a context
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, funcDef, model, null, null, Msg.FUNC_DEF_BODY_NOT_CONTEXT, node.getIdentifierString());
}
} else if (kind.equals(FunctionDefinition.Kind.PMML)) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.WARN, funcDef, model, null, null, Msg.FUNC_DEF_PMML_NOT_SUPPORTED, node.getIdentifierString());
} else {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, funcDef, model, null, null, Msg.FUNC_DEF_INVALID_KIND, kindStr, node.getIdentifierString());
}
return new DMNFunctionDefinitionEvaluator(node.getName(), funcDef);
}
Aggregations