Revision 56415
Added by Miriam Baglioni almost 5 years ago
Constraints.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.bulktag; |
2 | 2 |
|
3 |
import com.google.common.reflect.TypeToken; |
|
3 | 4 |
import com.google.gson.Gson; |
4 | 5 |
import eu.dnetlib.data.bulktag.selectioncriteria.VerbResolver; |
5 | 6 |
import org.apache.commons.logging.Log; |
... | ... | |
8 | 9 |
|
9 | 10 |
import java.io.Serializable; |
10 | 11 |
import java.lang.reflect.InvocationTargetException; |
12 |
import java.lang.reflect.Type; |
|
13 |
import java.util.Collection; |
|
11 | 14 |
import java.util.List; |
12 | 15 |
import java.util.Map; |
13 | 16 |
|
... | ... | |
16 | 19 |
*/ |
17 | 20 |
public class Constraints implements Serializable { |
18 | 21 |
private static final Log log = LogFactory.getLog(Constraints.class); |
19 |
private ConstraintEncapsulator ce; |
|
20 |
//private List<Constraint> ce;
|
|
22 |
//private ConstraintEncapsulator ce;
|
|
23 |
private List<Constraint> constraint;
|
|
21 | 24 |
|
22 | 25 |
|
23 | 26 |
public Constraints() { |
24 | 27 |
} |
28 |
public List<Constraint> getConstraint() { |
|
29 |
return constraint; |
|
30 |
} |
|
25 | 31 |
|
26 |
public ConstraintEncapsulator getCe() { |
|
32 |
public void setConstraint(List<Constraint> constraint) { |
|
33 |
this.constraint = constraint; |
|
34 |
} |
|
35 |
|
|
36 |
public void setSc(String json){ |
|
37 |
Type collectionType = new TypeToken<Collection<Constraint>>(){}.getType(); |
|
38 |
constraint = new Gson().fromJson(json, collectionType); |
|
39 |
|
|
40 |
} |
|
41 |
|
|
42 |
void setSelection(VerbResolver resolver) { |
|
43 |
for(Constraint st: constraint){ |
|
44 |
|
|
45 |
try { |
|
46 |
st.setSelection(resolver); |
|
47 |
} catch (NoSuchMethodException e) { |
|
48 |
log.error(e.getMessage()); |
|
49 |
} catch (IllegalAccessException e) { |
|
50 |
log.error(e.getMessage()); |
|
51 |
} catch (InvocationTargetException e) { |
|
52 |
log.error(e.getMessage()); |
|
53 |
} catch (InstantiationException e) { |
|
54 |
log.error(e.getMessage()); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
} |
|
59 |
|
|
60 |
// //Constraint in and |
|
61 |
// public boolean verifyCriteria(Map<String,String> param){ |
|
62 |
// for(Constraint constraint: constraint){ |
|
63 |
// if(!constraint.verifyCriteria(param.get(constraint.getField()))) |
|
64 |
// return false; |
|
65 |
// } |
|
66 |
// return true; |
|
67 |
// } |
|
68 |
|
|
69 |
//Constraint in and |
|
70 |
public boolean verifyCriteria(Map<String,List<String>> param){ |
|
71 |
|
|
72 |
for(Constraint sc: constraint){ |
|
73 |
boolean verified = false; |
|
74 |
for(String value : param.get(sc.getField())){ |
|
75 |
if (sc.verifyCriteria(value.trim())){ |
|
76 |
verified = true; |
|
77 |
} |
|
78 |
} |
|
79 |
if(!verified) |
|
80 |
return verified; |
|
81 |
} |
|
82 |
return true; |
|
83 |
} |
|
84 |
/* public ConstraintEncapsulator getCe() { |
|
27 | 85 |
return ce; |
28 | 86 |
} |
29 | 87 |
|
... | ... | |
31 | 89 |
this.ce = ce; |
32 | 90 |
} |
33 | 91 |
|
34 |
public void setSc(String json){
|
|
92 |
public void setConstraint(String json){
|
|
35 | 93 |
|
36 | 94 |
ce = new Gson().fromJson(json, ConstraintEncapsulator.class); |
37 | 95 |
|
... | ... | |
66 | 124 |
|
67 | 125 |
//Constraint in and |
68 | 126 |
public boolean verifyCriteria(Map<String,List<String>> param) throws NullPointerException { |
69 |
for(Constraint sc: ce.getConstraint()){
|
|
127 |
for(Constraint constraint: ce.getConstraint()){
|
|
70 | 128 |
boolean verified = false; |
71 |
for(String value : param.get(sc.getField())){
|
|
129 |
for(String value : param.get(constraint.getField())){
|
|
72 | 130 |
try { |
73 |
if (sc.verifyCriteria(value.trim())) {
|
|
131 |
if (constraint.verifyCriteria(value.trim())) {
|
|
74 | 132 |
verified = true; |
75 | 133 |
} |
76 | 134 |
}catch(NullPointerException npe){ |
... | ... | |
83 | 141 |
return verified; |
84 | 142 |
} |
85 | 143 |
return true; |
86 |
} |
|
144 |
}*/
|
|
87 | 145 |
} |
Also available in: Unified diff
removing not necessary incapsulation