fix front enums

This commit is contained in:
amentis 2023-10-23 17:58:56 +03:00
parent 3b9b348d4d
commit 10615c6fa9
5 changed files with 77 additions and 28 deletions

View File

@ -3,8 +3,6 @@ package eu.eudat.controllers.v2;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.commons.enums.ExternalReferencesType; import eu.eudat.commons.enums.ExternalReferencesType;
import eu.eudat.controllers.BaseController; import eu.eudat.controllers.BaseController;
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
@ -12,16 +10,12 @@ import eu.eudat.logic.services.externalreferences.ExternalReferencesService;
import eu.eudat.logic.services.externalreferences.FunderService; import eu.eudat.logic.services.externalreferences.FunderService;
import eu.eudat.logic.services.externalreferences.ProjectService; import eu.eudat.logic.services.externalreferences.ProjectService;
import eu.eudat.models.data.ExternalReference; import eu.eudat.models.data.ExternalReference;
import eu.eudat.models.data.ExternalReference2;
import eu.eudat.models.data.funder.Funder;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.project.Project;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;

View File

@ -5,17 +5,22 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.commons.enums.ExternalReferencesType; import eu.eudat.commons.enums.ExternalReferencesType;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.dao.criteria.DataRepositoryCriteria; import eu.eudat.data.dao.criteria.DataRepositoryCriteria;
import eu.eudat.data.dao.criteria.ExternalDatasetCriteria;
import eu.eudat.data.dao.criteria.RegistryCriteria; import eu.eudat.data.dao.criteria.RegistryCriteria;
import eu.eudat.data.dao.criteria.ServiceCriteria; import eu.eudat.data.dao.criteria.ServiceCriteria;
import eu.eudat.data.old.DataRepository; import eu.eudat.data.old.DataRepository;
import eu.eudat.data.old.ExternalDataset;
import eu.eudat.data.old.Registry; import eu.eudat.data.old.Registry;
import eu.eudat.data.old.Service; import eu.eudat.data.old.Service;
import eu.eudat.logic.builders.model.criteria.ExternalDatasetCriteriaBuilder;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria; import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.ExternalReference; import eu.eudat.models.data.ExternalReference;
import eu.eudat.queryable.QueryableList;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import java.util.Comparator; import java.util.Comparator;
@ -29,10 +34,12 @@ public class ExternalReferencesService {
private final ApiContext apiContext; private final ApiContext apiContext;
private final UserScope userScope; private final UserScope userScope;
private final RemoteFetcher remoteFetcher;
public ExternalReferencesService(ApiContext apiContext, UserScope userScope) { public ExternalReferencesService(ApiContext apiContext, UserScope userScope, RemoteFetcher remoteFetcher) {
this.apiContext = apiContext; this.apiContext = apiContext;
this.userScope = userScope; this.userScope = userScope;
this.remoteFetcher = remoteFetcher;
} }
// external references: // external references:
@ -138,17 +145,23 @@ public class ExternalReferencesService {
public List<ExternalReference> getExternalReference(ExternalReferencesType 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); ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
List<ExternalReference> list = this.fetchFromDb(externalType, query, type); List<Map<String, String>> remoteRepos = null;
if (externalType.equals(ExternalReferencesType.Datasets)){
remoteRepos = remoteFetcher.getDatasets(externalUrlCriteria, type);
}else {
remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
}
List<ExternalReference> list = this.fetchFromDb(externalType, query, type, remoteRepos);
list.addAll(remoteRepos.stream().map(ExternalReference::fromRemoteModel).toList()); list.addAll(remoteRepos.stream().map(ExternalReference::fromRemoteModel).toList());
list = list.stream().filter(x -> x.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList()); list = list.stream().filter(x -> x.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList());
list.sort(Comparator.comparing(ExternalReference::getName)); list.sort(Comparator.comparing(ExternalReference::getName));
return list; return list;
} }
private List<ExternalReference> fetchFromDb(ExternalReferencesType externalType, String query, String type) throws InvalidApplicationException { private List<ExternalReference> fetchFromDb(ExternalReferencesType externalType, String query, String type, List<Map<String, String>> remoteRepos) throws InvalidApplicationException {
List<ExternalReference> list = new LinkedList<>(); List<ExternalReference> list = new LinkedList<>();
switch (externalType) { switch (externalType) {
case DataRepositories: case DataRepositories:
@ -183,6 +196,15 @@ public class ExternalReferencesService {
list = serviceList.stream().map(item -> new ExternalReference().fromService(item)).collect(Collectors.toList()); list = serviceList.stream().map(item -> new ExternalReference().fromService(item)).collect(Collectors.toList());
} }
} }
case Datasets:{
ExternalDatasetCriteria criteria = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ExternalDatasetCriteriaBuilder.class).like(query).build();
criteria.setCreationUserId(this.userScope.getUserId());
QueryableList<ExternalDataset> items = apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao().getWithCriteria(criteria);
list = items.select(item -> new ExternalReference().fromDataset(item));
}
case Taxonomies: case Taxonomies:
case Publications: case Publications:
case Licenses: case Licenses:

View File

@ -1,15 +1,8 @@
package eu.eudat.models.data; package eu.eudat.models.data;
import eu.eudat.data.old.DataRepository; import eu.eudat.data.old.*;
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.Map;
import java.util.UUID;
public class ExternalReference { public class ExternalReference {
@ -209,4 +202,43 @@ public class ExternalReference {
} }
return this; return this;
} }
public ExternalReference fromResearcher(Researcher entity){
this.id = entity.getId().toString();
this.name = entity.getLabel();
String refParts[] = entity.getReference().split(":");
String source = refParts[0];
// if (source.equals("dmp")) {
// this.key = "Internal";
// }else {
// this.key = source;
// }
return this;
}
public ExternalReference fromOrganisation(Organisation entity){
this.id = entity.getId().toString();
this.name = entity.getLabel();
String refParts[] = entity.getReference().split(":");
String source = refParts[0];
// if (source.equals("dmp")) {
// this.key = "Internal";
// }else {
// this.key = source;
// }
return this;
}
public ExternalReference fromDataset(ExternalDataset entity){
this.id = entity.getId().toString();
this.name = entity.getLabel();
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source1.equals("dmp")) {
this.source = "Internal";
} else {
this.source = source1;
}
return this;
}
} }

View File

@ -12,7 +12,5 @@ export enum ExternalReferencesType {
Datasets = 10, Datasets = 10,
Organizations = 11, Organizations = 11,
Grants = 12, Grants = 12,
Validators = 13, Researcher = 13
Researcher = 14,
Prefillings = 15
} }

View File

@ -464,12 +464,13 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
} }
} }
searchDatasetExternalDatasets(query: string): Observable<ExternalSourceItemModel[]> { searchDatasetExternalDatasets(query: string): Observable<ExternalReference[]> {
const requestItem: RequestItem<ExternalDatasetCriteria> = new RequestItem(); const requestItem: RequestItem<ExternalDatasetCriteria> = new RequestItem();
requestItem.criteria = new ExternalDatasetCriteria(); requestItem.criteria = new ExternalDatasetCriteria();
requestItem.criteria.like = query; requestItem.criteria.like = query;
requestItem.criteria.type = ''; requestItem.criteria.type = '';
return this.externalSourcesService.searchDatasetSExternalDatasetservice(requestItem); //return this.externalSourcesService.searchDatasetSExternalDatasetservice(requestItem);
return this.externalSourcesService.listExternal(ExternalReferencesType.Datasets, requestItem.criteria.like, requestItem.criteria.type);
} }
searchDatasetExternalDataRepositories(query: string): Observable<ExternalReference[]> { searchDatasetExternalDataRepositories(query: string): Observable<ExternalReference[]> {
@ -590,12 +591,14 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
} }
} }
filterOrganisations(value: string): Observable<ExternalSourceItemModel[]> { filterOrganisations(value: string): Observable<ExternalReference[]> {
return this.externalSourcesService.searchDMPOrganizations(value); //return this.externalSourcesService.searchDMPOrganizations(value);
return this.externalSourcesService.listExternal(ExternalReferencesType.Organizations, value, '');
} }
filterResearchers(value: string): Observable<ExternalSourceItemModel[]> { filterResearchers(value: string): Observable<ExternalReference[]> {
return this.externalSourcesService.searchDMPResearchers({ criteria: { name: value, like: null } }); //return this.externalSourcesService.searchDMPResearchers({ criteria: { name: value, like: null } });
return this.externalSourcesService.listExternal(ExternalReferencesType.Researcher, value, '');
} }
getDatasetIdControl(name: string): UntypedFormControl { getDatasetIdControl(name: string): UntypedFormControl {