use of org.eclipse.bpmn2.Expression in project newts by OpenNMS.
the class ResultDescriptor method expression.
public ResultDescriptor expression(String label, String expression) {
final JexlEngine je = new JexlEngine();
final Expression expr = je.createExpression(expression);
final String[] labels = getLabels().toArray(new String[0]);
CalculationFunction evaluate = new CalculationFunction() {
private static final long serialVersionUID = -3328049421398096252L;
@Override
public double apply(double... ds) {
JexlContext jc = new MapContext();
for (int i = 0; i < labels.length; i++) {
jc.set(labels[i], ds[i]);
}
return ((Number) expr.evaluate(jc)).doubleValue();
}
};
return calculate(label, evaluate, labels);
}
use of org.eclipse.bpmn2.Expression in project jmeter by apache.
the class Jexl2Function method execute.
/** {@inheritDoc} */
@Override
public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
//$NON-NLS-1$
String str = "";
CompoundVariable var = (CompoundVariable) values[0];
String exp = var.execute();
//$NON-NLS-1$
String varName = "";
if (values.length > 1) {
varName = ((CompoundVariable) values[1]).execute().trim();
}
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
try {
JexlContext jc = new MapContext();
//$NON-NLS-1$
jc.set("log", log);
//$NON-NLS-1$
jc.set("ctx", jmctx);
//$NON-NLS-1$
jc.set("vars", vars);
//$NON-NLS-1$
jc.set("props", JMeterUtils.getJMeterProperties());
// Previously mis-spelt as theadName
//$NON-NLS-1$
jc.set("threadName", Thread.currentThread().getName());
//$NON-NLS-1$ (may be null)
jc.set("sampler", currentSampler);
//$NON-NLS-1$ (may be null)
jc.set("sampleResult", previousResult);
//$NON-NLS-1$
jc.set("OUT", System.out);
// Now evaluate the script, getting the result
Expression e = getJexlEngine().createExpression(exp);
Object o = e.evaluate(jc);
if (o != null) {
str = o.toString();
}
if (vars != null && varName.length() > 0) {
// vars will be null on TestPlan
vars.put(varName, str);
}
} catch (Exception e) {
log.error("An error occurred while evaluating the expression \"" + exp + "\"\n", e);
}
return str;
}
use of org.eclipse.bpmn2.Expression in project dhis2-core by dhis2.
the class ExpressionUtils method evaluate.
/**
* @param expression the expression.
* @param vars the variables, can be null.
* @param strict indicates whether to use strict or lenient engine mode.
* @return the result of the evaluation.
*/
private static Object evaluate(String expression, Map<String, Object> vars, boolean strict) {
expression = expression.replaceAll(IGNORED_KEYWORDS_REGEX, StringUtils.EMPTY);
JexlEngine engine = strict ? JEXL_STRICT : JEXL;
Expression exp = engine.createExpression(expression);
JexlContext context = vars != null ? new MapContext(vars) : new MapContext();
return exp.evaluate(context);
}
use of org.eclipse.bpmn2.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 org.eclipse.bpmn2.Expression in project kie-wb-common by kiegroup.
the class ExpressionContainerUIModelMapper method fromDMNModel.
@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
final GridData uiModel = this.uiModel.get();
final Optional<Expression> expression = dmnModel.get();
final Optional<HasName> hasName = this.hasName.get();
final HasExpression hasExpression = this.hasExpression.get();
final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitions.get().getExpressionEditorDefinition(expression);
expressionEditorDefinition.ifPresent(definition -> {
final Optional<BaseExpressionGrid> oEditor = definition.getEditor(parent, Optional.of(nodeUUID.get()), hasExpression, expression, hasName, 0);
uiModel.setCell(0, 0, () -> new ContextGridCell<>(new ExpressionCellValue(oEditor), listSelector));
final GridColumn<?> uiColumn = uiModel.getColumns().get(columnIndex);
uiColumn.setWidth(uiColumn.getMinimumWidth());
});
}
Aggregations