1
|
/**
|
2
|
* Copyright (C) 2019 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.data.validator;
|
10
|
|
11
|
import org.joda.time.DateTimeFieldType;
|
12
|
import org.joda.time.Partial;
|
13
|
|
14
|
import com.vaadin.data.Validator;
|
15
|
|
16
|
/**
|
17
|
* @author a.kohlbecker
|
18
|
* @since Mar 27, 2019
|
19
|
*
|
20
|
*/
|
21
|
public class PartialCompletenesValidator implements Validator {
|
22
|
|
23
|
private static final long serialVersionUID = -2739242148516872452L;
|
24
|
|
25
|
@Override
|
26
|
public void validate(Object value) throws InvalidValueException {
|
27
|
if(value != null){
|
28
|
Partial partial = (Partial)value;
|
29
|
|
30
|
if(partial.isSupported(DateTimeFieldType.monthOfYear())
|
31
|
&& !partial.isSupported(DateTimeFieldType.year())
|
32
|
){
|
33
|
throw new InvalidValueException("The Partial must support year if monthOfYear is set");
|
34
|
}
|
35
|
if(partial.isSupported(DateTimeFieldType.dayOfMonth())
|
36
|
&& ! (
|
37
|
partial.isSupported(DateTimeFieldType.monthOfYear())
|
38
|
&& partial.isSupported(DateTimeFieldType.year())
|
39
|
)
|
40
|
){
|
41
|
throw new InvalidValueException("The Partial must support monthOfYear and year if dayOfMonth is set");
|
42
|
}
|
43
|
}
|
44
|
}
|
45
|
}
|