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;
}
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());
}
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));
}
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());
}
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());
}
Aggregations