@Override protected void doValidate(final PlainAttrValue attrValue) { if (AttrSchemaType.Enum == schema.getType()) { final String[] enumeration = schema.getEnumerationValues().split(SyncopeConstants.ENUM_VALUES_SEPARATOR); final String value = attrValue.getStringValue(); boolean found = false; for (int i = 0; i < enumeration.length && !found; i++) { if (enumeration[i].trim().equals(value)) { found = true; } } if (!found) { throw new InvalidPlainAttrValueException( "'" + value + "' is not one of: " + schema.getEnumerationValues()); } } } }
@Override public boolean isValid(final PlainSchema schema, final ConstraintValidatorContext context) { boolean isValid = schema.getType() != AttrSchemaType.Enum || StringUtils.isNotBlank(schema.getEnumerationValues()); if (!isValid) { context.disableDefaultConstraintViolation();
@Override public PlainSchemaTO getPlainSchemaTO(final String key) { PlainSchema schema = plainSchemaDAO.find(key); if (schema == null) { throw new NotFoundException("Schema '" + key + "'"); } PlainSchemaTO schemaTO = new PlainSchemaTO(); schemaTO.setKey(schema.getKey()); schemaTO.setType(schema.getType()); schemaTO.setCipherAlgorithm(schema.getCipherAlgorithm()); schemaTO.setConversionPattern(schema.getConversionPattern()); schemaTO.setEnumerationKeys(schema.getEnumerationKeys()); schemaTO.setEnumerationValues(schema.getEnumerationValues()); schemaTO.setMandatoryCondition(schema.getMandatoryCondition()); schemaTO.setMimeType(schema.getMimeType()); schemaTO.setMultivalue(schema.isMultivalue()); schemaTO.setReadonly(schema.isReadonly()); schemaTO.setSecretKey(schema.getSecretKey()); schemaTO.setUniqueConstraint(schema.isUniqueConstraint()); labels(schema, schemaTO); schemaTO.setAnyTypeClass(schema.getAnyTypeClass() == null ? null : schema.getAnyTypeClass().getKey()); if (schema.getValidator() != null) { schemaTO.setValidator(schema.getValidator().getKey()); } return schemaTO; }