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