add more fields to reference-type.yml

This commit is contained in:
amentis 2023-10-31 17:57:41 +02:00
parent 7e391582b5
commit be9761b103
6 changed files with 176 additions and 71 deletions

View File

@ -7,6 +7,8 @@ import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.Reference;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.referencedefinition.Definition;
import eu.eudat.model.referencedefinition.Field;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
@ -57,17 +59,40 @@ public class ReferenceSearchBuilder extends BaseBuilder<Reference, Map<String, S
Reference m = new Reference();
if (d.containsKey("id")) m.setId(UUID.fromString(d.getOrDefault("id", null)));
m.setLabel(d.getOrDefault("name", null));
m.setDescription(d.getOrDefault("description", null));
m.setAbbreviation(d.getOrDefault("abbreviation", null));
m.setSource(d.getOrDefault("source", null));
m.setReference(d.getOrDefault("reference", null));
String sourceType = d.getOrDefault("type", null);
if (sourceType != null) m.setSourceType(ReferenceSourceType.valueOf(sourceType));
m.setSourceType(ReferenceSourceType.External);
String type = d.getOrDefault("referenceType", null);
if (type != null) m.setType(ReferenceType.valueOf(type));
m.setDefinition(this.builderFactory.builder(DefinitionSearchBuilder.class).authorize(this.authorize).build(null, d));
Definition definition = this.builderFactory.builder(DefinitionSearchBuilder.class).authorize(this.authorize).build(null, d);
m.setDefinition(definition);
switch (m.getType()){
case Researcher:
case Organizations:
case Funder:
case Grants:
case DataRepositories:
case PubRepositories:
case Journals:
case Datasets:
case Registries:
case Services:{
for (Field field : definition.getFields()) {
if (field.getCode().equals("pid") && field.getValue() != null) {
if (d.containsKey("key")) {
m.setReference(d.get("key") + ":" + field.getValue());
}
}
if (field.getCode().equals("tag") && field.getValue() != null){
m.setSource(field.getValue());
}
}
}
}
m.setDescription(d.getOrDefault("description", null));
m.setAbbreviation(d.getOrDefault("abbreviation", null));
models.add(m);
}

View File

@ -1,7 +1,9 @@
package eu.eudat.query.lookup;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.query.ReferenceQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
public class ReferenceSearchLookup extends Lookup {
@ -34,4 +36,13 @@ public class ReferenceSearchLookup extends Lookup {
public void setKey(String key) {
this.key = key;
}
public ReferenceQuery enrich(QueryFactory queryFactory) {
ReferenceQuery query = queryFactory.query(ReferenceQuery.class);
if (this.type != null) query.types(this.type);
this.enrichCommon(query);
return query;
}
}

View File

@ -51,17 +51,21 @@ public class RemoteFetcher {
).clientConnector(new ReactorClientHttpConnector(HttpClient.create().followRedirect(true))).build();
}
public List<Map<String, String>> get(ReferenceType externalType, ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
public List<Map<String, String>> get(ReferenceType referenceType, ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
FetchStrategy fetchStrategy = null;
GenericUrls exGenericUrls = this.getExternalUrls(externalType);
GenericUrls exGenericUrls = this.getExternalUrls(referenceType);
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);
List<Map<String, String>> results = getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
for (Map<String, String> result: results) {
result.put("referenceType", referenceType.name());
}
return results;
}
public GenericUrls getExternalUrls(ReferenceType externalType) {
switch (externalType){
public GenericUrls getExternalUrls(ReferenceType referenceType) {
switch (referenceType){
case Taxonomies: return configLoader.getExternalUrls().getTaxonomies();
case Licenses: return configLoader.getExternalUrls().getLicenses();
case Publications: return configLoader.getExternalUrls().getPublications();
@ -76,7 +80,7 @@ public class RemoteFetcher {
case Funder: return configLoader.getExternalUrls().getFunders();
case Project: return configLoader.getExternalUrls().getProjects();
case Researcher: return configLoader.getExternalUrls().getResearchers();
default: throw new IllegalArgumentException("Type not found" + externalType);
default: throw new IllegalArgumentException("Type not found" + referenceType);
}
}

View File

@ -31,6 +31,7 @@ import eu.eudat.model.persist.ReferencePersist;
import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
import eu.eudat.model.persist.referencedefinition.FieldPersist;
import eu.eudat.models.data.FetcherReference;
import eu.eudat.query.ReferenceQuery;
import eu.eudat.query.lookup.ReferenceSearchLookup;
import eu.eudat.queryable.QueryableList;
import gr.cite.commons.web.authz.service.AuthorizationService;
@ -188,71 +189,80 @@ public class ReferenceService {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(lookup.getLike());
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(lookup.getType(), externalUrlCriteria, lookup.getKey());
for (Map<String, String> repo: remoteRepos) {
repo.put("referenceType", lookup.getType().name());
}
// List<FetcherReference> list = this.fetchFromDb(externalType, query, type, remoteRepos);
List<Reference> externalModels = this.builderFactory.builder(ReferenceSearchBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), remoteRepos);
List<Reference> models = this.fetchFromDb(lookup);
models.addAll(externalModels);
List<Reference> models = this.builderFactory.builder(ReferenceSearchBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), remoteRepos);
//List<Reference> models = null;
models = models.stream().filter(x -> x.getLabel().toLowerCase().contains(lookup.getLike().toLowerCase())).collect(Collectors.toList());
models.sort(Comparator.comparing(Reference::getLabel));
return models;
}
private List<FetcherReference> fetchFromDb(ReferenceType externalType, String query, String type, List<Map<String, String>> remoteRepos) throws InvalidApplicationException {
List<FetcherReference> 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 FetcherReference().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 FetcherReference().fromRegistry(item)).collect(Collectors.toList());
}
}
case Services:
{
ServiceCriteria criteria = new ServiceCriteria();
private List<Reference> fetchFromDb(ReferenceSearchLookup lookup){
if (!query.isEmpty()) criteria.setLike(query);
criteria.setCreationUserId(this.userScope.getUserId());
List<String> fields = Arrays.asList(Reference._id, Reference._label, Reference._description, Reference._abbreviation, Reference._source,
Reference._isActive, Reference._createdAt, Reference._updatedAt, Reference._type, Reference._definition, Reference._reference, Reference._sourceType );
lookup.setProject(new BaseFieldSet(fields));
if (type.equals("")) {
List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList();
list = serviceList.stream().map(item -> new FetcherReference().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 FetcherReference().fromDataset(item));
}
case Taxonomies:
case Publications:
case Licenses:
break;
ReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission);
List<ReferenceEntity> datas = query.collectAs(lookup.getProject());
return this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), datas);
}
return list;
}
// private List<FetcherReference> fetchFromDb(ReferenceType externalType, String query, String type, List<Map<String, String>> remoteRepos) throws InvalidApplicationException {
// List<FetcherReference> 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 FetcherReference().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 FetcherReference().fromRegistry(item)).collect(Collectors.toList());
// }
// }
// case 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 FetcherReference().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 FetcherReference().fromDataset(item));
// }
// case Taxonomies:
// case Publications:
// case Licenses:
// break;
// }
//
// return list;
// }
}

View File

@ -5,14 +5,30 @@ reference-type:
dataType: Date
- code: endDate
dataType: Date
- code: pid
dataType: Text
- code: tag
dataType: Text
- code: key
dataType: Text
funder:
fields:
- code: uri
dataType: Text
- code: pid
dataType: Text
- code: tag
dataType: Text
- code: key
dataType: Text
researcher:
fields:
- code: pid
dataType: Text
- code: tag
dataType: Text
- code: key
dataType: Text
- code: firstName
dataType: Text
- code: lastName
@ -21,14 +37,22 @@ reference-type:
dataType: Text
service:
fields:
- code: pid
dataType: Text
- code: tag
dataType: Text
- code: key
dataType: Text
- code: uri
dataType: Text
registry:
fields:
- code: pid
dataType: Text
- code: tag
dataType: Text
- code: key
dataType: Text
- code: uri
dataType: Text
project:
@ -41,6 +65,8 @@ reference-type:
fields:
- code: tag
dataType: Text
- code: key
dataType: Text
- code: pid
dataType: Text
- code: uri
@ -49,34 +75,56 @@ reference-type:
dataType: Text
dataset:
fields:
- code: tag
dataType: Text
- code: key
dataType: Text
- code: pid
dataType: Text
- code: pidTypeField
dataType: Text
dataRepository:
fields:
- code: pid
dataType: Text
- code: tag
dataType: Text
- code: key
dataType: Text
pubRepository:
fields:
- code: pid
dataType: Text
- code: tag
dataType: Text
- code: key
dataType: Text
journal:
fields:
- code: pid
dataType: Text
- code: tag
dataType: Text
- code: key
dataType: Text
publication:
fields:
- code: tag
dataType: Text
- code: key
dataType: Text
- code: pid
dataType: Text
- code: pidTypeField
dataType: Text
licence:
fields:
- code: pid
dataType: Text
- code: tag
dataType: Text
- code: key
dataType: Text
- code: uri
dataType: Text
taxonomy:

View File

@ -56,6 +56,8 @@ import { ExtraPropertiesFormModel } from '../editor/general-tab/extra-properties
import { FunderFormModel } from '../editor/grant-tab/funder-form-model';
import { GrantTabModel } from '../editor/grant-tab/grant-tab-model';
import { ProjectFormModel } from '../editor/grant-tab/project-form-model';
import { ReferenceSearchLookup } from '@app/core/query/reference-search.lookup';
import { Reference } from '@app/core/model/reference/reference';
interface Visible {
value: boolean;
@ -1035,8 +1037,13 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
// Researchers
filterResearchers(value: string): Observable<ExternalSourceItemModel[]> {
return this.externalSourcesService.searchDMPResearchers({ criteria: { name: value, like: null } });
filterResearchers(value: string): Observable<Reference[]> {
//return this.externalSourcesService.searchDMPResearchers({ criteria: { name: value, like: null } });
const lookup = new ReferenceSearchLookup();
lookup.like = value;
lookup.key = '';
lookup.type = ReferenceType.Researcher;
return this.referenceService.search(lookup);
}
addResearcher(event: MouseEvent) {