Search in sources :

Example 16 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class TaskServiceImplTest method shouldFindActionForGivenInformation.

@Test
public void shouldFindActionForGivenInformation() throws ActionNotFoundException {
    ActionEvent expected = new ActionEventBuilder().build();
    expected.setSubject(action.getSubject());
    expected.setDisplayName("receive");
    Channel c = new Channel();
    c.setActionTaskEvents(asList(expected));
    when(channelService.getChannel("test-action")).thenReturn(c);
    TaskEvent actual = taskService.getActionEventFor(action);
    assertEquals(expected, actual);
}
Also used : ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskEvent(org.motechproject.tasks.domain.mds.channel.TaskEvent) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) Test(org.junit.Test)

Example 17 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel 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 18 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class TaskAnnotationBeanPostProcessor method postProcessAfterInitialization.

@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
    if (bean == null) {
        return null;
    }
    final Class<?> targetClass = getTargetClass(bean);
    final TaskChannel taskChannel = targetClass.getAnnotation(TaskChannel.class);
    if (taskChannel != null) {
        LOGGER.debug("The @TaskChannel annotation was found in {}", targetClass.getName());
        doWithMethods(targetClass, new ReflectionUtils.MethodCallback() {

            @Override
            public void doWith(Method method) throws IllegalAccessException {
                Method targetMethod = findMethod(targetClass, method.getName(), method.getParameterTypes());
                if (targetMethod != null) {
                    TaskAction taskAction = targetMethod.getAnnotation(TaskAction.class);
                    if (taskAction != null) {
                        LOGGER.debug("The @TaskAction annotation was found in method: {}", targetMethod.getName());
                        String serviceInterface = getServiceInterface(targetClass);
                        Channel channel = getChannel(taskChannel);
                        addActionTaskEvent(channel, serviceInterface, targetMethod, taskAction);
                    }
                }
            }
        });
    }
    return bean;
}
Also used : TaskChannel(org.motechproject.tasks.annotations.TaskChannel) TaskAction(org.motechproject.tasks.annotations.TaskAction) Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskChannel(org.motechproject.tasks.annotations.TaskChannel) ReflectionUtils.findMethod(org.springframework.util.ReflectionUtils.findMethod) Method(java.lang.reflect.Method) ReflectionUtils(org.springframework.util.ReflectionUtils)

Example 19 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class TaskAnnotationBeanPostProcessor method getChannel.

private Channel getChannel(TaskChannel taskChannel) {
    String displayName = taskChannel.channelName();
    String moduleName = taskChannel.moduleName();
    String moduleVersion = taskChannel.moduleVersion();
    Channel channel = channelService.getChannel(moduleName);
    if (channel == null) {
        LOGGER.debug("Creating new channel: {}  for module: {}", displayName, moduleName);
        channel = new Channel(displayName, moduleName, moduleVersion);
    } else {
        LOGGER.debug("Channel: {}  for module: {} was retrieved", displayName, moduleName);
    }
    return channel;
}
Also used : Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskChannel(org.motechproject.tasks.annotations.TaskChannel)

Example 20 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class TaskServiceImplTest method shouldValidateTasksAfterChannelUpdateForValidTaskDataProviders.

@Test
public void shouldValidateTasksAfterChannelUpdateForValidTaskDataProviders() {
    TaskConfig config = new TaskConfig().add(new DataSource("TestProvider", 1234L, 1L, "Test", "id", "specifiedName", asList(new Lookup("id", "trigger.value")), true));
    Task task = new Task("name", trigger, asList(action), config, true, false);
    Set<TaskError> existingErrors = new HashSet<>();
    existingErrors.add(new TaskError("task.validation.error.providerObjectLookupNotExist"));
    task.addValidationErrors(existingErrors);
    TaskDataProvider provider = new TaskDataProvider("TestProvider", asList(new TaskDataProviderObject("test", "Test", null, null)));
    provider.setId(1234L);
    LinkedHashMap<String, Object> hashMap = new LinkedHashMap<>();
    hashMap.put("displayName", "id");
    ArrayList<String> list = new ArrayList<>();
    list.add("id");
    hashMap.put("fields", list);
    provider.getObjects().get(0).setLookupFields(asList((Object) hashMap));
    Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SEND", "", 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()));
    when(tasksDataService.retrieveAll()).thenReturn(asList(task));
    when(providerService.getProvider(provider.getName())).thenReturn(provider);
    when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
    when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
    taskService.validateTasksAfterTaskDataProviderUpdate(getProviderUpdateEvent(provider.getName()));
    Task actualTask = verifyCreateAndCaptureTask();
    assertTrue(task.isEnabled());
    assertTrue(actualTask.getValidationErrors().isEmpty());
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) ArrayList(java.util.ArrayList) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) LinkedHashMap(java.util.LinkedHashMap) TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Channel (org.motechproject.tasks.domain.mds.channel.Channel)35 Test (org.junit.Test)25 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)14 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)13 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)13 Task (org.motechproject.tasks.domain.mds.task.Task)12 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)9 ArrayList (java.util.ArrayList)8 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)8 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)8 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)8 HashSet (java.util.HashSet)6 QueryExecution (org.motechproject.mds.query.QueryExecution)6 TaskDataProvider (org.motechproject.tasks.domain.mds.task.TaskDataProvider)6 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)5 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)5 LookupFieldsParameter (org.motechproject.tasks.domain.mds.task.LookupFieldsParameter)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 TaskChannel (org.motechproject.tasks.annotations.TaskChannel)4