Search in sources :

Example 6 with Channel

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

the class ChannelServiceImpl method delete.

@Override
@Transactional
public synchronized void delete(final String moduleName) {
    final Channel existingChannel = getChannel(moduleName);
    if (existingChannel != null) {
        LOGGER.debug("Deleting channel {}", moduleName);
        channelsDataService.delete(existingChannel);
        sendChannelDeleteEvent(moduleName);
    } else if (existingChannel == null) {
        LOGGER.debug("Channel doesn't exists {}", moduleName);
    }
}
Also used : Channel(org.motechproject.tasks.domain.mds.channel.Channel) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Channel

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

the class TaskServiceImpl method getActionEventFor.

@Override
@Transactional
public ActionEvent getActionEventFor(TaskActionInformation taskActionInformation) throws ActionNotFoundException {
    Channel channel = channelService.getChannel(taskActionInformation.getModuleName());
    ActionEvent event = null;
    for (ActionEvent action : channel.getActionTaskEvents()) {
        if (action.accept(taskActionInformation)) {
            event = action;
            break;
        }
    }
    if (event == null) {
        throw new ActionNotFoundException(format("Cant find action on the basic of information: %s", taskActionInformation));
    }
    return event;
}
Also used : ActionNotFoundException(org.motechproject.tasks.exception.ActionNotFoundException) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) HandlerPredicates.tasksWithRegisteredChannel(org.motechproject.tasks.service.util.HandlerPredicates.tasksWithRegisteredChannel) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Channel

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

the class TaskServiceImpl method validateTasksAfterChannelUpdate.

@MotechListener(subjects = CHANNEL_UPDATE_SUBJECT)
@Transactional
public void validateTasksAfterChannelUpdate(MotechEvent event) {
    String moduleName = event.getParameters().get(CHANNEL_MODULE_NAME).toString();
    Channel channel = channelService.getChannel(moduleName);
    LOGGER.debug("Handling Channel update: {} for module: {}", channel.getDisplayName(), moduleName);
    List<Task> tasks = findTasksDependentOnModule(moduleName);
    for (Task task : tasks) {
        Set<TaskError> errors;
        if (task.getTrigger() != null) {
            errors = validateTrigger(task);
            handleValidationErrors(task, errors, TASK_TRIGGER_VALIDATION_ERRORS);
        }
        errors = validateActions(task, channel);
        handleValidationErrors(task, errors, TASK_ACTION_VALIDATION_ERRORS);
    }
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) Channel(org.motechproject.tasks.domain.mds.channel.Channel) HandlerPredicates.tasksWithRegisteredChannel(org.motechproject.tasks.service.util.HandlerPredicates.tasksWithRegisteredChannel) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) MotechListener(org.motechproject.event.listener.annotations.MotechListener) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Channel

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

the class ChannelsDataServiceBundleIT method loadChannels.

private List<Channel> loadChannels() throws IOException {
    Type type = new TypeToken<ChannelRequest>() {
    }.getType();
    HashMap<Type, Object> typeAdapters = new HashMap<>();
    typeAdapters.put(ActionEventRequest.class, new ActionEventRequestDeserializer());
    List<StringWriter> writers = new ArrayList<>(2);
    for (String json : Arrays.asList("/message-campaign-test-channel.json", "/pillreminder-test-channel.json")) {
        try (InputStream stream = getClass().getResourceAsStream(json)) {
            StringWriter writer = new StringWriter();
            IOUtils.copy(stream, writer);
            writers.add(writer);
        }
    }
    List<Channel> channelRequests = new ArrayList<>(2);
    for (StringWriter writer : writers) {
        ChannelRequest channelRequest = (ChannelRequest) motechJsonReader.readFromString(writer.toString(), type, typeAdapters);
        channelRequest.setModuleName(channelRequest.getDisplayName());
        channelRequest.setModuleVersion("1.0");
        channelRequests.add(ChannelBuilder.fromChannelRequest(channelRequest).build());
    }
    return channelRequests;
}
Also used : ChannelRequest(org.motechproject.tasks.contract.ChannelRequest) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Channel(org.motechproject.tasks.domain.mds.channel.Channel) ArrayList(java.util.ArrayList) Type(java.lang.reflect.Type) StringWriter(java.io.StringWriter) ActionEventRequestDeserializer(org.motechproject.tasks.contract.json.ActionEventRequestDeserializer)

Example 10 with Channel

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

the class ChannelsDataServiceBundleIT method shouldFindChannelByChannelInfo.

@Test
public void shouldFindChannelByChannelInfo() throws Exception {
    List<Channel> channels = loadChannels();
    channelsDataService.create(channels.get(0));
    channelsDataService.create(channels.get(1));
    List<Channel> channelList = channelsDataService.retrieveAll();
    // ignore the channels that register with the test bundle and with MDS
    removeOwnAndMDSChannels(channelList);
    assertEquals(channels, channelList);
    Channel channel = channelList.get(0);
    Channel actual = channelsDataService.findByModuleName(channel.getModuleName());
    assertEquals(channel, actual);
    channel = channelList.get(1);
    actual = channelsDataService.findByModuleName(channel.getModuleName());
    assertEquals(channel, actual);
}
Also used : Channel(org.motechproject.tasks.domain.mds.channel.Channel) 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