1
2
3
4
5
6 package pt.digitalis.dif.dem.objects.parameters.constraints.impl.date;
7
8 import java.text.ParseException;
9 import java.util.Calendar;
10 import java.util.Date;
11
12 import pt.digitalis.dif.dem.interfaces.IStageInstance;
13 import pt.digitalis.utils.common.DateUtils;
14
15
16
17
18
19
20
21
22 public class ParameterConstraintDateInFutureImpl extends ParameterConstraintDateImpl {
23
24
25
26
27
28
29 private boolean isDateInFuture(Date value)
30 {
31 Calendar calendarValue = Calendar.getInstance();
32 calendarValue.setTime(value);
33
34 return !Calendar.getInstance().after(calendarValue);
35 }
36
37
38
39
40
41 @Override
42 public boolean validateConstraint(Object value, IStageInstance stageInstance)
43 {
44 if (value == null)
45 return true;
46 else if (value instanceof Date)
47 {
48 lastTestedValue = DateUtils.simpleDateToString((Date) value);
49 return isDateInFuture((Date) value);
50 }
51 else if (value instanceof String)
52 return this.validateConstraint(value.toString(), stageInstance);
53 else
54 return false;
55 }
56
57
58
59
60
61 @Override
62 public boolean validateConstraint(String value, IStageInstance stageInstance)
63 {
64 if (super.validateConstraint(value, stageInstance))
65 {
66 try
67 {
68 return isDateInFuture(DateUtils.stringToSimpleDate(value));
69 }
70 catch (ParseException e)
71 {
72 return false;
73 }
74 }
75 else
76 return false;
77 }
78 }