diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/referencetype/ReferenceTypeProperties.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/referencetype/ReferenceTypeProperties.java index 2f37252e3..62a2d8dfb 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/referencetype/ReferenceTypeProperties.java +++ b/dmp-backend/core/src/main/java/eu/eudat/configurations/referencetype/ReferenceTypeProperties.java @@ -19,7 +19,7 @@ public class ReferenceTypeProperties { private Map> project; private Map> organisation; private Map> dataset; - private Map> dataRepository; + private Map> dataRepository; private Map> pubRepository; private Map> journal; private Map> publication; @@ -31,7 +31,7 @@ public class ReferenceTypeProperties { Map> researcher, Map> service, Map> registry, Map> project, Map> organisation, Map> dataset, - Map> dataRepository, Map> pubRepository, + Map> dataRepository, Map> pubRepository, Map> journal, Map> publication, Map> licence, Map> taxonomy) { this.grant = grant; @@ -114,11 +114,11 @@ public class ReferenceTypeProperties { this.dataset = dataset; } - public Map> getDataRepository() { + public Map> getDataRepository() { return dataRepository; } - public void setDataRepository(Map> dataRepository) { + public void setDataRepository(Map> dataRepository) { this.dataRepository = dataRepository; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencesearch/DefinitionSearchBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencesearch/DefinitionSearchBuilder.java new file mode 100644 index 000000000..0a7515b7d --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencesearch/DefinitionSearchBuilder.java @@ -0,0 +1,58 @@ +package eu.eudat.model.builder.referencesearch; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.configurations.referencetype.ReferenceTypeProperties; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.BaseBuilder; +import eu.eudat.model.referencedefinition.Definition; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DefinitionSearchBuilder extends BaseBuilder> { + + private final BuilderFactory builderFactory; + private final ReferenceTypeProperties properties; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public DefinitionSearchBuilder( + ConventionService conventionService, BuilderFactory builderFactory, ReferenceTypeProperties properties) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DefinitionSearchBuilder.class))); + this.builderFactory = builderFactory; + this.properties = properties; + } + + public DefinitionSearchBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List> data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (data == null) + return new ArrayList<>(); + + List models = new ArrayList<>(); + //for (Map d : data) { + Definition m = new Definition(); + m.setFields(this.builderFactory.builder(FieldSearchBuilder.class).authorize(this.authorize).build(null, data)); + models.add(m); + //} + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencesearch/FieldSearchBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencesearch/FieldSearchBuilder.java new file mode 100644 index 000000000..f277ee2a3 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencesearch/FieldSearchBuilder.java @@ -0,0 +1,88 @@ +package eu.eudat.model.builder.referencesearch; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.enums.ReferenceFieldDataType; +import eu.eudat.commons.enums.ReferenceType; +import eu.eudat.configurations.referencetype.ReferenceTypeField; +import eu.eudat.configurations.referencetype.ReferenceTypeProperties; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.BaseBuilder; +import eu.eudat.model.referencedefinition.Field; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class FieldSearchBuilder extends BaseBuilder> { + + private final ReferenceTypeProperties properties; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public FieldSearchBuilder( + ConventionService conventionService, ReferenceTypeProperties properties) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldSearchBuilder.class))); + this.properties = properties; + } + + public FieldSearchBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List< Map> data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (data == null) + return new ArrayList<>(); + + List models = new ArrayList<>(); + for (Map d : data) { + + ReferenceType referenceType = ReferenceType.valueOf(d.getOrDefault("referenceType", null)); + List typeFields = this.getPropertiesFields(referenceType); + if (typeFields.isEmpty()){ + return new ArrayList<>(); + } + + for (ReferenceTypeField typeField: typeFields){ + Field m = new Field(); + m.setCode(typeField.getCode()); + m.setDataType(ReferenceFieldDataType.valueOf(typeField.getDataType())); + m.setValue(d.getOrDefault(typeField.getCode(), null)); + models.add(m); + } + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } + + private List getPropertiesFields(ReferenceType referenceType){ + switch (referenceType){ + case Taxonomies: return properties.getTaxonomy().get("fields"); + case Licenses: return properties.getLicence().get("fields"); + case Publications: return properties.getPublication().get("fields"); + case Journals: return properties.getJournal().get("fields"); + case PubRepositories: return properties.getPubRepository().get("fields"); + case DataRepositories: return properties.getDataRepository().get("fields"); + case Registries: return properties.getRegistry().get("fields"); + case Services: return properties.getService().get("fields"); + case Organizations: return properties.getOrganisation().get("fields"); + case Datasets: return properties.getDataset().get("fields"); + case Funder: return properties.getFunder().get("fields"); + case Project: return properties.getProject().get("fields"); + case Researcher: return properties.getResearcher().get("fields"); + default: return null; + } + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencesearch/ReferenceSearchBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencesearch/ReferenceSearchBuilder.java new file mode 100644 index 000000000..3ebc0fc29 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencesearch/ReferenceSearchBuilder.java @@ -0,0 +1,78 @@ +package eu.eudat.model.builder.referencesearch; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.XmlHandlingService; +import eu.eudat.commons.enums.ReferenceSourceType; +import eu.eudat.commons.enums.ReferenceType; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.Reference; +import eu.eudat.model.builder.BaseBuilder; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ReferenceSearchBuilder extends BaseBuilder> { + + private final BuilderFactory builderFactory; + private final QueryFactory queryFactory; + private final XmlHandlingService xmlHandlingService; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public ReferenceSearchBuilder( + ConventionService conventionService, + BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceSearchBuilder.class))); + this.builderFactory = builderFactory; + this.queryFactory = queryFactory; + this.xmlHandlingService = xmlHandlingService; + } + + public ReferenceSearchBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List> data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (data == null) + return new ArrayList<>(); + + List models = new ArrayList<>(); + for (Map d : data) { + 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)); + 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)); + models.add(m); + + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/ReferenceSearchLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/ReferenceSearchLookup.java new file mode 100644 index 000000000..ee5f1649d --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/ReferenceSearchLookup.java @@ -0,0 +1,37 @@ +package eu.eudat.query.lookup; + +import eu.eudat.commons.enums.ReferenceType; +import gr.cite.tools.data.query.Lookup; + +public class ReferenceSearchLookup extends Lookup { + + private String like; + + private ReferenceType type; + + private String key; + + public String getLike() { + return like; + } + + public void setLike(String like) { + this.like = like; + } + + public ReferenceType getType() { + return type; + } + + public void setType(ReferenceType type) { + this.type = type; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceController.java index f5a5cd41f..08ea00bd1 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceController.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; -import eu.eudat.commons.enums.ReferenceType; import eu.eudat.controllers.BaseController; import eu.eudat.data.ReferenceEntity; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; @@ -20,6 +19,7 @@ import eu.eudat.models.data.FetcherReference; import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.query.ReferenceQuery; import eu.eudat.query.lookup.ReferenceLookup; +import eu.eudat.query.lookup.ReferenceSearchLookup; import eu.eudat.types.ApiMessageCode; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.auditing.AuditService; @@ -99,6 +99,18 @@ public class ReferenceController extends BaseController { return new QueryResult(models, count); } + @PostMapping("search") + public @ResponseBody ResponseEntity>> searchReference(@RequestBody ReferenceSearchLookup lookup) throws HugeResultSet, NoURLFound, InvalidApplicationException { + this.authorizationService.authorizeForce(Permission.AuthenticatedRole); + // ReferenceType referenceType = ReferenceType.of((short) externalType); + + if (lookup.getType() != null){ + List references = this.referenceService.searchReference(lookup); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(references)); + } + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); + } + @GetMapping("{id}") public Reference get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { logger.debug(new MapLogEntry("retrieving" + Reference.class.getSimpleName()).And("id", id).And("fields", fieldSet)); @@ -134,17 +146,17 @@ public class ReferenceController extends BaseController { return persisted; } - @GetMapping(path = {"search/{externalType}"}, produces = "application/json") - public @ResponseBody ResponseEntity>> searchReference(@PathVariable(value = "externalType") int externalType, - @RequestParam(value = "query", required = false) String query, - @RequestParam(value = "type", required = false) String type - ) throws HugeResultSet, NoURLFound, InvalidApplicationException { - this.authorizationService.authorizeForce(Permission.AuthenticatedRole); - ReferenceType referenceType = ReferenceType.of((short) externalType); - - List fetcherReferences = this.referenceService.searchReference(referenceType, query, type); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(fetcherReferences)); - } +// @GetMapping(path = {"search/{externalType}"}, produces = "application/json") +// public @ResponseBody ResponseEntity>> searchReference(@PathVariable(value = "externalType") int externalType, +// @RequestParam(value = "query", required = false) String query, +// @RequestParam(value = "type", required = false) String type +// ) throws HugeResultSet, NoURLFound, InvalidApplicationException { +// this.authorizationService.authorizeForce(Permission.AuthenticatedRole); +// ReferenceType referenceType = ReferenceType.of((short) externalType); +// +// List fetcherReferences = this.referenceService.searchReference(referenceType, query, type); +// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(fetcherReferences)); +// } @DeleteMapping("{id}") @Transactional @@ -156,15 +168,4 @@ public class ReferenceController extends BaseController { this.auditService.track(AuditableAction.Reference_Delete, "id", id); } - -// @Transactional -// @PostMapping(path = {"persist"}, consumes = "application/json", produces = "application/json") -// public @ResponseBody -// ResponseEntity> 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().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE)); -// } - } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ReferenceService.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ReferenceService.java index 4a2f05870..8e3d12434 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ReferenceService.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ReferenceService.java @@ -25,11 +25,13 @@ import eu.eudat.logic.proxy.fetching.RemoteFetcher; import eu.eudat.logic.services.ApiContext; import eu.eudat.model.Reference; import eu.eudat.model.builder.ReferenceBuilder; +import eu.eudat.model.builder.referencesearch.ReferenceSearchBuilder; import eu.eudat.model.deleter.ReferenceDeleter; 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.lookup.ReferenceSearchLookup; import eu.eudat.queryable.QueryableList; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.builder.BuilderFactory; @@ -169,17 +171,35 @@ public class ReferenceService { this.deleterFactory.deleter(ReferenceDeleter.class).deleteAndSaveByIds(List.of(id)); } - public List searchReference(ReferenceType externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException { - ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); +// public List searchReference(ReferenceType externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException { +// ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query); +// +// List> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type); +// +// List list = this.fetchFromDb(externalType, query, type, remoteRepos); +// +// list.addAll(remoteRepos.stream().map(FetcherReference::fromRemoteModel).toList()); +// list = list.stream().filter(x -> x.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList()); +// list.sort(Comparator.comparing(FetcherReference::getName)); +// return list; +// } - List> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type); + public List searchReference(ReferenceSearchLookup lookup) throws HugeResultSet, NoURLFound, InvalidApplicationException { + ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(lookup.getLike()); - List list = this.fetchFromDb(externalType, query, type, remoteRepos); + List> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(lookup.getType(), externalUrlCriteria, lookup.getKey()); + for (Map repo: remoteRepos) { + repo.put("referenceType", lookup.getType().name()); + } - list.addAll(remoteRepos.stream().map(FetcherReference::fromRemoteModel).toList()); - list = list.stream().filter(x -> x.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList()); - list.sort(Comparator.comparing(FetcherReference::getName)); - return list; + // List list = this.fetchFromDb(externalType, query, type, remoteRepos); + + List models = this.builderFactory.builder(ReferenceSearchBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), remoteRepos); + //List 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 fetchFromDb(ReferenceType externalType, String query, String type, List> remoteRepos) throws InvalidApplicationException { diff --git a/dmp-backend/web/src/main/resources/config/reference-type.yml b/dmp-backend/web/src/main/resources/config/reference-type.yml index da97e5940..b072b15e1 100644 --- a/dmp-backend/web/src/main/resources/config/reference-type.yml +++ b/dmp-backend/web/src/main/resources/config/reference-type.yml @@ -2,63 +2,81 @@ reference-type: grant: fields: - code: startDate - dataType: date + dataType: Date - code: endDate - dataType: date + dataType: Date funder: fields: - code: uri - dataType: text + dataType: Text researcher: fields: + - code: tag + dataType: Text - code: firstName - dataType: text + dataType: Text - code: lastName - dataType: text + dataType: Text - code: uri - dataType: text + dataType: Text service: fields: + - code: tag + dataType: Text - code: uri - dataType: text + dataType: Text registry: fields: + - code: tag + dataType: Text - code: uri - dataType: text + dataType: Text project: fields: - code: startDate - dataType: date + dataType: Date - code: endDate - dataType: date + dataType: Date organisation: fields: + - code: tag + dataType: Text - code: pid - dataType: text + dataType: Text - code: uri - dataType: text + dataType: Text - code: pidTypeField - dataType: text + dataType: Text dataset: fields: - code: pid - dataType: text + dataType: Text - code: pidTypeField - dataType: text + dataType: Text dataRepository: fields: + - code: tag + dataType: Text pubRepository: fields: + - code: tag + dataType: Text journal: fields: + - code: tag + dataType: Text publication: fields: + - code: tag + dataType: Text - code: pid - dataType: text + dataType: Text - code: pidTypeField - dataType: text + dataType: Text licence: fields: + - code: tag + dataType: Text - code: uri dataType: text taxonomy: diff --git a/dmp-frontend/src/app/core/services/reference/reference.service.ts b/dmp-frontend/src/app/core/services/reference/reference.service.ts index bcabd3885..08254bb41 100644 --- a/dmp-frontend/src/app/core/services/reference/reference.service.ts +++ b/dmp-frontend/src/app/core/services/reference/reference.service.ts @@ -14,6 +14,7 @@ import { nameof } from 'ts-simple-nameof'; import { ConfigurationService } from '../configuration/configuration.service'; import { BaseHttpV2Service } from '../http/base-http-v2.service'; import { ReferenceSourceType } from '@app/core/common/enum/reference-source-type'; +import { ReferenceSearchLookup } from '@app/core/query/reference-search.lookup'; @Injectable() export class ReferenceService { @@ -32,6 +33,11 @@ export class ReferenceService { return this.http.post>(url, q).pipe(catchError((error: any) => throwError(error))); } + search(q: ReferenceSearchLookup): Observable { + const url = `${this.apiBase}/search`; + return this.http.post(url, q).pipe(catchError((error: any) => throwError(error))); + } + getSingle(id: Guid, reqFields: string[] = []): Observable { const url = `${this.apiBase}/${id}`; const options = { params: { f: reqFields } }; diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts index 3b4c22ab1..bb3a47cf5 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts @@ -48,9 +48,12 @@ import {MatDialog} from "@angular/material/dialog"; import {HttpError} from "@common/modules/errors/error-handling/http-error-handling.service"; import {HttpErrorResponse} from "@angular/common/http"; import * as FileSaver from "file-saver"; -import { FetcherReference } from '@app/core/model/reference/reference'; +import { FetcherReference, Reference } from '@app/core/model/reference/reference'; import { ReferenceType } from '@app/core/common/enum/reference-type'; import { FileUtils } from '@app/core/services/utilities/file-utils.service'; +import { ReferenceSearchLookup } from '@app/core/query/reference-search.lookup'; +import { lookup } from 'dns'; +import { ReferenceService } from '@app/core/services/reference/reference.service'; @Component({ selector: 'app-form-field', @@ -131,7 +134,8 @@ export class FormFieldComponent extends BaseComponent implements OnInit { private cdr: ChangeDetectorRef, private uiNotificationService: UiNotificationService, public dialog: MatDialog, - private fileUtils: FileUtils + private fileUtils: FileUtils, + private referenceService: ReferenceService ) { super(); @@ -466,35 +470,55 @@ export class FormFieldComponent extends BaseComponent implements OnInit { } } - searchDatasetExternalDatasets(query: string): Observable { - const requestItem: RequestItem = new RequestItem(); - requestItem.criteria = new ExternalDatasetCriteria(); - requestItem.criteria.like = query; - requestItem.criteria.type = ''; - //return this.externalSourcesService.searchDatasetSExternalDatasetservice(requestItem); - return this.externalSourcesService.listExternal(ReferenceType.Datasets, requestItem.criteria.like, requestItem.criteria.type); + searchDatasetExternalDatasets(query: string): Observable { + // const requestItem: RequestItem = new RequestItem(); + // requestItem.criteria = new ExternalDatasetCriteria(); + // requestItem.criteria.like = query; + // requestItem.criteria.type = ''; + // //return this.externalSourcesService.searchDatasetSExternalDatasetservice(requestItem); + // return this.externalSourcesService.listExternal(ReferenceType.Datasets, requestItem.criteria.like, requestItem.criteria.type); + const lookup = new ReferenceSearchLookup(); + lookup.like = query; + lookup.key = ''; + lookup.type = ReferenceType.Datasets; + return this.referenceService.search(lookup); } - searchDatasetExternalDataRepositories(query: string): Observable { - const requestItem: RequestItem = new RequestItem(); - requestItem.criteria = new DataRepositoryCriteria(); - requestItem.criteria.like = query; - requestItem.criteria.type = ''; - return this.externalSourcesService.listExternal(ReferenceType.DataRepositories, requestItem.criteria.like, requestItem.criteria.type); + searchDatasetExternalDataRepositories(query: string): Observable { + // const requestItem: RequestItem = new RequestItem(); + // requestItem.criteria = new DataRepositoryCriteria(); + // requestItem.criteria.like = query; + // requestItem.criteria.type = ''; + // return this.externalSourcesService.listExternal(ReferenceType.DataRepositories, requestItem.criteria.like, requestItem.criteria.type); + const lookup = new ReferenceSearchLookup(); + lookup.like = query; + lookup.key = ''; + lookup.type = ReferenceType.DataRepositories; + return this.referenceService.search(lookup); } - searchDatasetExternalPubRepositories(query: string): Observable { - const requestItem: RequestItem = new RequestItem(); - requestItem.criteria = new DataRepositoryCriteria(); - requestItem.criteria.like = query; - requestItem.criteria.type = ''; - return this.externalSourcesService.listExternal(ReferenceType.PubRepositories, requestItem.criteria.like, requestItem.criteria.type); + searchDatasetExternalPubRepositories(query: string): Observable { + // const requestItem: RequestItem = new RequestItem(); + // requestItem.criteria = new DataRepositoryCriteria(); + // requestItem.criteria.like = query; + // requestItem.criteria.type = ''; + // return this.externalSourcesService.listExternal(ReferenceType.PubRepositories, requestItem.criteria.like, requestItem.criteria.type); + const lookup = new ReferenceSearchLookup(); + lookup.like = query; + lookup.key = ''; + lookup.type = ReferenceType.PubRepositories; + return this.referenceService.search(lookup); } - searchDatasetExternalJournalRepositories(query: string): Observable { - const requestItem: RequestItem = new RequestItem(); - requestItem.criteria = new DataRepositoryCriteria(); - requestItem.criteria.like = query; - requestItem.criteria.type = ''; - return this.externalSourcesService.listExternal(ReferenceType.Journals, requestItem.criteria.like, requestItem.criteria.type); + searchDatasetExternalJournalRepositories(query: string): Observable { + // const requestItem: RequestItem = new RequestItem(); + // requestItem.criteria = new DataRepositoryCriteria(); + // requestItem.criteria.like = query; + // requestItem.criteria.type = ''; + // return this.externalSourcesService.listExternal(ReferenceType.Journals, requestItem.criteria.like, requestItem.criteria.type); + const lookup = new ReferenceSearchLookup(); + lookup.like = query; + lookup.key = ''; + lookup.type = ReferenceType.Journals; + return this.referenceService.search(lookup); } searchDatasetExternalTaxonomies(query: string): Observable { const requestItem: RequestItem = new RequestItem(); @@ -503,19 +527,30 @@ export class FormFieldComponent extends BaseComponent implements OnInit { requestItem.criteria.type = ''; return this.externalSourcesService.listExternal(ReferenceType.Taxonomies, requestItem.criteria.like, requestItem.criteria.type); } - searchDatasetExternalLicences(query: string): Observable { - const requestItem: RequestItem = new RequestItem(); - requestItem.criteria = new LicenseCriteria(); - requestItem.criteria.like = query; - requestItem.criteria.type = ''; - return this.externalSourcesService.listExternal(ReferenceType.Licenses, requestItem.criteria.like, requestItem.criteria.type); + searchDatasetExternalLicences(query: string): Observable { + // const requestItem: RequestItem = new RequestItem(); + // requestItem.criteria = new LicenseCriteria(); + // requestItem.criteria.like = query; + // requestItem.criteria.type = ''; + // return this.externalSourcesService.listExternal(ReferenceType.Licenses, requestItem.criteria.like, requestItem.criteria.type); + const lookup = new ReferenceSearchLookup(); + lookup.like = query; + lookup.key = ''; + lookup.type = ReferenceType.Licenses; + return this.referenceService.search(lookup); } - searchDatasetExternalPublications(query: string): Observable { - const requestItem: RequestItem = new RequestItem(); - requestItem.criteria = new PublicationCriteria(); - requestItem.criteria.like = query; - requestItem.criteria.type = ''; - return this.externalSourcesService.listExternal(ReferenceType.Publications, requestItem.criteria.like, requestItem.criteria.type); + searchDatasetExternalPublications(query: string): Observable { + // const requestItem: RequestItem = new RequestItem(); + // requestItem.criteria = new PublicationCriteria(); + // requestItem.criteria.like = query; + // requestItem.criteria.type = ''; + //return this.externalSourcesService.listExternal(ReferenceType.Publications, requestItem.criteria.like, requestItem.criteria.type); + + const lookup = new ReferenceSearchLookup(); + lookup.like = query; + lookup.key = ''; + lookup.type = ReferenceType.Publications; + return this.referenceService.search(lookup); } searchDatasetExternalRegistries(query: string): Observable { @@ -593,14 +628,24 @@ export class FormFieldComponent extends BaseComponent implements OnInit { } } - filterOrganisations(value: string): Observable { + filterOrganisations(value: string): Observable { //return this.externalSourcesService.searchDMPOrganizations(value); - return this.externalSourcesService.listExternal(ReferenceType.Organizations, value, ''); + //return this.externalSourcesService.listExternal(ReferenceType.Organizations, value, ''); + const lookup = new ReferenceSearchLookup(); + lookup.like = value; + lookup.key = ''; + lookup.type = ReferenceType.Organizations; + return this.referenceService.search(lookup); } - filterResearchers(value: string): Observable { + filterResearchers(value: string): Observable { //return this.externalSourcesService.searchDMPResearchers({ criteria: { name: value, like: null } }); - return this.externalSourcesService.listExternal(ReferenceType.Researcher, value, ''); + //return this.externalSourcesService.listExternal(ReferenceType.Researcher, value, ''); + const lookup = new ReferenceSearchLookup(); + lookup.like = value; + lookup.key = ''; + lookup.type = ReferenceType.Researcher; + return this.referenceService.search(lookup); } getDatasetIdControl(name: string): UntypedFormControl {