1
|
package eu.dnetlib.enabling.datasources;
|
2
|
|
3
|
import java.util.Date;
|
4
|
import java.util.List;
|
5
|
import java.util.Map;
|
6
|
|
7
|
import org.apache.commons.lang3.StringUtils;
|
8
|
import org.springframework.beans.factory.annotation.Autowired;
|
9
|
import org.springframework.web.bind.annotation.PathVariable;
|
10
|
import org.springframework.web.bind.annotation.RequestBody;
|
11
|
import org.springframework.web.bind.annotation.RequestMapping;
|
12
|
import org.springframework.web.bind.annotation.RequestMethod;
|
13
|
import org.springframework.web.bind.annotation.RequestParam;
|
14
|
import org.springframework.web.bind.annotation.RestController;
|
15
|
|
16
|
import eu.dnetlib.clients.dsManager.BrowsableField;
|
17
|
import eu.dnetlib.clients.dsManager.BrowseTerm;
|
18
|
import eu.dnetlib.clients.dsManager.DatasourceDesc;
|
19
|
import eu.dnetlib.clients.dsManager.DatasourcePoint;
|
20
|
import eu.dnetlib.clients.dsManager.IfaceDesc;
|
21
|
import eu.dnetlib.clients.dsManager.SearchInterfacesEntry;
|
22
|
import eu.dnetlib.clients.dsManager.SimpleDatasourceDesc;
|
23
|
import eu.dnetlib.enabling.annotations.DnetService;
|
24
|
import eu.dnetlib.enabling.annotations.DnetServiceType;
|
25
|
import eu.dnetlib.services.BaseService;
|
26
|
|
27
|
@RestController
|
28
|
@RequestMapping(value = "/dsManager")
|
29
|
@DnetService(DnetServiceType.dsManager)
|
30
|
public class DatasourceManagerController extends BaseService {
|
31
|
|
32
|
@Autowired
|
33
|
private DatasourceManagerCore core;
|
34
|
|
35
|
@RequestMapping(value = "map", method = RequestMethod.GET)
|
36
|
public List<DatasourcePoint> getRepositoryMap() throws DatasourceManagerServiceException {
|
37
|
return core.getDatasourceMap();
|
38
|
}
|
39
|
|
40
|
@RequestMapping(value = "ds/{type}", method = RequestMethod.GET)
|
41
|
public List<SimpleDatasourceDesc> simpleListDatasourcesByType(@PathVariable final String type) throws DatasourceManagerServiceException {
|
42
|
return core.simpleListDatasourcesByType(type);
|
43
|
}
|
44
|
|
45
|
@RequestMapping(value = "ds", method = RequestMethod.POST)
|
46
|
public String addDatasource(@RequestBody final DatasourceDesc ds) throws DatasourceManagerServiceException {
|
47
|
return core.addDatasource(ds);
|
48
|
}
|
49
|
|
50
|
@RequestMapping(value = "ds", method = RequestMethod.DELETE)
|
51
|
public boolean deleteDatasource(@RequestParam final String dsId) throws DatasourceManagerServiceException {
|
52
|
return core.deleteDatasource(dsId);
|
53
|
}
|
54
|
|
55
|
@RequestMapping(value = "ds", method = RequestMethod.GET)
|
56
|
public DatasourceDesc getDatasource(@RequestParam final String dsId) throws DatasourceManagerServiceException {
|
57
|
return core.getDatasource(dsId);
|
58
|
}
|
59
|
|
60
|
@RequestMapping(value = "search/ds", method = RequestMethod.GET)
|
61
|
public List<DatasourceDesc> listDatasources(
|
62
|
@RequestParam(required = false) final String compliance,
|
63
|
@RequestParam(required = false) final String contentDescription,
|
64
|
@RequestParam(required = false) final String collectedFrom) throws DatasourceManagerServiceException {
|
65
|
return core.listDatasources(compliance, contentDescription, collectedFrom);
|
66
|
}
|
67
|
|
68
|
@RequestMapping(value = "api/compliance", method = RequestMethod.GET)
|
69
|
public boolean updateLevelOfCompliance(@RequestParam final String dsId,
|
70
|
@RequestParam final String ifaceId,
|
71
|
@RequestParam(required = false, defaultValue = "") final String level,
|
72
|
@RequestParam(required = false, defaultValue = "false") final boolean override) throws DatasourceManagerServiceException {
|
73
|
|
74
|
if (override && StringUtils.isBlank(level)) {
|
75
|
return core.resetLevelOfCompliance(dsId, ifaceId);
|
76
|
} else {
|
77
|
return core.updateLevelOfCompliance(dsId, ifaceId, level, override);
|
78
|
}
|
79
|
}
|
80
|
|
81
|
@RequestMapping(value = "api/baseUrl", method = RequestMethod.GET)
|
82
|
public boolean updateBaseUrl(@RequestParam final String dsId,
|
83
|
@RequestParam final String ifaceId,
|
84
|
@RequestParam final String baseUrl)
|
85
|
throws DatasourceManagerServiceException {
|
86
|
return core.updateBaseUrl(dsId, ifaceId, baseUrl);
|
87
|
}
|
88
|
|
89
|
@RequestMapping(value = "api/activation", method = RequestMethod.GET)
|
90
|
public boolean updateActivationStatus(@RequestParam final String dsId,
|
91
|
@RequestParam final String ifaceId,
|
92
|
@RequestParam final boolean active) throws DatasourceManagerServiceException {
|
93
|
return core.updateActivationStatus(dsId, ifaceId, active);
|
94
|
}
|
95
|
|
96
|
@RequestMapping(value = "api/contentDescr", method = RequestMethod.GET)
|
97
|
public boolean updateContentDescription(@RequestParam final String dsId,
|
98
|
@RequestParam final String ifaceId,
|
99
|
@RequestParam final String desc) throws DatasourceManagerServiceException {
|
100
|
return core.updateContentDescription(dsId, ifaceId, desc);
|
101
|
}
|
102
|
|
103
|
@RequestMapping(value = "api/extraField/{field}", method = RequestMethod.GET)
|
104
|
public boolean updateExtraField(@RequestParam final String dsId,
|
105
|
@RequestParam final String ifaceId,
|
106
|
@PathVariable final String field,
|
107
|
@RequestParam final String value,
|
108
|
@RequestParam(required = false, defaultValue = "true") final boolean preserveOriginal) throws DatasourceManagerServiceException {
|
109
|
return core.updateExtraField(dsId, ifaceId, field, value, preserveOriginal);
|
110
|
}
|
111
|
|
112
|
@RequestMapping(value = "api/extraField/{field}", method = RequestMethod.DELETE)
|
113
|
public boolean deleteExtraField(@RequestParam final String dsId,
|
114
|
@RequestParam final String ifaceId,
|
115
|
@PathVariable final String field) throws DatasourceManagerServiceException {
|
116
|
return core.deleteExtraField(dsId, ifaceId, field);
|
117
|
}
|
118
|
|
119
|
@RequestMapping(value = "api/accessParam/{field}", method = RequestMethod.GET)
|
120
|
public boolean updateAccessParam(@RequestParam final String dsId,
|
121
|
@RequestParam final String ifaceId,
|
122
|
@PathVariable final String field,
|
123
|
@RequestParam final String value,
|
124
|
@RequestParam(required = false, defaultValue = "true") final boolean preserveOriginal) throws DatasourceManagerServiceException {
|
125
|
return core.updateAccessParam(dsId, ifaceId, field, value, preserveOriginal);
|
126
|
}
|
127
|
|
128
|
@RequestMapping(value = "api/accessParam/{field}", method = RequestMethod.DELETE)
|
129
|
public boolean deleteAccessParam(@RequestParam final String dsId,
|
130
|
@RequestParam final String ifaceId,
|
131
|
@PathVariable final String field) throws DatasourceManagerServiceException {
|
132
|
return core.deleteAccessParam(dsId, ifaceId, field);
|
133
|
}
|
134
|
|
135
|
@RequestMapping(value = "api", method = RequestMethod.POST)
|
136
|
public boolean addInterface(@RequestParam final String dsId, @RequestBody final IfaceDesc iface) throws DatasourceManagerServiceException {
|
137
|
return core.addInterface(dsId, iface);
|
138
|
}
|
139
|
|
140
|
@RequestMapping(value = "api", method = RequestMethod.DELETE)
|
141
|
public boolean deleteInterface(@RequestParam final String dsId, @RequestParam final String ifaceId) throws DatasourceManagerServiceException {
|
142
|
return core.deleteInterface(dsId, ifaceId);
|
143
|
}
|
144
|
|
145
|
@RequestMapping(value = "api/nextScheduledExecution", method = RequestMethod.GET)
|
146
|
public Date findNextScheduledExecution(@RequestParam final String dsId, @RequestParam final String ifaceId) throws DatasourceManagerServiceException {
|
147
|
return core.findNextScheduledExecution(dsId, ifaceId);
|
148
|
}
|
149
|
|
150
|
@RequestMapping(value = "api/extraFields", method = RequestMethod.POST)
|
151
|
public boolean bulkUpdateApiExtraFields(@RequestParam final String dsId,
|
152
|
@RequestParam final String ifaceId,
|
153
|
@RequestBody final Map<String, String> fields) throws DatasourceManagerServiceException {
|
154
|
return core.bulkUpdateApiExtraFields(dsId, ifaceId, fields);
|
155
|
}
|
156
|
|
157
|
@RequestMapping(value = "api/accessParams", method = RequestMethod.POST)
|
158
|
public boolean bulkUpdateApiAccessParams(@RequestParam final String dsId,
|
159
|
@RequestParam final String ifaceId,
|
160
|
@RequestBody final Map<String, String> params) throws DatasourceManagerServiceException {
|
161
|
return core.bulkUpdateApiAccessParams(dsId, ifaceId, params);
|
162
|
}
|
163
|
|
164
|
@RequestMapping(value = "browse/api/fields", method = RequestMethod.GET)
|
165
|
public List<BrowsableField> listBrowsableFields() throws DatasourceManagerServiceException {
|
166
|
return core.listBrowsableFields();
|
167
|
}
|
168
|
|
169
|
@RequestMapping(value = "browse/api/{field}", method = RequestMethod.GET)
|
170
|
public List<BrowseTerm> browseField(@PathVariable final String field) throws DatasourceManagerServiceException {
|
171
|
return core.browseField(field);
|
172
|
}
|
173
|
|
174
|
@RequestMapping(value = "search/api/{field}", method = RequestMethod.GET)
|
175
|
public List<SearchInterfacesEntry> searchInterface(@PathVariable final String field, @RequestParam final String value)
|
176
|
throws DatasourceManagerServiceException {
|
177
|
return core.searchInterface(field, value);
|
178
|
}
|
179
|
|
180
|
}
|