use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskServiceImpl method validateTasksAfterTaskDataProviderUpdate.
@MotechListener(subjects = DATA_PROVIDER_UPDATE_SUBJECT)
@Transactional
public void validateTasksAfterTaskDataProviderUpdate(MotechEvent event) {
String providerName = event.getParameters().get(DATA_PROVIDER_NAME).toString();
TaskDataProvider provider = providerService.getProvider(providerName);
LOGGER.debug("Handling a task data provider update: {}", providerName);
for (Task task : getAllTasks()) {
SortedSet<DataSource> dataSources = task.getTaskConfig().getDataSources(provider.getName());
if (isNotEmpty(dataSources)) {
Set<TaskError> errors = new HashSet<>();
for (DataSource dataSource : dataSources) {
errors.addAll(validateProvider(provider, dataSource, task, new HashMap<Long, TaskDataProvider>()));
}
errors.addAll(validateActions(task));
handleValidationErrors(task, errors, TASK_DATA_PROVIDER_VALIDATION_ERRORS);
}
}
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class ChannelValidator method validate.
/**
* Validates the given channel by checking if all necessary data is set. Returns the set of {@code TaskError}s
* containing information about missing fields.
*
* @param channel the channel to be validated, not null
* @return the set of encountered errors
*/
public static Set<TaskError> validate(Channel channel) {
Set<TaskError> errors = new HashSet<>();
checkBlankValue(errors, CHANNEL, "displayName", channel.getDisplayName());
checkBlankValue(errors, CHANNEL, "moduleName", channel.getModuleName());
checkBlankValue(errors, CHANNEL, "moduleVersion", channel.getModuleVersion());
checkVersion(errors, CHANNEL, "moduleVersion", channel.getModuleVersion());
boolean containsTriggers = !isEmpty(channel.getTriggerTaskEvents());
boolean containsActions = !isEmpty(channel.getActionTaskEvents());
if (!containsTriggers && !containsActions) {
errors.add(new TaskError("task.validation.error.channel"));
} else {
if (containsTriggers) {
for (int i = 0; i < channel.getTriggerTaskEvents().size(); ++i) {
errors.addAll(validateTrigger(i, channel.getTriggerTaskEvents().get(i)));
}
}
if (containsActions) {
for (int i = 0; i < channel.getActionTaskEvents().size(); ++i) {
errors.addAll(validateAction(i, channel.getActionTaskEvents().get(i)));
}
}
}
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class ChannelValidator method validateAction.
private static Set<TaskError> validateAction(int index, ActionEvent action) {
Set<TaskError> errors = new HashSet<>();
String field = "actionTaskEvents[" + index + "]";
checkNullValue(errors, CHANNEL, field, action);
if (isEmpty(errors)) {
String objectName = CHANNEL + "." + field;
checkBlankValue(errors, objectName, "displayName", action.getDisplayName());
if (!action.hasSubject() && !action.hasService()) {
errors.add(new TaskError("task.validation.error.channelAction"));
}
for (ActionParameter parameter : action.getActionParameters()) {
errors.addAll(validateActionParameter(objectName, "actionParameters[" + parameter.getOrder() + "]", parameter));
}
for (ActionParameter parameter : action.getPostActionParameters()) {
errors.addAll(validateActionParameter(objectName, "postActionParameters[" + parameter.getOrder() + "]", parameter));
}
}
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskDataProviderValidator method validateProviderName.
private static void validateProviderName(Set<TaskError> errors, String providerName) {
checkBlankValue(errors, TASK_DATA_PROVIDER, "name", providerName);
// check only non-blank, we already validated against blank names one line above
if (StringUtils.isNotBlank(providerName)) {
Pattern pattern = Pattern.compile("^[A-Za-z0-9\\-_]+$");
Matcher matcher = pattern.matcher(providerName);
if (!matcher.matches()) {
errors.add(new TaskError("task.validation.error.provider.name", providerName));
}
}
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskValidator method validateFilter.
private Set<TaskError> validateFilter(Integer setOrder, int index, Filter filter, TaskConfig config) {
Set<TaskError> errors = new HashSet<>();
String field = String.format("taskConfig.filterSet[%d].filters[%d]", setOrder, index);
KeyInformation key = parse(filter.getKey());
DataSource dataSource = config.getDataSource(key.getDataProviderName(), key.getObjectId(), key.getObjectType());
checkNullValue(errors, TASK, field, filter);
if (isEmpty(errors)) {
String objectName = "task." + field;
if (key.fromAdditionalData() && dataSource == null) {
errors.add(new TaskError("task.validation.error.DataSourceNotExist", key.getObjectType()));
}
checkBlankValue(errors, objectName, "key", filter.getKey());
checkBlankValue(errors, objectName, "displayName", filter.getDisplayName());
checkBlankValue(errors, objectName, "operator", filter.getOperator());
checkNullValue(errors, objectName, "type", filter.getType());
if (OperatorType.needExpression(filter.getOperator())) {
checkBlankValue(errors, objectName, "expression", filter.getExpression());
}
}
return errors;
}
Aggregations