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