Search in sources :

Example 1 with TaskFilterExecutor

use of org.motechproject.tasks.service.util.TaskFilterExecutor in project motech by motech.

the class TaskInitializer method checkActionFilter.

@Transactional
public boolean checkActionFilter(int actualFilterIndex, List<FilterSet> filterSetList) throws TaskHandlerException {
    boolean result;
    TaskFilterExecutor taskFilterExecutor = new TaskFilterExecutor();
    try {
        result = taskFilterExecutor.checkFilters(filterSetList.get(actualFilterIndex).getFilters(), filterSetList.get(actualFilterIndex).getOperator(), taskContext);
    } catch (RuntimeException e) {
        throw new TaskHandlerException(FILTER, "task.error.filterError", e);
    }
    return result;
}
Also used : TaskFilterExecutor(org.motechproject.tasks.service.util.TaskFilterExecutor) TaskHandlerException(org.motechproject.tasks.exception.TaskHandlerException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with TaskFilterExecutor

use of org.motechproject.tasks.service.util.TaskFilterExecutor in project motech by motech.

the class TaskInitializer method evalConfigSteps.

/**
 * Executes all config steps (loading data from data sources, checking filters) defined for this task.
 *
 * @param dataProviders  the map of data providers, not null or empty
 * @return  true if all steps were executed, false otherwise
 * @throws TaskHandlerException if there were error while handling task
 */
@Transactional
public boolean evalConfigSteps(Map<String, DataProvider> dataProviders) throws TaskHandlerException {
    LOGGER.info("Executing all config steps for task: {}", taskContext.getTask().getName());
    Iterator<TaskConfigStep> iterator = taskContext.getTask().getTaskConfig().getSteps().iterator();
    boolean result = true;
    TaskFilterExecutor taskFilterExecutor = new TaskFilterExecutor();
    while (result && iterator.hasNext()) {
        TaskConfigStep step = iterator.next();
        if (step instanceof DataSource) {
            DataSource ds = (DataSource) step;
            taskContext.addDataSourceObject(ds.getObjectId().toString(), getDataSourceObject(ds, dataProviders), ds.isFailIfDataNotFound());
            LOGGER.info("Task data source: {} for task: {} added", ds.getName(), taskContext.getTask().getName());
        } else if (step instanceof FilterSet && !isActionFilter((FilterSet) step)) {
            try {
                FilterSet filterSet = (FilterSet) step;
                result = taskFilterExecutor.checkFilters(filterSet.getFilters(), filterSet.getOperator(), taskContext);
            } catch (RuntimeException e) {
                throw new TaskHandlerException(FILTER, "task.error.filterError", e);
            }
        }
    }
    return result;
}
Also used : TaskFilterExecutor(org.motechproject.tasks.service.util.TaskFilterExecutor) TaskConfigStep(org.motechproject.tasks.domain.mds.task.TaskConfigStep) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) TaskHandlerException(org.motechproject.tasks.exception.TaskHandlerException) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TaskHandlerException (org.motechproject.tasks.exception.TaskHandlerException)2 TaskFilterExecutor (org.motechproject.tasks.service.util.TaskFilterExecutor)2 Transactional (org.springframework.transaction.annotation.Transactional)2 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)1 FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)1 TaskConfigStep (org.motechproject.tasks.domain.mds.task.TaskConfigStep)1