use of org.motechproject.tasks.domain.mds.channel.ActionEvent in project motech by motech.
the class TaskServiceImplTest method shouldThrowActionNotFoundExceptionWhenChannelContainsEmptyActionList.
@Test(expected = ActionNotFoundException.class)
public void shouldThrowActionNotFoundExceptionWhenChannelContainsEmptyActionList() throws ActionNotFoundException {
Channel c = new Channel();
c.setActionTaskEvents(new ArrayList<ActionEvent>());
when(channelService.getChannel("test-action")).thenReturn(c);
taskService.getActionEventFor(action);
}
use of org.motechproject.tasks.domain.mds.channel.ActionEvent in project motech by motech.
the class TaskAnnotationBeanPostProcessor method getAction.
private ActionEvent getAction(Channel channel, String serviceInterface, Method method, String actionName) {
TaskActionInformation info = new TaskActionInformation(method.getName(), actionName, channel.getDisplayName(), channel.getModuleName(), channel.getModuleVersion(), serviceInterface, method.getName());
ActionEvent actionEvent = null;
for (ActionEvent action : channel.getActionTaskEvents()) {
if (action.accept(info)) {
actionEvent = action;
break;
}
}
return actionEvent;
}
use of org.motechproject.tasks.domain.mds.channel.ActionEvent in project motech by motech.
the class TaskAnnotationBeanPostProcessor method addActionTaskEvent.
private void addActionTaskEvent(Channel channel, String serviceInterface, Method method, TaskAction taskAction) {
ActionEvent action = getAction(channel, serviceInterface, method, taskAction.displayName());
boolean foundAction = action != null;
if (!foundAction) {
action = new ActionEventBuilder().build();
}
action.setDisplayName(taskAction.displayName());
action.setServiceInterface(serviceInterface);
action.setServiceMethod(method.getName());
action.setActionParameters(getActionParams(method));
action.setPostActionParameters(getPostActionParams(method));
if (!foundAction) {
channel.addActionTaskEvent(action);
LOGGER.debug("Action task event: {} added to channel: {}", action.getName(), channel.getDisplayName());
}
channelService.addOrUpdate(channel);
}
use of org.motechproject.tasks.domain.mds.channel.ActionEvent in project motech by motech.
the class ChannelBuilder method fromChannelRequest.
/**
* Creates a builder, which allows building Channels based on the given {@code channelRequest}.
*
* @param channelRequest the channel request
* @return the created builder
*/
public static ChannelBuilder fromChannelRequest(ChannelRequest channelRequest) {
ChannelBuilder builder = new ChannelBuilder().setDisplayName(channelRequest.getDisplayName()).setModuleName(channelRequest.getModuleName()).setModuleVersion(channelRequest.getModuleVersion());
List<TriggerEvent> triggerEvents = new ArrayList<>();
for (TriggerEventRequest triggerEventRequest : channelRequest.getTriggerTaskEvents()) {
triggerEvents.add(TriggerEventBuilder.fromTriggerEventRequest(triggerEventRequest).build());
}
builder.setTriggerTaskEvents(triggerEvents);
List<ActionEvent> actionEvents = new ArrayList<>();
for (ActionEventRequest actionEventRequest : channelRequest.getActionTaskEvents()) {
actionEvents.add(ActionEventBuilder.fromActionEventRequest(actionEventRequest).build());
}
builder.setActionTaskEvents(actionEvents);
return builder;
}
use of org.motechproject.tasks.domain.mds.channel.ActionEvent in project motech by motech.
the class TaskActionExecutorTest method shouldExecuteTaskAndUsePostActionParameters.
@Test
public void shouldExecuteTaskAndUsePostActionParameters() throws Exception {
TaskActionInformation actionInformation = prepareTaskActionInformationWithService("key", "value");
TaskActionInformation actionInformationWithPostActionParameter = prepareTaskActionInformationWithService("key", "{{pa.0.testKey}}");
ActionEvent actionEvent = prepareActionEventWithService();
when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
when(taskService.getActionEventFor(actionInformationWithPostActionParameter)).thenReturn(actionEvent);
ServiceReference serviceReference = mock(ServiceReference.class);
when(bundleContext.getServiceReference("serviceInterface")).thenReturn(serviceReference);
when(bundleContext.getService(serviceReference)).thenReturn(new TestService());
Task task = new Task();
task.addAction(actionInformation);
task.addAction(actionInformationWithPostActionParameter);
taskActionExecutor.setBundleContext(bundleContext);
TaskContext taskContext = new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService);
for (TaskActionInformation action : task.getActions()) {
taskActionExecutor.execute(task, action, task.getActions().indexOf(action), taskContext, TASK_ACTIVITY_ID);
}
assertEquals("testObject", taskContext.getPostActionParameterValue("0", "testKey"));
assertEquals("testObject", taskContext.getPostActionParameterValue("1", "testKey"));
}
Aggregations