use of org.motechproject.tasks.domain.mds.channel.EventParameter in project motech by motech.
the class TaskServiceImplTest method shouldNotSaveTaskIfNotMatchExtraValidationConditions.
@Test(expected = ValidationException.class)
public void shouldNotSaveTaskIfNotMatchExtraValidationConditions() {
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);
Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SENDING", "", asList(new EventParameter("test", "value")), "")), null);
Channel actionChannel = new Channel("test", "test-action", "0.14", "", null, asList(new ActionEventBuilder().setDisplayName("receive").setSubject("RECEIVE").setDescription("").setActionParameters(null).build()));
TaskDataProvider provider = new TaskDataProvider("TestProvider", asList(new TaskDataProviderObject("test", "Test", asList(new LookupFieldsParameter("id", asList("id"))), null)));
provider.setId(1234L);
Set<TaskError> errors = new HashSet<>();
errors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName()));
when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
when(providerService.getProviderById(1234L)).thenReturn(provider);
when(triggerEventService.validateTrigger(trigger)).thenReturn(errors);
taskService.save(task);
}
use of org.motechproject.tasks.domain.mds.channel.EventParameter 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.channel.EventParameter in project motech by motech.
the class SchedulerChannelProvider method getTrigger.
@Override
public TriggerEvent getTrigger(TaskTriggerInformation info) {
try (Connection conn = DBConnectionManager.getInstance().getConnection(sqlProperties.getProperty(DATA_SOURCE));
Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery(buildGetTriggerQuery(info.getSubject()));
if (rs.next()) {
try (InputStream is = new ByteArrayInputStream(rs.getBytes(JOB_DATA));
ObjectInputStream ois = new ObjectInputStream(is)) {
JobDataMap dataMap = (JobDataMap) ois.readObject();
List<EventParameter> parameters = new ArrayList<>();
parameters.add(new EventParameter("scheduler.jobId", MotechSchedulerService.JOB_ID_KEY));
return new TriggerEvent("Job: " + rs.getString(JOB_NAME), rs.getString(JOB_NAME), rs.getString(JOB_DESCRIPTION), parameters, dataMap.getString(SchedulerConstants.EVENT_TYPE_KEY_NAME));
}
}
return null;
} catch (SQLException | IOException | ClassNotFoundException e) {
throw new TriggerRetrievalException("Couldn't retrieve triggers for Scheduler channel", e);
}
}
use of org.motechproject.tasks.domain.mds.channel.EventParameter in project motech by motech.
the class SchedulerChannelProviderBundleIT method getExpectedTriggers.
private List<TriggerEvent> getExpectedTriggers() {
List<TriggerEvent> triggers = new ArrayList<>();
List<EventParameter> parameters = new ArrayList<>();
parameters.add(new EventParameter("scheduler.jobId", "JobID"));
triggers.add(new TriggerEvent("Job: test-event-job_id", "test-event-job_id", null, parameters, TEST_EVENT));
triggers.add(new TriggerEvent("Job: test-event-job_id-repeat", "test-event-job_id-repeat", null, parameters, TEST_EVENT));
triggers.add(new TriggerEvent("Job: test-event-job_id-runonce", "test-event-job_id-runonce", null, parameters, TEST_EVENT));
return triggers;
}
use of org.motechproject.tasks.domain.mds.channel.EventParameter in project motech by motech.
the class TriggerEventBuilder method fromTriggerEventRequest.
/**
* Creates a builder, which allows building trigger events based on the given {@code triggerEventRequest}.
*
* @param triggerEventRequest the trigger event request
* @return the created builder
*/
public static TriggerEventBuilder fromTriggerEventRequest(TriggerEventRequest triggerEventRequest) {
TriggerEventBuilder builder = new TriggerEventBuilder().setDisplayName(triggerEventRequest.getDisplayName()).setSubject(triggerEventRequest.getSubject()).setDescription(triggerEventRequest.getDescription()).setTriggerListenerSubject(triggerEventRequest.getTriggerListenerSubject());
List<EventParameter> eventParameters = new ArrayList<>();
for (EventParameterRequest eventParameterRequest : triggerEventRequest.getEventParameters()) {
eventParameters.add(EventParameterBuilder.fromEventParameterRequest(eventParameterRequest).build());
}
builder.setEventParameters(eventParameters);
return builder;
}
Aggregations