Search in sources :

Example 6 with TaskConfig

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

the class TaskConfigDeserializer method deserialize.

@Override
public TaskConfig deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    JsonNode jsonNode = parser.readValueAsTree();
    TaskConfig config = new TaskConfig();
    ObjectMapper mapper;
    ObjectCodec codec = parser.getCodec();
    if (codec instanceof ObjectMapper) {
        mapper = (ObjectMapper) codec;
    } else {
        mapper = new ObjectMapper();
    }
    if (jsonNode.has("steps")) {
        Iterator<JsonNode> steps = jsonNode.get("steps").getElements();
        while (steps.hasNext()) {
            JsonNode next = steps.next();
            if (isDtoType(next)) {
                config.add(mapper.readValue(next, TaskConfigStepDto.class));
            } else {
                config.add(mapper.readValue(next, TaskConfigStep.class));
            }
        }
    }
    return config;
}
Also used : TaskConfigStep(org.motechproject.tasks.domain.mds.task.TaskConfigStep) TaskConfigStepDto(org.motechproject.tasks.dto.TaskConfigStepDto) JsonNode(org.codehaus.jackson.JsonNode) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) ObjectCodec(org.codehaus.jackson.ObjectCodec) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 7 with TaskConfig

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

the class TaskConfigTest method shouldRemoveOnlyFilterSets.

@Test
public void shouldRemoveOnlyFilterSets() 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.removeFilterSets();
    assertNotNull(config.getSteps());
    assertFalse(config.getSteps().isEmpty());
    assertTrue(config.getFilters().isEmpty());
    assertFalse(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 8 with TaskConfig

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

the class TaskConfigTest method shouldAddStepAndSetNewOrderNumber.

@Test
public void shouldAddStepAndSetNewOrderNumber() 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();
    for (TaskConfigStep step : steps) {
        config.add(step);
    }
    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) ArrayList(java.util.ArrayList) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) Test(org.junit.Test)

Example 9 with TaskConfig

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

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

the class TaskServiceImplTest method shouldRemoveValidationErrorAndUpdateTaskOnlyIfItHasAnyValidationErrors.

@Test
public void shouldRemoveValidationErrorAndUpdateTaskOnlyIfItHasAnyValidationErrors() {
    Task task = new Task("name", trigger, asList(action), new TaskConfig(), true, false);
    Set<TaskError> existingErrors = new HashSet<>();
    existingErrors.add(new TaskError("task.validation.error.triggerNotExist"));
    task.addValidationErrors(existingErrors);
    when(tasksDataService.executeQuery(any(QueryExecution.class))).thenReturn(asList(task));
    Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SEND", "", asList(new EventParameter("test", "value")), "")), null);
    when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
    when(triggerEventService.triggerExists(task.getTrigger())).thenReturn(true);
    taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(trigger));
    Task actualTask = verifyCreateAndCaptureTask();
    assertFalse(actualTask.hasValidationErrors());
}
Also used : EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) Task(org.motechproject.tasks.domain.mds.task.Task) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) QueryExecution(org.motechproject.mds.query.QueryExecution) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)25 Test (org.junit.Test)23 Task (org.motechproject.tasks.domain.mds.task.Task)19 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)17 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)12 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)12 ArrayList (java.util.ArrayList)11 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)10 FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)10 Channel (org.motechproject.tasks.domain.mds.channel.Channel)9 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)9 HashMap (java.util.HashMap)8 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)8 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)7 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)7 HashSet (java.util.HashSet)6 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)6 Matchers.anyString (org.mockito.Matchers.anyString)5 QueryExecution (org.motechproject.mds.query.QueryExecution)5 LinkedHashMap (java.util.LinkedHashMap)4