1
|
package eu.dnetlib.openaire.exporter;
|
2
|
|
3
|
import javax.servlet.http.HttpServletRequest;
|
4
|
|
5
|
import org.springframework.stereotype.Component;
|
6
|
|
7
|
@Component
|
8
|
public class ProjectQueryParamsFactory {
|
9
|
|
10
|
private static final String BASE_PATH = "/openaire/export/";
|
11
|
private static final String NO_FILTER = "ALL";
|
12
|
|
13
|
public ProjectQueryParams generateParams(final HttpServletRequest request,
|
14
|
final String startFrom,
|
15
|
final String startUntil,
|
16
|
final String endFrom,
|
17
|
final String endUntil) {
|
18
|
ProjectQueryParams params = new ProjectQueryParams();
|
19
|
|
20
|
String[] arr = request.getPathInfo().replace(BASE_PATH, "").split("\\/");
|
21
|
if (arr.length != 5) throw new IllegalArgumentException("Invalid url");
|
22
|
|
23
|
params.setFundingProgramme(arr[0]);
|
24
|
String stream = NO_FILTER.equals(arr[1]) ? null : arr[1];
|
25
|
String substream = NO_FILTER.equals(arr[2]) ? null : arr[2];
|
26
|
if (substream == null) {
|
27
|
params.setFundingPath(stream);
|
28
|
} else {
|
29
|
if (stream == null) {
|
30
|
stream = "%";
|
31
|
}
|
32
|
params.setFundingPath(stream + "::" + substream);
|
33
|
}
|
34
|
// params.setSpecificProgramme(NO_FILTER.equals(arr[1]) ? null : arr[1]);
|
35
|
// params.setSubdivision(NO_FILTER.equals(arr[2]) ? null : arr[2]);
|
36
|
// NB: arr[3] should be 'projects'
|
37
|
// NB: arr[4] should be '[file].do'
|
38
|
params.setStartFrom(startFrom);
|
39
|
params.setStartUntil(startUntil);
|
40
|
params.setEndFrom(endFrom);
|
41
|
params.setEndUntil(endUntil);
|
42
|
|
43
|
return params;
|
44
|
}
|
45
|
}
|