Search in sources :

Example 11 with FilterSet

use of org.motechproject.tasks.domain.mds.task.FilterSet in project motech by motech.

the class TaskConfigTest method shouldRemoveOnlyDataSources.

@Test
public void shouldRemoveOnlyDataSources() throws Exception {
    TaskConfig config = new TaskConfig().add(new FilterSet(), new FilterSet(), new FilterSet()).add(new DataSource(), new DataSource(), new DataSource());
    assertNotNull(config.getSteps());
    assertFalse(config.getSteps().isEmpty());
    config.removeDataSources();
    assertNotNull(config.getSteps());
    assertFalse(config.getSteps().isEmpty());
    assertFalse(config.getFilters().isEmpty());
    assertTrue(config.getDataSources().isEmpty());
}
Also used : FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) Test(org.junit.Test)

Example 12 with FilterSet

use of org.motechproject.tasks.domain.mds.task.FilterSet 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 13 with FilterSet

use of org.motechproject.tasks.domain.mds.task.FilterSet in project motech by motech.

the class ProviderNameTaskMigrator method migrateFilters.

private void migrateFilters(Task task) {
    for (FilterSet filterSet : task.getTaskConfig().getFilters()) {
        for (Filter filter : filterSet.getFilters()) {
            // replace data source references in filter expressions
            String oldVal = filter.getExpression();
            String newVal = replaceTaskValue(oldVal, EXPR_PATTERN, task);
            filter.setExpression(newVal);
            // also make sure the key is correct
            oldVal = filter.getKey();
            newVal = replaceTaskValue(oldVal, FILTER_KEY_PATTERN, task);
            filter.setKey(newVal);
        }
    }
}
Also used : FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) Filter(org.motechproject.tasks.domain.mds.task.Filter)

Example 14 with FilterSet

use of org.motechproject.tasks.domain.mds.task.FilterSet in project motech by motech.

the class TaskConfigTest method shouldRemoveAllSteps.

@Test
public void shouldRemoveAllSteps() throws Exception {
    TaskConfig config = new TaskConfig().add(new FilterSet(), new FilterSet(), new FilterSet()).add(new DataSource(), new DataSource(), new DataSource());
    assertNotNull(config.getSteps());
    assertFalse(config.getSteps().isEmpty());
    config.removeAll();
    assertNotNull(config.getSteps());
    assertTrue(config.getSteps().isEmpty());
}
Also used : FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) Test(org.junit.Test)

Example 15 with FilterSet

use of org.motechproject.tasks.domain.mds.task.FilterSet in project motech by motech.

the class TaskConfigTest method shouldAddAllStepsAndSetNewOrderNumber.

@Test
public void shouldAddAllStepsAndSetNewOrderNumber() throws Exception {
    List<TaskConfigStep> steps = new ArrayList<>();
    steps.add(new FilterSet());
    steps.add(new DataSource());
    steps.add(new DataSource());
    steps.add(new FilterSet());
    Random random = new Random();
    for (TaskConfigStep step : steps) {
        step.setOrder(random.nextInt());
    }
    TaskConfig config = new TaskConfig().addAll(null).addAll(new TreeSet<TaskConfigStep>()).addAll(new TreeSet<>(steps));
    List<Integer> orders = new ArrayList<>(steps.size());
    for (TaskConfigStep step : config.getSteps()) {
        orders.add(step.getOrder());
    }
    assertThat(orders, hasItems(0, 1, 2, 3));
}
Also used : TaskConfigStep(org.motechproject.tasks.domain.mds.task.TaskConfigStep) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) Random(java.util.Random) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) Test(org.junit.Test)

Aggregations

FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)16 Test (org.junit.Test)11 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)11 ArrayList (java.util.ArrayList)9 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)9 Filter (org.motechproject.tasks.domain.mds.task.Filter)7 Matchers.anyString (org.mockito.Matchers.anyString)5 Task (org.motechproject.tasks.domain.mds.task.Task)5 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)4 TaskHandlerException (org.motechproject.tasks.exception.TaskHandlerException)4 MotechEvent (org.motechproject.event.MotechEvent)3 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)3 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)3 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)3 TaskConfigStep (org.motechproject.tasks.domain.mds.task.TaskConfigStep)3 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)3 HashMap (java.util.HashMap)2 Random (java.util.Random)2 DataProvider (org.motechproject.commons.api.DataProvider)2 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)2