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 ParameterConstraintDateInPastImpl extends ParameterConstraintDateImpl {
23
24
25
26
27
28
29 private boolean isDateInPast(Date value)
30 {
31 Calendar calendarValue = Calendar.getInstance();
32 calendarValue.setTime(value);
33
34 return !Calendar.getInstance().before(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
50 return isDateInPast((Date) value);
51 }
52 else if (value instanceof String)
53 return this.validateConstraint(value.toString(), stageInstance);
54 else
55 return false;
56 }
57
58
59
60
61
62 @Override
63 public boolean validateConstraint(String value, IStageInstance stageInstance)
64 {
65 if (super.validateConstraint(value, stageInstance))
66 {
67 try
68 {
69 return isDateInPast(DateUtils.stringToSimpleDate(value));
70 }
71 catch (ParseException e)
72 {
73 return false;
74 }
75 }
76 else
77 return false;
78 }
79 }