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);
}
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations