}
ApplicationValidationContext context = (ApplicationValidationContext) response.getContext();
if (StringUtils.isEmpty(repo.getId())) {
response.addValidationError(new ValidationMessage("id", "Repository ID's may not be empty!"));
}
else if (!repo.getId().matches(REPOSITORY_ID_PATTERN)) {
response.addValidationError(
new ValidationMessage("id",
"Only letters, digits, underscores(_), hyphens(-), and dots(.) are allowed in Repository ID"));
}
// if repo id isn't valid, nothing below here will validate properly
else {
if (StringUtils.isEmpty(repo.getName())) {
repo.setName(repo.getId());
response.addValidationWarning(new ValidationMessage("id", "Repository with ID='" + repo.getId()
+ "' has no name, defaulted to it's ID."));
response.setModified(true);
}
if (!validateLocalStatus(repo.getLocalStatus())) {
response.addValidationError(
new ValidationMessage("id", "LocalStatus of repository with ID='" + repo.getId()) + "' is wrong "
+ repo.getLocalStatus() + "! (Allowed values are: '" + LocalStatus.IN_SERVICE + "' and '"
+ LocalStatus.OUT_OF_SERVICE + "')");
}
if (context.getExistingRepositoryIds() != null) {
if (context.getExistingRepositoryIds().contains(repo.getId())) {
response.addValidationError(
new ValidationMessage("id", "Repository with ID=" + repo.getId() + " already exists!"));
}
context.getExistingRepositoryIds().add(repo.getId());
}
if (context.getExistingRepositoryShadowIds() != null) {
if (context.getExistingRepositoryShadowIds().contains(repo.getId())) {
response.addValidationError(new ValidationMessage("id", "Repository " + repo.getId()
+ " conflicts with existing Shadow with same ID='" + repo.getId() + "'!"));
}
}
if (context.getExistingRepositoryGroupIds() != null) {
if (context.getExistingRepositoryGroupIds().contains(repo.getId())) {
response.addValidationError(new ValidationMessage("id", "Repository " + repo.getId()
+ " conflicts with existing Group with same ID='" + repo.getId() + "'!"));
}
}
}