@SuppressWarnings("unchecked") private Object replaceList(List<?> values, String taskId, DocumentContext io) { List<Object> replacedList = new LinkedList<>(); for (Object listVal : values) { if (listVal instanceof String) { Object replaced = replaceVariables(listVal.toString(), io, taskId); replacedList.add(replaced); } else if (listVal instanceof Map) { Object replaced = replace((Map<String, Object>) listVal, io, taskId); replacedList.add(replaced); } else if (listVal instanceof List) { Object replaced = replaceList((List<?>) listVal, taskId, io); replacedList.add(replaced); } else { replacedList.add(listVal); } } return replacedList; }
public ObservableQueue getQueue(String eventType) { String event = parametersUtils.replace(eventType).toString(); int index = event.indexOf(':'); if (index == -1) { logger.error("Queue cannot be configured for illegal event: {}", event); throw new IllegalArgumentException("Illegal event " + event); } String type = event.substring(0, index); String queueURI = event.substring(index + 1); EventQueueProvider provider = providers.get(type); if (provider != null) { return provider.getQueue(queueURI); } else { logger.error("Queue {} is not configured for event:{}", type, eventType); throw new IllegalArgumentException("Unknown queue type " + type); } } }
@SuppressWarnings("unchecked") private Map<String, Object> replace(Map<String, Object> input, DocumentContext documentContext, String taskId) { for (Entry<String, Object> e : input.entrySet()) { Object value = e.getValue(); if (value instanceof String) { Object replaced = replaceVariables(value.toString(), documentContext, taskId); e.setValue(replaced); } else if (value instanceof Map) { //recursive call Object replaced = replace((Map<String, Object>) value, documentContext, taskId); e.setValue(replaced); } else if (value instanceof List) { Object replaced = replaceList((List<?>) value, taskId, documentContext); e.setValue(replaced); } else { e.setValue(value); } } return input; }
public Map<String, Object> replace(Map<String, Object> input, Object json) { Object doc; if (json instanceof String) { doc = JsonPath.parse(json.toString()); } else { doc = json; } Configuration option = Configuration.defaultConfiguration().addOptions(Option.SUPPRESS_EXCEPTIONS); DocumentContext documentContext = JsonPath.parse(doc, option); return replace(input, documentContext, null); }
@SuppressWarnings("unchecked") private Object replaceList(List<?> values, String taskId, DocumentContext io) { List<Object> replacedList = new LinkedList<>(); for (Object listVal : values) { if (listVal instanceof String) { Object replaced = replaceVariables(listVal.toString(), io, taskId); replacedList.add(replaced); } else if (listVal instanceof Map) { Object replaced = replace((Map<String, Object>) listVal, io, taskId); replacedList.add(replaced); } else if (listVal instanceof List) { Object replaced = replaceList((List<?>) listVal, taskId, io); replacedList.add(replaced); } else { replacedList.add(listVal); } } return replacedList; }
private Map<String, Object> startWorkflow(Action action, Object payload, String event, String messageId) { StartWorkflow params = action.getStart_workflow(); Map<String, Object> output = new HashMap<>(); try { Map<String, Object> inputParams = params.getInput(); Map<String, Object> workflowInput = parametersUtils.replace(inputParams, payload); workflowInput.put("conductor.event.messageId", messageId); workflowInput.put("conductor.event.name", event); String id = executor.startWorkflow(params.getName(), params.getVersion(), params.getCorrelationId(), workflowInput, null, event, params.getTaskToDomain()); output.put("workflowId", id); } catch (RuntimeException e) { logger.error("Error starting workflow: {}, version: {}, for event: {} for message: {}", params.getName(), params.getVersion(), event, messageId, e); output.put("error", e.getMessage()); throw e; } return output; } }
@SuppressWarnings("unchecked") private Map<String, Object> replace(Map<String, Object> input, DocumentContext documentContext, String taskId) { for (Entry<String, Object> e : input.entrySet()) { Object value = e.getValue(); if (value instanceof String) { Object replaced = replaceVariables(value.toString(), documentContext, taskId); e.setValue(replaced); } else if (value instanceof Map) { //recursive call Object replaced = replace((Map<String, Object>) value, documentContext, taskId); e.setValue(replaced); } else if (value instanceof List) { Object replaced = replaceList((List<?>) value, taskId, documentContext); e.setValue(replaced); } else { e.setValue(value); } } return input; }
@Test public void testEvent() { System.setProperty("QUEUE_NAME", "queue_name_001"); String eventt = "queue_${QUEUE_NAME}"; String event = parametersUtils.replace(eventt).toString(); assertNotNull(event); assertEquals("queue_queue_name_001", event); eventt = "queue_9"; event = parametersUtils.replace(eventt).toString(); assertNotNull(event); assertEquals(eventt, event); }
@Test public void testReplace() throws Exception { Map<String, Object> map = new HashMap<>(); map.put("name", "conductor"); map.put("version", 2); map.put("externalId", "{\"taskRefName\":\"t001\",\"workflowId\":\"w002\"}"); Map<String, Object> input = new HashMap<>(); input.put("k1", "${$.externalId}"); input.put("k4", "${name}"); input.put("k5", "${version}"); Object jsonObj = objectMapper.readValue(objectMapper.writeValueAsString(map), Object.class); Map<String, Object> replaced = parametersUtils.replace(input, jsonObj); assertNotNull(replaced); System.out.println("testNoExpand(): " + replaced); assertEquals("{\"taskRefName\":\"t001\",\"workflowId\":\"w002\"}", replaced.get("k1")); assertEquals("conductor", replaced.get("k4")); assertEquals(2, replaced.get("k5")); }
input.putAll(taskDetails.getOutput()); Map<String, Object> replaced = parametersUtils.replace(input, payload); String workflowId = (String) replaced.get("workflowId"); String taskId = (String) replaced.get("taskId");
@Test public void testReplaceWithMapExpand() { Map<String, Object> map = new HashMap<>(); map.put("externalId", "{\"taskRefName\":\"t001\",\"workflowId\":\"w002\"}"); map.put("name", "conductor"); map.put("version", 2); jsonUtils.expand(map); Map<String, Object> input = new HashMap<>(); input.put("k1", "${$.externalId}"); input.put("k2", "${externalId.taskRefName}"); input.put("k4", "${name}"); input.put("k5", "${version}"); Map<String, Object> replaced = parametersUtils.replace(input, map); assertNotNull(replaced); assertEquals("t001", replaced.get("k2")); assertNull(replaced.get("k3")); assertEquals("conductor", replaced.get("k4")); assertEquals(2, replaced.get("k5")); } }
@Test public void testReplaceWithArrayExpand() { List<Object> list = new LinkedList<>(); Map<String, Object> map = new HashMap<>(); map.put("externalId", "[{\"taskRefName\":\"t001\",\"workflowId\":\"w002\"}]"); map.put("name", "conductor"); map.put("version", 2); list.add(map); jsonUtils.expand(list); Map<String, Object> input = new HashMap<>(); input.put("k1", "${$..externalId}"); input.put("k2", "${$[0].externalId[0].taskRefName}"); input.put("k3", "${__json_externalId.taskRefName}"); input.put("k4", "${$[0].name}"); input.put("k5", "${$[0].version}"); Map<String, Object> replaced = parametersUtils.replace(input, list); assertNotNull(replaced); assertEquals(replaced.get("k2"), "t001"); assertNull(replaced.get("k3")); assertEquals(replaced.get("k4"), "conductor"); assertEquals(replaced.get("k5"), 2); }
.addOptions(Option.SUPPRESS_EXCEPTIONS); DocumentContext documentContext = JsonPath.parse(inputMap, option); return replace(inputParams, documentContext, taskId);
public ObservableQueue getQueue(String eventType) { String event = parametersUtils.replace(eventType).toString(); int index = event.indexOf(':'); if (index == -1) { logger.error("Queue cannot be configured for illegal event: {}", event); throw new IllegalArgumentException("Illegal event " + event); } String type = event.substring(0, index); String queueURI = event.substring(index + 1); EventQueueProvider provider = providers.get(type); if (provider != null) { return provider.getQueue(queueURI); } else { logger.error("Queue {} is not configured for event:{}", type, eventType); throw new IllegalArgumentException("Unknown queue type " + type); } } }
public Map<String, Object> replace(Map<String, Object> input, Object json) { Object doc; if (json instanceof String) { doc = JsonPath.parse(json.toString()); } else { doc = json; } Configuration option = Configuration.defaultConfiguration().addOptions(Option.SUPPRESS_EXCEPTIONS); DocumentContext documentContext = JsonPath.parse(doc, option); return replace(input, documentContext, null); }
private Map<String, Object> startWorkflow(Action action, Object payload, String event, String messageId) { StartWorkflow params = action.getStart_workflow(); Map<String, Object> output = new HashMap<>(); try { Map<String, Object> inputParams = params.getInput(); Map<String, Object> workflowInput = parametersUtils.replace(inputParams, payload); workflowInput.put("conductor.event.messageId", messageId); workflowInput.put("conductor.event.name", event); String id = executor.startWorkflow(params.getName(), params.getVersion(), params.getCorrelationId(), workflowInput, null, event, params.getTaskToDomain()); output.put("workflowId", id); } catch (RuntimeException e) { logger.error("Error starting workflow: {}, version: {}, for event: {} for message: {}", params.getName(), params.getVersion(), event, messageId, e); output.put("error", e.getMessage()); throw e; } return output; } }
input.putAll(taskDetails.getOutput()); Map<String, Object> replaced = parametersUtils.replace(input, payload); String workflowId = (String) replaced.get("workflowId"); String taskId = (String) replaced.get("taskId");
.addOptions(Option.SUPPRESS_EXCEPTIONS); DocumentContext documentContext = JsonPath.parse(inputMap, option); return replace(inputParams, documentContext, taskId);