use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskValidator method validateProvider.
/**
* Validates if the given provider contains the given data source and trigger event.
*
* @param provider the provider to be checked, not null
* @param dataSource the data source to be validated, not null
* @param trigger the trigger to be validated, not null
* @param availableProviders the map of the IDs and the providers, not null
* @return the set of encountered errors
*/
@Transactional
public Set<TaskError> validateProvider(TaskDataProvider provider, DataSource dataSource, TriggerEvent trigger, Map<Long, TaskDataProvider> availableProviders) {
Set<TaskError> errors = new HashSet<>();
Map<String, String> fields = new HashMap<>();
Map<String, ParameterType> fieldsTypes = new HashMap<>();
if (!provider.containsProviderObject(dataSource.getType())) {
errors.add(new TaskError("task.validation.error.providerObjectNotExist", dataSource.getType(), provider.getName()));
} else {
for (Lookup lookup : dataSource.getLookup()) {
if (!provider.containsProviderObjectLookup(dataSource.getType(), dataSource.getName())) {
errors.add(new TaskError("task.validation.error.providerObjectLookupNotExist", lookup.getField(), dataSource.getType(), provider.getName()));
}
fields.put(lookup.getField(), lookup.getValue());
fieldsTypes.put(lookup.getField(), ParameterType.UNKNOWN);
}
errors.addAll(validateFieldsParameter(fields, fieldsTypes, trigger, availableProviders));
}
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskValidator method validateTrigger.
/**
* Validates the trigger of the given task by checking if it is specified in the given channel.
*
* @param task the task for which the trigger should be validated, not null
* @return the set of encountered errors
*/
@Transactional
public Set<TaskError> validateTrigger(Task task) {
Set<TaskError> errors = new HashSet<>();
TaskTriggerInformation triggerInformation = task.getTrigger();
boolean exists = triggerEventService.triggerExists(triggerInformation);
if (!exists) {
errors.add(new TaskError("task.validation.error.triggerNotExist", triggerInformation.getDisplayName()));
}
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskValidator method validateAction.
/**
* Checks if the channel contains the given actions.
*
* @param actionInformation the information about action, not null
* @param channel the channel to be checked, not null
* @return the set of encountered errors
*/
@Transactional
public Set<TaskError> validateAction(TaskActionInformation actionInformation, Channel channel) {
Set<TaskError> errors = new HashSet<>();
boolean exists = channel.containsAction(actionInformation);
if (!exists) {
errors.add(new TaskError("task.validation.error.actionNotExist", actionInformation.getDisplayName(), channel.getDisplayName()));
}
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskValidator method validateManipulations.
private Set<TaskError> validateManipulations(String manipulation, KeyInformation key, ParameterType parameterType, ParameterType fieldType) {
Set<TaskError> errors = new HashSet<>();
TaskError error;
String at = key.getKey() + "?" + manipulation;
if (parameterType == ParameterType.UNICODE || parameterType == ParameterType.TEXTAREA || parameterType == ParameterType.UNKNOWN) {
error = validateStringManipulation(manipulation, at);
if (error != null) {
errors.add(error);
}
} else if (parameterType == ParameterType.DATE) {
error = validateDateManipulation(manipulation, fieldType, at);
if (error != null) {
errors.add(error);
}
} else {
errors.add(new TaskError("task.validation.error.wrongAnotherManipulation", manipulation, at));
}
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskValidator method validateDateManipulation.
private TaskError validateDateManipulation(String manipulation, ParameterType fieldType, String foundAt) {
TaskError error = null;
ManipulationType type = ManipulationType.fromString(manipulation.replaceAll("\\((.*?)\\)", ""));
if (type.getTarget() != ManipulationTarget.DATE) {
if (type.getTarget() == ManipulationTarget.ALL) {
error = new TaskError("task.validation.error.wrongAnotherManipulation", manipulation, foundAt);
} else {
error = new TaskError("task.validation.error.wrongDateManipulation", manipulation, foundAt);
}
} else if (fieldType.equals(ParameterType.DATE) && !type.allowResultType(ManipulationTarget.DATE)) {
error = new TaskError("task.validation.error.wrongDateManipulationTarget", manipulation, foundAt);
}
return error;
}
Aggregations