use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskServiceImpl method validateTasksAfterTaskDataProviderUpdate.
@MotechListener(subjects = DATA_PROVIDER_UPDATE_SUBJECT)
@Transactional
public void validateTasksAfterTaskDataProviderUpdate(MotechEvent event) {
String providerName = event.getParameters().get(DATA_PROVIDER_NAME).toString();
TaskDataProvider provider = providerService.getProvider(providerName);
LOGGER.debug("Handling a task data provider update: {}", providerName);
for (Task task : getAllTasks()) {
SortedSet<DataSource> dataSources = task.getTaskConfig().getDataSources(provider.getName());
if (isNotEmpty(dataSources)) {
Set<TaskError> errors = new HashSet<>();
for (DataSource dataSource : dataSources) {
errors.addAll(validateProvider(provider, dataSource, task, new HashMap<Long, TaskDataProvider>()));
}
errors.addAll(validateActions(task));
handleValidationErrors(task, errors, TASK_DATA_PROVIDER_VALIDATION_ERRORS);
}
}
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskServiceImpl method exportTask.
@Override
@Transactional
public String exportTask(Long taskId) {
Task task = getTask(taskId);
if (null != task) {
LOGGER.info("Exporting task: {} with ID: {}", task.getName(), task.getId());
JsonNode node = new ObjectMapper().valueToTree(task.toDto());
removeIgnoredFields(node);
return node.toString();
} else {
throw new TaskNotFoundException(taskId);
}
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskServiceImpl method checkTimeWindowInTasks.
private List<Task> checkTimeWindowInTasks(List<Task> tasks) {
List<Task> checked = new ArrayList<>();
if (CollectionUtils.isNotEmpty(tasks)) {
for (Task task : tasks) {
if (checkTimeWindowInTask(task)) {
if (!task.isEnabled()) {
task.setEnabled(true);
addOrUpdate(task);
}
checked.add(task);
} else {
if (task.isEnabled()) {
task.setEnabled(false);
addOrUpdate(task);
}
}
}
}
return checked;
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskServiceImpl method findActiveTasksForTriggerSubject.
@Override
@Transactional
public List<Task> findActiveTasksForTriggerSubject(final String subject) {
List<Task> list = null;
if (isNotBlank(subject)) {
List enabledTasks = tasksDataService.executeQuery(new QueryExecution<List<Task>>() {
@Override
public List<Task> execute(Query query, InstanceSecurityRestriction restriction) {
String byTriggerSubject = "trigger.subject == param";
String isTaskActive = "enabled == true";
String isUsingTimeWindow = "useTimeWindow == true";
String filter = String.format("((%s) || (%s)) && (%s)", isTaskActive, isUsingTimeWindow, byTriggerSubject);
query.setFilter(filter);
query.declareParameters("java.lang.String param");
query.setOrdering("id asc");
return (List) QueryExecutor.execute(query, subject, restriction);
}
});
if (enabledTasks != null) {
checkChannelAvailableInTasks(enabledTasks);
list = checkTimeWindowInTasks(enabledTasks);
CollectionUtils.filter(list, tasksWithRegisteredChannel());
}
}
return list == null ? new ArrayList<>() : list;
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskTriggerHandler method handleRetry.
@Override
@Transactional
public void handleRetry(MotechEvent event) {
LOGGER.info("Handling the motech event with subject: {} for task retry", event.getSubject());
Map<String, Object> eventParams = event.getParameters();
Map<String, Object> eventMetadata = event.getMetadata();
Task task = taskService.getTask((Long) eventMetadata.get(TASK_ID));
if (task != null && task.isEnabled()) {
checkAndHandleTask(task, eventParams);
}
}
Aggregations