1
|
package eu.dnetlib.data.bulktag;
|
2
|
|
3
|
import com.google.common.reflect.TypeToken;
|
4
|
import com.google.gson.Gson;
|
5
|
import eu.dnetlib.data.bulktag.selectioncriteria.VerbResolver;
|
6
|
import org.apache.commons.logging.Log;
|
7
|
import org.apache.commons.logging.LogFactory;
|
8
|
|
9
|
|
10
|
import java.io.Serializable;
|
11
|
import java.lang.reflect.InvocationTargetException;
|
12
|
import java.lang.reflect.Type;
|
13
|
import java.util.Collection;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
|
17
|
/**
|
18
|
* Created by miriam on 02/08/2018.
|
19
|
*/
|
20
|
public class Constraints implements Serializable {
|
21
|
private static final Log log = LogFactory.getLog(Constraints.class);
|
22
|
private List<Constraint> sc;
|
23
|
|
24
|
|
25
|
public Constraints() {
|
26
|
}
|
27
|
|
28
|
public List<Constraint> getSc() {
|
29
|
return sc;
|
30
|
}
|
31
|
|
32
|
public void setSc(List<Constraint> sc) {
|
33
|
this.sc = sc;
|
34
|
}
|
35
|
|
36
|
public void setSc(String json){
|
37
|
Type collectionType = new TypeToken<Collection<Constraint>>(){}.getType();
|
38
|
sc = new Gson().fromJson(json, collectionType);
|
39
|
|
40
|
}
|
41
|
|
42
|
void setSelection(VerbResolver resolver) {
|
43
|
for(Constraint st: sc){
|
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 sc: sc){
|
63
|
// if(!sc.verifyCriteria(param.get(sc.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: sc){
|
73
|
boolean verified = false;
|
74
|
for(String value : param.get(sc.getField())){
|
75
|
if (sc.verifyCriteria(value)){
|
76
|
verified = true;
|
77
|
}
|
78
|
}
|
79
|
if(!verified)
|
80
|
return verified;
|
81
|
}
|
82
|
return true;
|
83
|
}
|
84
|
}
|