return OrganizationForm.class.isAssignableFrom(aClass);
}
@Override
public void validate(Object o, Errors errors) {
OrganizationForm organizationForm = (OrganizationForm) o;
if (organizationForm.getName() == null || "".equals(organizationForm.getName().trim())) {
errors.rejectValue(NAME_FIELD, "organizationValidator.emptyName");
}
if ((organizationForm.getStorageConfigurationId() == null || organizationForm.getStorageConfigurationId() <= 0) && !organizationForm.isEditing()) {
errors.rejectValue(STORAGE_CONFIGURATION_ID_FIELD, "organizationValidator.emptyStorageConfigurationId");
}
if (!organizationForm.isEditing() && (organizationForm.getStoragePrefix() == null || "".equals(organizationForm.getStoragePrefix().trim()))) {
errors.rejectValue(STORAGE_PREFIX_FIELD, "organizationValidator.emptyPrefix");
}
Organization organization = organizationService.getByName(organizationForm.getName());
if (organization != null && !organization.getId().equals(organizationForm.getId())) {
errors.rejectValue(NAME_FIELD, "organizationValidator.nameEquals");
}
if (!organizationForm.isEditing()) {
OrgStorageConfig orgStorageConfig = orgStorageConfigService.getByPrefix(organizationForm.getStoragePrefix());
if (orgStorageConfig != null && !orgStorageConfig.getOrganization().getId().equals(organizationForm.getId())) {
errors.rejectValue(STORAGE_PREFIX_FIELD, "organizationValidator.prefix");
}
}
if(organizationForm.getSubdomain() != null && !organizationForm.getSubdomain().isEmpty()) {
CustomBranding customBranding = customBrandingService.getBySubdomain(organizationForm.getSubdomain());
if(customBranding != null && !organization.getCustomBranding().getId().equals(customBranding.getId())) {
errors.rejectValue(SUBDOMAIN_FIELD, "organizationValidator.subdomain");
}
}
if (organizationForm.getLogo() != null) {
BufferedImage bufferedImage = imageValidator.createBufferedImage(organizationForm.getLogo());
boolean logoErrorExists = false;
if (!imageValidator.isValidImageSize(organizationForm.getLogo(), MAX_IMAGE_BYTES /*Bytes: 800 KB*/)) {
errors.rejectValue(LOGO_FIELD, "organizationValidator.logo.invalidSize", new Object[]{MAX_IMAGE_BYTES * 0.0009765625 /*Convert bytes to KiloBytes*/}, "");
logoErrorExists = true;
}
if (!imageValidator.isValidImageType(organizationForm.getLogo())) {
errors.rejectValue(LOGO_FIELD, "organizationValidator.logo.invalidType");
logoErrorExists = true;
}
if (bufferedImage == null || !imageValidator.isValidMaxDimensions(bufferedImage, 150, 50)) {
errors.rejectValue(LOGO_FIELD, "organizationValidator.logo.invalidDimensions", new Object[]{Long.toString(150), Long.toString(50)}, "");
logoErrorExists = true;
}
if (logoErrorExists) {
organizationForm.setLogo(null);
}
}
}