Search in sources :

Example 31 with TaskError

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

the class TaskValidator method validateStringManipulation.

private TaskError validateStringManipulation(String manipulation, String foundAt) {
    TaskError error = null;
    ManipulationType type = ManipulationType.fromString(manipulation.replaceAll("\\((.*?)\\)", ""));
    if (type.getTarget() != ManipulationTarget.STRING) {
        if (type.getTarget() == ManipulationTarget.ALL) {
            error = new TaskError("task.validation.error.wrongAnotherManipulation", manipulation, foundAt);
        } else {
            error = new TaskError("task.validation.error.wrongStringManipulation", manipulation, foundAt);
        }
    }
    return error;
}
Also used : TaskError(org.motechproject.tasks.domain.mds.task.TaskError) ManipulationType(org.motechproject.tasks.domain.ManipulationType)

Example 32 with TaskError

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

the class TaskValidator method validateAction.

private Set<TaskError> validateAction(int idx, TaskActionInformation action) {
    Set<TaskError> errors = new HashSet<>();
    checkNullValue(errors, TASK, String.format("actions[%d]", idx), action);
    if (isEmpty(errors)) {
        String objectName = String.format("%s.actions[%d]", TASK, idx);
        checkBlankValue(errors, objectName, "channelName", action.getChannelName());
        checkBlankValue(errors, objectName, "moduleName", action.getModuleName());
        checkBlankValue(errors, objectName, MODULE_VERSION, action.getModuleVersion());
        checkVersion(errors, objectName, MODULE_VERSION, action.getModuleVersion());
        if (!action.hasSubject() && !action.hasService()) {
            errors.add(new TaskError("task.validation.error.taskAction"));
        }
        checkNullValue(errors, objectName, "values", action.getValues());
        for (Map.Entry<String, String> entry : action.getValues().entrySet()) {
            checkBlankValue(errors, String.format("%s.values", objectName), entry.getKey(), entry.getValue());
        }
        errors.addAll(validateDateFormat(action.getValues()));
    }
    return errors;
}
Also used : TaskError(org.motechproject.tasks.domain.mds.task.TaskError) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 33 with TaskError

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

the class TaskValidator method validateDateFormat.

private Set<TaskError> validateDateFormat(Map<String, String> actionInputFields) {
    Set<TaskError> errors = new HashSet<>();
    for (Map.Entry<String, String> entry : actionInputFields.entrySet()) {
        String entryValue = entry.getValue();
        if (entryValue.contains("dateTime")) {
            Pattern pattern = Pattern.compile("\\{\\{(.*?)\\?dateTime\\((.*?)\\)\\}\\}");
            Matcher matcher = pattern.matcher(entryValue);
            while (matcher.find()) {
                try {
                    DateTime now = DateTime.now();
                    DateTimeFormat.forPattern(matcher.group(2)).print(now);
                } catch (IllegalArgumentException e) {
                    String[] objectFields = matcher.group(1).split("\\.");
                    errors.add(new TaskError("task.validation.error.dateFormat", String.format("%s.%s", objectFields[objectFields.length - 2], objectFields[objectFields.length - 1]), entry.getKey()));
                }
            }
        }
    }
    return errors;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) HashMap(java.util.HashMap) Map(java.util.Map) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet)

Example 34 with TaskError

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

the class TaskValidator method validateRetryOnFailureValues.

private static Set<TaskError> validateRetryOnFailureValues(int numberOfRetries, int retryIntervalInMilliseconds) {
    Set<TaskError> errors = new HashSet<>();
    if (numberOfRetries < 0 || retryIntervalInMilliseconds < 0) {
        TaskError error = new TaskError("task.validation.error.invalidRetryOnFailureValues");
        errors.add(error);
    }
    return errors;
}
Also used : TaskError(org.motechproject.tasks.domain.mds.task.TaskError) HashSet(java.util.HashSet)

Example 35 with TaskError

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

the class TaskValidator method validateDataProviderObjects.

private Set<TaskError> validateDataProviderObjects(KeyInformation key, Map<Long, TaskDataProvider> providers) {
    Set<TaskError> errors = new HashSet<>();
    boolean isObjectValid = false;
    if (key.fromAdditionalData()) {
        for (Map.Entry<Long, TaskDataProvider> entry : providers.entrySet()) {
            for (TaskDataProviderObject dataProviderObject : entry.getValue().getObjects()) {
                if (dataProviderObject.getType().equals(key.getObjectType())) {
                    isObjectValid = true;
                    break;
                }
            }
        }
        if (!isObjectValid) {
            errors.add(new TaskError("task.validation.error.providerObjectFieldNotExist", key.getKey(), key.getObjectType()));
        }
    }
    return errors;
}
Also used : TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

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