@Test public void calculateOutputVariablesShouldDoMappingWhenThereIsMappingSet() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); ProcessExtensionModel extensions = objectMapper.readValue(new File("src/test/resources/task-variable-mapping-extensions.json"), ProcessExtensionModel.class); Extension processExtensions = extensions.getExtensions("Process_taskVarMapping"); DelegateExecution execution = buildExecution(processExtensions); ExpressionResolver expressionResolver = ExpressionResolverHelper.initContext(execution, processExtensions); ReflectionTestUtils.setField(variablesMappingProvider, "expressionResolver", expressionResolver); Map<String, Object> entityVariables = singletonMap("task_output_variable_name_1", "var-one"); ExpressionResolverHelper.setExecutionVariables(execution, entityVariables); Map<String, Object> outPutVariables = variablesMappingProvider.calculateOutPutVariables(buildMappingExecutionContext(execution), entityVariables); assertThat(outPutVariables.get("process_variable_outputmap_1")).isEqualTo("var-one"); assertThat(outPutVariables).doesNotContainKey("property-with-no-default-value"); }
public Map<String, Object> calculateOutPutVariables(MappingExecutionContext mappingExecutionContext, Map<String, Object> availableVariables) { Extension extensions = processExtensionService.getExtensionsForId(mappingExecutionContext.getProcessDefinitionId()); if (!extensions.hasMapping(mappingExecutionContext.getActivityId())) { return emptyMap(); } if (extensions.shouldMapAllOutputs(mappingExecutionContext.getActivityId())) { return (availableVariables != null ? new HashMap<>(availableVariables) : emptyMap()); } if (availableVariables != null && !availableVariables.isEmpty()) { if (expressionResolver.containsExpression(availableVariables)) { throw new ActivitiIllegalArgumentException("Expressions are not allowed as variable values in the output mapping"); } return calculateOutPutVariables(mappingExecutionContext, extensions, availableVariables); } else { return emptyMap(); } }
ExtensionsVariablesMappingProvider implements VariablesCalculator { public Map<String, Object> calculateOutPutVariables(MappingExecutionContext mappingExecutionContext, Map<String, Object> availableVariables) { Extension extensions = processExtensionService.getExtensionsForId(mappingExecutionContext.getProcessDefinitionId()); if (!extensions.hasMapping(mappingExecutionContext.getActivityId())) { return emptyMap(); } if (extensions.shouldMapAllOutputs(mappingExecutionContext.getActivityId())) { return (availableVariables != null ? new HashMap<>(availableVariables) : emptyMap()); } if (availableVariables != null && !availableVariables.isEmpty()) { if (expressionResolver.containsExpression(availableVariables)) { throw new ActivitiIllegalArgumentException("Expressions are not allowed as variable values in the output mapping"); } return calculateOutPutVariables(mappingExecutionContext, extensions, availableVariables); } else { return emptyMap(); } } }
ExtensionsVariablesMappingProvider implements VariablesCalculator { public Map<String, Object> calculateOutPutVariables(MappingExecutionContext mappingExecutionContext, Map<String, Object> availableVariables) { Extension extensions = processExtensionService.getExtensionsForId(mappingExecutionContext.getProcessDefinitionId()); if (!extensions.hasMapping(mappingExecutionContext.getActivityId())) { return emptyMap(); } if (extensions.shouldMapAllOutputs(mappingExecutionContext.getActivityId())) { return (availableVariables != null ? new HashMap<>(availableVariables) : emptyMap()); } if (availableVariables != null && !availableVariables.isEmpty()) { if (expressionResolver.containsExpression(availableVariables)) { throw new ActivitiIllegalArgumentException("Expressions are not allowed as variable values in the output mapping"); } return calculateOutPutVariables(mappingExecutionContext, extensions, availableVariables); } else { return emptyMap(); } } ExtensionsVariablesMappingProvider(ProcessExtensionService processExtensionService,
                                    ExpressionResolver expressionResolver); }
ExtensionsVariablesMappingProvider implements VariablesCalculator { public Map<String, Object> calculateOutPutVariables(MappingExecutionContext mappingExecutionContext, Map<String, Object> availableVariables) { Extension extensions = processExtensionService.getExtensionsForId(mappingExecutionContext.getProcessDefinitionId()); if (!extensions.hasMapping(mappingExecutionContext.getActivityId())) { return emptyMap(); } if (extensions.shouldMapAllOutputs(mappingExecutionContext.getActivityId())) { return (availableVariables != null ? new HashMap<>(availableVariables) : emptyMap()); } if (availableVariables != null && !availableVariables.isEmpty()) { if (expressionResolver.containsExpression(availableVariables)) { throw new ActivitiIllegalArgumentException("Expressions are not allowed as variable values in the output mapping"); } return calculateOutPutVariables(mappingExecutionContext, extensions, availableVariables); } else { return emptyMap(); } } ExtensionsVariablesMappingProvider(ProcessExtensionService processExtensionService,
                                    ExpressionResolver expressionResolver); Map<String, Object> calculateInputVariables(DelegateExecution execution); Map<String, Object> calculateOutPutVariables(MappingExecutionContext mappingExecutionContext,
                                                        Map<String, Object> availableVariables); }
ExtensionsVariablesMappingProvider implements VariablesCalculator { public Map<String, Object> calculateOutPutVariables(MappingExecutionContext mappingExecutionContext, Map<String, Object> availableVariables) { Extension extensions = processExtensionService.getExtensionsForId(mappingExecutionContext.getProcessDefinitionId()); if (!extensions.hasMapping(mappingExecutionContext.getActivityId())) { return emptyMap(); } if (extensions.shouldMapAllOutputs(mappingExecutionContext.getActivityId())) { return (availableVariables != null ? new HashMap<>(availableVariables) : emptyMap()); } if (availableVariables != null && !availableVariables.isEmpty()) { if (expressionResolver.containsExpression(availableVariables)) { throw new ActivitiIllegalArgumentException("Expressions are not allowed as variable values in the output mapping"); } return calculateOutPutVariables(mappingExecutionContext, extensions, availableVariables); } else { return emptyMap(); } } ExtensionsVariablesMappingProvider(ProcessExtensionService processExtensionService,
                                    ExpressionResolver expressionResolver); Map<String, Object> calculateInputVariables(DelegateExecution execution); Map<String, Object> calculateOutPutVariables(MappingExecutionContext mappingExecutionContext,
                                                        Map<String, Object> availableVariables);  }