/** * Find all fields from given input and convert them to the instance of {@link KeyInformation}. * * <p>This method should be used to find and convert all of string representation of the field * from trigger and/or data sources. Fields in input have to adhere to one of the following * formats: * * <ul> * <li>trigger field format: <b>{{trigger.<i>eventKey</i>}}</b> * <li>data source format: * <b>{{ad.<i>dataProviderId</i>.<i>objectType</i>#<i>objectId</i>.<i>fieldKey</i>}}</b> * <li>post action parameter format: <b>pa.<i>fieldKey</i></b> * </ul> * * <p>To find fields in the input argument this method uses regular expression. When field is * found it is converted to an instance of {@link KeyInformation} by using the {@link * #parse(String)} method. * * <p>Fields are found by the following regular expression: <b>\{\{((.*?))(\}\})(?![^(]*\))</b>. * The expression searches for strings that start with <i>{{</i> and end with <i>}}</i> and are * not within <i>(</i> and <i>)</i>. Because of manipulations which contain additional data in * <i>(...)</i> needed to execute manipulation on the field (e.g.: join needs to have the join * character) and the text in <i>(...)</i> can be another string representation of the dragged * field, the expression has to check if the field has this kind of manipulation. * * <p>Example of input argument: * * <ul> * <li>{{trigger.message?format(Ala,cat)?capitalize}} * <li>You get the following message: {{trigger.message}} * </ul> * * @param input string with one or more string representation of dragged fields from trigger * and/or data sources * @return list of object representation of dragged fields. * @throws IllegalArgumentException in the same situations as the {@link #parse(String)} method. */ public static List<KeyInformation> parseAll(String input) { List<KeyInformation> keys = new ArrayList<>(); Pattern pattern = Pattern.compile("\\{\\{((.*?))(\\}\\})(?![^(]*\\))"); Matcher matcher = pattern.matcher(isEmpty(input) ? "" : input); while (matcher.find()) { keys.add(KeyInformation.parse(matcher.group(1))); } return keys; }
private Object getValue(String row, KeyEvaluator keyEvaluator) throws TaskHandlerException { List<KeyInformation> keys = KeyInformation.parseAll(row); Object result; if (keys.isEmpty()) { result = row; } else { KeyInformation rowKeyInfo = keys.get(0); result = keyEvaluator.getValue(rowKeyInfo); } return result; }