use of org.motechproject.tasks.domain.mds.channel.ActionParameter in project motech by motech.
the class TaskTriggerHandlerTest method shouldTriggerErrorWhenActionDoesNotFindDataSourceWithFailIfDataNotFoundSelected.
@Test
public void shouldTriggerErrorWhenActionDoesNotFindDataSourceWithFailIfDataNotFoundSelected() throws Exception {
Map<String, DataProvider> providers = new HashMap<>();
DataProvider provider = mock(DataProvider.class);
Map<String, String> lookup = new HashMap<>();
lookup.put("patientId", "123");
when(provider.lookup("Patient", "", lookup)).thenReturn(null);
providers.put(TASK_DATA_PROVIDER_NAME, provider);
handler.setDataProviders(providers);
TriggerEvent trigger = new TriggerEvent();
trigger.setSubject("trigger");
List<EventParameter> triggerEventParameters = new ArrayList<>();
triggerEventParameters.add(new EventParameter("patientId", "123"));
trigger.setEventParameters(triggerEventParameters);
ActionEvent action = new ActionEventBuilder().build();
action.setSubject("action");
SortedSet<ActionParameter> actionEventParameters = new TreeSet<>();
actionEventParameters.add(new ActionParameterBuilder().setDisplayName("Patient ID").setKey("patientId").setType(UNICODE).setOrder(0).build());
action.setActionParameters(actionEventParameters);
Task task = new Task();
task.setName("task");
task.setTrigger(new TaskTriggerInformation("Trigger", "channel", "module", "0.1", "trigger", "listener"));
Map<String, String> actionValues = new HashMap<>();
actionValues.put("patientId", "{{ad.providerId.Patient#1.patientId}}");
task.addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "action", actionValues));
task.setId(44l);
task.setHasRegisteredChannel(true);
TaskConfig taskConfig = new TaskConfig();
task.setTaskConfig(taskConfig);
taskConfig.add(new DataSource(TASK_DATA_PROVIDER_NAME, 4L, 1L, "Patient", "provider", "specifiedName", asList(new Lookup("patientId", "trigger.patientId")), true));
List<Task> tasks = asList(task);
when(taskService.findActiveTasksForTriggerSubject("trigger")).thenReturn(tasks);
when(taskService.getActionEventFor(task.getActions().get(0))).thenReturn(action);
setTaskActivities();
task.setFailuresInRow(taskActivities.size());
Map<String, Object> param = new HashMap<>(4);
param.put("patientId", "123");
handler.handle(new MotechEvent("trigger", param));
verify(postExecutionHandler).handleError(anyMap(), anyMap(), eq(task), any(TaskHandlerException.class), eq(TASK_ACTIVITY_ID));
}
use of org.motechproject.tasks.domain.mds.channel.ActionParameter in project motech by motech.
the class MethodHandler method initForNamedParametersCall.
private void initForNamedParametersCall(Map<String, Object> parameters, SortedSet<ActionParameter> actionParameters) {
if (!actionParameters.isEmpty()) {
classes = new Class[parameters.size()];
objects = new Object[parameters.size()];
for (ActionParameter actionParameter : actionParameters) {
Object obj = parameters.get(actionParameter.getKey());
Integer idx = actionParameter.getOrder();
objects[idx] = obj;
if (obj instanceof Map) {
classes[idx] = Map.class;
} else if (obj instanceof List) {
classes[idx] = List.class;
} else if (obj != null) {
classes[idx] = obj.getClass();
} else if (actionParameter.getType() != null) {
classes[idx] = actionParameter.getType().getUnderlyingClass();
} else {
classes[idx] = Object.class;
}
}
} else {
classes = new Class[0];
objects = new Object[0];
}
}
use of org.motechproject.tasks.domain.mds.channel.ActionParameter in project motech by motech.
the class TaskAnnotationBeanPostProcessor method getActionParams.
private SortedSet<ActionParameter> getActionParams(Method method) {
SortedSet<ActionParameter> parameters = new TreeSet<>();
int order = 0;
for (Annotation[] annotations : method.getParameterAnnotations()) {
for (Annotation annotation : annotations) {
if (annotation instanceof TaskActionParam) {
LOGGER.debug("The @TaskActionParam annotation was found in parameters from method: {}", method.getName());
TaskActionParam param = (TaskActionParam) annotation;
LOGGER.debug("Task action parameter: {} added", param.displayName());
parameters.add(new ActionParameterBuilder().setDisplayName(param.displayName()).setKey(param.key()).setType(param.type()).setOrder(order).setRequired(param.required()).build());
++order;
}
}
}
return parameters.isEmpty() ? null : parameters;
}
use of org.motechproject.tasks.domain.mds.channel.ActionParameter in project motech by motech.
the class TaskAnnotationBeanPostProcessor method getPostActionParams.
private SortedSet<ActionParameter> getPostActionParams(Method method) {
SortedSet<ActionParameter> parameters = new TreeSet<>();
int order = 0;
for (Annotation[] annotations : method.getParameterAnnotations()) {
for (Annotation annotation : annotations) {
if (annotation instanceof TaskPostActionParam) {
LOGGER.debug("The @TaskPostActionParam annotation was found in parameters from method: {}", method.getName());
TaskPostActionParam param = (TaskPostActionParam) annotation;
LOGGER.debug("Task action parameter: {} added", param.displayName());
parameters.add(new ActionParameterBuilder().setDisplayName(param.displayName()).setKey(param.key()).setType(param.type()).setOrder(order).setRequired(param.required()).build());
++order;
}
}
}
return parameters.isEmpty() ? null : parameters;
}
use of org.motechproject.tasks.domain.mds.channel.ActionParameter in project motech by motech.
the class TaskActionExecutorTest method prepareActionEvent.
private ActionEvent prepareActionEvent() {
ActionEvent actionEvent = new ActionEvent();
actionEvent.setDisplayName("Action");
actionEvent.setSubject("actionSubject");
actionEvent.setDescription("");
SortedSet<ActionParameter> parameters = new TreeSet<>();
ActionParameter parameter = new ActionParameter();
parameter.setDisplayName("Map");
parameter.setKey("map");
parameter.setType(MAP);
parameter.setOrder(1);
parameters.add(parameter);
actionEvent.setActionParameters(parameters);
actionEvent.setPostActionParameters(parameters);
return actionEvent;
}
Aggregations