use of org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder in project motech by motech.
the class TaskAnnotationBeanPostProcessor method getActionParams.
private SortedSet<ActionParameter> getActionParams(Method method) {
SortedSet<ActionParameter> parameters = new TreeSet<>();
int order = 0;
for (Annotation[] annotations : method.getParameterAnnotations()) {
for (Annotation annotation : annotations) {
if (annotation instanceof TaskActionParam) {
LOGGER.debug("The @TaskActionParam annotation was found in parameters from method: {}", method.getName());
TaskActionParam param = (TaskActionParam) annotation;
LOGGER.debug("Task action parameter: {} added", param.displayName());
parameters.add(new ActionParameterBuilder().setDisplayName(param.displayName()).setKey(param.key()).setType(param.type()).setOrder(order).setRequired(param.required()).build());
++order;
}
}
}
return parameters.isEmpty() ? null : parameters;
}
use of org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder in project motech by motech.
the class TaskAnnotationBeanPostProcessor method getPostActionParams.
private SortedSet<ActionParameter> getPostActionParams(Method method) {
SortedSet<ActionParameter> parameters = new TreeSet<>();
int order = 0;
for (Annotation[] annotations : method.getParameterAnnotations()) {
for (Annotation annotation : annotations) {
if (annotation instanceof TaskPostActionParam) {
LOGGER.debug("The @TaskPostActionParam annotation was found in parameters from method: {}", method.getName());
TaskPostActionParam param = (TaskPostActionParam) annotation;
LOGGER.debug("Task action parameter: {} added", param.displayName());
parameters.add(new ActionParameterBuilder().setDisplayName(param.displayName()).setKey(param.key()).setType(param.type()).setOrder(order).setRequired(param.required()).build());
++order;
}
}
}
return parameters.isEmpty() ? null : parameters;
}
use of org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder in project motech by motech.
the class TaskServiceImplTest method shouldImportTask.
@Test
public void shouldImportTask() throws Exception {
ObjectMapper mapper = new ObjectMapper();
action.getValues().put("phone", "{{ad.providerName.Test#1.id}}");
List<String> filtersManipulations = new ArrayList<>();
Task given = new TaskBuilder().withName("test").withTrigger(trigger).addAction(action).addDataSource(new DataSource("providerName", 1234L, 1L, "Test", "id", asList(new Lookup("id", "trigger.value")), true)).addFilterSet(new FilterSet(asList(new Filter("displayName", "ad.providerName.Test#1.id", UNICODE, true, OperatorType.EXIST.getValue(), "", filtersManipulations)))).isEnabled(true).build();
TaskDataProvider provider = new TaskDataProvider();
provider.setName("providerName");
provider.setId(56789L);
provider.setObjects(asList(new TaskDataProviderObject("display", "Test", asList(new LookupFieldsParameter("id", asList("id"))), asList(new FieldParameter("display", "id", UNICODE)))));
Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SEND", "", asList(new EventParameter("test", "value")), "")), null);
ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("receive").setSubject("RECEIVE").setDescription("").setActionParameters(null).build();
actionEvent.addParameter(new ActionParameterBuilder().setDisplayName("Phone").setKey("phone").build(), true);
Channel actionChannel = new Channel("test", "test-action", "0.14", "", null, asList(actionEvent));
when(providerService.getProviders()).thenReturn(asList(provider));
when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
when(triggerEventService.triggerExists(given.getTrigger())).thenReturn(true);
when(providerService.getProvider("providerName")).thenReturn(provider);
String json = mapper.writeValueAsString(given);
taskService.importTask(json);
action.getValues().put("phone", "{{ad.providerName.Test#1.id}}");
Task expected = new TaskBuilder().withName("test").withTrigger(trigger).addAction(action).addDataSource(new DataSource("providerName", 56789L, 1L, "Test", "id", asList(new Lookup("id", "trigger.value")), true)).addFilterSet(new FilterSet(asList(new Filter("displayName", "ad.providerName.Test#1.id", UNICODE, true, OperatorType.EXIST.getValue(), "", filtersManipulations)))).isEnabled(true).build();
Task actual = verifyCreateAndCaptureTask();
assertEquals(expected, actual);
verify(taskMigrationManager).migrateTask(actual);
}
use of org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder in project motech by motech.
the class TaskServiceImplTest method shouldSaveTask.
@Test
public void shouldSaveTask() {
Map<String, String> map = new HashMap<>();
map.put("phone", "12345");
TaskConfig config = new TaskConfig().add(new DataSource("TestProvider", 1234L, 1L, "Test", "id", "specifiedName", asList(new Lookup("id", "trigger.value")), true));
action.setValues(map);
Task task = new Task("name", trigger, asList(action), config, true, false);
task.setNumberOfRetries(5);
task.setRetryTaskOnFailure(true);
Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SEND", "", asList(new EventParameter("test", "value")), "")), null);
ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("receive").setSubject("RECEIVE").setDescription("").setActionParameters(null).build();
actionEvent.addParameter(new ActionParameterBuilder().setDisplayName("Phone").setKey("phone").build(), true);
Channel actionChannel = new Channel("test", "test-action", "0.14", "", null, asList(actionEvent));
TaskDataProvider provider = new TaskDataProvider("TestProvider", asList(new TaskDataProviderObject("test", "Test", asList(new LookupFieldsParameter("id", asList("id"))), null)));
provider.setId(1234L);
when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
when(providerService.getProvider("TestProvider")).thenReturn(provider);
when(triggerEventService.triggerExists(task.getTrigger())).thenReturn(true);
taskService.save(task);
verify(triggerHandler).registerHandlerFor(task.getTrigger().getEffectiveListenerSubject());
// Because task has set number of retries to 5, it should register retries handler for this task
verify(triggerHandler).registerHandlerFor(task.getTrigger().getEffectiveListenerRetrySubject(), true);
verifyCreateAndCaptureTask();
}
use of org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder in project motech by motech.
the class TaskAnnotationBeanPostProcessorTest method getExpectedActionParameters.
private SortedSet<ActionParameter> getExpectedActionParameters() {
SortedSet<ActionParameter> set = new TreeSet<>();
set.add(new ActionParameterBuilder().setDisplayName(EXTERNAL_DISPLAY_NAME).setKey(EXTERNAL_KEY).setOrder(0).build());
set.add(new ActionParameterBuilder().setDisplayName(MOTECH_DISPLAY_NAME).setKey(MOTECH_KEY).setOrder(1).setType(ParameterType.INTEGER).build());
return set;
}
Aggregations