1
|
package eu.dnetlib.data.bulktag;
|
2
|
|
3
|
import eu.dnetlib.data.bulktag.selectioncriteria.Selection;
|
4
|
import eu.dnetlib.data.bulktag.selectioncriteria.VerbResolver;
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
|
7
|
import java.io.Serializable;
|
8
|
import java.lang.reflect.InvocationTargetException;
|
9
|
|
10
|
|
11
|
public class Constraint implements Serializable {
|
12
|
private String verb;
|
13
|
private String field;
|
14
|
private String value;
|
15
|
private Selection selection;
|
16
|
|
17
|
// @Autowired
|
18
|
// private VerbResolver resolver;
|
19
|
|
20
|
public Constraint() {
|
21
|
}
|
22
|
|
23
|
public String getVerb() {
|
24
|
return verb;
|
25
|
}
|
26
|
|
27
|
public void setVerb(String verb) {
|
28
|
this.verb = verb;
|
29
|
}
|
30
|
|
31
|
public String getField() {
|
32
|
return field;
|
33
|
}
|
34
|
|
35
|
public void setField(String field) {
|
36
|
this.field = field;
|
37
|
}
|
38
|
|
39
|
public String getValue() {
|
40
|
return value;
|
41
|
}
|
42
|
|
43
|
public void setValue(String value) {
|
44
|
this.value = value;
|
45
|
}
|
46
|
|
47
|
|
48
|
|
49
|
public void setSelection(Selection sel){
|
50
|
selection = sel;
|
51
|
}
|
52
|
|
53
|
public void setSelection(VerbResolver resolver) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
54
|
selection = resolver.getSelectionCriteria(verb,value);
|
55
|
}
|
56
|
|
57
|
|
58
|
public boolean verifyCriteria(String metadata){
|
59
|
return selection.apply(metadata);
|
60
|
}
|
61
|
|
62
|
/* public boolean verifyCriteria(String metadata) throws InvocationTargetException, IllegalAccessException {
|
63
|
Method method;
|
64
|
boolean ret = false;
|
65
|
if(verb.contains("equal")){
|
66
|
method = getStringMethod(metadata,verb);
|
67
|
}else{
|
68
|
method = getCharSequenceMethod(metadata,verb);
|
69
|
}
|
70
|
if (method == null)
|
71
|
return false;
|
72
|
ret = (boolean)method.invoke(metadata,value);
|
73
|
if(verb.startsWith("not_"))
|
74
|
return !ret;
|
75
|
return ret;
|
76
|
}
|
77
|
|
78
|
private Method getCharSequenceMethod(String metadata, String verb) {
|
79
|
try{
|
80
|
if(verb.startsWith("not_")) {
|
81
|
return metadata.getClass().getMethod(verb.substring(4), CharSequence.class);
|
82
|
}
|
83
|
else{
|
84
|
return metadata.getClass().getMethod(verb, CharSequence.class);
|
85
|
}
|
86
|
|
87
|
}catch(NoSuchMethodException nsme){
|
88
|
|
89
|
}
|
90
|
|
91
|
return null;
|
92
|
}
|
93
|
|
94
|
private Method getStringMethod(String metadata, String verb) {
|
95
|
try{
|
96
|
if(verb.startsWith("not_")) {
|
97
|
return metadata.getClass().getMethod(verb.substring(4), String.class);
|
98
|
}
|
99
|
else{
|
100
|
return metadata.getClass().getMethod(verb, String.class);
|
101
|
}
|
102
|
|
103
|
}catch(NoSuchMethodException nsme){
|
104
|
|
105
|
}
|
106
|
return null;
|
107
|
}*/
|
108
|
|
109
|
}
|