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