@Override
public ValidationResponse validateGroupsSettingPathMappingItem(ApplicationValidationContext ctx,
CPathMappingItem item)
{
ValidationResponse response = new ApplicationValidationResponse();
if (ctx != null) {
response.setContext(ctx);
}
ApplicationValidationContext context = (ApplicationValidationContext) response.getContext();
if (StringUtils.isEmpty(item.getId())
|| "0".equals(item.getId())
|| (context.getExistingPathMappingIds() != null && context.getExistingPathMappingIds().contains(
item.getId()))) {
String newId = generateId();
item.setId(newId);
response.addValidationWarning("Fixed wrong route ID from '" + item.getId() + "' to '" + newId + "'");
response.setModified(true);
}
if (StringUtils.isEmpty(item.getGroupId())) {
item.setGroupId(CPathMappingItem.ALL_GROUPS);
response
.addValidationWarning("Fixed route without groupId set, set to ALL_GROUPS to keep backward comp, ID='"
+ item.getId() + "'.");
response.setModified(true);
}
if (item.getRoutePatterns() == null || item.getRoutePatterns().isEmpty()) {
response.addValidationError("The Route with ID='" + item.getId() + "' must contain at least one Route Pattern.");
}
for (String regexp : item.getRoutePatterns()) {
if (!isValidRegexp(regexp)) {
response.addValidationError("The regexp in Route with ID='" + item.getId() + "' is not valid: "
+ regexp);
}
}
if (context.getExistingPathMappingIds() != null) {
context.getExistingPathMappingIds().add(item.getId());
}
if (!CPathMappingItem.INCLUSION_RULE_TYPE.equals(item.getRouteType())
&& !CPathMappingItem.EXCLUSION_RULE_TYPE.equals(item.getRouteType())
&& !CPathMappingItem.BLOCKING_RULE_TYPE.equals(item.getRouteType())) {
response.addValidationError("The groupMapping pattern with ID=" + item.getId()
+ " have invalid routeType='" + item.getRouteType() + "'. Valid route types are '"
+ CPathMappingItem.INCLUSION_RULE_TYPE + "', '" + CPathMappingItem.EXCLUSION_RULE_TYPE + "' and '"
+ CPathMappingItem.BLOCKING_RULE_TYPE + "'.");
}
// REMOVED: check that a blocking route is not empty
// if you delete a repo(ses) that were belonging to a route, we insist on
// leaving the route "empty" (to save a users hardly concieved regexp) but with empty
// repo list
if (context.getExistingRepositoryIds() != null && context.getExistingRepositoryShadowIds() != null) {
List<String> existingReposes = context.getExistingRepositoryIds();
List<String> existingShadows = context.getExistingRepositoryShadowIds();
for (String repoId : item.getRepositories()) {
if (!existingReposes.contains(repoId) && !existingShadows.contains(repoId)) {
response.addValidationError("The groupMapping pattern with ID=" + item.getId()
+ " refers to a nonexistent repository with repoID = " + repoId);
}
}
}