public void validate(final Form form) {
final FormComponent[] components = getDependentFormComponents();
final FormComponent wsComponent = components[0];
final FormComponent nameComponent = components[1];
WorkspaceInfo workspace = (WorkspaceInfo) wsComponent.getConvertedInput();
String name = (String) nameComponent.getConvertedInput();
if(name == null) {
ValidationError error = new ValidationError();
error.addMessageKey("StoreNameValidator.storeNameRequired");
nameComponent.error((IValidationError) error);
return;
}
Catalog catalog = GeoServerApplication.get().getCatalog();
final StoreInfo existing = catalog.getStoreByName(workspace, name, StoreInfo.class);
if (existing != null) {
final String existingId = existing.getId();
if (!existingId.equals(edittingStoreId)) {
ValidationError error = new ValidationError();
error.addMessageKey("StoreNameValidator.storeExistsInWorkspace");
error.setVariable("workspace", workspace.getName());
error.setVariable("storeName", name);
nameComponent.error((IValidationError) error);
}
}
}