1
|
package eu.dnetlib.repo.manager.service;
|
2
|
|
3
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
4
|
import com.google.gson.JsonArray;
|
5
|
import com.google.gson.JsonElement;
|
6
|
import com.google.gson.JsonObject;
|
7
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
8
|
import eu.dnetlib.domain.data.Repository;
|
9
|
import eu.dnetlib.domain.data.RepositoryInterface;
|
10
|
import eu.dnetlib.domain.enabling.Vocabulary;
|
11
|
import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
12
|
import eu.dnetlib.repo.manager.domain.*;
|
13
|
import eu.dnetlib.repo.manager.domain.dto.Role;
|
14
|
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
15
|
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
|
16
|
import eu.dnetlib.repo.manager.service.security.AuthoritiesUpdater;
|
17
|
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
|
18
|
import eu.dnetlib.repo.manager.service.security.RoleMappingService;
|
19
|
import eu.dnetlib.repo.manager.utils.Converter;
|
20
|
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
|
21
|
import org.apache.commons.codec.digest.DigestUtils;
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.json.JSONArray;
|
24
|
import org.json.JSONException;
|
25
|
import org.json.JSONObject;
|
26
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
27
|
import org.springframework.beans.factory.annotation.Autowired;
|
28
|
import org.springframework.beans.factory.annotation.Value;
|
29
|
import org.springframework.context.annotation.Lazy;
|
30
|
import org.springframework.core.ParameterizedTypeReference;
|
31
|
import org.springframework.http.*;
|
32
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
33
|
import org.springframework.security.core.Authentication;
|
34
|
import org.springframework.security.core.context.SecurityContextHolder;
|
35
|
import org.springframework.stereotype.Service;
|
36
|
import org.springframework.web.client.HttpClientErrorException;
|
37
|
import org.springframework.web.client.RestTemplate;
|
38
|
import org.springframework.web.util.UriComponents;
|
39
|
import org.springframework.web.util.UriComponentsBuilder;
|
40
|
|
41
|
import javax.annotation.PostConstruct;
|
42
|
import java.io.IOException;
|
43
|
import java.sql.Timestamp;
|
44
|
import java.util.*;
|
45
|
import java.util.concurrent.ConcurrentHashMap;
|
46
|
import java.util.stream.Collectors;
|
47
|
|
48
|
@Service("repositoryService")
|
49
|
public class RepositoryServiceImpl implements RepositoryService {
|
50
|
|
51
|
private static final Logger LOGGER = Logger.getLogger(RepositoryServiceImpl.class);
|
52
|
|
53
|
private final AuthorizationService authorizationService;
|
54
|
private final RoleMappingService roleMappingService;
|
55
|
private final AaiRegistryService registryCalls;
|
56
|
private final AuthoritiesUpdater authoritiesUpdater;
|
57
|
private final RestTemplate restTemplate;
|
58
|
private final VocabularyLoader vocabularyLoader;
|
59
|
private final PiWikService piWikService;
|
60
|
private final EmailUtils emailUtils;
|
61
|
private final ValidatorService validatorService;
|
62
|
|
63
|
@Value("${services.provide.clients.dsm}")
|
64
|
private String baseAddress;
|
65
|
|
66
|
@Value("${services.provide.adminEmail}")
|
67
|
private String adminEmail;
|
68
|
|
69
|
@Value("${services.provide.usageStatisticsDiagramsBaseURL}")
|
70
|
private String usageStatisticsDiagramsBaseURL;
|
71
|
|
72
|
@Value("${services.provide.usageStatisticsNumbersBaseURL}")
|
73
|
private String usageStatisticsNumbersBaseURL;
|
74
|
|
75
|
|
76
|
private static final Map<String, List<String>> dataSourceClass = new HashMap<>();
|
77
|
private static final Map<String, String> invertedDataSourceClass = new HashMap<>();
|
78
|
|
79
|
|
80
|
private final String[] vocabularyNames = {"dnet:countries", "dnet:datasource_typologies", "dnet:compatibilityLevel"};
|
81
|
private final Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<>();
|
82
|
private final Map<String, String> countriesMap = new HashMap<>();
|
83
|
private final Map<String, String> inverseCountriesMap = new HashMap<>();
|
84
|
|
85
|
private HttpHeaders httpHeaders;
|
86
|
|
87
|
@Autowired
|
88
|
public RepositoryServiceImpl(AuthorizationService authorizationService,
|
89
|
RoleMappingService roleMappingService,
|
90
|
AaiRegistryService registryCalls,
|
91
|
AuthoritiesUpdater authoritiesUpdater,
|
92
|
VocabularyLoader vocabularyLoader,
|
93
|
RestTemplate restTemplate,
|
94
|
@Lazy EmailUtils emailUtils,
|
95
|
@Lazy ValidatorService validatorService,
|
96
|
@Lazy PiWikService piWikService) {
|
97
|
this.authorizationService = authorizationService;
|
98
|
this.roleMappingService = roleMappingService;
|
99
|
this.registryCalls = registryCalls;
|
100
|
this.authoritiesUpdater = authoritiesUpdater;
|
101
|
this.vocabularyLoader = vocabularyLoader;
|
102
|
this.piWikService = piWikService;
|
103
|
this.emailUtils = emailUtils;
|
104
|
this.validatorService = validatorService;
|
105
|
this.restTemplate = restTemplate;
|
106
|
}
|
107
|
|
108
|
@PostConstruct
|
109
|
private void init() {
|
110
|
LOGGER.debug("Initialization method of repository api!");
|
111
|
LOGGER.debug("Updated version!");
|
112
|
|
113
|
for (String key : this.getVocabulary("dnet:datasource_typologies").getAsMap().keySet()) {
|
114
|
if (key.contains("aggregator")) {
|
115
|
dataSourceClass.putIfAbsent("aggregator", new ArrayList<>());
|
116
|
dataSourceClass.get("aggregator").add(key);
|
117
|
} else if (key.contains("crissystem")) {
|
118
|
dataSourceClass.putIfAbsent("cris", new ArrayList<>());
|
119
|
dataSourceClass.get("cris").add(key);
|
120
|
} else if (key.contains("pubsrepository::journal")) { // do not change order -->
|
121
|
dataSourceClass.putIfAbsent("journal", Collections.singletonList("pubsrepository::journal"));
|
122
|
} else if (key.contains("pubsrepository")) { // do not change order <--
|
123
|
dataSourceClass.putIfAbsent("opendoar", new ArrayList<>());
|
124
|
dataSourceClass.get("opendoar").add(key);
|
125
|
} else if (key.contains("datarepository")) {
|
126
|
dataSourceClass.putIfAbsent("re3data", Collections.singletonList("datarepository::unknown"));
|
127
|
}
|
128
|
}
|
129
|
|
130
|
for (Map.Entry<String, List<String>> entry : dataSourceClass.entrySet()) {
|
131
|
entry.getValue().forEach(v -> invertedDataSourceClass.put(v, entry.getKey()));
|
132
|
}
|
133
|
|
134
|
httpHeaders = new HttpHeaders();
|
135
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
136
|
|
137
|
for (String vocName : vocabularyNames) {
|
138
|
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
|
139
|
}
|
140
|
|
141
|
Country[] countries = getCountries();
|
142
|
for (Country c : countries) {
|
143
|
countriesMap.put(c.getName(), c.getCode());
|
144
|
inverseCountriesMap.put(c.getCode(), c.getName());
|
145
|
}
|
146
|
|
147
|
|
148
|
}
|
149
|
|
150
|
@Override
|
151
|
public Country[] getCountries() {
|
152
|
UriComponents uriComponents = UriComponentsBuilder
|
153
|
.fromHttpUrl(baseAddress + "/ds/countries")
|
154
|
.build().encode();
|
155
|
return restTemplate.getForObject(uriComponents.toUri(), Country[].class);
|
156
|
}
|
157
|
|
158
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
159
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
160
|
// another way for paging must be implemented.
|
161
|
@Override
|
162
|
public List<Repository> getRepositories(List<String> ids) throws JSONException {
|
163
|
return getRepositories(ids, 0, 10);
|
164
|
}
|
165
|
|
166
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
167
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
168
|
// another way for paging must be implemented.
|
169
|
@Override
|
170
|
public List<Repository> getRepositories(List<String> ids, int page, int size) throws JSONException {
|
171
|
List<Repository> repos = new ArrayList<>();
|
172
|
LOGGER.debug("Retrieving repositories with ids : " + String.join(", ", ids));
|
173
|
UriComponents uriComponents = searchDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
174
|
RequestFilter requestFilter = new RequestFilter();
|
175
|
|
176
|
for (String repoId : ids) {
|
177
|
requestFilter.setId(repoId);
|
178
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
179
|
|
180
|
repos.addAll(Converter.jsonToRepositoryList(new JSONObject(rs)));
|
181
|
}
|
182
|
|
183
|
for (Repository r : repos)
|
184
|
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
185
|
return repos;
|
186
|
}
|
187
|
|
188
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
189
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
190
|
// another way for paging must be implemented.
|
191
|
@Override
|
192
|
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids) throws Exception {
|
193
|
return getRepositoriesSnippets(ids, 0, 10);
|
194
|
}
|
195
|
|
196
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
197
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
198
|
// another way for paging must be implemented.
|
199
|
@Override
|
200
|
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids, int page, int size) throws Exception {
|
201
|
List<RepositorySnippet> resultSet = new ArrayList<>();
|
202
|
ObjectMapper mapper = new ObjectMapper();
|
203
|
|
204
|
// here page should be 0
|
205
|
UriComponents uriComponents = searchSnipperDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
206
|
RequestFilter requestFilter = new RequestFilter();
|
207
|
|
208
|
try {
|
209
|
for (String repoId : ids) {
|
210
|
requestFilter.setId(repoId);
|
211
|
|
212
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
213
|
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
214
|
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray),
|
215
|
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
216
|
}
|
217
|
} catch (Exception e) {
|
218
|
LOGGER.debug("Exception on getRepositoriesSnippetOfUser", e);
|
219
|
throw e;
|
220
|
}
|
221
|
|
222
|
LOGGER.debug("resultSet:" + resultSet);
|
223
|
resultSet.parallelStream().forEach(repositorySnippet -> {
|
224
|
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
|
225
|
});
|
226
|
return resultSet;
|
227
|
}
|
228
|
|
229
|
|
230
|
@Override
|
231
|
public List<RepositorySnippet> getRepositoriesByCountry(String country,
|
232
|
String mode,
|
233
|
Boolean managed) throws JSONException, IOException {
|
234
|
|
235
|
LOGGER.debug("Getting repositories by country!");
|
236
|
int page = 0;
|
237
|
int size = 100;
|
238
|
List<RepositorySnippet> resultSet = new ArrayList<>();
|
239
|
ObjectMapper mapper = new ObjectMapper();
|
240
|
|
241
|
String filterKey = "UNKNOWN";
|
242
|
if (mode.equalsIgnoreCase("opendoar"))
|
243
|
filterKey = "openaire____::opendoar";
|
244
|
else if (mode.equalsIgnoreCase("re3data"))
|
245
|
filterKey = "openaire____::re3data";
|
246
|
else if (mode.equalsIgnoreCase("cris"))
|
247
|
filterKey = "eurocrisdris::dris";
|
248
|
|
249
|
|
250
|
LOGGER.debug("Country code equals : " + country);
|
251
|
LOGGER.debug("Filter mode equals : " + filterKey);
|
252
|
|
253
|
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
|
254
|
RequestFilter requestFilter = new RequestFilter();
|
255
|
requestFilter.setCountry(country);
|
256
|
requestFilter.setCollectedfrom(filterKey);
|
257
|
|
258
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
259
|
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
260
|
while (jsonArray.length() > 0) {
|
261
|
|
262
|
LOGGER.debug("json: " + jsonArray);
|
263
|
|
264
|
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray),
|
265
|
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
266
|
page += 1;
|
267
|
uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
|
268
|
rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
269
|
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
270
|
}
|
271
|
return resultSet;
|
272
|
}
|
273
|
|
274
|
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
|
275
|
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
|
276
|
|
277
|
LOGGER.debug("Searching registered repositories");
|
278
|
|
279
|
List<RepositorySnippet> resultSet = new ArrayList<>();
|
280
|
ObjectMapper mapper = new ObjectMapper();
|
281
|
|
282
|
UriComponents uriComponents = searchRegisteredDatasource(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize));
|
283
|
|
284
|
RequestFilter requestFilter = new RequestFilter();
|
285
|
requestFilter.setCountry(country);
|
286
|
requestFilter.setTypology(typology);
|
287
|
requestFilter.setOfficialname(officialName);
|
288
|
requestFilter.setEnglishname(englishName);
|
289
|
|
290
|
try {
|
291
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
292
|
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
293
|
|
294
|
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
295
|
|
296
|
return resultSet;
|
297
|
} catch (Exception e) {
|
298
|
LOGGER.error("Error searching registered datasources", e);
|
299
|
throw e;
|
300
|
}
|
301
|
}
|
302
|
|
303
|
@Override
|
304
|
public int getTotalRegisteredRepositories() {
|
305
|
UriComponents uriComponents = UriComponentsBuilder
|
306
|
.fromHttpUrl(baseAddress + "/ds/countregistered")
|
307
|
.queryParam("fromDate", "1900-01-01")
|
308
|
.build().encode();
|
309
|
|
310
|
return restTemplate.getForObject(uriComponents.toUri(), Integer.class);
|
311
|
}
|
312
|
|
313
|
private Repository updateRepositoryInfo(Repository r) throws JSONException {
|
314
|
|
315
|
/*
|
316
|
* from datasource class
|
317
|
* we get the datasource type form the inverted map
|
318
|
* */
|
319
|
r.setDatasourceType(getRepositoryType(r.getDatasourceClass()));
|
320
|
r.setInterfaces(this.getRepositoryInterface(r.getId()));
|
321
|
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
322
|
r.setCountryName(getCountryName(r.getCountryCode()));
|
323
|
return r;
|
324
|
}
|
325
|
|
326
|
@Override
|
327
|
public List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException {
|
328
|
String userEmail = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
|
329
|
LOGGER.debug("Retrieving repositories of authenticated user : " + userEmail);
|
330
|
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles());
|
331
|
return getRepositories(new ArrayList<>(repoIds));
|
332
|
}
|
333
|
|
334
|
@Override
|
335
|
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) throws JSONException {
|
336
|
LOGGER.debug("Retrieving repositories of authenticated user : " + userEmail);
|
337
|
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles(userEmail));
|
338
|
return getRepositories(new ArrayList<>(repoIds));
|
339
|
}
|
340
|
|
341
|
@Override
|
342
|
public List<RepositorySnippet> getRepositoriesSnippetsOfUser(String page, String size) throws Exception {
|
343
|
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles());
|
344
|
return getRepositoriesSnippets(new ArrayList<>(repoIds));
|
345
|
}
|
346
|
|
347
|
@Override
|
348
|
public List<RepositorySnippet> getRepositoriesSnippetsOfUser(String userEmail, String page, String size) throws Exception {
|
349
|
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles(userEmail));
|
350
|
return getRepositoriesSnippets(new ArrayList<>(repoIds));
|
351
|
}
|
352
|
|
353
|
@Override
|
354
|
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException {
|
355
|
|
356
|
LOGGER.debug("Retrieving repositories with id : " + id);
|
357
|
RepositorySnippet repo = null;
|
358
|
UriComponents uriComponents = searchSnipperDatasource("0", "100");
|
359
|
RequestFilter requestFilter = new RequestFilter();
|
360
|
requestFilter.setId(id);
|
361
|
|
362
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
363
|
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
364
|
|
365
|
if (jsonArray.length() == 0)
|
366
|
throw new ResourceNotFoundException();
|
367
|
|
368
|
repo = Converter.jsonToRepositorySnippetObject(jsonArray.getJSONObject(0));
|
369
|
return repo;
|
370
|
}
|
371
|
|
372
|
@Override
|
373
|
public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException {
|
374
|
|
375
|
LOGGER.debug("Retrieving repositories with id : " + id);
|
376
|
Repository repo = null;
|
377
|
UriComponents uriComponents = searchDatasource("0", "100");
|
378
|
RequestFilter requestFilter = new RequestFilter();
|
379
|
requestFilter.setId(id);
|
380
|
|
381
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
382
|
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
383
|
|
384
|
if (jsonArray.length() == 0)
|
385
|
throw new ResourceNotFoundException();
|
386
|
|
387
|
repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0));
|
388
|
return updateRepositoryInfo(repo);
|
389
|
}
|
390
|
|
391
|
|
392
|
@Override
|
393
|
public List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException {
|
394
|
|
395
|
LOGGER.debug("Retrieving aggregations for repository with id : " + id);
|
396
|
UriComponents uriComponents = getAggregationHistory(id);
|
397
|
|
398
|
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
399
|
JSONArray aggregationInfo = new JSONObject(rs).getJSONArray("aggregationInfo");
|
400
|
|
401
|
List<AggregationDetails> aggregationHistory = new ArrayList<>(Converter.getAggregationHistoryFromJson(aggregationInfo));
|
402
|
|
403
|
return aggregationHistory;
|
404
|
// return aggregationHistory.size() == 0 ? aggregationHistory : aggregationHistory.stream()
|
405
|
// .sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
|
406
|
// .collect(Collectors.toList());
|
407
|
}
|
408
|
|
409
|
@Override
|
410
|
public List<AggregationDetails> getRepositoryAggregations(String id, int from, int size) throws JSONException {
|
411
|
|
412
|
return getRepositoryAggregations(id).subList(from, from + size);
|
413
|
}
|
414
|
|
415
|
@Override
|
416
|
public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException {
|
417
|
LOGGER.debug("Retrieving aggregations (by year) for repository with id : " + id);
|
418
|
|
419
|
List<AggregationDetails> aggregationHistory = getRepositoryAggregations(id);
|
420
|
Map<String, List<AggregationDetails>> aggregationByYear = new HashMap<>();
|
421
|
|
422
|
return aggregationHistory.size() == 0 ? aggregationByYear : createYearMap(aggregationHistory);
|
423
|
}
|
424
|
|
425
|
private Map<String, List<AggregationDetails>> createYearMap(List<AggregationDetails> aggregationHistory) {
|
426
|
|
427
|
aggregationHistory = aggregationHistory.stream()
|
428
|
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
|
429
|
.collect(Collectors.toList());
|
430
|
|
431
|
return aggregationHistory.stream()
|
432
|
.collect(Collectors.groupingBy(AggregationDetails::getYear));
|
433
|
}
|
434
|
|
435
|
|
436
|
@Override
|
437
|
public List<Repository> getRepositoriesByName(String name,
|
438
|
String page,
|
439
|
String size) throws JSONException {
|
440
|
|
441
|
LOGGER.debug("Retrieving repositories with official name : " + name);
|
442
|
UriComponents uriComponents = searchDatasource("0", "100");
|
443
|
RequestFilter requestFilter = new RequestFilter();
|
444
|
requestFilter.setOfficialname(name);
|
445
|
|
446
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
447
|
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
|
448
|
for (Repository r : repos)
|
449
|
updateRepositoryInfo(r);
|
450
|
return repos;
|
451
|
|
452
|
}
|
453
|
|
454
|
@Override
|
455
|
public List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException {
|
456
|
|
457
|
UriComponents uriComponents = UriComponentsBuilder
|
458
|
.fromHttpUrl(baseAddress + "/ds/api/")
|
459
|
.path("/{id}")
|
460
|
.build().expand(id).encode();
|
461
|
|
462
|
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
463
|
return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs));
|
464
|
|
465
|
}
|
466
|
|
467
|
@Override
|
468
|
public Repository addRepository(String datatype, Repository repository) throws Exception {
|
469
|
|
470
|
LOGGER.debug("storing " + datatype + " repository with id: " + repository.getId());
|
471
|
|
472
|
repository.setCountryCode(countriesMap.get(repository.getCountryName()));
|
473
|
repository.setActivationId(UUID.randomUUID().toString());
|
474
|
repository.setCollectedFrom("infrastruct_::openaire");
|
475
|
|
476
|
if (datatype.equals("journal")) {
|
477
|
repository.setId("openaire____::issn" + repository.getIssn());
|
478
|
repository.setNamespacePrefix("issn" + repository.getIssn());
|
479
|
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication());
|
480
|
} else if (datatype.equals("aggregator")) {
|
481
|
repository.setId("openaire____::" + DigestUtils.md5Hex(repository.getOfficialName()));
|
482
|
repository.setNamespacePrefix(DigestUtils.md5Hex(repository.getOfficialName()).substring(0, 12));
|
483
|
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication());
|
484
|
} else {
|
485
|
this.latentUpdate(repository, SecurityContextHolder.getContext().getAuthentication());
|
486
|
}
|
487
|
|
488
|
// TODO: move the following code elsewhere (creation and assignment of role to user) ??
|
489
|
// Create new role
|
490
|
String newRoleName = roleMappingService.getRoleIdByRepoId(repository.getId());
|
491
|
Role newRole = new Role(newRoleName, repository.getOfficialName());
|
492
|
Integer couId = null;
|
493
|
try {
|
494
|
couId = registryCalls.createRole(newRole);
|
495
|
} catch (HttpClientErrorException e) {
|
496
|
couId = registryCalls.getCouId(newRoleName);
|
497
|
if (couId == null) {
|
498
|
LOGGER.error(String.format("Could not create role '%s'", newRoleName), e);
|
499
|
}
|
500
|
} catch (Exception e) {
|
501
|
LOGGER.error(String.format("Could not create role '%s'", newRoleName), e);
|
502
|
throw e;
|
503
|
}
|
504
|
|
505
|
// Assign new role to the user that created it
|
506
|
Integer coPersonId = registryCalls.getCoPersonIdByIdentifier();
|
507
|
if (couId != null) {
|
508
|
Integer role = registryCalls.getRoleId(coPersonId, couId);
|
509
|
try {
|
510
|
registryCalls.assignMemberRole(coPersonId, couId, role);
|
511
|
|
512
|
// Add role to current user authorities
|
513
|
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(repository.getId()));
|
514
|
} catch (Exception e) {
|
515
|
LOGGER.debug("Exception on assign role to user during add repository", e);
|
516
|
throw e;
|
517
|
}
|
518
|
|
519
|
}
|
520
|
|
521
|
|
522
|
return repository;
|
523
|
}
|
524
|
|
525
|
/* update method acting as add -> send email with registration topic/body*/
|
526
|
private Repository latentUpdate(Repository repository, Authentication authentication) throws Exception {
|
527
|
UriComponents uriComponents = UriComponentsBuilder
|
528
|
.fromHttpUrl(baseAddress + "/ds/update/")
|
529
|
.build()
|
530
|
.encode();
|
531
|
|
532
|
String json_repository = Converter.repositoryObjectToJson(repository);
|
533
|
LOGGER.debug("JSON to add(update) -> " + json_repository);
|
534
|
|
535
|
HttpEntity<String> httpEntity = new HttpEntity<>(json_repository, httpHeaders);
|
536
|
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
537
|
|
538
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
539
|
try {
|
540
|
emailUtils.sendUserRegistrationEmail(repository, authentication);
|
541
|
emailUtils.sendAdminRegistrationEmail(repository, authentication);
|
542
|
} catch (Exception e) {
|
543
|
LOGGER.error("Error sending email", e);
|
544
|
}
|
545
|
} else
|
546
|
LOGGER.error("Error storing repository: " + responseEntity.getBody().toString());
|
547
|
|
548
|
return repository;
|
549
|
}
|
550
|
|
551
|
@Override
|
552
|
public Repository updateRepository(Repository repository, Authentication authentication) throws Exception {
|
553
|
UriComponents uriComponents = UriComponentsBuilder
|
554
|
.fromHttpUrl(baseAddress + "/ds/update/")
|
555
|
.build()
|
556
|
.encode();
|
557
|
|
558
|
String json_repository = Converter.repositoryObjectToJson(repository);
|
559
|
|
560
|
LOGGER.debug("JSON to update -> " + json_repository);
|
561
|
|
562
|
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
|
563
|
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity
|
564
|
, ResponseEntity.class);
|
565
|
|
566
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
567
|
try {
|
568
|
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
|
569
|
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
|
570
|
} catch (Exception e) {
|
571
|
LOGGER.error("Error sending emails: " + e);
|
572
|
}
|
573
|
} else
|
574
|
LOGGER.debug(responseEntity.getBody().toString());
|
575
|
|
576
|
return repository;
|
577
|
}
|
578
|
|
579
|
private void storeRepository(Repository repository, Authentication authentication) throws Exception {
|
580
|
|
581
|
Date utilDate = new Date();
|
582
|
Timestamp date = new Timestamp(utilDate.getTime());
|
583
|
repository.setDateOfCollection(date);
|
584
|
repository.setAggregator("OPENAIRE");
|
585
|
repository.setCountryCode(countriesMap.get(repository.getCountryName()));
|
586
|
|
587
|
UriComponents uriComponents = UriComponentsBuilder
|
588
|
.fromHttpUrl(baseAddress + "/ds/add/")
|
589
|
.build()
|
590
|
.encode();
|
591
|
String json_repository = Converter.repositoryObjectToJson(repository);
|
592
|
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
|
593
|
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
594
|
|
595
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
596
|
try {
|
597
|
emailUtils.sendUserRegistrationEmail(repository, authentication);
|
598
|
emailUtils.sendAdminRegistrationEmail(repository, authentication);
|
599
|
} catch (Exception e) {
|
600
|
LOGGER.error("Error sending emails: " + e);
|
601
|
}
|
602
|
} else {
|
603
|
LOGGER.debug(responseEntity.getBody().toString());
|
604
|
}
|
605
|
}
|
606
|
|
607
|
@Override
|
608
|
public void deleteRepositoryInterface(String id,
|
609
|
String registeredBy) {
|
610
|
UriComponents uriComponents = UriComponentsBuilder
|
611
|
.fromHttpUrl(baseAddress + "/ds/api/")
|
612
|
.path("/{id}")
|
613
|
.build().expand(id).encode();
|
614
|
LOGGER.debug(uriComponents.toUri());
|
615
|
restTemplate.delete(uriComponents.toUri());
|
616
|
}
|
617
|
|
618
|
@Override
|
619
|
public RepositoryInterface addRepositoryInterface(String datatype,
|
620
|
String repoId,
|
621
|
String registeredBy,
|
622
|
String comment, RepositoryInterface repositoryInterface) throws Exception {
|
623
|
Repository e = this.getRepositoryById(repoId);
|
624
|
repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype);
|
625
|
String json_interface = Converter.repositoryInterfaceObjectToJson(e, repositoryInterface);
|
626
|
|
627
|
UriComponents uriComponents = UriComponentsBuilder
|
628
|
.fromHttpUrl(baseAddress + "/ds/api/add/")
|
629
|
.build()
|
630
|
.encode();
|
631
|
|
632
|
HttpEntity<String> httpEntity = new HttpEntity<>(json_interface, httpHeaders);
|
633
|
|
634
|
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
|
635
|
|
636
|
try {
|
637
|
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
|
638
|
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
|
639
|
} catch (Exception ex) {
|
640
|
LOGGER.error("Error sending emails: " + ex);
|
641
|
}
|
642
|
|
643
|
submitInterfaceValidation(e, registeredBy, repositoryInterface, false);
|
644
|
|
645
|
return repositoryInterface;
|
646
|
}
|
647
|
|
648
|
@Override
|
649
|
public RepositoryInterface updateRepositoryInterface(String repoId,
|
650
|
String registeredBy,
|
651
|
String comment, RepositoryInterface repositoryInterface) throws Exception {
|
652
|
|
653
|
this.updateBaseUrl(repoId, repositoryInterface.getId(), repositoryInterface.getBaseUrl());
|
654
|
this.updateCompliance(repoId, repositoryInterface.getId(), repositoryInterface.getCompliance());
|
655
|
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
|
656
|
|
657
|
Repository repository = this.getRepositoryById(repoId);
|
658
|
try {
|
659
|
try {
|
660
|
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
|
661
|
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
|
662
|
} catch (Exception e) {
|
663
|
LOGGER.error("Error sending emails: " + e);
|
664
|
}
|
665
|
} catch (Exception e) {
|
666
|
LOGGER.warn("Could not send emails", e);
|
667
|
}
|
668
|
|
669
|
submitInterfaceValidation(getRepositoryById(repoId), registeredBy, repositoryInterface, true);
|
670
|
|
671
|
return repositoryInterface;
|
672
|
}
|
673
|
|
674
|
private void submitInterfaceValidation(Repository repo, String userEmail, RepositoryInterface iFace, boolean updateExisting) throws ValidatorServiceException {
|
675
|
JobForValidation job = new JobForValidation();
|
676
|
|
677
|
job.setActivationId(UUID.randomUUID().toString());
|
678
|
job.setAdminEmails(Collections.singletonList(this.adminEmail));
|
679
|
job.setBaseUrl(iFace.getBaseUrl());
|
680
|
job.setDatasourceId(repo.getId());
|
681
|
job.setDesiredCompatibilityLevel(iFace.getDesiredCompatibilityLevel());
|
682
|
job.setInterfaceId(iFace.getId());
|
683
|
job.setOfficialName(repo.getOfficialName());
|
684
|
job.setRepoType(repo.getDatasourceType());
|
685
|
job.setUserEmail(userEmail);
|
686
|
job.setValidationSet((iFace.getAccessSet().isEmpty() ? "none" : iFace.getAccessSet()));
|
687
|
job.setRecords(-1);
|
688
|
job.setRegistration(!updateExisting);
|
689
|
job.setUpdateExisting(updateExisting);
|
690
|
|
691
|
this.validatorService.submitJobForValidation(job);
|
692
|
}
|
693
|
|
694
|
private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) {
|
695
|
|
696
|
iFace.setContentDescription("metadata");
|
697
|
iFace.setCompliance("UNKNOWN");
|
698
|
|
699
|
if (datatype.equals("re3data"))
|
700
|
iFace.setAccessFormat("oai_datacite");
|
701
|
else
|
702
|
iFace.setAccessFormat("oai_dc");
|
703
|
|
704
|
|
705
|
if (repo.getDatasourceClass() != null && !repo.getDatasourceClass().isEmpty())
|
706
|
iFace.setTypology(repo.getDatasourceClass());
|
707
|
else if (datatype.equalsIgnoreCase("journal"))
|
708
|
iFace.setTypology("pubsrepository::journal");
|
709
|
else if (datatype.equalsIgnoreCase("aggregator"))
|
710
|
iFace.setTypology("aggregator::pubsrepository::unknown");
|
711
|
else if (datatype.equalsIgnoreCase("opendoar"))
|
712
|
iFace.setTypology("pubsrepository::unknown");
|
713
|
else if (datatype.equalsIgnoreCase("re3data"))
|
714
|
iFace.setTypology("datarepository::unknown");
|
715
|
|
716
|
iFace.setRemovable(true);
|
717
|
iFace.setAccessProtocol("oai");
|
718
|
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
|
719
|
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
|
720
|
if (iFace.getAccessSet() == null || iFace.getAccessSet().isEmpty()) {
|
721
|
LOGGER.debug("set is empty: " + iFace.getAccessSet());
|
722
|
iFace.removeAccessSet();
|
723
|
iFace.setAccessSet("none");
|
724
|
}
|
725
|
return iFace;
|
726
|
}
|
727
|
|
728
|
@Override
|
729
|
public List<String> getDnetCountries() {
|
730
|
LOGGER.debug("Getting dnet-countries!");
|
731
|
return Converter.readFile("countries.txt");
|
732
|
}
|
733
|
|
734
|
@Override
|
735
|
public List<String> getTypologies() {
|
736
|
return Converter.readFile("typologies.txt");
|
737
|
}
|
738
|
|
739
|
@Override
|
740
|
public List<Timezone> getTimezones() {
|
741
|
List<String> timezones = Converter.readFile("timezones.txt");
|
742
|
return Converter.toTimezones(timezones);
|
743
|
}
|
744
|
|
745
|
@Override
|
746
|
public List<String> getUrlsOfUserRepos(String userEmail,
|
747
|
String page,
|
748
|
String size) {
|
749
|
UriComponents uriComponents = UriComponentsBuilder
|
750
|
.fromHttpUrl(baseAddress + "/api/baseurl/")
|
751
|
.path("/{page}/{size}")
|
752
|
.build().expand(page, size).encode();
|
753
|
|
754
|
RequestFilter requestFilter = new RequestFilter();
|
755
|
requestFilter.setRegisteredby(userEmail);
|
756
|
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class));
|
757
|
}
|
758
|
|
759
|
@Override
|
760
|
public List<String> getDatasourceVocabularies(String mode) {
|
761
|
|
762
|
List<String> resultSet = new ArrayList<>();
|
763
|
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
|
764
|
if (mode.equalsIgnoreCase("aggregator")) {
|
765
|
if (entry.getKey().contains("aggregator"))
|
766
|
resultSet.add(entry.getValue());
|
767
|
} else if (mode.equalsIgnoreCase("journal")) {
|
768
|
if (entry.getKey().contains("journal"))
|
769
|
resultSet.add(entry.getValue());
|
770
|
} else if (mode.equalsIgnoreCase("opendoar")) {
|
771
|
if (entry.getKey().contains("pubsrepository"))
|
772
|
resultSet.add(entry.getValue());
|
773
|
} else if (mode.equalsIgnoreCase("re3data")) {
|
774
|
if (entry.getKey().contains("datarepository"))
|
775
|
resultSet.add(entry.getValue());
|
776
|
} else if (mode.equalsIgnoreCase("cris")) {
|
777
|
if (entry.getKey().contains("crissystem"))
|
778
|
resultSet.add(entry.getValue());
|
779
|
}
|
780
|
}
|
781
|
|
782
|
|
783
|
return resultSet;
|
784
|
}
|
785
|
|
786
|
private Vocabulary getVocabulary(String vocName) {
|
787
|
|
788
|
if (!vocabularyMap.containsKey(vocName)) {
|
789
|
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
|
790
|
}
|
791
|
return vocabularyMap.get(vocName);
|
792
|
}
|
793
|
|
794
|
|
795
|
@Override
|
796
|
public Map<String, String> getCompatibilityClasses(String mode) {
|
797
|
|
798
|
LOGGER.debug("Getting compatibility classes for mode: " + mode);
|
799
|
Map<String, String> retMap = new HashMap<String, String>();
|
800
|
|
801
|
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
|
802
|
boolean foundData = false;
|
803
|
for (Map.Entry<String, String> entry : compatibilityClasses.entrySet()) {
|
804
|
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_ALL))
|
805
|
return compatibilityClasses;
|
806
|
else if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) {
|
807
|
if (entry.getKey().matches("^openaire[1-9].0_data$")) {
|
808
|
retMap.put(entry.getKey(), entry.getValue());
|
809
|
foundData = true;
|
810
|
}
|
811
|
}
|
812
|
else if (mode.equalsIgnoreCase("cris")) {
|
813
|
if (entry.getKey().contains("openaire-cris")) {
|
814
|
retMap.put(entry.getKey(), entry.getValue());
|
815
|
foundData = true;
|
816
|
}
|
817
|
} else {
|
818
|
if (entry.getKey().matches("^openaire[1-9].0$") || entry.getKey().equals("driver"))
|
819
|
retMap.put(entry.getKey(), entry.getValue());
|
820
|
}
|
821
|
}
|
822
|
|
823
|
//TODO TO BE REMOVED WHEN VOCABULARIES ARE UPDATED
|
824
|
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA) && !foundData)
|
825
|
retMap.put("openaire2.0_data", "OpenAIRE Data (funded, referenced datasets)");
|
826
|
|
827
|
return retMap;
|
828
|
}
|
829
|
|
830
|
@Override
|
831
|
public Map<String, String> getDatasourceClasses(String mode) {
|
832
|
|
833
|
LOGGER.debug("Getting datasource classes for mode: " + mode);
|
834
|
|
835
|
Map<String, String> retMap = new HashMap<String, String>();
|
836
|
|
837
|
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
|
838
|
if (mode.equalsIgnoreCase("aggregator")) {
|
839
|
if (entry.getKey().contains("aggregator"))
|
840
|
retMap.put(entry.getKey(), entry.getValue());
|
841
|
} else if (mode.equalsIgnoreCase("journal")) {
|
842
|
if (entry.getKey().contains("journal"))
|
843
|
retMap.put(entry.getKey(), entry.getValue());
|
844
|
} else if (mode.equalsIgnoreCase("opendoar")) {
|
845
|
if (entry.getKey().contains("pubsrepository"))
|
846
|
retMap.put(entry.getKey(), entry.getValue());
|
847
|
} else if (mode.equalsIgnoreCase("re3data")) {
|
848
|
if (entry.getKey().contains("datarepository"))
|
849
|
retMap.put(entry.getKey(), entry.getValue());
|
850
|
} else if (mode.equalsIgnoreCase("cris")) {
|
851
|
if (entry.getKey().contains("crissystem"))
|
852
|
retMap.put(entry.getKey(), entry.getValue());
|
853
|
}
|
854
|
}
|
855
|
return filterResults(retMap, mode);
|
856
|
|
857
|
}
|
858
|
|
859
|
private Map<String, String> filterResults(Map<String, String> map, String mode) {
|
860
|
|
861
|
HashMap<String, String> filteredMap = new HashMap<>();
|
862
|
for (String key : map.keySet())
|
863
|
if (dataSourceClass.get(mode).contains(key))
|
864
|
filteredMap.put(key, map.get(key));
|
865
|
|
866
|
return filteredMap;
|
867
|
}
|
868
|
|
869
|
@Override
|
870
|
public String getCountryName(String countryCode) {
|
871
|
return inverseCountriesMap.get(countryCode);
|
872
|
}
|
873
|
|
874
|
@Override
|
875
|
public MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException {
|
876
|
try {
|
877
|
|
878
|
MetricsInfo metricsInfo = new MetricsInfo();
|
879
|
metricsInfo.setDiagramsBaseURL(this.usageStatisticsDiagramsBaseURL);
|
880
|
metricsInfo.setMetricsNumbers(getMetricsNumbers(getOpenAIREId(repoId)));
|
881
|
return metricsInfo;
|
882
|
|
883
|
} catch (Exception e) {
|
884
|
LOGGER.error("Error while getting metrics info for repository: ", e);
|
885
|
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
886
|
}
|
887
|
}
|
888
|
|
889
|
@Override
|
890
|
public Map<String, String> getListLatestUpdate(String mode) throws JSONException {
|
891
|
if (mode.equals("opendoar"))
|
892
|
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate());
|
893
|
else if (mode.equals("cris"))
|
894
|
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("eurocrisdris::dris").get(0).getLastCollectionDate());
|
895
|
else
|
896
|
/*
|
897
|
* first api of re3data has null value on collection date
|
898
|
* */
|
899
|
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::" + mode).get(1).getLastCollectionDate());
|
900
|
}
|
901
|
|
902
|
private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) throws Exception {
|
903
|
UriComponents uriComponents = UriComponentsBuilder
|
904
|
.fromHttpUrl(baseAddress + "/ds/api/oaiset")
|
905
|
.queryParam("dsId", repositoryId)
|
906
|
.queryParam("apiId", repositoryInterfaceId)
|
907
|
.queryParam("oaiSet", validationSet)
|
908
|
.build().encode();
|
909
|
restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, null, ResponseEntity.class);
|
910
|
|
911
|
}
|
912
|
|
913
|
|
914
|
private void updateBaseUrl(String repositoryId, String repositoryInterfaceId, String baseUrl) {
|
915
|
UriComponents uriComponents = UriComponentsBuilder
|
916
|
.fromHttpUrl(baseAddress + "/ds/api/baseurl")
|
917
|
.queryParam("dsId", repositoryId)
|
918
|
.queryParam("apiId", repositoryInterfaceId)
|
919
|
.queryParam("baseUrl", baseUrl)
|
920
|
.build().encode();
|
921
|
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
922
|
}
|
923
|
|
924
|
private void updateCompliance(String repositoryId, String repositoryInterfaceId, String compliance) {
|
925
|
UriComponents uriComponents = UriComponentsBuilder
|
926
|
.fromHttpUrl(baseAddress + "/ds/api/compliance")
|
927
|
.queryParam("dsId", repositoryId)
|
928
|
.queryParam("apiId", repositoryInterfaceId)
|
929
|
.queryParam("compliance", compliance)
|
930
|
.build().encode();
|
931
|
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
932
|
}
|
933
|
|
934
|
private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException {
|
935
|
|
936
|
//build the uri params
|
937
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usageStatisticsNumbersBaseURL + openAIREID + "/clicks");
|
938
|
|
939
|
//create new template engine
|
940
|
RestTemplate template = new RestTemplate();
|
941
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
942
|
ResponseEntity<MetricsNumbers> resp;
|
943
|
|
944
|
//communicate with endpoint
|
945
|
resp = template.exchange(
|
946
|
builder.build().encode().toUri(),
|
947
|
HttpMethod.GET,
|
948
|
null,
|
949
|
new ParameterizedTypeReference<MetricsNumbers>() {
|
950
|
});
|
951
|
|
952
|
return resp.getBody();
|
953
|
}
|
954
|
|
955
|
private String getOpenAIREId(String repoId) {
|
956
|
|
957
|
if (repoId != null && repoId.contains("::")) {
|
958
|
return repoId.split("::")[0] + "::" + DigestUtils.md5Hex(repoId.split("::")[1]);
|
959
|
}
|
960
|
|
961
|
return null;
|
962
|
}
|
963
|
|
964
|
private UriComponents getAggregationHistory(String repoId) {
|
965
|
return UriComponentsBuilder
|
966
|
.fromHttpUrl(baseAddress + "/ds/aggregationhistory/")
|
967
|
.path("/repoId")
|
968
|
.build().expand(repoId).encode();
|
969
|
}
|
970
|
|
971
|
private UriComponents searchDatasource(String page, String size) {
|
972
|
|
973
|
return UriComponentsBuilder
|
974
|
.fromHttpUrl(baseAddress + "/ds/searchdetails/")
|
975
|
.path("/{page}/{size}/")
|
976
|
.queryParam("requestSortBy", "officialname")
|
977
|
.queryParam("order", "ASCENDING")
|
978
|
.build().expand(page, size).encode();
|
979
|
}
|
980
|
|
981
|
private UriComponents searchSnipperDatasource(String page, String size) {
|
982
|
|
983
|
return UriComponentsBuilder
|
984
|
.fromHttpUrl(baseAddress + "/ds/searchsnippet/")
|
985
|
.path("/{page}/{size}/")
|
986
|
.queryParam("requestSortBy", "officialname")
|
987
|
.queryParam("order", "ASCENDING")
|
988
|
.build().expand(page, size).encode();
|
989
|
}
|
990
|
|
991
|
private UriComponents searchRegisteredDatasource(String requestSortBy, String order, String page, String size) {
|
992
|
|
993
|
return UriComponentsBuilder
|
994
|
.fromHttpUrl(baseAddress + "/ds/searchregistered/")
|
995
|
.path("/{page}/{size}/")
|
996
|
.queryParam("requestSortBy", requestSortBy)
|
997
|
.queryParam("order", order)
|
998
|
.build().expand(page, size).encode();
|
999
|
}
|
1000
|
|
1001
|
private String getRepositoryType(String typology) {
|
1002
|
return invertedDataSourceClass.get(typology);
|
1003
|
}
|
1004
|
|
1005
|
private List<String> getRoleIdsFromUserRoles(String userEmail) {
|
1006
|
Integer coPersonId = registryCalls.getCoPersonIdByEmail(userEmail);
|
1007
|
JsonArray roles;
|
1008
|
ArrayList<String> roleIds = new ArrayList<>();
|
1009
|
ArrayList<Integer> couIds = new ArrayList<>();
|
1010
|
if (coPersonId != null) {
|
1011
|
roles = registryCalls.getRolesWithStatus(coPersonId, AaiRegistryService.RoleStatus.ACTIVE);
|
1012
|
for (JsonElement role : roles) {
|
1013
|
JsonObject object = role.getAsJsonObject();
|
1014
|
if (object.get("CouId") == null) {
|
1015
|
continue;
|
1016
|
}
|
1017
|
couIds.add(object.get("CouId").getAsInt());
|
1018
|
}
|
1019
|
|
1020
|
roleIds.addAll(registryCalls.getCouNames(couIds).values());
|
1021
|
|
1022
|
}
|
1023
|
return roleIds;
|
1024
|
}
|
1025
|
}
|