public static VariableMapping copy(String source, String target) { return new VariableMapping(source, null, null, target, false); }
String source = m.getSource(); String sourceExpression = m.getSourceExpression(); Object sourceValue = m.getSourceValue(); if (m.isInterpolateValue()) { ExecutionContext ctx = contextFactory.create(src); v = ctx.interpolate(sourceValue); dst = dst.setVariable(m.getTarget(), v); } catch (PropertyNotFoundException e) { if (!ignoreMappingErrors) {
inVariables = new HashSet<>(); inVariables.add(VariableMapping.copy(ExecutionContext.PROCESS_BUSINESS_KEY, ExecutionContext.PROCESS_BUSINESS_KEY));
public static VariableMapping set(Object value, String target) { return new VariableMapping(null, null, value, target, false); }
public static VariableMapping eval(String expr, String target) { return new VariableMapping(null, expr, null, target, false); }
private VariableMapping parseVariableMapping(Attributes attributes) { String source = attributes.getValue("source"); String sourceExpression = attributes.getValue("sourceExpression"); String target = attributes.getValue("target"); return new VariableMapping(source, sourceExpression, target); }
static Set<VariableMapping> appendWithItemsVar(Set<VariableMapping> inVars) { Set<VariableMapping> vars = new HashSet<>(); if (inVars != null) { vars.addAll(inVars); } vars.add(new VariableMapping(null, "${item}", null, "item", true)); return vars; }
private static Set<VariableMapping> toVarMapping(Map<String, Object> params) { Set<VariableMapping> result = new HashSet<>(); for (Map.Entry<String, Object> e : params.entrySet()) { String target = e.getKey(); String sourceExpr = null; Object sourceValue = null; Object v = StepConverter.deepConvert(e.getValue()); if (StepConverter.isExpression(v)) { sourceExpr = v.toString(); } else { sourceValue = v; } result.add(new VariableMapping(null, sourceExpr, sourceValue, target, true)); } return result; }
private static Set<VariableMapping> toVariableMapping(Map<String, Object> m) throws ParserException { Object o = m.get(IN_VARS_KEY); if (o == null) { return null; } if (!(o instanceof Map)) { throw new ParserException("Invalid element type of input variables mapping: " + o); } Set<VariableMapping> result = new HashSet<>(); Map<String, Object> vars = (Map<String, Object>) o; for (Map.Entry<String, Object> e : vars.entrySet()) { String sourceExpression = null; String target = e.getKey(); Object v = e.getValue(); if (v instanceof String) { sourceExpression = (String) v; } else { throw new ParserException("Source variable values must be a string or an expression. Key: " + target + ", value: " + v); } result.add(new VariableMapping(null, sourceExpression, target)); } return result; }
String k = "__" + idx++; Object v = i.next(); maps.add(new VariableMapping(null, null, v, k, true)); if (isExpression(args)) { String s = args.toString().trim(); maps.add(new VariableMapping(null, s, null, k)); } else { maps.add(new VariableMapping(null, null, args, k, true));
@Override public Chunk convert(ConverterContext ctx, YamlCheckpoint s) throws YamlConverterException { Chunk c = new Chunk(); String id = ctx.nextId(); String checkpoint = s.getKey(); Set<VariableMapping> inVars = new HashSet<>(); inVars.add(new VariableMapping(null, null, checkpoint, "checkpointName", true)); Set<VariableMapping> outVars = new HashSet<>(); outVars.add(new VariableMapping("checkpointId", null, null, "checkpointId", true)); outVars.add(new VariableMapping("checkpointName", null, null, "checkpointName", true)); c.addElement(new ServiceTask(id, ExpressionType.DELEGATE, "${checkpoint}", inVars, outVars, true)); c.addSourceMap(id, toSourceMap(s, "Checkpoint: " + s.getKey())); c.addOutput(id); return c; } }
@SuppressWarnings("unchecked") default Set<VariableMapping> getVarMap(Map<String, Object> options, String key) { if (options == null) { return null; } Seq<KV<String, Object>> s = (Seq<KV<String, Object>>) options.get(key); if (s == null) { return null; } Set<VariableMapping> result = new HashSet<>(); for (KV<String, Object> kv : s.toList()) { String target = kv.getKey(); String sourceExpr = null; Object sourceValue = null; Object v = deepConvert(kv.getValue()); if (isExpression(v)) { sourceExpr = v.toString(); } else { sourceValue = v; } result.add(new VariableMapping(null, sourceExpr, sourceValue, target, true)); } if (key.equals("in") && getWithItems(options) != null) { result = appendWithItemsVar(result); } return result; }
@Override public Chunk convert(ConverterContext ctx, YamlSetVariablesStep s) throws YamlConverterException { Chunk c = new Chunk(); String id = ctx.nextId(); String expression = "${vars.set(execution, __0)}"; Object vars = StepConverter.deepConvert(s.getVariables()); Set<VariableMapping> inVars = Collections.singleton(new VariableMapping(null, null, vars, "__0", true)); c.addElement(new ServiceTask(id, ExpressionType.SIMPLE, expression, inVars, null, true)); c.addOutput(id); c.addSourceMap(id, toSourceMap(s, "Set variables")); return c; } }
@Override public Chunk convert(ConverterContext ctx, YamlExpressionStep s) throws YamlConverterException { Chunk c = new Chunk(); Set<VariableMapping> outVars = null; Map<String, Object> opts = s.getOptions(); if (opts != null) { String out = (String) opts.get("out"); if (out != null) { outVars = Collections.singleton(new VariableMapping(ServiceTask.EXPRESSION_RESULT_VAR, null, out)); } } String id = ctx.nextId(); c.addElement(new ServiceTask(id, ExpressionType.SIMPLE, s.getExpr(), null, outVars, true)); c.addOutput(id); c.addSourceMap(id, toSourceMap(s, "Expression: " + s.getExpr())); applyErrorBlock(ctx, c, id, s.getOptions()); return c; } }
VariableMapping taskVars = new VariableMapping(null, null, withItems, "items", true); Set<String> outVars = Optional.ofNullable(getVarMap(opts, "out")).map(vars -> vars.stream().map(VariableMapping::getTarget).collect(Collectors.toSet())).orElse(Collections.emptySet()); VariableMapping outVarsMapping = new VariableMapping(null, null, outVars, "__0", true);
Set<VariableMapping> outVars = Collections.singleton(new VariableMapping(ServiceTask.EXPRESSION_RESULT_VAR, null, switchExprResultVarName)); c.addElement(new ServiceTask(id, ExpressionType.SIMPLE, s.getExpr(), null, outVars, true)); c.addSourceMap(id, toSourceMap(s, "Switch expression: " + s.getExpr()));