1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package tools.gsf.facade.assetapi.asset;
17
18 import com.fatwire.assetapi.data.AssetData;
19 import com.openmarket.xcelerate.interfaces.IAsset;
20 import org.apache.commons.lang3.StringUtils;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import tools.gsf.facade.assetapi.AssetClosure;
24 import tools.gsf.facade.assetapi.AttributeDataUtils;
25
26 import java.util.Date;
27
28
29
30
31
32 public class DateFilterClosure implements AssetClosure {
33 protected static final Logger LOG = LoggerFactory.getLogger("tools.gsf.facade.assetapi.asset.DateFilterClosure");
34
35 private final Date cutoff;
36
37 private final AssetClosure target;
38
39 private static Date parseDate(final String date) {
40
41 return StringUtils.isNotBlank(date) ? com.fatwire.cs.core.db.Util.parseJdbcDate(date) : null;
42 }
43
44
45
46
47
48 public DateFilterClosure(final String cutoff, final AssetClosure target) {
49 this(parseDate(cutoff), target);
50
51 }
52
53
54
55
56
57 public DateFilterClosure(final Date cuttoff, final AssetClosure target) {
58 if (target == null) {
59 throw new IllegalArgumentException("target cannot be null");
60 }
61 this.target = target;
62 this.cutoff = cuttoff == null ? null : new Date(cuttoff.getTime());
63
64 }
65
66 public boolean work(final AssetData assetData) {
67 if (cutoff != null) {
68 final Date assetStartDate = AttributeDataUtils.asDate(assetData.getAttributeData(IAsset.STARTDATE, true));
69 final Date assetEndDate = AttributeDataUtils.asDate(assetData.getAttributeData(IAsset.ENDDATE, true));
70 if (LOG.isTraceEnabled()) {
71 LOG.trace("assetStartDate " + assetStartDate + " assetEndDate " + assetEndDate);
72 }
73 if (assetEndDate != null && assetEndDate.before(cutoff)) {
74
75 return true;
76 }
77 if (assetStartDate != null && assetStartDate.after(cutoff)) {
78
79 return true;
80 }
81 }
82
83 if (LOG.isDebugEnabled()) {
84 LOG.debug("passing thru " + assetData.getAssetId());
85 }
86 return target.work(assetData);
87 }
88
89 }