1
|
package eu.dnetlib.data.search.web.utils;
|
2
|
|
3
|
import java.util.Arrays;
|
4
|
import java.util.List;
|
5
|
|
6
|
/**
|
7
|
* Created by kiatrop on 19/9/2016.
|
8
|
*/
|
9
|
public class RequestResponseHandler {
|
10
|
|
11
|
public enum Entity {
|
12
|
RESULT("result"),
|
13
|
PUBLICATION("publication"),
|
14
|
DATASET("dataset"),
|
15
|
PROJECT("project"),
|
16
|
DATASOURCE("datasource"),
|
17
|
ORGANIZATION("organization"),
|
18
|
//PERSON("person"),
|
19
|
SOFTWARE("software"),
|
20
|
OTHER("other"),
|
21
|
NONE("");
|
22
|
|
23
|
private final List<String> RESULT_FIELD_QUERIES = Arrays.asList("oaftype exact result");
|
24
|
private final List<String> PUBLICATION_FIELD_QUERIES = Arrays.asList("oaftype exact result", "resulttypeid exact publication");
|
25
|
private final List<String> DATASET_FIELD_QUERIES = Arrays.asList("oaftype exact result", "resulttypeid exact dataset");
|
26
|
private final List<String> SOFTWARE_FIELD_QUERIES = Arrays.asList("oaftype exact result", "resulttypeid exact software");
|
27
|
private final List<String> OTHER_FIELD_QUERIES = Arrays.asList("oaftype exact result", "resulttypeid exact other");
|
28
|
private final List<String> PROJECT_FIELD_QUERIES = Arrays.asList("oaftype exact project");
|
29
|
private final List<String> DATASOURCE_FIELD_QUERIES = Arrays.asList("oaftype exact datasource", "(datasourcecompatibilityid <> \"UNKNOWN\")");
|
30
|
private final List<String> ORGANIZATION_FIELD_QUERIES = Arrays.asList("oaftype exact organization");
|
31
|
/*private final List<String> ORGANIZATION_FIELD_QUERIES = Arrays.asList("oaftype exact organization",
|
32
|
"reldatasourcecompatibilityid exact driver or reldatasourcecompatibilityid exact driver-openaire2.0 or " +
|
33
|
"reldatasourcecompatibilityid exact openaire2.0 or reldatasourcecompatibilityid exact openaire3.0 or " +
|
34
|
"reldatasourcecompatibilityid exact openaire2.0_data or reldatasourcecompatibilityid exact hostedBy or relproject=*");
|
35
|
*/
|
36
|
//private final List<String> PERSON_FIELD_QUERIES = Arrays.asList("oaftype exact person");
|
37
|
|
38
|
private final String RESULT_QUERY = "oaftype exact result";
|
39
|
private final String PUBLICATION_QUERY = "resulttypeid exact publication";
|
40
|
private final String DATASET_QUERY = "resulttypeid exact dataset";
|
41
|
private final String SOFTWARE_QUERY = "resulttypeid exact software";
|
42
|
private final String OTHER_QUERY = "resulttypeid exact other";
|
43
|
|
44
|
private String value;
|
45
|
Entity(String value) {
|
46
|
this.value = value;
|
47
|
}
|
48
|
private String getValue() {
|
49
|
return value;
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
public String toString() {
|
54
|
return this.getValue();
|
55
|
}
|
56
|
|
57
|
public String getQueryPrefix() {
|
58
|
switch (this) {
|
59
|
case RESULT:
|
60
|
return RESULT_PREFIX;
|
61
|
|
62
|
case PUBLICATION:
|
63
|
return PUBLICATION_PREFIX;
|
64
|
|
65
|
case DATASET:
|
66
|
return DATASET_PREFIX;
|
67
|
|
68
|
case SOFTWARE:
|
69
|
return SOFTWARE_PREFIX;
|
70
|
|
71
|
case OTHER:
|
72
|
return OTHER_PREFIX;
|
73
|
|
74
|
case PROJECT:
|
75
|
return PROJECT_PREFIX;
|
76
|
|
77
|
case DATASOURCE:
|
78
|
return DATASOURCE_PREFIX;
|
79
|
|
80
|
case ORGANIZATION:
|
81
|
return ORGANIZATION_PREFIX;
|
82
|
|
83
|
//case PERSON:
|
84
|
// return PERSON_PREFIX;
|
85
|
|
86
|
case NONE:
|
87
|
return "";
|
88
|
|
89
|
default:
|
90
|
throw new IllegalArgumentException();
|
91
|
}
|
92
|
|
93
|
}
|
94
|
|
95
|
public String getPlural() {
|
96
|
switch (this) {
|
97
|
case RESULT:
|
98
|
return "results";
|
99
|
|
100
|
case PUBLICATION:
|
101
|
return "publications";
|
102
|
|
103
|
case DATASET:
|
104
|
return "datasets";
|
105
|
|
106
|
case SOFTWARE:
|
107
|
return "software";
|
108
|
|
109
|
case OTHER:
|
110
|
return "other";
|
111
|
|
112
|
case PROJECT:
|
113
|
return "projects";
|
114
|
|
115
|
case DATASOURCE:
|
116
|
return "datasources";
|
117
|
|
118
|
case ORGANIZATION:
|
119
|
return "organizations";
|
120
|
|
121
|
//case PERSON:
|
122
|
// return "people";
|
123
|
|
124
|
case NONE:
|
125
|
return "resources";
|
126
|
|
127
|
default:
|
128
|
throw new IllegalArgumentException();
|
129
|
}
|
130
|
}
|
131
|
|
132
|
public List<String> getFieldQueries() {
|
133
|
switch (this) {
|
134
|
case RESULT:
|
135
|
return RESULT_FIELD_QUERIES;
|
136
|
|
137
|
case PUBLICATION:
|
138
|
return PUBLICATION_FIELD_QUERIES;
|
139
|
|
140
|
case DATASET:
|
141
|
return DATASET_FIELD_QUERIES;
|
142
|
|
143
|
case SOFTWARE:
|
144
|
return SOFTWARE_FIELD_QUERIES;
|
145
|
|
146
|
case OTHER:
|
147
|
return OTHER_FIELD_QUERIES;
|
148
|
|
149
|
case PROJECT:
|
150
|
return PROJECT_FIELD_QUERIES;
|
151
|
|
152
|
case DATASOURCE:
|
153
|
return DATASOURCE_FIELD_QUERIES;
|
154
|
|
155
|
case ORGANIZATION:
|
156
|
return ORGANIZATION_FIELD_QUERIES;
|
157
|
|
158
|
//case PERSON:
|
159
|
// return PERSON_FIELD_QUERIES;
|
160
|
|
161
|
default:
|
162
|
throw new IllegalArgumentException();
|
163
|
}
|
164
|
}
|
165
|
|
166
|
public String getSimpleQuery() {
|
167
|
switch (this) {
|
168
|
case RESULT:
|
169
|
return RESULT_QUERY;
|
170
|
|
171
|
case PUBLICATION:
|
172
|
return PUBLICATION_QUERY;
|
173
|
|
174
|
case DATASET:
|
175
|
return DATASET_QUERY;
|
176
|
|
177
|
case SOFTWARE:
|
178
|
return SOFTWARE_QUERY;
|
179
|
|
180
|
case OTHER:
|
181
|
return OTHER_QUERY;
|
182
|
|
183
|
default:
|
184
|
throw new IllegalArgumentException();
|
185
|
}
|
186
|
}
|
187
|
}
|
188
|
|
189
|
public final static String RESULT_PREFIX = "(oaftype exact result)";
|
190
|
public final static String PUBLICATION_PREFIX = "(oaftype exact result) and (resulttypeid exact publication)";
|
191
|
public final static String DATASET_PREFIX = "(oaftype exact result) and (resulttypeid exact dataset)";
|
192
|
public final static String SOFTWARE_PREFIX = "(oaftype exact result) and (resulttypeid exact software)";
|
193
|
public final static String OTHER_PREFIX = "(oaftype exact result) and (resulttypeid exact other)";
|
194
|
public final static String PROJECT_PREFIX = "(oaftype exact project)";
|
195
|
public final static String DATASOURCE_PREFIX = "(oaftype exact datasource) and (datasourcecompatibilityid <> \"UNKNOWN\")";
|
196
|
public final static String ORGANIZATION_PREFIX = "(oaftype exact organization and " +
|
197
|
"(reldatasourcecompatibilityid=driver or reldatasourcecompatibilityid=driver-openaire2.0 or " +
|
198
|
"reldatasourcecompatibilityid=openaire2.0 or reldatasourcecompatibilityid=openaire3.0 or " +
|
199
|
"reldatasourcecompatibilityid=openaire2.0_data or reldatasourcecompatibilityid=hostedBy " +
|
200
|
"or relproject=*)";
|
201
|
//public final static String PERSON_PREFIX = "(oaftype exact person)";
|
202
|
|
203
|
|
204
|
|
205
|
}
|