Revision 51525
Added by Panagiotis Kanakakis about 6 years ago
RepositoryApiImpl.java | ||
---|---|---|
151 | 151 |
|
152 | 152 |
String countryCode = countriesMap.get(country); |
153 | 153 |
String filterKey = "UNKNOWN"; |
154 |
if (mode.equalsIgnoreCase("opendoar")) {
|
|
154 |
if (mode.equalsIgnoreCase("opendoar")) |
|
155 | 155 |
filterKey = "openaire____::opendoar"; |
156 |
} else if (mode.equalsIgnoreCase("re3data")) {
|
|
156 |
else if (mode.equalsIgnoreCase("re3data"))
|
|
157 | 157 |
filterKey = "openaire____::re3data"; |
158 |
} else if (mode.equalsIgnoreCase("jour_aggr")) { |
|
159 |
filterKey = "infrastruct_::openaire"; |
|
160 |
} |
|
161 | 158 |
|
159 |
|
|
162 | 160 |
LOGGER.debug("Country code equals : " + countryCode); |
163 | 161 |
LOGGER.debug("Filter mode equals : " + filterKey); |
162 |
|
|
164 | 163 |
UriComponents uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size)); |
165 | 164 |
RequestFilter requestFilter = new RequestFilter(); |
166 | 165 |
requestFilter.setCountry(countryCode); |
... | ... | |
168 | 167 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
169 | 168 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
170 | 169 |
while (jsonArray.length() > 0 ) { |
171 |
List<Repository> rep = Converter.jsonToRepositoryList(new JSONObject(rs)); |
|
172 |
|
|
173 |
Collection<Repository> repos = this.getRepositoriesByMode(filterKey, rep); |
|
174 |
resultSet.addAll(repos); |
|
175 |
|
|
170 |
resultSet.addAll(this.getRepositoriesByMode(filterKey, Converter.jsonToRepositoryList(new JSONObject(rs)))); |
|
176 | 171 |
page += 1; |
177 | 172 |
uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size)); |
178 |
|
|
179 | 173 |
rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
180 | 174 |
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
181 | 175 |
} |
... | ... | |
198 | 192 |
for (Repository r : rs) { |
199 | 193 |
if (r.getCollectedFrom() != null && r.getCollectedFrom().equals(mode)) |
200 | 194 |
reps.add(r); |
195 |
|
|
201 | 196 |
} |
202 | 197 |
return reps; |
203 | 198 |
} |
... | ... | |
298 | 293 |
|
299 | 294 |
repository = this.setRepositoryFeatures(datatype,repository); |
300 | 295 |
LOGGER.debug("storing " + datatype + " repository with id: " + repository.getId()); |
301 |
if (!datatype.equalsIgnoreCase("opendoar") && !datatype.equalsIgnoreCase("re3data")) { |
|
302 |
if (datatype.equalsIgnoreCase("journal") || datatype.equalsIgnoreCase("aggregator")) { |
|
303 |
LOGGER.debug("looking if " + datatype + " " + repository.getOfficialName() + " is already in datasources"); |
|
304 |
if (getRepositoryById(repository.getId()) != null) { |
|
305 |
String retMessage = datatype + " '" + repository.getOfficialName() + "' is already in datasources."; |
|
306 |
repository.getInterfaces().clear(); |
|
307 |
LOGGER.debug(retMessage); |
|
308 |
} else { |
|
309 |
LOGGER.debug(datatype + " " + repository.getOfficialName() + " is not in datasources. Inserting.."); |
|
310 |
this.storeRepository(repository); |
|
311 |
} |
|
312 |
} |
|
313 |
} else { |
|
314 |
this.updateRepository(repository); |
|
315 |
} |
|
316 |
|
|
317 |
LOGGER.debug("Inserting Interfaces"); |
|
318 |
Iterator var11 = repository.getInterfaces().iterator(); |
|
319 |
|
|
320 |
while (var11.hasNext()) { |
|
321 |
RepositoryInterface iFace = (RepositoryInterface) var11.next(); |
|
322 |
if (!iFace.getBaseUrl().isEmpty() && !iFace.getDesiredCompatibilityLevel().isEmpty()) { |
|
323 |
if (iFace.getId() != null && !iFace.getId().isEmpty()) { |
|
324 |
LOGGER.debug("updating iface.."); |
|
325 |
this.updateInterface(datatype,iFace); |
|
326 |
LOGGER.debug("updated successfully"); |
|
327 |
} else { |
|
328 |
LOGGER.debug("adding new iface.."); |
|
329 |
this.registerRepositoryInterface(repository.getId(),iFace,datatype); |
|
330 |
} |
|
331 |
} |
|
332 |
} |
|
296 |
this.storeRepository(repository); |
|
333 | 297 |
return repository; |
334 | 298 |
} |
335 | 299 |
|
... | ... | |
345 | 309 |
return repository; |
346 | 310 |
} |
347 | 311 |
|
348 |
private void updateRegisteredByValue(String id, String registeredBy) { |
|
349 |
|
|
350 |
LOGGER.debug("Updating registered by value with : " + registeredBy ); |
|
351 |
UriComponents uriComponents = UriComponentsBuilder |
|
352 |
.fromHttpUrl(baseAddress + "/ds/registeredby/") |
|
353 |
.queryParam("dsId",id) |
|
354 |
.queryParam("registeredBy", registeredBy) |
|
355 |
.build() |
|
356 |
.encode(); |
|
357 |
|
|
358 |
restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
359 |
} |
|
360 |
|
|
361 | 312 |
private Repository setRepositoryFeatures(String datatype, Repository repository) { |
362 | 313 |
|
363 | 314 |
//TODO update map |
... | ... | |
415 | 366 |
|
416 | 367 |
} |
417 | 368 |
|
418 |
private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) { |
|
419 |
|
|
420 |
iFace.setContentDescription("metadata"); |
|
421 |
iFace.setCompliance("UNKNOWN"); |
|
422 |
if (datatype.equals("re3data")) { |
|
423 |
iFace.setAccessFormat("oai_datacite"); |
|
424 |
} else { |
|
425 |
iFace.setAccessFormat("oai_dc"); |
|
426 |
} |
|
427 |
|
|
428 |
if (repo.getDatasourceClass() != null && !repo.getDatasourceClass().isEmpty()) { |
|
429 |
iFace.setTypology(repo.getDatasourceClass()); |
|
430 |
} else if (datatype.equalsIgnoreCase("journal")) { |
|
431 |
iFace.setTypology("pubsrepository::journal"); |
|
432 |
} else if (datatype.equalsIgnoreCase("aggregator")) { |
|
433 |
iFace.setTypology("aggregator::pubsrepository::unknown"); |
|
434 |
} else if (datatype.equalsIgnoreCase("opendoar")) { |
|
435 |
iFace.setTypology("pubsrepository::unknown"); |
|
436 |
} else if (datatype.equalsIgnoreCase("re3data")) { |
|
437 |
iFace.setTypology("datarepository::unknown"); |
|
438 |
} |
|
439 |
|
|
440 |
iFace.setRemovable(true); |
|
441 |
iFace.setAccessProtocol("oai"); |
|
442 |
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']"); |
|
443 |
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8)); |
|
444 |
if (iFace.getAccessSet().isEmpty()) { |
|
445 |
LOGGER.debug("set is empty: " + iFace.getAccessSet()); |
|
446 |
iFace.removeAccessSet(); |
|
447 |
} |
|
448 |
return iFace; |
|
449 |
} |
|
450 |
|
|
451 | 369 |
private void storeRepository(Repository repository) throws JSONException { |
452 | 370 |
|
453 | 371 |
Date utilDate = new Date(); |
454 | 372 |
Timestamp date = new Timestamp(utilDate.getTime()); |
455 | 373 |
repository.setDateOfCollection(date); |
456 | 374 |
repository.setAggregator("OPENAIRE"); |
375 |
repository.setCountryCode(countriesMap.get(repository.getCountryName())); |
|
457 | 376 |
|
458 | 377 |
UriComponents uriComponents = UriComponentsBuilder |
459 | 378 |
.fromHttpUrl(baseAddress + "/ds/add/") |
... | ... | |
465 | 384 |
} |
466 | 385 |
|
467 | 386 |
@Override |
468 |
public void deleteRepositoryInterface(@PathVariable("id") String id){
|
|
387 |
public void deleteRepositoryInterface(@RequestParam("id") String id){
|
|
469 | 388 |
UriComponents uriComponents = UriComponentsBuilder |
470 | 389 |
.fromHttpUrl(baseAddress + "/ds/api/") |
471 |
.path("/{id}/")
|
|
390 |
.path("/{id}") |
|
472 | 391 |
.build().expand(id).encode(); |
392 |
LOGGER.debug(uriComponents.toUri()); |
|
473 | 393 |
restTemplate.delete(uriComponents.toUri()); |
474 | 394 |
} |
475 | 395 |
|
... | ... | |
477 | 397 |
public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype, |
478 | 398 |
@RequestParam("repoId") String repoId, |
479 | 399 |
@RequestBody RepositoryInterface repositoryInterface) throws JSONException { |
480 |
return registerRepositoryInterface(repoId,repositoryInterface,datatype); |
|
481 |
} |
|
482 |
|
|
483 |
private RepositoryInterface registerRepositoryInterface(String repoId, RepositoryInterface iFace, String datatype) { |
|
484 |
Repository e = null; |
|
485 | 400 |
try { |
486 |
e = this.getRepositoryById(repoId); |
|
487 |
iFace = createRepositoryInterface(e,iFace,datatype); |
|
401 |
Repository e = this.getRepositoryById(repoId); |
|
402 |
repositoryInterface = createRepositoryInterface(e,repositoryInterface,datatype); |
|
403 |
String json_interface = Converter.repositoryInterfaceObjectToJson(e,repositoryInterface); |
|
488 | 404 |
|
489 |
String json_interface = Converter.repositoryInterfaceObjectToJson(e,iFace); |
|
490 |
LOGGER.debug("iFace equals -> " + json_interface); |
|
491 | 405 |
UriComponents uriComponents = UriComponentsBuilder |
492 | 406 |
.fromHttpUrl(baseAddress + "/ds/api/add/") |
493 | 407 |
.build() |
494 | 408 |
.encode(); |
495 | 409 |
|
496 |
|
|
497 | 410 |
HttpEntity<String> httpEntity = new HttpEntity <String> (json_interface,httpHeaders); |
498 | 411 |
restTemplate.postForObject(uriComponents.toUri(),httpEntity,String.class); |
499 |
return iFace;
|
|
412 |
return repositoryInterface;
|
|
500 | 413 |
|
501 | 414 |
} catch (JSONException e1) { |
502 | 415 |
LOGGER.debug("Error parsing json ",e1); |
... | ... | |
504 | 417 |
return null; |
505 | 418 |
} |
506 | 419 |
|
420 |
private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) { |
|
421 |
|
|
422 |
iFace.setContentDescription("metadata"); |
|
423 |
iFace.setCompliance("UNKNOWN"); |
|
424 |
|
|
425 |
if (datatype.equals("re3data")) |
|
426 |
iFace.setAccessFormat("oai_datacite"); |
|
427 |
else |
|
428 |
iFace.setAccessFormat("oai_dc"); |
|
429 |
|
|
430 |
|
|
431 |
if (repo.getDatasourceClass() != null && !repo.getDatasourceClass().isEmpty()) |
|
432 |
iFace.setTypology(repo.getDatasourceClass()); |
|
433 |
else if (datatype.equalsIgnoreCase("journal")) |
|
434 |
iFace.setTypology("pubsrepository::journal"); |
|
435 |
else if (datatype.equalsIgnoreCase("aggregator")) |
|
436 |
iFace.setTypology("aggregator::pubsrepository::unknown"); |
|
437 |
else if (datatype.equalsIgnoreCase("opendoar")) |
|
438 |
iFace.setTypology("pubsrepository::unknown"); |
|
439 |
else if (datatype.equalsIgnoreCase("re3data")) |
|
440 |
iFace.setTypology("datarepository::unknown"); |
|
441 |
|
|
442 |
iFace.setRemovable(true); |
|
443 |
iFace.setAccessProtocol("oai"); |
|
444 |
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']"); |
|
445 |
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8)); |
|
446 |
if (iFace.getAccessSet().isEmpty()) { |
|
447 |
LOGGER.debug("set is empty: " + iFace.getAccessSet()); |
|
448 |
iFace.removeAccessSet(); |
|
449 |
} |
|
450 |
return iFace; |
|
451 |
} |
|
452 |
|
|
507 | 453 |
@Override |
508 | 454 |
public List<String> getDnetCountries() { |
509 | 455 |
LOGGER.debug("Getting dnet-countries!"); |
... | ... | |
656 | 602 |
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(1).getLastCollectionDate()); |
657 | 603 |
} |
658 | 604 |
|
605 |
@Override |
|
606 |
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String repoId, |
|
607 |
@RequestBody RepositoryInterface repositoryInterface) throws JSONException { |
|
608 |
|
|
609 |
this.updateBaseUrl(repoId,repositoryInterface.getId(),repositoryInterface.getBaseUrl()); |
|
610 |
this.updateCompliance(repoId,repositoryInterface.getId(),repositoryInterface.getCompliance()); |
|
611 |
return repositoryInterface; |
|
612 |
} |
|
613 |
|
|
614 |
|
|
615 |
private void updateBaseUrl(String repositoryId, String repositoryInterfaceId, String baseUrl) { |
|
616 |
UriComponents uriComponents = UriComponentsBuilder |
|
617 |
.fromHttpUrl(baseAddress + "/ds/api/baseurl") |
|
618 |
.queryParam("dsId",repositoryId) |
|
619 |
.queryParam("apiId",repositoryInterfaceId) |
|
620 |
.queryParam("baseUrl",baseUrl) |
|
621 |
.build().encode(); |
|
622 |
restTemplate.postForObject(uriComponents.toUri(),null,String.class); |
|
623 |
} |
|
624 |
|
|
625 |
private void updateCompliance(String repositoryId, String repositoryInterfaceId,String compliance) { |
|
626 |
UriComponents uriComponents = UriComponentsBuilder |
|
627 |
.fromHttpUrl(baseAddress + "/ds/api/compliance") |
|
628 |
.queryParam("dsId",repositoryId) |
|
629 |
.queryParam("apiId",repositoryInterfaceId) |
|
630 |
.queryParam("compliance",compliance) |
|
631 |
.build().encode(); |
|
632 |
restTemplate.postForObject(uriComponents.toUri(),null,String.class); |
|
633 |
} |
|
634 |
|
|
659 | 635 |
private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException { |
660 | 636 |
|
661 | 637 |
//build the uri params |
Also available in: Unified diff
1. Add roles for aai
2. Changes on converter file for new interface object
3. Move emailUtils to avoid bug on bean definitions
4. Add openaire provider authorities mapper class
5. Bug fixes on controllers