From f0c076fe4fbece254810f7165e6467e6737ee082 Mon Sep 17 00:00:00 2001 From: amentis Date: Fri, 1 Mar 2024 18:45:32 +0200 Subject: [PATCH] prefilling source changes --- .../java/eu/eudat/audit/AuditableAction.java | 6 +-- .../persist/DescriptionProfilingRequest.java | 8 ++-- .../DescriptionProfilingWithDataRequest.java | 14 +++---- .../PrefillingSourceServiceImpl.java | 41 +++++++++++-------- .../PrefillingSourceController.java | 4 +- .../description-profiling-request.ts | 12 ++++++ .../prefilling-source.service.ts | 18 ++++++++ .../editor/description-editor.module.ts | 4 +- .../prefill-description.component.html | 18 ++++++-- .../prefill-description.component.ts | 21 +++++++--- dmp-frontend/src/assets/i18n/en.json | 1 + 11 files changed, 103 insertions(+), 44 deletions(-) create mode 100644 dmp-frontend/src/app/core/model/description-profiling-request/description-profiling-request.ts diff --git a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java index 7e747ebe4..5c7571155 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java +++ b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java @@ -134,10 +134,6 @@ public class AuditableAction { public static final EventId ContactSupport_Sent = new EventId(210000, "ContactSupport_Sent"); public static final EventId ContactSupport_PublicSent = new EventId(210001, "ContactSupport_PublicSent"); - public static final EventId Prefilling_Query = new EventId(220000, "Prefilling_Query"); - public static final EventId Prefilling_Generate = new EventId(210001, "Prefilling_Generate"); - public static final EventId Prefilling_GenerateWithData = new EventId(210002, "Prefilling_GenerateWithData"); - public static final EventId Maintenance_GenerateElastic = new EventId(220000, "Maintenance_GenerateElastic"); public static final EventId Maintenance_ClearElastic = new EventId(230000, "Maintenance_ClearElastic"); @@ -149,6 +145,8 @@ public class AuditableAction { public static final EventId PrefillingSource_Lookup = new EventId(260001, "PrefillingSource_Lookup"); public static final EventId PrefillingSource_Persist = new EventId(260002, "PrefillingSource_Persist"); public static final EventId PrefillingSource_Delete = new EventId(260003, "PrefillingSource_Delete"); + public static final EventId PrefillingSource_Generate = new EventId(260005, "PrefillingSource_Generate"); + public static final EventId PrefillingSource_GenerateWithData = new EventId(260006, "PrefillingSource_GenerateWithData"); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingRequest.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingRequest.java index 0b4a577b0..d1f89e0fe 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingRequest.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingRequest.java @@ -80,10 +80,10 @@ public class DescriptionProfilingRequest { .failOn(DescriptionProfilingRequest._descriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingRequest._descriptionTemplateId}, LocaleContextHolder.getLocale())), this.spec() .must(() -> this.isValidGuid(item.getPrefillingSourceId())) - .failOn(DescriptionProfilingRequest._prefillingSourceId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingRequest._prefillingSourceId}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> item.getProject() != null) - .failOn(DescriptionProfilingRequest._project).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingRequest._project}, LocaleContextHolder.getLocale())) + .failOn(DescriptionProfilingRequest._prefillingSourceId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingRequest._prefillingSourceId}, LocaleContextHolder.getLocale())) +// this.spec() TODO +// .must(() -> item.getProject() != null) +// .failOn(DescriptionProfilingRequest._project).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingRequest._project}, LocaleContextHolder.getLocale())) ); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingWithDataRequest.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingWithDataRequest.java index 87de6af19..63790b828 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingWithDataRequest.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingWithDataRequest.java @@ -91,13 +91,13 @@ public class DescriptionProfilingWithDataRequest { .failOn(DescriptionProfilingWithDataRequest._descriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._descriptionTemplateId}, LocaleContextHolder.getLocale())), this.spec() .must(() -> this.isValidGuid(item.getPrefillingSourceId())) - .failOn(DescriptionProfilingWithDataRequest._prefillingSourceId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._prefillingSourceId}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> item.getData() != null) - .failOn(DescriptionProfilingWithDataRequest._data).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._data}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> item.getProject() != null) - .failOn(DescriptionProfilingWithDataRequest._project).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._project}, LocaleContextHolder.getLocale())) + .failOn(DescriptionProfilingWithDataRequest._prefillingSourceId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._prefillingSourceId}, LocaleContextHolder.getLocale())) +// this.spec() TODO +// .must(() -> item.getData() != null) +// .failOn(DescriptionProfilingWithDataRequest._data).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._data}, LocaleContextHolder.getLocale())) +// this.spec() +// .must(() -> item.getProject() != null) +// .failOn(DescriptionProfilingWithDataRequest._project).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._project}, LocaleContextHolder.getLocale())) ); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java index 8ce773a54..7985ef706 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java @@ -35,6 +35,7 @@ import eu.eudat.model.referencedefinition.Definition; import eu.eudat.query.PrefillingSourceQuery; import eu.eudat.query.lookup.ReferenceSearchLookup; import eu.eudat.service.externalfetcher.ExternalFetcherService; +import eu.eudat.service.externalfetcher.criteria.ExternalReferenceCriteria; import eu.eudat.service.externalfetcher.models.ExternalDataResult; import eu.eudat.service.reference.ReferenceService; import gr.cite.commons.web.authz.service.AuthorizationService; @@ -91,7 +92,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { private final JsonHandlingService jsonHandlingService; private final ReferenceService referenceService; - private static final String Zenodo = "zenodo"; + private static final String Zenodo = "Zenodo"; public PrefillingSourceServiceImpl( EntityManager entityManager, AuthorizationService authorizationService, DeleterFactory deleterFactory, BuilderFactory builderFactory, @@ -327,8 +328,8 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { PrefillingSourceDefinitionEntity prefillingSourceDefinition = this.xmlHandlingService.fromXmlSafe(PrefillingSourceDefinitionEntity.class, prefillingSourceEntity.getDefinition()); if (prefillingSourceDefinition == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSourceDefinition.class.getSimpleName()}, LocaleContextHolder.getLocale())); - - ExternalDataResult externalData = this.externalFetcherService.getExternalData(Stream.of(prefillingSourceDefinition.getGetConfiguration()).collect(Collectors.toList()), null, null); + + ExternalDataResult externalData = this.externalFetcherService.getExternalData(Stream.of(prefillingSourceDefinition.getGetConfiguration()).collect(Collectors.toList()), new ExternalReferenceCriteria(), null); if (externalData == null || this.conventionService.isListNullOrEmpty(externalData.getResults())) { return null; } @@ -343,24 +344,32 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { } private Description mapPrefilledEntityToDescription(Description description, DefinitionEntity descriptionTemplateDefinition, PrefillingSourceDefinitionEntity prefillingSourceDefinition, String type, Map externalData){ - for (PrefillingSourceDefinitionFieldEntity field: prefillingSourceDefinition.getFields()) { - String sourceValue = externalData.get(field.getCode()); - this.prefillSystemValueToDescription(description, field.getSystemFieldTarget(), sourceValue); - this.prefillSemanticValueToDescription(description, field.getSemanticTarget(), sourceValue, descriptionTemplateDefinition, type); + if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFields())) { + for (PrefillingSourceDefinitionFieldEntity field : prefillingSourceDefinition.getFields()) { + String sourceValue = externalData.get(field.getCode()); + this.prefillSystemValueToDescription(description, field.getSystemFieldTarget(), sourceValue); + this.prefillSemanticValueToDescription(description, field.getSemanticTarget(), sourceValue, descriptionTemplateDefinition, type); + } } - for (PrefillingSourceDefinitionFixedValueFieldEntity field: prefillingSourceDefinition.getFixedValueFields()) { - this.prefillSystemValueToDescription(description, field.getSystemFieldTarget(), field.getFixedValue()); - this.prefillSemanticValueToDescription(description, field.getSemanticTarget(), field.getFixedValue(), descriptionTemplateDefinition, type); + if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFixedValueFields())){ + for (PrefillingSourceDefinitionFixedValueFieldEntity field: prefillingSourceDefinition.getFixedValueFields()) { + this.prefillSystemValueToDescription(description, field.getSystemFieldTarget(), field.getFixedValue()); + this.prefillSemanticValueToDescription(description, field.getSemanticTarget(), field.getFixedValue(), descriptionTemplateDefinition, type); + } } - for (PrefillingSourceDefinitionFieldEntity field: prefillingSourceDefinition.getFields()) { - String sourceValue = externalData.get(field.getCode()); - this.ensureZenodoFields(description, field.getSemanticTarget(), sourceValue, descriptionTemplateDefinition, type); + if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFields())) { + for (PrefillingSourceDefinitionFieldEntity field : prefillingSourceDefinition.getFields()) { + String sourceValue = externalData.get(field.getCode()); + this.ensureZenodoFields(description, field.getSemanticTarget(), sourceValue, descriptionTemplateDefinition, type); + } } - for (PrefillingSourceDefinitionFixedValueFieldEntity field: prefillingSourceDefinition.getFixedValueFields()) { - this.ensureZenodoFields(description, field.getSemanticTarget(), field.getFixedValue(), descriptionTemplateDefinition, type); + if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFixedValueFields())) { + for (PrefillingSourceDefinitionFixedValueFieldEntity field : prefillingSourceDefinition.getFixedValueFields()) { + this.ensureZenodoFields(description, field.getSemanticTarget(), field.getFixedValue(), descriptionTemplateDefinition, type); + } } return description; @@ -371,7 +380,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { if (semanticTarget.equals("rda.dataset.distribution.data_access")) { if (value.equals("open")) { List issuedFieldEntities = definition.getAllField().stream().filter(x -> x.getSchematics() != null && x.getSchematics().contains("rda.dataset.issued")).toList(); - if (this.conventionService.isListNullOrEmpty(issuedFieldEntities)) { + if (!this.conventionService.isListNullOrEmpty(issuedFieldEntities)) { String issuedIdNode = issuedFieldEntities.getFirst().getId(); String issuedValue = this.conventionService.isNullOrEmpty(issuedIdNode) ? null : description.getProperties().getFieldSets().values().stream().map(PropertyDefinitionFieldSet::getItems).flatMap(List::stream) .filter(x -> x.getFields() != null && x.getFields().containsKey(issuedIdNode)).map(x -> x.getFields().get(issuedIdNode).getTextValue()).findFirst().orElse(null); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java index 4d0e008c2..8ed3be40a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java @@ -153,7 +153,7 @@ public class PrefillingSourceController { Description item = this.prefillingSourceService.getPrefilledDescription(model); - this.auditService.track(AuditableAction.Prefilling_Generate, Map.ofEntries( + this.auditService.track(AuditableAction.PrefillingSource_Generate, Map.ofEntries( new AbstractMap.SimpleEntry("model", model) )); @@ -169,7 +169,7 @@ public class PrefillingSourceController { Description item = this.prefillingSourceService.getPrefilledDescriptionUsingData(model); - this.auditService.track(AuditableAction.Prefilling_GenerateWithData, Map.ofEntries( + this.auditService.track(AuditableAction.PrefillingSource_GenerateWithData, Map.ofEntries( new AbstractMap.SimpleEntry("model", model) )); diff --git a/dmp-frontend/src/app/core/model/description-profiling-request/description-profiling-request.ts b/dmp-frontend/src/app/core/model/description-profiling-request/description-profiling-request.ts new file mode 100644 index 000000000..2300e6942 --- /dev/null +++ b/dmp-frontend/src/app/core/model/description-profiling-request/description-profiling-request.ts @@ -0,0 +1,12 @@ +import { Guid } from "@common/types/guid"; + +export interface DescriptionProfilingRequest { + prefillingSourceId: Guid; + descriptionTemplateId: Guid; +} + +export interface DescriptionProfilingWithDataRequest { + prefillingSourceId: Guid; + descriptionTemplateId: Guid; + data: Map; +} \ No newline at end of file diff --git a/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts b/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts index f2d1fcd73..5c6d36802 100644 --- a/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts +++ b/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts @@ -12,6 +12,8 @@ import { catchError, map } from 'rxjs/operators'; import { nameof } from 'ts-simple-nameof'; import { ConfigurationService } from '../configuration/configuration.service'; import { BaseHttpV2Service } from '../http/base-http-v2.service'; +import { DescriptionProfilingRequest, DescriptionProfilingWithDataRequest } from '@app/core/model/description-profiling-request/description-profiling-request'; +import { Description } from '@app/core/model/description/description'; @Injectable() export class PrefillingSourceService { @@ -55,6 +57,22 @@ export class PrefillingSourceService { catchError((error: any) => throwError(error))); } + generate(item: DescriptionProfilingRequest): Observable { + const url = `${this.apiBase}/generate`; + + return this.http + .post(url, item).pipe( + catchError((error: any) => throwError(error))); + } + + generateWithData(item: DescriptionProfilingWithDataRequest): Observable { + const url = `${this.apiBase}/generate-with-data`; + + return this.http + .post(url, item).pipe( + catchError((error: any) => throwError(error))); + } + // // Autocomplete Commons // diff --git a/dmp-frontend/src/app/ui/description/editor/description-editor.module.ts b/dmp-frontend/src/app/ui/description/editor/description-editor.module.ts index 23a6ecdd5..55b7b6c4d 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-editor.module.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-editor.module.ts @@ -13,6 +13,7 @@ import { TableOfContentsModule } from './table-of-contents/table-of-contents.mod import { RichTextEditorModule } from '@app/library/rich-text-editor/rich-text-editor.module'; import { TagsFieldModule } from '@app/ui/tag/tags-field/tags-field.module'; import { PrefillDescriptionDialogComponent } from './prefill-description/prefill-description.component'; +import { AutoCompleteModule } from '@app/library/auto-complete/auto-complete.module'; @NgModule({ imports: [ @@ -25,7 +26,8 @@ import { PrefillDescriptionDialogComponent } from './prefill-description/prefill DescriptionFormModule, DescriptionEditorRoutingModule, RichTextEditorModule, - TagsFieldModule + TagsFieldModule, + AutoCompleteModule ], declarations: [ DescriptionEditorComponent, diff --git a/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html b/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html index 8e416f9c2..8b78f17a5 100644 --- a/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html +++ b/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html @@ -25,14 +25,24 @@

{{'PREFILL-DESCRIPTION-DIALOG.DESCRIPTION-TEMPLATE' | translate}}

- - + +
- {{descriptionTempalte.label}} + {{descriptionTemplate.label}}
- {{prefillForm.get('descriptionTempalte').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} +
+
+

{{'PREFILL-DESCRIPTION-DIALOG.PREFILLING-SOURCE' | translate}}

+
+ + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}}