DateComparisonPredicateEvaluator.java
3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.search.Predicate
* com.day.cq.search.eval.AbstractPredicateEvaluator
* com.day.cq.search.eval.EvaluationContext
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.query.Row
* org.apache.felix.scr.annotations.Component
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aem.formsndocuments.predicateevaluator;
import com.day.cq.search.Predicate;
import com.day.cq.search.eval.AbstractPredicateEvaluator;
import com.day.cq.search.eval.EvaluationContext;
import java.util.Calendar;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.query.Row;
import org.apache.felix.scr.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0, factory="com.day.cq.search.eval.PredicateEvaluator/dateComparison")
public class DateComparisonPredicateEvaluator
extends AbstractPredicateEvaluator {
private static final Logger log = LoggerFactory.getLogger(DateComparisonPredicateEvaluator.class);
public static final String DATE_COMPARISON = "dateComparison";
public static final String PROPERTY1 = "property1";
public static final String PROPERTY2 = "property2";
public static final String OPERATION = "operation";
public static final String OP_EQUALS = "equals";
public static final String OP_UNEQUALS = "unequals";
public static final String OP_GT = "greater";
public static final String OP_GTE = "greaterthanequal";
public boolean includes(Predicate p, Row row, EvaluationContext context) {
String prop1 = p.get("property1");
String prop2 = p.get("property2");
String operation = p.get("operation", "equals");
Node node = null;
String path = null;
try {
if (prop1 != null && prop1.trim().length() != 0 && prop2 != null && prop2.trim().length() != 0) {
node = context.getNode(row);
path = context.getPath(row);
if (node.hasProperty(prop1) && node.hasProperty(prop2)) {
Property property1 = node.getProperty(prop1);
Property property2 = node.getProperty(prop2);
if (property1.getType() == 5 && property2.getType() == 5) {
int compareStatus = property1.getDate().compareTo(property2.getDate());
if ("equals".equals(operation)) {
return compareStatus == 0;
}
if ("unequals".equals(operation)) {
return compareStatus != 0;
}
if ("greater".equals(operation)) {
return compareStatus > 0;
}
if ("greaterthanequal".equals(operation)) {
return compareStatus > 0 || compareStatus == 0;
}
}
}
}
}
catch (RepositoryException e) {
log.error("Could not evaluate property1 = '" + prop1 + "', property2 = '" + prop2 + "', node = '" + path, (Throwable)e);
return false;
}
return false;
}
public boolean canXpath(Predicate predicate, EvaluationContext context) {
return false;
}
public boolean canFilter(Predicate predicate, EvaluationContext context) {
return true;
}
}