use of org.kie.workbench.common.dmn.api.definition.v1_1.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.kie.workbench.common.dmn.api.definition.v1_1.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.kie.workbench.common.dmn.api.definition.v1_1.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.kie.workbench.common.dmn.api.definition.v1_1.Expression in project kie-wb-common by kiegroup.
the class RelationGridTest method testInitialiseUiModel.
@Test
public void testInitialiseUiModel() throws Exception {
relation.getColumn().add(new InformationItem() {
{
getName().setValue("first column header");
}
});
final String firstRowValue = "first column value 1";
final String secondRowValue = "first column value 2";
relation.getRow().add(new List() {
{
getExpression().add(new LiteralExpression() {
{
setText(firstRowValue);
}
});
}
});
relation.getRow().add(new List() {
{
getExpression().add(new LiteralExpression() {
{
setText(secondRowValue);
}
});
}
});
expression = Optional.of(relation);
setupGrid(0);
assertEquals(2, grid.getModel().getRowCount());
assertEquals(firstRowValue, grid.getModel().getRow(0).getCells().get(1).getValue().getValue());
assertEquals(secondRowValue, grid.getModel().getRow(1).getCells().get(1).getValue().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project kie-wb-common by kiegroup.
the class UndefinedExpressionGridTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() {
definition = new UndefinedExpressionEditorDefinition(gridPanel, gridLayer, definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, cellEditorControls, listSelector, translationService, expressionEditorDefinitionsSupplier);
expression = definition.getModelClass();
final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
expressionEditorDefinitions.add(definition);
expressionEditorDefinitions.add(literalExpressionEditorDefinition);
doReturn(expressionEditorDefinitions).when(expressionEditorDefinitionsSupplier).get();
doReturn(ExpressionType.LITERAL_EXPRESSION).when(literalExpressionEditorDefinition).getType();
doReturn(LiteralExpression.class.getSimpleName()).when(literalExpressionEditorDefinition).getName();
doReturn(Optional.of(literalExpression)).when(literalExpressionEditorDefinition).getModelClass();
doReturn(Optional.of(literalExpressionEditor)).when(literalExpressionEditorDefinition).getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), any(Optional.class), anyInt());
doReturn(0).when(parent).getRowIndex();
doReturn(0).when(parent).getColumnIndex();
doReturn(parentGridWidget).when(parent).getGridWidget();
doReturn(mock(GridData.class)).when(parentGridWidget).getModel();
doReturn(session).when(sessionManager).getCurrentSession();
doReturn(handler).when(session).getCanvasHandler();
when(parentGridWidget.getModel()).thenReturn(parentGridUiModel);
when(parent.getGridWidget()).thenReturn(parentGridWidget);
when(parent.getRowIndex()).thenReturn(0);
when(parent.getColumnIndex()).thenReturn(1);
}
Aggregations