diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionTemplateSemanticsLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionTemplateSemanticsLookup.java new file mode 100644 index 000000000..163ba4117 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionTemplateSemanticsLookup.java @@ -0,0 +1,14 @@ +package eu.eudat.query.lookup; + +public class DescriptionTemplateSemanticsLookup { + + private String like; + + public String getLike() { + return like; + } + + public void setLike(String like) { + this.like = like; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/remotefetcher/RemoteFetcherServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/remotefetcher/RemoteFetcherServiceImpl.java index 9a75fbfc3..c81a1c569 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/remotefetcher/RemoteFetcherServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/remotefetcher/RemoteFetcherServiceImpl.java @@ -5,9 +5,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.PathNotFoundException; +import eu.eudat.commons.JsonHandlingService; import eu.eudat.commons.enums.ReferenceTypeSourceType; import eu.eudat.commons.exceptions.HugeResultSetException; -import eu.eudat.commons.types.dashborad.RecentActivityItemEntity; import eu.eudat.convention.ConventionService; import eu.eudat.data.ReferenceEntity; import eu.eudat.model.Reference; @@ -39,10 +39,12 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService { private WebClient webClient; private final ExternalUrlConfigProvider externalUrlConfigProvider; private final ConventionService conventionService; + private final JsonHandlingService jsonHandlingService; @Autowired - public RemoteFetcherServiceImpl(ExternalUrlConfigProvider externalUrlConfigProvider, ConventionService conventionService) { + public RemoteFetcherServiceImpl(ExternalUrlConfigProvider externalUrlConfigProvider, ConventionService conventionService, JsonHandlingService jsonHandlingService) { this.externalUrlConfigProvider = externalUrlConfigProvider; this.conventionService = conventionService; + this.jsonHandlingService = jsonHandlingService; } private WebClient getWebClient(){ @@ -304,10 +306,13 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService { Object value = JsonPath.parse(resultItem).read(field.getResponsePath()); map.put(field.getCode(), normalizeJsonValue(value)); }catch (PathNotFoundException e){ - List nextLevelResults = jsonContext.read(resultsConfigurationEntity.getResultsArrayPath() + field.getResponsePath()); - for(Object nextLevelResultValue : nextLevelResults) { - map.put(field.getCode(), normalizeJsonValue(nextLevelResultValue)); - } +// List nextLevelResults = jsonContext.read(resultsConfigurationEntity.getResultsArrayPath() + field.getResponsePath()); +// for(Object nextLevelResultValue : nextLevelResults) { +// map.put(field.getCode(), normalizeJsonValue(nextLevelResultValue)); +// } + logger.debug("Json Path Error: " + e.getMessage() + " on source " + jsonHandlingService.toJsonSafe(resultItem)); + //TODO if value don't exist + continue; } } parsedData.add(map); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateController.java index 1ffbc5d97..280d415df 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateController.java @@ -3,6 +3,7 @@ package eu.eudat.controllers; import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.query.lookup.DescriptionTemplateSemanticsLookup; import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.validation.ValidationFilterAnnotation; import eu.eudat.data.DescriptionTemplateEntity; @@ -202,14 +203,14 @@ public class DescriptionTemplateController { return model; } - @RequestMapping(method = RequestMethod.GET, value = {"/get-semantics"}, produces = "application/json") - public List getSemantics(@RequestParam(value = "query", required = false) String query) throws IOException { - logger.debug(new MapLogEntry("import" + DescriptionTemplate.class.getSimpleName()).And("query", query)); + @RequestMapping(method = RequestMethod.POST, value = {"get-semantics"}) + public List getSemantics(@RequestBody DescriptionTemplateSemanticsLookup lookup) throws IOException { + logger.debug(new MapLogEntry("retrieving {}" + DescriptionTemplate.class.getSimpleName()).And("like", lookup.getLike())); - List semantics = this.descriptionTemplateTypeService.getSemantics(query); + List semantics = this.descriptionTemplateTypeService.getSemantics(lookup.getLike()); this.auditService.track(AuditableAction.DescriptionTemplate_GetSemantics, Map.ofEntries( - new AbstractMap.SimpleEntry("query", query) + new AbstractMap.SimpleEntry("lookup", lookup) )); return semantics; diff --git a/dmp-db-scema/updates/00.01.000_Add_Reference_ReferenceType_SupportiveMaterial.sql b/dmp-db-scema/updates/00.01.000_Add_Reference_ReferenceType_SupportiveMaterial.sql index 6657f1f06..1db957054 100644 --- a/dmp-db-scema/updates/00.01.000_Add_Reference_ReferenceType_SupportiveMaterial.sql +++ b/dmp-db-scema/updates/00.01.000_Add_Reference_ReferenceType_SupportiveMaterial.sql @@ -15,7 +15,7 @@ BEGIN created_by uuid, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - type smallint NOT NULL, + type uuid NOT NULL, definition character varying COLLATE pg_catalog."default", reference character varying(1024) COLLATE pg_catalog."default" NOT NULL, source_type smallint NOT NULL, @@ -30,6 +30,13 @@ BEGIN OIDS = FALSE ); + ALTER TABLE public."Reference" + ADD CONSTRAINT "Reference_type_fkey" FOREIGN KEY (type) + REFERENCES public."ReferenceType" (id) + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID; + CREATE TABLE public."ReferenceType" ( id uuid NOT NULL, diff --git a/dmp-frontend/src/app/core/services/description-template/description-template.service.ts b/dmp-frontend/src/app/core/services/description-template/description-template.service.ts index 02e4f4946..1174d2f0b 100644 --- a/dmp-frontend/src/app/core/services/description-template/description-template.service.ts +++ b/dmp-frontend/src/app/core/services/description-template/description-template.service.ts @@ -18,6 +18,7 @@ import { ConfigurationService } from '../configuration/configuration.service'; import { BaseHttpV2Service } from '../http/base-http-v2.service'; import { DescriptionTemplateVersionStatus } from '@app/core/common/enum/description-template-version-status'; import { DescriptionTemplateStatus } from '@app/core/common/enum/description-template-status'; +import { DescriptionTemplateSemanticsLookup } from '@app/core/query/description-template-semantics.lookup'; @Injectable() export class DescriptionTemplateService { @@ -98,6 +99,11 @@ export class DescriptionTemplateService { return this.http.post(url, formData, { params: params }); } + searchSemantics(q: DescriptionTemplateSemanticsLookup ): Observable { + const url = `${this.apiBase}/get-semantics`; + return this.http.post(url, q).pipe(catchError((error: any) => throwError(error))); + } + // // Autocomplete Commons // diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/reference-type/description-template-editor-reference-type-field.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/reference-type/description-template-editor-reference-type-field.component.html index 03d349164..55230f78e 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/reference-type/description-template-editor-reference-type-field.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/reference-type/description-template-editor-reference-type-field.component.html @@ -15,7 +15,7 @@
{{'DESCRIPTION-TEMPLATE-EDITOR.FIELDS.REFERENCE-TYPE' | translate}} - + {{form.get('data').get('referenceTypeId').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.ts index 67877419a..7a1269635 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.ts @@ -26,6 +26,8 @@ import { Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; import { DescriptionTemplateFieldEditorModel, DescriptionTemplateRuleEditorModel } from '../../description-template-editor.model'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; +import { DescriptionTemplateSemanticsLookup } from '@app/core/query/description-template-semantics.lookup'; +import { FilterService } from '@common/modules/text-filter/filter-service'; @Component({ selector: 'app-description-template-editor-field-component', @@ -51,22 +53,29 @@ export class DescriptionTemplateEditorFieldComponent extends BaseComponent imple readonly separatorKeysCodes: number[] = [ENTER, COMMA]; semanticsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = { - filterFn: this.filterSemantics.bind(this), - initialItems: (excludedItems: any[]) => this.filterSemantics('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x !== resultItem)))), + initialItems: (data?: any) => this.descriptionTemplateService.searchSemantics(this.buildAutocompleteLookup()).pipe(map(x => x)), + filterFn: (searchQuery: string, data?: any) => this.descriptionTemplateService.searchSemantics(this.buildAutocompleteLookup(searchQuery)).pipe(map(x => x)), displayFn: (item) => item, - titleFn: (item) => item + titleFn: (item) => item, } - filterSemantics(value: string): Observable { - // return this.descriptionTemplateService.searchSemantics(value); - return of([]); + // filterSemantics(value: string): Observable { + // // return this.descriptionTemplateService.searchSemantics(value); + // return of([]); + // } + + private buildAutocompleteLookup(like?: string ): DescriptionTemplateSemanticsLookup { + const lookup: DescriptionTemplateSemanticsLookup = new DescriptionTemplateSemanticsLookup(); + if (like) { lookup.like = this.filterService.transformLike(like); } + return lookup; } constructor( public enumUtils: EnumUtils, public descriptionTemplateService: DescriptionTemplateService, private dialog: MatDialog, - private configurationService: ConfigurationService + private configurationService: ConfigurationService, + private filterService: FilterService ) { super();