Search in sources :

Example 6 with ActionParameterBuilder

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;
}
Also used : ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) TreeSet(java.util.TreeSet) TaskActionParam(org.motechproject.tasks.annotations.TaskActionParam) ActionParameter(org.motechproject.tasks.domain.mds.channel.ActionParameter) Annotation(java.lang.annotation.Annotation)

Example 7 with ActionParameterBuilder

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;
}
Also used : ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) TreeSet(java.util.TreeSet) ActionParameter(org.motechproject.tasks.domain.mds.channel.ActionParameter) TaskPostActionParam(org.motechproject.tasks.annotations.TaskPostActionParam) Annotation(java.lang.annotation.Annotation)

Example 8 with ActionParameterBuilder

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);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) ArrayList(java.util.ArrayList) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) Filter(org.motechproject.tasks.domain.mds.task.Filter) LookupFieldsParameter(org.motechproject.tasks.domain.mds.task.LookupFieldsParameter) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) FieldParameter(org.motechproject.tasks.domain.mds.task.FieldParameter) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 9 with ActionParameterBuilder

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();
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) LookupFieldsParameter(org.motechproject.tasks.domain.mds.task.LookupFieldsParameter) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) Test(org.junit.Test)

Example 10 with ActionParameterBuilder

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;
}
Also used : ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) TreeSet(java.util.TreeSet) ActionParameter(org.motechproject.tasks.domain.mds.channel.ActionParameter)

Aggregations

ActionParameterBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder)19 TreeSet (java.util.TreeSet)6 ActionParameter (org.motechproject.tasks.domain.mds.channel.ActionParameter)6 Test (org.junit.Test)5 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)5 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)5 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)5 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)5 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)4 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)4 Task (org.motechproject.tasks.domain.mds.task.Task)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Matchers.anyString (org.mockito.Matchers.anyString)3 MotechEvent (org.motechproject.event.MotechEvent)3 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)3 Annotation (java.lang.annotation.Annotation)2 DataProvider (org.motechproject.commons.api.DataProvider)2 Channel (org.motechproject.tasks.domain.mds.channel.Channel)2 LookupFieldsParameter (org.motechproject.tasks.domain.mds.task.LookupFieldsParameter)2