@Test public void shouldHandleFormatManipulation() throws Exception { setTriggerEvent(); setActionEvent(); setFormatManipulation(); setAdditionalData(true); Map<String, String> testObjectLookup = new HashMap<>(); testObjectLookup.put("id", "123456789-6789"); TestObject testObject = new TestObject(); TestObjectField testObjectField = new TestObjectField(); Map<String, String> testObjectFieldLookup = new HashMap<>(); testObjectFieldLookup.put("id", "123456789"); when(taskService.findActiveTasksForTriggerSubject(TRIGGER_SUBJECT)).thenReturn(tasks); when(taskService.getActionEventFor(any(TaskActionInformation.class))).thenReturn(actionEvent); when(dataProvider.getName()).thenReturn("TEST"); when(dataProvider.supports("TestObject")).thenReturn(true); when(dataProvider.lookup("TestObject", "id", testObjectLookup)).thenReturn(testObject); when(dataProvider.supports("TestObjectField")).thenReturn(true); when(dataProvider.lookup("TestObjectField", "id", testObjectFieldLookup)).thenReturn(testObjectField); ArgumentCaptor<MotechEvent> captor = ArgumentCaptor.forClass(MotechEvent.class); handler.handle(createEvent()); verify(eventRelay).sendEventMessage(captor.capture()); MotechEvent event = captor.getAllValues().get(0); assertEquals("123456789 || 6789 || YourName", event.getParameters().get("format")); }
@Override @Transactional public void handle(MotechEvent event) { LOGGER.info("Handling the motech event with subject: {}", event.getSubject()); Map<String, Object> eventParams = event.getParameters(); eventParams.putAll(event.getMetadata()); TasksEventParser parser = null; if (eventParams != null) { parser = taskService.findCustomParser((String) eventParams.get(TasksEventParser.CUSTOM_PARSER_EVENT_KEY)); } String triggerSubject = parser == null ? event.getSubject() : parser.parseEventSubject(event.getSubject(), eventParams); Map<String, Object> parameters = parser == null ? eventParams : parser.parseEventParameters(event.getSubject(), eventParams); List<Task> tasks = taskService.findActiveTasksForTriggerSubject(triggerSubject); for (Task task : tasks) { checkAndHandleTask(task, parameters); } }
TaskTriggerHandler implements TriggerHandler { @Override @Transactional public void handle(MotechEvent event) { LOGGER.info("Handling the motech event with subject: {}", event.getSubject()); Map<String, Object> eventParams = event.getParameters(); eventParams.putAll(event.getMetadata()); TasksEventParser parser = null; if (eventParams != null) { parser = taskService.findCustomParser((String) eventParams.get(TasksEventParser.CUSTOM_PARSER_EVENT_KEY)); } String triggerSubject = parser == null ? event.getSubject() : parser.parseEventSubject(event.getSubject(), eventParams); Map<String, Object> parameters = parser == null ? eventParams : parser.parseEventParameters(event.getSubject(), eventParams); List<Task> tasks = taskService.findActiveTasksForTriggerSubject(triggerSubject); for (Task task : tasks) { checkAndHandleTask(task, parameters); } } }
TaskTriggerHandler implements TriggerHandler { @Override @Transactional public void handle(MotechEvent event) { LOGGER.info("Handling the motech event with subject: {}", event.getSubject()); Map<String, Object> eventParams = event.getParameters(); eventParams.putAll(event.getMetadata()); TasksEventParser parser = null; if (eventParams != null) { parser = taskService.findCustomParser((String) eventParams.get(TasksEventParser.CUSTOM_PARSER_EVENT_KEY)); } String triggerSubject = parser == null ? event.getSubject() : parser.parseEventSubject(event.getSubject(), eventParams); Map<String, Object> parameters = parser == null ? eventParams : parser.parseEventParameters(event.getSubject(), eventParams); List<Task> tasks = taskService.findActiveTasksForTriggerSubject(triggerSubject); for (Task task : tasks) { checkAndHandleTask(task, parameters); } }  }
TaskTriggerHandler implements TriggerHandler { @Override @Transactional public void handle(MotechEvent event) { LOGGER.info("Handling the motech event with subject: {}", event.getSubject()); Map<String, Object> eventParams = event.getParameters(); eventParams.putAll(event.getMetadata()); TasksEventParser parser = null; if (eventParams != null) { parser = taskService.findCustomParser((String) eventParams.get(TasksEventParser.CUSTOM_PARSER_EVENT_KEY)); } String triggerSubject = parser == null ? event.getSubject() : parser.parseEventSubject(event.getSubject(), eventParams); Map<String, Object> parameters = parser == null ? eventParams : parser.parseEventParameters(event.getSubject(), eventParams); List<Task> tasks = taskService.findActiveTasksForTriggerSubject(triggerSubject); for (Task task : tasks) { checkAndHandleTask(task, parameters); } }  @PostConstruct void init(); @PreDestroy void preDestroy(); @Override void registerHandlerFor(String subject); @Override void registerHandlerFor(String subject, boolean isRetryHandler); @Override @Transactional void handle(MotechEvent event); @Override @Transactional void handleRetry(MotechEvent event); @Override @Transactional void retryTask(Long activityId); @Override void addDataProvider(DataProvider provider); @Override void removeDataProvider(String taskDataProviderId); @Autowired void setBundleContext(BundleContext bundleContext); }
TaskTriggerHandler implements TriggerHandler { @Override @Transactional public void handle(MotechEvent event) { LOGGER.info("Handling the motech event with subject: {}", event.getSubject()); Map<String, Object> eventParams = event.getParameters(); eventParams.putAll(event.getMetadata()); TasksEventParser parser = null; if (eventParams != null) { parser = taskService.findCustomParser((String) eventParams.get(TasksEventParser.CUSTOM_PARSER_EVENT_KEY)); } String triggerSubject = parser == null ? event.getSubject() : parser.parseEventSubject(event.getSubject(), eventParams); Map<String, Object> parameters = parser == null ? eventParams : parser.parseEventParameters(event.getSubject(), eventParams); List<Task> tasks = taskService.findActiveTasksForTriggerSubject(triggerSubject); for (Task task : tasks) { checkAndHandleTask(task, parameters); } }  @PostConstruct void init(); @PreDestroy void preDestroy(); @Override void registerHandlerFor(String subject); @Override void registerHandlerFor(String subject, boolean isRetryHandler); @Override @Transactional void handle(MotechEvent event); @Override @Transactional void handleRetry(MotechEvent event); @Override @Transactional void retryTask(Long activityId); @Override void addDataProvider(DataProvider provider); @Override void removeDataProvider(String taskDataProviderId); @Autowired void setBundleContext(BundleContext bundleContext);  }