TODO comment to the ClassInfoBridge
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / validation / constraint / ReferenceCheckValidator.java
1 package eu.etaxonomy.cdm.validation.constraint;
2
3 import javax.validation.ConstraintValidator;
4 import javax.validation.ConstraintValidatorContext;
5
6 import eu.etaxonomy.cdm.model.reference.Reference;
7 import eu.etaxonomy.cdm.model.reference.ReferenceType;
8 import eu.etaxonomy.cdm.validation.annotation.InReference;
9 import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
10 import eu.etaxonomy.cdm.validation.annotation.ReferenceCheck;
11
12 public class ReferenceCheckValidator implements
13 ConstraintValidator<ReferenceCheck, Reference>{
14
15 //@Override
16 public boolean isValid(Reference value,
17 ConstraintValidatorContext constraintValidatorContext) {
18 boolean isValid = true;
19
20 isValid &= validIsbn(value, constraintValidatorContext);
21 if (value.getType() == ReferenceType.Journal && value.getDatePublished() != null) {
22 isValid &= false;
23 constraintValidatorContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.InReference.JournalShouldNotHaveDatePublished.message}");
24 }
25
26 return isValid;
27 }
28
29
30
31 private boolean validIsbn(Reference value, ConstraintValidatorContext constraintValidatorContext){
32 boolean isValid = true;
33
34 if ((value.getType() != ReferenceType.Book && value.getType() != ReferenceType.Proceedings) ) {
35 if (value.getIsbn()!= null){
36 isValid = false;
37 constraintValidatorContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.InReference.ReferenceShouldNotHaveIsbn.message}");
38 }
39 }
40 return isValid;
41 }
42
43
44
45 //@Override
46 public void initialize(ReferenceCheck constraintAnnotation) {
47 // TODO Auto-generated method stub
48
49 }
50
51
52
53
54
55 }