Search in sources :

Example 16 with ActionEvent

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);
}
Also used : ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) Test(org.junit.Test)

Example 17 with ActionEvent

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;
}
Also used : ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation)

Example 18 with 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);
}
Also used : ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)

Example 19 with ActionEvent

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;
}
Also used : TriggerEventRequest(org.motechproject.tasks.contract.TriggerEventRequest) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) ArrayList(java.util.ArrayList) ActionEventRequest(org.motechproject.tasks.contract.ActionEventRequest)

Example 20 with ActionEvent

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"));
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) TaskContext(org.motechproject.tasks.service.util.TaskContext) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Aggregations

ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)32 Test (org.junit.Test)21 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)18 Task (org.motechproject.tasks.domain.mds.task.Task)13 TreeSet (java.util.TreeSet)12 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)12 HashMap (java.util.HashMap)10 ObjectTest (org.motechproject.tasks.domain.ObjectTest)9 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)9 Channel (org.motechproject.tasks.domain.mds.channel.Channel)8 TaskContext (org.motechproject.tasks.service.util.TaskContext)8 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)7 MotechEvent (org.motechproject.event.MotechEvent)6 ArrayList (java.util.ArrayList)5 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)5 ActionParameterBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder)5 ActionParameter (org.motechproject.tasks.domain.mds.channel.ActionParameter)4 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)4 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)4 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)3