Search in sources :

Example 6 with TaskError

use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.

the class TaskValidator method validateDataSource.

private Set<TaskError> validateDataSource(DataSource dataSource) {
    Set<TaskError> errors = new HashSet<>();
    String field = "taskConfig.dataSource[" + dataSource.getOrder() + "]";
    for (Lookup lookup : dataSource.getLookup()) {
        if (isEmpty(errors)) {
            String objectName = "task." + field;
            checkNullValue(errors, objectName, "objectId", dataSource.getObjectId());
            checkBlankValue(errors, objectName, "type", dataSource.getType());
            checkBlankValue(errors, objectName, "lookup.field", lookup.getField());
            checkBlankValue(errors, objectName, "lookup.value", lookup.getValue());
        }
    }
    return errors;
}
Also used : TaskError(org.motechproject.tasks.domain.mds.task.TaskError) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) HashSet(java.util.HashSet)

Example 7 with TaskError

use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.

the class TaskServiceImpl method validateAction.

private Set<TaskError> validateAction(Task task, Channel channel, TaskActionInformation action) {
    LOGGER.debug("Validating task action: {} from task: {} with ID: {}", action.getName(), task.getName(), task.getId());
    Set<TaskError> errors = new HashSet<>();
    if (channel == null) {
        errors.add(new TaskError("task.validation.error.actionChannelNotRegistered"));
        return errors;
    }
    if (channel.getModuleName().equalsIgnoreCase(action.getModuleName())) {
        errors.addAll(taskValidator.validateAction(action, channel));
        TriggerEvent trigger = triggerEventService.getTrigger(task.getTrigger());
        Map<Long, TaskDataProvider> providers = getProviders(task);
        ActionEvent actionEvent = channel.getAction(action);
        if (actionEvent != null) {
            errors.addAll(taskValidator.validateActionFields(action, actionEvent, trigger, providers));
        }
    }
    logResultOfValidation("task action", task.getName(), errors);
    return errors;
}
Also used : TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) HashSet(java.util.HashSet)

Example 8 with TaskError

use of org.motechproject.tasks.domain.mds.task.TaskError 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 TaskError

use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.

the class TaskServiceImpl method validateProvider.

private Set<TaskError> validateProvider(TaskDataProvider provider, DataSource dataSource, Task task, Map<Long, TaskDataProvider> availableDataProviders) {
    LOGGER.debug("Validating task data provider: {} in task: {} with ID: {}", dataSource.getProviderName(), task.getName(), task.getId());
    Set<TaskError> errors = new HashSet<>();
    TaskTriggerInformation trigger = task.getTrigger();
    if (provider != null) {
        errors.addAll(taskValidator.validateProvider(provider, dataSource, triggerEventService.getTrigger(trigger), availableDataProviders));
    } else {
        errors.add(new TaskError("task.validation.error.providerNotExist", dataSource.getProviderName()));
    }
    logResultOfValidation("task data provider", task.getName(), errors);
    return errors;
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) HashSet(java.util.HashSet)

Example 10 with TaskError

use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.

the class TaskServiceImpl method validateDataSources.

private Set<TaskError> validateDataSources(Task task) {
    LOGGER.debug("Validating task data sources in task: {} with ID: {}", task.getName(), task.getId());
    Set<TaskError> errors = new HashSet<>();
    Map<Long, TaskDataProvider> availableDataProviders = new HashMap<>();
    for (DataSource dataSource : task.getTaskConfig().getDataSources()) {
        TaskDataProvider provider = providerService.getProvider(dataSource.getProviderName());
        errors.addAll(validateProvider(provider, dataSource, task, availableDataProviders));
        if (provider != null) {
            availableDataProviders.put(provider.getId(), provider);
        }
    }
    logResultOfValidation("task data sources", task.getName(), errors);
    return errors;
}
Also used : TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) HashMap(java.util.HashMap) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) HashSet(java.util.HashSet) DataSource(org.motechproject.tasks.domain.mds.task.DataSource)

Aggregations

TaskError (org.motechproject.tasks.domain.mds.task.TaskError)36 HashSet (java.util.HashSet)25 Test (org.junit.Test)10 Channel (org.motechproject.tasks.domain.mds.channel.Channel)8 Task (org.motechproject.tasks.domain.mds.task.Task)8 Transactional (org.springframework.transaction.annotation.Transactional)8 HashMap (java.util.HashMap)7 TaskDataProvider (org.motechproject.tasks.domain.mds.task.TaskDataProvider)7 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)7 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)6 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)6 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)5 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)5 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)4 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)4 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)4 Map (java.util.Map)3 QueryExecution (org.motechproject.mds.query.QueryExecution)3 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)3 ValidationException (org.motechproject.tasks.exception.ValidationException)3