1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.persistence.jpa.validation.entity;
20
21 import javax.validation.ConstraintValidatorContext;
22 import org.apache.syncope.common.lib.types.EntityViolationType;
23 import org.apache.syncope.core.persistence.api.entity.Entity;
24 import org.apache.syncope.core.persistence.api.entity.Schema;
25 import org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtils;
26
27 public class SchemaKeyValidator extends AbstractValidator<SchemaKeyCheck, Schema> {
28
29 @Override
30 public boolean isValid(final Schema schema, final ConstraintValidatorContext context) {
31
32 if (schema.getKey() == null || !Entity.ID_PATTERN.matcher(schema.getKey()).matches()) {
33 context.disableDefaultConstraintViolation();
34 context.buildConstraintViolationWithTemplate(
35 getTemplate(EntityViolationType.InvalidKey, schema.getKey())).
36 addPropertyNode("key").addConstraintViolation();
37
38 return false;
39 } else if (JPAAnyUtils.matchesFieldName(schema.getKey())) {
40 context.disableDefaultConstraintViolation();
41 context.buildConstraintViolationWithTemplate(
42 getTemplate(EntityViolationType.InvalidKey, "Schema key not allowed: " + schema.getKey())).
43 addPropertyNode("key").addConstraintViolation();
44
45 return false;
46 }
47
48 return true;
49 }
50 }