changes for remote fetcher

This commit is contained in:
Efstratios Giannopoulos 2023-10-19 17:56:53 +03:00
parent 2a4e61f08f
commit 0b3178177a
6 changed files with 422 additions and 224 deletions

View File

@ -0,0 +1,37 @@
package eu.eudat.commons.enums;
import java.util.Map;
public enum ExternalReferencesType {
Taxonomies((short) 0),
Licenses((short) 1),
Publications((short) 2),
Journals((short) 3),
PubRepositories((short) 4),
DataRepositories((short) 5),
Registries((short) 6),
Services((short) 7),
Project((short) 8),
Founder((short) 8),
Datasets((short) 9),
Organizations((short) 10),
Grants((short) 11),
Prefillings((short) 12),
Validators((short) 13),
Researcher((short) 14);
private final Short value;
ExternalReferencesType(Short value) {
this.value = value;
}
public Short getValue() {
return value;
}
private static final Map<Short, IsActive> map = EnumUtils.getEnumValueMap(IsActive.class);
public static IsActive of(Short i) {
return map.get(i);
}
}

View File

@ -38,6 +38,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.management.InvalidApplicationException;
import java.time.Instant;
@ -46,6 +48,7 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
@Service
public class EntityDoiServiceImpl implements EntityDoiService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(EntityDoiServiceImpl.class));

View File

@ -1,6 +1,7 @@
package eu.eudat.controllers.v2;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.enums.ExternalReferencesType;
import eu.eudat.controllers.BaseController;
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest;
@ -50,27 +51,28 @@ public class ExternalReferencesController extends BaseController {
this.authorizationService = authorizationService;
}
@PostMapping(path = {"funders"}, consumes = "application/json", produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<Funder>>> getWithExternal(@RequestBody FunderCriteriaRequest funderCriteria) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
List<Funder> dataTable = this.funderService.getCriteriaWithExternal(funderCriteria);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Funder>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
}
@PostMapping(path = {"projects"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<List<Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
List<Project> dataTable = this.projectService.getCriteriaWithExternal(projectCriteria);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
}
// @PostMapping(path = {"funders"}, consumes = "application/json", produces = "application/json")
// public @ResponseBody ResponseEntity<ResponseItem<List<Funder>>> getWithExternal(@RequestBody FunderCriteriaRequest funderCriteria) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// List<Funder> dataTable = this.funderService.getCriteriaWithExternal(funderCriteria);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Funder>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
// }
//
// @PostMapping(path = {"projects"}, consumes = "application/json", produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<List<Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// List<Project> dataTable = this.projectService.getCriteriaWithExternal(projectCriteria);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
// }
@GetMapping(path = {"data-repo/{externalType}"}, produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference>>> listExternalReferecnes(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query,
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference>>> listExternalReferecnes(@RequestParam(value = "externalType") ExternalReferencesType externalType,
@RequestParam(value = "query", required = false) String query,
@RequestParam(value = "type", required = false) String type
) throws HugeResultSet, NoURLFound, InvalidApplicationException {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
@ -79,37 +81,37 @@ public class ExternalReferencesController extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
}
@Transactional
@PostMapping(path = {"data-repo/persist"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<ExternalReference>> createExternalReferecnes(@RequestBody ExternalReference externalReference) throws Exception {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
ExternalReference newExternalReference = this.externalReferencesService.createDataRepo(externalReference);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
}
// @Transactional
// @PostMapping(path = {"data-repo/persist"}, consumes = "application/json", produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<ExternalReference>> createExternalReferecnes(@RequestBody ExternalReference externalReference) throws Exception {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// ExternalReference newExternalReference = this.externalReferencesService.createDataRepo(externalReference);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
// }
@GetMapping(path = {"{externalType}"}, produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference2>>> listExternalReferecnes2(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query,
@RequestParam(value = "type", required = false) String type
) throws HugeResultSet, NoURLFound, InvalidApplicationException {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
List<ExternalReference2> externalReferences = this.externalReferencesService.getExternalReference2(externalType, query, type);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference2>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
}
@Transactional
@PostMapping(value = {"{externalType}/persist"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<ExternalReference2>> create(@RequestBody ExternalReference2 externalReference) throws Exception {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
ExternalReference2 newExternalReference = this.externalReferencesService.create(externalReference);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference2>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
}
// @GetMapping(path = {"{externalType}"}, produces = "application/json")
// public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference2>>> listExternalReferecnes2(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query,
// @RequestParam(value = "type", required = false) String type
// ) throws HugeResultSet, NoURLFound, InvalidApplicationException {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// List<ExternalReference2> externalReferences = this.externalReferencesService.getExternalReference2(externalType, query, type);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference2>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
// }
//
// @Transactional
// @PostMapping(value = {"{externalType}/persist"}, consumes = "application/json", produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<ExternalReference2>> create(@RequestBody ExternalReference2 externalReference) throws Exception {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// ExternalReference2 newExternalReference = this.externalReferencesService.create(externalReference);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference2>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
// }
}

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import eu.eudat.commons.enums.ExternalReferencesType;
import eu.eudat.logic.proxy.config.*;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.logic.proxy.config.entities.GenericUrls;
@ -50,55 +51,37 @@ public class RemoteFetcher {
).clientConnector(new ReactorClientHttpConnector(HttpClient.create().followRedirect(true))).build();
}
public List<Map<String, String>> get(String externalType, ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
List<UrlConfiguration> urlConfigs = null;
public List<Map<String, String>> get(ExternalReferencesType externalType, ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
FetchStrategy fetchStrategy = null;
switch (externalType){
case "taxonomies":
urlConfigs = key != null && !key.isEmpty() ? configLoader.getExternalUrls().getTaxonomies().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
: configLoader.getExternalUrls().getTaxonomies().getUrls();
fetchStrategy = configLoader.getExternalUrls().getTaxonomies().getFetchMode();
break;
case "licenses":
urlConfigs = key != null && !key.isEmpty() ? configLoader.getExternalUrls().getLicenses().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
: configLoader.getExternalUrls().getLicenses().getUrls();
fetchStrategy = configLoader.getExternalUrls().getLicenses().getFetchMode();
break;
case "publications":
urlConfigs = key != null && !key.isEmpty() ? configLoader.getExternalUrls().getPublications().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
: configLoader.getExternalUrls().getPublications().getUrls();
fetchStrategy = configLoader.getExternalUrls().getPublications().getFetchMode();
break;
case "journals":
urlConfigs = key != null && !key.isEmpty() ? configLoader.getExternalUrls().getJournals().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
: configLoader.getExternalUrls().getJournals().getUrls();
fetchStrategy = configLoader.getExternalUrls().getJournals().getFetchMode();
break;
case "pubRepositories":
urlConfigs = key != null && !key.isEmpty() ? configLoader.getExternalUrls().getPubRepositories().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
: configLoader.getExternalUrls().getPubRepositories().getUrls();
fetchStrategy = configLoader.getExternalUrls().getPubRepositories().getFetchMode();
break;
case "dataRepositories":
urlConfigs = key != null && !key.isEmpty() ? configLoader.getExternalUrls().getRepositories().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
: configLoader.getExternalUrls().getRepositories().getUrls();
fetchStrategy = configLoader.getExternalUrls().getRepositories().getFetchMode();
break;
case "registries":
urlConfigs = key != null && !key.isEmpty() ? configLoader.getExternalUrls().getRegistries().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
: configLoader.getExternalUrls().getRegistries().getUrls();
fetchStrategy = configLoader.getExternalUrls().getRegistries().getFetchMode();
break;
case "services":
urlConfigs = key != null && !key.isEmpty() ? configLoader.getExternalUrls().getServices().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
: configLoader.getExternalUrls().getServices().getUrls();
fetchStrategy = configLoader.getExternalUrls().getServices().getFetchMode();
break;
}
GenericUrls exGenericUrls = this.getExternalUrls(externalType);
List<UrlConfiguration> urlConfigs = key != null && !key.isEmpty() ? exGenericUrls.getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
: exGenericUrls.getUrls();
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
}
public GenericUrls getExternalUrls(ExternalReferencesType externalType) {
switch (externalType){
case Taxonomies: return configLoader.getExternalUrls().getTaxonomies();
case Licenses: return configLoader.getExternalUrls().getLicenses();
case Publications: return configLoader.getExternalUrls().getPublications();
case Journals: return configLoader.getExternalUrls().getJournals();
case PubRepositories: return configLoader.getExternalUrls().getPubRepositories();
case DataRepositories: return configLoader.getExternalUrls().getRepositories();
case Registries: return configLoader.getExternalUrls().getRegistries();
case Services: return configLoader.getExternalUrls().getServices();
case Grants: return configLoader.getExternalUrls().getGrants();
case Organizations: return configLoader.getExternalUrls().getOrganisations();
case Datasets: return configLoader.getExternalUrls().getDatasets();
case Founder: return configLoader.getExternalUrls().getFunders();
case Project: return configLoader.getExternalUrls().getProjects();
case Researcher: return configLoader.getExternalUrls().getResearchers();
case Validators: return configLoader.getExternalUrls().getValidations();
// case Prefillings: return configLoader.getExternalUrls().getPrefillings();
default: throw new IllegalArgumentException("Type not found" + externalType);
}
}
@Cacheable(value = "repositories", keyGenerator = "externalUrlsKeyGenerator")
public List<Map<String, String>> getRepositories(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
List<UrlConfiguration> urlConfigs =

View File

@ -2,6 +2,7 @@ package eu.eudat.logic.services.externalreferences;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.commons.enums.ExternalReferencesType;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.dao.criteria.DataRepositoryCriteria;
import eu.eudat.data.dao.criteria.RegistryCriteria;
@ -15,9 +16,9 @@ import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.ExternalReference;
import eu.eudat.models.data.ExternalReference2;
import javax.management.InvalidApplicationException;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -42,36 +43,36 @@ public class ExternalReferencesService {//implements ExternalReferencesService{
// pubRepositories,
// dataRepositories
public ExternalReference createDataRepo(ExternalReference externalReference) throws Exception {
// only dataRepositories, pubRepositories, journals
DataRepository dataRepository = externalReference.toDataModel();
dataRepository.getCreationUser().setId(this.userScope.getUserId());
// public ExternalReference createDataRepo(ExternalReference externalReference) throws Exception {
// // only dataRepositories, pubRepositories, journals
// DataRepository dataRepository = externalReference.toDataModel();
// dataRepository.getCreationUser().setId(this.userScope.getUserId());
//
// dataRepository = apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().createOrUpdate(dataRepository);
// return new ExternalReference().fromDataModel(dataRepository);
// }
dataRepository = apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().createOrUpdate(dataRepository);
return new ExternalReference().fromDataModel(dataRepository);
}
public List<ExternalReference> getExternalReference(String externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
DataRepositoryCriteria criteria = new DataRepositoryCriteria();
if (!query.isEmpty()) criteria.setLike(query);
List<ExternalReference> list = new LinkedList<>();
if((externalType.equals("dataRepositories") || externalType.equals("pubRepositories") || externalType.equals("journals"))){
criteria.setCreationUserId(this.userScope.getUserId());
if (type.equals("")) {
List<DataRepository> dataRepositoryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().getWithCriteria(criteria)).toList();
list = dataRepositoryList.stream().map(item -> new ExternalReference().fromDataModel(item)).collect(Collectors.toList());
}
}
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
list.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, ExternalReference.class)).collect(Collectors.toList()));
list = list.stream().filter(x -> x.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList());
return list;
}
// public List<ExternalReference> getExternalReference(String externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
// ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
// List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
//
// DataRepositoryCriteria criteria = new DataRepositoryCriteria();
// if (!query.isEmpty()) criteria.setLike(query);
//
// List<ExternalReference> list = new LinkedList<>();
// if((externalType.equals("dataRepositories") || externalType.equals("pubRepositories") || externalType.equals("journals"))){
// criteria.setCreationUserId(this.userScope.getUserId());
// if (type.equals("")) {
// List<DataRepository> dataRepositoryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().getWithCriteria(criteria)).toList();
// list = dataRepositoryList.stream().map(item -> new ExternalReference().fromDataModel(item)).collect(Collectors.toList());
// }
// }
//
// ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// list.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, ExternalReference.class)).collect(Collectors.toList()));
// list = list.stream().filter(x -> x.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList());
// return list;
// }
@ -79,45 +80,99 @@ public class ExternalReferencesService {//implements ExternalReferencesService{
// registries,
// services
public ExternalReference2 create(ExternalReference2 externalReference) throws Exception {
if (externalReference.getLabel() == null || externalReference.getAbbreviation() == null || externalReference.getUri() == null) {
throw new Exception("Missing mandatory entity.");
}
// public ExternalReference2 create(ExternalReference2 externalReference) throws Exception {
// if (externalReference.getLabel() == null || externalReference.getAbbreviation() == null || externalReference.getUri() == null) {
// throw new Exception("Missing mandatory entity.");
// }
//
// ExternalReference2 newExternalReference = null;
// if(externalReference.getExternalType().equals("registries")){
// Registry registry = externalReference.toDataModelRegistry();
// registry.getCreationUser().setId(this.userScope.getUserId());
// registry = apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().createOrUpdate(registry);
// newExternalReference = new ExternalReference2().fromDataModel(registry);
// } else if (externalReference.getExternalType().equals("services")) {
// Service service = externalReference.toDataModelService();
// service.getCreationUser().setId(this.userScope.getUserId());
// service = apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().createOrUpdate(service);
// newExternalReference = new ExternalReference2().fromDataModel(service);
// }
//
// return newExternalReference;
// }
//
//
// public List<ExternalReference2> getExternalReference2(String externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
// ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
// List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType,externalUrlCriteria, type);
//
// List<ExternalReference2> list = new LinkedList<>();
//
// if (externalType.equals("registries")){
// RegistryCriteria criteria = new RegistryCriteria();
//
// if (!query.isEmpty()) criteria.setLike(query);
// criteria.setCreationUserId(this.userScope.getUserId());
//
// if (type.equals("")) {
// List<Registry> registryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().getWithCriteria(criteria)).toList();
// list = registryList.stream().map(item -> new ExternalReference2().fromDataModel(item)).collect(Collectors.toList());
// }
// } else if (externalType.equals("services")) {
// ServiceCriteria criteria = new ServiceCriteria();
//
// if (!query.isEmpty()) criteria.setLike(query);
// criteria.setCreationUserId(this.userScope.getUserId());
//
// if (type.equals("")) {
// List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList();
// list = serviceList.stream().map(item -> new ExternalReference2().fromDataModel(item)).collect(Collectors.toList());
// }
// }
//
// ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// list.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, ExternalReference2.class)).collect(Collectors.toList()));
//
// return list;
// }
ExternalReference2 newExternalReference = null;
if(externalReference.getExternalType().equals("registries")){
Registry registry = externalReference.toDataModelRegistry();
registry.getCreationUser().setId(this.userScope.getUserId());
registry = apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().createOrUpdate(registry);
newExternalReference = new ExternalReference2().fromDataModel(registry);
} else if (externalReference.getExternalType().equals("services")) {
Service service = externalReference.toDataModelService();
service.getCreationUser().setId(this.userScope.getUserId());
service = apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().createOrUpdate(service);
newExternalReference = new ExternalReference2().fromDataModel(service);
}
return newExternalReference;
}
public List<ExternalReference2> getExternalReference2(String externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
public List<ExternalReference> getExternalReference(ExternalReferencesType externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
List<ExternalReference2> list = new LinkedList<>();
List<ExternalReference> list = this.fetchFromDb(externalType, query, type);
if (externalType.equals("registries")){
RegistryCriteria criteria = new RegistryCriteria();
list.addAll(remoteRepos.stream().map(ExternalReference::fromRemoteModel).toList());
list = list.stream().filter(x -> x.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList());
list.sort(Comparator.comparing(ExternalReference::getName));
return list;
}
private List<ExternalReference> fetchFromDb(ExternalReferencesType externalType, String query, String type) throws InvalidApplicationException {
List<ExternalReference> list = new LinkedList<>();
switch (externalType) {
case DataRepositories:
case PubRepositories:
case Journals: {
DataRepositoryCriteria criteria = new DataRepositoryCriteria();
if (!query.isEmpty()) criteria.setLike(query);
criteria.setCreationUserId(this.userScope.getUserId());
if (type.equals("")) {
List<DataRepository> dataRepositoryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().getWithCriteria(criteria)).toList();
list = dataRepositoryList.stream().map(item -> new ExternalReference().fromDataRepository(item)).collect(Collectors.toList());
}
}
case Registries: {
RegistryCriteria criteria = new RegistryCriteria();
if (!query.isEmpty()) criteria.setLike(query);
criteria.setCreationUserId(this.userScope.getUserId());
if (type.equals("")) {
List<Registry> registryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().getWithCriteria(criteria)).toList();
list = registryList.stream().map(item -> new ExternalReference2().fromDataModel(item)).collect(Collectors.toList());
list = registryList.stream().map(item -> new ExternalReference().fromRegistry(item)).collect(Collectors.toList());
}
} else if (externalType.equals("services")) {
}
case Services:
{
ServiceCriteria criteria = new ServiceCriteria();
if (!query.isEmpty()) criteria.setLike(query);
@ -125,12 +180,14 @@ public class ExternalReferencesService {//implements ExternalReferencesService{
if (type.equals("")) {
List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList();
list = serviceList.stream().map(item -> new ExternalReference2().fromDataModel(item)).collect(Collectors.toList());
list = serviceList.stream().map(item -> new ExternalReference().fromService(item)).collect(Collectors.toList());
}
}
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
list.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, ExternalReference2.class)).collect(Collectors.toList()));
case Taxonomies:
case Publications:
case Licenses:
break;
}
return list;
}

View File

@ -1,34 +1,64 @@
package eu.eudat.models.data;
import eu.eudat.data.old.DataRepository;
import eu.eudat.data.old.Registry;
import eu.eudat.data.old.Service;
import eu.eudat.data.old.UserInfo;
import eu.eudat.models.data.datarepository.DataRepositoryModel;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class ExternalReference {
private UUID id;
private String name;
private String pid;
private String abbreviation;
private String uri;
private Date created;
private Date modified;
private String tag; // Api fetching the data
private String source; // Actual harvested source
public UUID getId() {
private String id;
private String name;
private String abbreviation;
private String pid;
private String originalId;
private String key;
private String pidTypeField;
private String uri;
private String description;
private String source;
private String count;
private String path;
private String host;
private String types;
private String firstName;
private String lastName;
private String tag;
public String getOriginalId() {
return originalId;
}
public void setOriginalId(String originalId) {
this.originalId = originalId;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getId() {
return id;
}
public void setId(UUID id) {
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ -36,58 +66,136 @@ public class ExternalReference {
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
public String getAbbreviation() {
return abbreviation;
public String getPidTypeField() {
return pidTypeField;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
public void setPidTypeField(String pidTypeField) {
this.pidTypeField = pidTypeField;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
public String getDescription() {
return description;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
public void setDescription(String description) {
this.description = description;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getCount() {
return count;
}
public ExternalReference fromDataModel(DataRepository entity) {
public void setCount(String count) {
this.count = count;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getTypes() {
return types;
}
public void setTypes(String types) {
this.types = types;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
public static ExternalReference fromRemoteModel(Map<String, String> data) {
ExternalReference externalReference = new ExternalReference();
if (data == null) return externalReference;
externalReference.setId(data.getOrDefault("id", null));
externalReference.setName(data.getOrDefault("name", null));
externalReference.setAbbreviation(data.getOrDefault("abbreviation", null));
externalReference.setPid(data.getOrDefault("pid", null));
externalReference.setOriginalId(data.getOrDefault("originalId", null));
externalReference.setKey(data.getOrDefault("key", null));
externalReference.setPidTypeField(data.getOrDefault("pidTypeField", null));
externalReference.setUri(data.getOrDefault("uri", null));
externalReference.setDescription(data.getOrDefault("description", null));
externalReference.setSource(data.getOrDefault("source", null));
externalReference.setCount(data.getOrDefault("count", null));
externalReference.setPath(data.getOrDefault("path", null));
externalReference.setHost(data.getOrDefault("host", null));
externalReference.setTypes(data.getOrDefault("types", null));
externalReference.setFirstName(data.getOrDefault("firstName", null));
externalReference.setLastName(data.getOrDefault("lastName", null));
externalReference.setTag(data.getOrDefault("tag", null));
return externalReference;
}
public ExternalReference fromDataRepository(DataRepository entity) {
this.setAbbreviation(entity.getAbbreviation());
this.setName(entity.getLabel());
this.setUri(entity.getUri());
this.setId(entity.getId());
this.setId(entity.getId().toString());
this.setPid(entity.getReference());
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source1.equals("dmp")) {
@ -98,29 +206,37 @@ public class ExternalReference {
return this;
}
public DataRepository toDataModel() throws Exception {
DataRepository dataRepository = new DataRepository();
dataRepository.setId(this.id != null ? this.id : UUID.randomUUID());
dataRepository.setAbbreviation(this.abbreviation);
dataRepository.setCreated(this.created != null ? this.created : new Date());
dataRepository.setModified(new Date());
dataRepository.setLabel(this.name);
if (this.source != null) {
if (this.source.equals("Internal") || this.source.equals(this.id.toString().substring(0, this.source.length()))) {
dataRepository.setReference(this.id.toString());
public ExternalReference fromRegistry(Registry entity){
this.id = entity.getId().toString();
this.abbreviation = entity.getAbbreviation();
// this.created = entity.getCreated();
// this.label = entity.getLabel();
this.name = entity.getLabel();
// this.modified = entity.getModified();
this.uri = entity.getUri();
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source1.equals("dmp")) {
this.source = "Internal";
} else {
dataRepository.setReference(this.source + ":" + dataRepository.getId());
this.source = source1;
}
// this.reference = entity.getReference();
return this;
}
public ExternalReference fromService(Service entity) {
this.abbreviation = entity.getAbbreviation();
// this.created = entity.getCreated();
this.id = entity.getId().toString();
// this.label = entity.getLabel();
this.name = entity.getLabel();
// this.modified = entity.getModified();
this.uri = entity.getUri();
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source.equals("dmp")) {
this.source = "Internal";
} else {
dataRepository.setReference("dmp:" + dataRepository.getId());
this.source = source;
}
dataRepository.setUri(this.uri);
dataRepository.setStatus((short) 0);
dataRepository.setCreationUser(new UserInfo());
return dataRepository;
}
public String getHint() {
return null;
return this;
}
}