From 41583745be1bae08fa221ba3f37c576a68765aa8 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Wed, 12 Jun 2024 12:42:53 +0300 Subject: [PATCH] add code to prefilling source --- ...BlueprintPrefillingSourceImportExport.java | 11 +++++ .../opencdmp/data/PrefillingSourceEntity.java | 31 +++++++++---- .../errorcode/ErrorThesaurusProperties.java | 20 +++++++++ .../PrefillingSourceBuilder.java | 1 + .../persist/PrefillingSourcePersist.java | 44 ++++++++++++++----- .../model/persist/ReferenceTypePersist.java | 26 +++++------ .../prefillingsource/PrefillingSource.java | 28 ++++++++---- .../opencdmp/query/PrefillingSourceQuery.java | 30 ++++++++++++- .../query/lookup/PrefillingSourceLookup.java | 15 ++++--- .../dmpblueprint/DmpBlueprintServiceImpl.java | 10 ++++- .../PrefillingSourceServiceImpl.java | 4 ++ .../ReferenceTypeServiceImpl.java | 14 ++++-- .../web/src/main/resources/config/errors.yml | 8 +++- .../00.01.057_Add_PrefillingSource_table.sql | 1 + .../updates/00.01.060_Insert_values.sql | 4 +- .../core/common/enum/respone-error-code.ts | 8 +++- .../prefilling-source/prefilling-source.ts | 2 + .../core/query/prefilling-source.lookup.ts | 4 +- .../editor/dmp-blueprint-editor.resolver.ts | 1 + .../prefilling-source-editor.component.html | 10 ++++- .../editor/prefilling-source-editor.model.ts | 14 +++--- .../prefilling-source-editor.resolver.ts | 3 +- .../prefilling-source-listing.component.ts | 5 +++ dmp-frontend/src/assets/i18n/en.json | 3 ++ 24 files changed, 229 insertions(+), 68 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/dmpblueprint/importexport/BlueprintPrefillingSourceImportExport.java b/backend/core/src/main/java/org/opencdmp/commons/types/dmpblueprint/importexport/BlueprintPrefillingSourceImportExport.java index 3622e4a88..15ac45059 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/dmpblueprint/importexport/BlueprintPrefillingSourceImportExport.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/dmpblueprint/importexport/BlueprintPrefillingSourceImportExport.java @@ -11,6 +11,9 @@ public class BlueprintPrefillingSourceImportExport { @XmlElement(name = "id") private UUID id; + @XmlElement(name = "code") + private String code; + public UUID getId() { return this.id; } @@ -18,4 +21,12 @@ public class BlueprintPrefillingSourceImportExport { public void setId(UUID id) { this.id = id; } + + public String getCode() { + return this.code; + } + + public void setCode(String code) { + this.code = code; + } } diff --git a/backend/core/src/main/java/org/opencdmp/data/PrefillingSourceEntity.java b/backend/core/src/main/java/org/opencdmp/data/PrefillingSourceEntity.java index cdfb81d69..1c49ce158 100644 --- a/backend/core/src/main/java/org/opencdmp/data/PrefillingSourceEntity.java +++ b/backend/core/src/main/java/org/opencdmp/data/PrefillingSourceEntity.java @@ -1,11 +1,11 @@ package org.opencdmp.data; +import jakarta.persistence.*; +import org.hibernate.annotations.Type; import org.opencdmp.commons.enums.IsActive; import org.opencdmp.data.converters.enums.IsActiveConverter; import org.opencdmp.data.tenant.TenantScopedBaseEntity; import org.opencdmp.data.types.SQLXMLType; -import jakarta.persistence.*; -import org.hibernate.annotations.Type; import java.time.Instant; import java.util.UUID; @@ -24,7 +24,12 @@ public class PrefillingSourceEntity extends TenantScopedBaseEntity { public static final String _label = "label"; public static final int _labelLength = 250; - @Type(value = SQLXMLType.class) + @Column(name = "code", length = _codeLength, nullable = false) + private String code; + public static final String _code = "code"; + public static final int _codeLength = 100; + + @Type(SQLXMLType.class) @Column(name = "definition", nullable = false, columnDefinition = "xml") private String definition; public static final String _definition = "definition"; @@ -43,15 +48,23 @@ public class PrefillingSourceEntity extends TenantScopedBaseEntity { public static final String _updatedAt = "updatedAt"; public UUID getId() { - return id; + return this.id; } public void setId(UUID id) { this.id = id; } + public String getCode() { + return this.code; + } + + public void setCode(String code) { + this.code = code; + } + public String getLabel() { - return label; + return this.label; } public void setLabel(String label) { @@ -59,7 +72,7 @@ public class PrefillingSourceEntity extends TenantScopedBaseEntity { } public String getDefinition() { - return definition; + return this.definition; } public void setDefinition(String definition) { @@ -67,7 +80,7 @@ public class PrefillingSourceEntity extends TenantScopedBaseEntity { } public IsActive getIsActive() { - return isActive; + return this.isActive; } public void setIsActive(IsActive isActive) { @@ -75,7 +88,7 @@ public class PrefillingSourceEntity extends TenantScopedBaseEntity { } public Instant getCreatedAt() { - return createdAt; + return this.createdAt; } public void setCreatedAt(Instant createdAt) { @@ -83,7 +96,7 @@ public class PrefillingSourceEntity extends TenantScopedBaseEntity { } public Instant getUpdatedAt() { - return updatedAt; + return this.updatedAt; } public void setUpdatedAt(Instant updatedAt) { diff --git a/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java b/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java index 370442509..5d69b373f 100644 --- a/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java +++ b/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java @@ -338,4 +338,24 @@ public class ErrorThesaurusProperties { public void setDuplicateDmpUser(ErrorDescription duplicateDmpUser) { this.duplicateDmpUser = duplicateDmpUser; } + + private ErrorDescription referenceTypeCodeExists; + + public ErrorDescription getReferenceTypeCodeExists() { + return this.referenceTypeCodeExists; + } + + public void setReferenceTypeCodeExists(ErrorDescription referenceTypeCodeExists) { + this.referenceTypeCodeExists = referenceTypeCodeExists; + } + + private ErrorDescription prefillingSourceCodeExists; + + public ErrorDescription getPrefillingSourceCodeExists() { + return this.prefillingSourceCodeExists; + } + + public void setPrefillingSourceCodeExists(ErrorDescription prefillingSourceCodeExists) { + this.prefillingSourceCodeExists = prefillingSourceCodeExists; + } } diff --git a/backend/core/src/main/java/org/opencdmp/model/builder/prefillingsource/PrefillingSourceBuilder.java b/backend/core/src/main/java/org/opencdmp/model/builder/prefillingsource/PrefillingSourceBuilder.java index 66ef0f474..e0c847ebc 100644 --- a/backend/core/src/main/java/org/opencdmp/model/builder/prefillingsource/PrefillingSourceBuilder.java +++ b/backend/core/src/main/java/org/opencdmp/model/builder/prefillingsource/PrefillingSourceBuilder.java @@ -58,6 +58,7 @@ public class PrefillingSourceBuilder extends BaseBuilder this.isValidGuid(item.getId())) .must(() -> this.isValidHash(item.getHash())) - .failOn(PrefillingSourcePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{PrefillingSourcePersist._hash}, LocaleContextHolder.getLocale())), + .failOn(PrefillingSourcePersist._hash).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PrefillingSourcePersist._hash}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> !this.isValidGuid(item.getId())) .must(() -> !this.isValidHash(item.getHash())) - .failOn(PrefillingSourcePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + .failOn(PrefillingSourcePersist._hash).failWith(this.messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isEmpty(item.getLabel())) - .failOn(PrefillingSourcePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{PrefillingSourcePersist._label}, LocaleContextHolder.getLocale())), + .failOn(PrefillingSourcePersist._label).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PrefillingSourcePersist._label}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isNull(item.getDefinition())) - .failOn(PrefillingSourcePersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{PrefillingSourcePersist._definition}, LocaleContextHolder.getLocale())), + .failOn(PrefillingSourcePersist._definition).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PrefillingSourcePersist._definition}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getCode())) + .failOn(PrefillingSourcePersist._code).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PrefillingSourcePersist._code}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isEmpty(item.getCode())) + .must(() -> this.lessEqualLength(item.getCode(), ReferenceTypeEntity._codeLength)) + .failOn(PrefillingSourcePersist._code).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{PrefillingSourcePersist._code}, LocaleContextHolder.getLocale())), this.refSpec() .iff(() -> !this.isNull(item.getDefinition())) .on(PrefillingSourcePersist._definition) diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/ReferenceTypePersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/ReferenceTypePersist.java index 109725618..637b71d57 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/ReferenceTypePersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/ReferenceTypePersist.java @@ -1,8 +1,8 @@ package org.opencdmp.model.persist; -import org.opencdmp.commons.validation.BaseValidator; import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.specification.Specification; +import org.opencdmp.commons.validation.BaseValidator; import org.opencdmp.convention.ConventionService; import org.opencdmp.data.ReferenceTypeEntity; import org.opencdmp.errorcode.ErrorThesaurusProperties; @@ -38,7 +38,7 @@ public class ReferenceTypePersist { public static final String _hash = "hash"; public UUID getId() { - return id; + return this.id; } public void setId(UUID id) { @@ -46,7 +46,7 @@ public class ReferenceTypePersist { } public String getName() { - return name; + return this.name; } public void setName(String name) { @@ -54,7 +54,7 @@ public class ReferenceTypePersist { } public String getCode() { - return code; + return this.code; } public void setCode(String code) { @@ -62,7 +62,7 @@ public class ReferenceTypePersist { } public ReferenceTypeDefinitionPersist getDefinition() { - return definition; + return this.definition; } public void setDefinition(ReferenceTypeDefinitionPersist definition) { @@ -70,7 +70,7 @@ public class ReferenceTypePersist { } public String getHash() { - return hash; + return this.hash; } public void setHash(String hash) { @@ -104,29 +104,29 @@ public class ReferenceTypePersist { this.spec() .iff(() -> this.isValidGuid(item.getId())) .must(() -> this.isValidHash(item.getHash())) - .failOn(ReferenceTypePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._hash}, LocaleContextHolder.getLocale())), + .failOn(ReferenceTypePersist._hash).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._hash}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> !this.isValidGuid(item.getId())) .must(() -> !this.isValidHash(item.getHash())) - .failOn(ReferenceTypePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + .failOn(ReferenceTypePersist._hash).failWith(this.messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isEmpty(item.getName())) - .failOn(ReferenceTypePersist._name).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._name}, LocaleContextHolder.getLocale())), + .failOn(ReferenceTypePersist._name).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._name}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> !this.isEmpty(item.getName())) .must(() -> this.lessEqualLength(item.getName(), ReferenceTypeEntity._nameLength)) - .failOn(ReferenceTypePersist._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferenceTypePersist._name}, LocaleContextHolder.getLocale())), + .failOn(ReferenceTypePersist._name).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{ReferenceTypePersist._name}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isEmpty(item.getCode())) - .failOn(ReferenceTypePersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._code}, LocaleContextHolder.getLocale())), + .failOn(ReferenceTypePersist._code).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._code}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> !this.isEmpty(item.getCode())) .must(() -> this.lessEqualLength(item.getCode(), ReferenceTypeEntity._codeLength)) - .failOn(ReferenceTypePersist._code).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferenceTypePersist._code}, LocaleContextHolder.getLocale())), + .failOn(ReferenceTypePersist._code).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{ReferenceTypePersist._code}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isNull(item.getDefinition())) - .failOn(ReferenceTypePersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._definition}, LocaleContextHolder.getLocale())), + .failOn(ReferenceTypePersist._definition).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypePersist._definition}, LocaleContextHolder.getLocale())), this.refSpec() .iff(() -> !this.isNull(item.getDefinition())) .on(ReferenceTypePersist._definition) diff --git a/backend/core/src/main/java/org/opencdmp/model/prefillingsource/PrefillingSource.java b/backend/core/src/main/java/org/opencdmp/model/prefillingsource/PrefillingSource.java index 88d210c0a..54d0fd43d 100644 --- a/backend/core/src/main/java/org/opencdmp/model/prefillingsource/PrefillingSource.java +++ b/backend/core/src/main/java/org/opencdmp/model/prefillingsource/PrefillingSource.java @@ -1,7 +1,6 @@ package org.opencdmp.model.prefillingsource; import org.opencdmp.commons.enums.IsActive; -import org.opencdmp.model.prefillingsource.PrefillingSourceDefinition; import java.time.Instant; import java.util.UUID; @@ -14,6 +13,9 @@ public class PrefillingSource { private String label; public static final String _label = "label"; + private String code; + public static final String _code = "code"; + private PrefillingSourceDefinition definition; public static final String _definition = "definition"; @@ -33,15 +35,23 @@ public class PrefillingSource { public static final String _belongsToCurrentTenant = "belongsToCurrentTenant"; public UUID getId() { - return id; + return this.id; } public void setId(UUID id) { this.id = id; } + public String getCode() { + return this.code; + } + + public void setCode(String code) { + this.code = code; + } + public String getLabel() { - return label; + return this.label; } public void setLabel(String label) { @@ -49,7 +59,7 @@ public class PrefillingSource { } public PrefillingSourceDefinition getDefinition() { - return definition; + return this.definition; } public void setDefinition(PrefillingSourceDefinition definition) { @@ -57,7 +67,7 @@ public class PrefillingSource { } public IsActive getIsActive() { - return isActive; + return this.isActive; } public void setIsActive(IsActive isActive) { @@ -65,7 +75,7 @@ public class PrefillingSource { } public Instant getCreatedAt() { - return createdAt; + return this.createdAt; } public void setCreatedAt(Instant createdAt) { @@ -73,7 +83,7 @@ public class PrefillingSource { } public Instant getUpdatedAt() { - return updatedAt; + return this.updatedAt; } public void setUpdatedAt(Instant updatedAt) { @@ -81,7 +91,7 @@ public class PrefillingSource { } public String getHash() { - return hash; + return this.hash; } public void setHash(String hash) { @@ -89,7 +99,7 @@ public class PrefillingSource { } public Boolean getBelongsToCurrentTenant() { - return belongsToCurrentTenant; + return this.belongsToCurrentTenant; } public void setBelongsToCurrentTenant(Boolean belongsToCurrentTenant) { diff --git a/backend/core/src/main/java/org/opencdmp/query/PrefillingSourceQuery.java b/backend/core/src/main/java/org/opencdmp/query/PrefillingSourceQuery.java index df3bbb8a4..3d73e7449 100644 --- a/backend/core/src/main/java/org/opencdmp/query/PrefillingSourceQuery.java +++ b/backend/core/src/main/java/org/opencdmp/query/PrefillingSourceQuery.java @@ -31,6 +31,7 @@ public class PrefillingSourceQuery extends QueryBase { private Collection isActives; private Collection excludedIds; + private Collection codes; private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); @@ -55,6 +56,21 @@ public class PrefillingSourceQuery extends QueryBase { return this; } + public PrefillingSourceQuery codes(String value) { + this.codes = List.of(value); + return this; + } + + public PrefillingSourceQuery codes(String... value) { + this.codes = Arrays.asList(value); + return this; + } + + public PrefillingSourceQuery codes(Collection values) { + this.codes = values; + return this; + } + public PrefillingSourceQuery isActive(IsActive value) { this.isActives = List.of(value); return this; @@ -121,7 +137,7 @@ public class PrefillingSourceQuery extends QueryBase { @Override protected Boolean isFalseQuery() { - return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds); + return this.isEmpty(this.ids) || this.isEmpty(this.codes) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds); } @Override @@ -134,7 +150,9 @@ public class PrefillingSourceQuery extends QueryBase { predicates.add(inClause); } if (this.like != null && !this.like.isEmpty()) { - predicates.add(this.queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(PrefillingSourceEntity._label), this.like)); + predicates.add(queryContext.CriteriaBuilder.or(this.queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(PrefillingSourceEntity._code), this.like), + this.queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(PrefillingSourceEntity._label), this.like) + )); } if (this.isActives != null) { CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(PrefillingSourceEntity._isActive)); @@ -148,6 +166,12 @@ public class PrefillingSourceQuery extends QueryBase { notInClause.value(item); predicates.add(notInClause.not()); } + if (this.codes != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(PrefillingSourceEntity._code)); + for (String item : this.codes) + inClause.value(item); + predicates.add(inClause); + } if (!predicates.isEmpty()) { Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); return queryContext.CriteriaBuilder.and(predicatesArray); @@ -160,6 +184,7 @@ public class PrefillingSourceQuery extends QueryBase { protected PrefillingSourceEntity convert(Tuple tuple, Set columns) { PrefillingSourceEntity item = new PrefillingSourceEntity(); item.setId(QueryBase.convertSafe(tuple, columns, PrefillingSourceEntity._id, UUID.class)); + item.setCode(QueryBase.convertSafe(tuple, columns, PrefillingSourceEntity._code, String.class)); item.setTenantId(QueryBase.convertSafe(tuple, columns, PrefillingSourceEntity._tenantId, UUID.class)); item.setLabel(QueryBase.convertSafe(tuple, columns, PrefillingSourceEntity._label, String.class)); item.setDefinition(QueryBase.convertSafe(tuple, columns, PrefillingSourceEntity._definition, String.class)); @@ -173,6 +198,7 @@ public class PrefillingSourceQuery extends QueryBase { protected String fieldNameOf(FieldResolver item) { if (item.match(PrefillingSource._id)) return PrefillingSourceEntity._id; else if (item.match(PrefillingSource._label)) return PrefillingSourceEntity._label; + else if (item.match(PrefillingSource._code)) return PrefillingSourceEntity._code; else if (item.prefix(PrefillingSource._definition)) return PrefillingSourceEntity._definition; else if (item.match(PrefillingSource._createdAt)) return PrefillingSourceEntity._createdAt; else if (item.match(PrefillingSource._updatedAt)) return PrefillingSourceEntity._updatedAt; diff --git a/backend/core/src/main/java/org/opencdmp/query/lookup/PrefillingSourceLookup.java b/backend/core/src/main/java/org/opencdmp/query/lookup/PrefillingSourceLookup.java index 14103ae92..82924eb43 100644 --- a/backend/core/src/main/java/org/opencdmp/query/lookup/PrefillingSourceLookup.java +++ b/backend/core/src/main/java/org/opencdmp/query/lookup/PrefillingSourceLookup.java @@ -1,9 +1,9 @@ package org.opencdmp.query.lookup; -import org.opencdmp.commons.enums.IsActive; -import org.opencdmp.query.PrefillingSourceQuery; import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.QueryFactory; +import org.opencdmp.commons.enums.IsActive; +import org.opencdmp.query.PrefillingSourceQuery; import java.util.List; import java.util.UUID; @@ -18,8 +18,10 @@ public class PrefillingSourceLookup extends Lookup { private List excludedIds; + private List codes; + public String getLike() { - return like; + return this.like; } public void setLike(String like) { @@ -27,7 +29,7 @@ public class PrefillingSourceLookup extends Lookup { } public List getIsActive() { - return isActive; + return this.isActive; } public void setIsActive(List isActive) { @@ -35,7 +37,7 @@ public class PrefillingSourceLookup extends Lookup { } public List getIds() { - return ids; + return this.ids; } public void setIds(List ids) { @@ -43,7 +45,7 @@ public class PrefillingSourceLookup extends Lookup { } public List getExcludedIds() { - return excludedIds; + return this.excludedIds; } public void setExcludedIds(List excludeIds) { @@ -54,6 +56,7 @@ public class PrefillingSourceLookup extends Lookup { public PrefillingSourceQuery enrich(QueryFactory queryFactory) { PrefillingSourceQuery query = queryFactory.query(PrefillingSourceQuery.class); if (this.like != null) query.like(this.like); + if (this.codes != null) query.codes(this.codes); if (this.isActive != null) query.isActive(this.isActive); if (this.ids != null) query.ids(this.ids); if (this.excludedIds != null) query.excludedIds(this.excludedIds); diff --git a/backend/core/src/main/java/org/opencdmp/service/dmpblueprint/DmpBlueprintServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/dmpblueprint/DmpBlueprintServiceImpl.java index 2f0a02680..3d5447949 100644 --- a/backend/core/src/main/java/org/opencdmp/service/dmpblueprint/DmpBlueprintServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/dmpblueprint/DmpBlueprintServiceImpl.java @@ -25,6 +25,7 @@ import org.opencdmp.commons.types.dmpblueprint.*; import org.opencdmp.commons.types.dmpblueprint.importexport.*; import org.opencdmp.convention.ConventionService; import org.opencdmp.data.DmpBlueprintEntity; +import org.opencdmp.data.PrefillingSourceEntity; import org.opencdmp.data.ReferenceTypeEntity; import org.opencdmp.data.TenantEntityManager; import org.opencdmp.errorcode.ErrorThesaurusProperties; @@ -564,7 +565,11 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { private BlueprintPrefillingSourceImportExport prefillingSourceXmlToExport(UUID id) { BlueprintPrefillingSourceImportExport xml = new BlueprintPrefillingSourceImportExport(); + PrefillingSourceEntity data = this.queryFactory.query(PrefillingSourceQuery.class).disableTracking().ids(id).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._code)); + if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale())); + xml.setId(id); + xml.setCode(data.getCode()); return xml; } @@ -729,7 +734,10 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { private UUID xmlPrefillingSourceToPersist(BlueprintPrefillingSourceImportExport importXml) { org.opencdmp.data.PrefillingSourceEntity data = importXml.getId() != null ? this.queryFactory.query(PrefillingSourceQuery.class).disableTracking().ids(importXml.getId()).disableTracking().firstAs(new BaseFieldSet().ensure(PrefillingSource._id)) : null; - if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{importXml.getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (data == null) { + if (!this.conventionService.isNullOrEmpty(importXml.getCode())) data = this.queryFactory.query(PrefillingSourceQuery.class).disableTracking().codes(importXml.getCode()).disableTracking().firstAs(new BaseFieldSet().ensure(PrefillingSource._id)); + if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{importXml.getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); + } return data.getId(); } diff --git a/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java index 1da2a89de..c809e79ba 100644 --- a/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java @@ -142,6 +142,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { data.setCreatedAt(Instant.now()); } + data.setCode(model.getCode()); data.setLabel(model.getLabel()); data.setDefinition(this.xmlHandlingService.toXml(this.buildDefinitionEntity(model.getDefinition()))); data.setUpdatedAt(Instant.now()); @@ -151,6 +152,9 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { this.entityManager.flush(); + Long prefillingSourcesWithThisCode = this.queryFactory.query(PrefillingSourceQuery.class).codes(data.getCode()).count(); + if (prefillingSourcesWithThisCode > 1) throw new MyValidationException(this.errors.getPrefillingSourceCodeExists().getCode(), this.errors.getPrefillingSourceCodeExists().getMessage()); + return this.builderFactory.builder(PrefillingSourceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, PrefillingSource._id), data); } diff --git a/backend/core/src/main/java/org/opencdmp/service/referencetype/ReferenceTypeServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/referencetype/ReferenceTypeServiceImpl.java index 0596fcc1b..baa7151d3 100644 --- a/backend/core/src/main/java/org/opencdmp/service/referencetype/ReferenceTypeServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/referencetype/ReferenceTypeServiceImpl.java @@ -3,6 +3,7 @@ package org.opencdmp.service.referencetype; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.deleter.DeleterFactory; +import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyForbiddenException; import gr.cite.tools.exception.MyNotFoundException; @@ -32,6 +33,7 @@ import org.opencdmp.model.persist.externalfetcher.*; import org.opencdmp.model.persist.referencetypedefinition.ReferenceTypeDefinitionPersist; import org.opencdmp.model.persist.referencetypedefinition.ReferenceTypeFieldPersist; import org.opencdmp.model.referencetype.ReferenceType; +import org.opencdmp.query.ReferenceTypeQuery; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; @@ -56,12 +58,12 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService { private final MessageSource messageSource; private final XmlHandlingService xmlHandlingService; private final ErrorThesaurusProperties errors; - + private final QueryFactory queryFactory; public ReferenceTypeServiceImpl( - TenantEntityManager entityManager, AuthorizationService authorizationService, DeleterFactory deleterFactory, BuilderFactory builderFactory, - ConventionService conventionService, MessageSource messageSource, - XmlHandlingService xmlHandlingService, ErrorThesaurusProperties errors) { + TenantEntityManager entityManager, AuthorizationService authorizationService, DeleterFactory deleterFactory, BuilderFactory builderFactory, + ConventionService conventionService, MessageSource messageSource, + XmlHandlingService xmlHandlingService, ErrorThesaurusProperties errors, QueryFactory queryFactory) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -70,6 +72,7 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService { this.messageSource = messageSource; this.xmlHandlingService = xmlHandlingService; this.errors = errors; + this.queryFactory = queryFactory; } @@ -103,6 +106,9 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService { else this.entityManager.persist(data); this.entityManager.flush(); + + Long referenceTypesWithThisCode = this.queryFactory.query(ReferenceTypeQuery.class).codes(data.getCode()).count(); + if (referenceTypesWithThisCode > 1) throw new MyValidationException(this.errors.getReferenceTypeCodeExists().getCode(), this.errors.getReferenceTypeCodeExists().getMessage()); return this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, ReferenceType._id), data); } diff --git a/backend/web/src/main/resources/config/errors.yml b/backend/web/src/main/resources/config/errors.yml index c7cc8161c..08b179d3c 100644 --- a/backend/web/src/main/resources/config/errors.yml +++ b/backend/web/src/main/resources/config/errors.yml @@ -106,4 +106,10 @@ error-thesaurus: message: Already created draft for this description template dmpBlueprintNewVersionAlreadyCreatedDraft: code: 139 - message: Already created draft for this blueprint \ No newline at end of file + message: Already created draft for this blueprint + referenceTypeCodeExists: + code: 140 + message: Reference type exists + prefillingSourceCodeExists: + code: 141 + message: Prefilling source code exists \ No newline at end of file diff --git a/dmp-db-scema/updates/00.01.057_Add_PrefillingSource_table.sql b/dmp-db-scema/updates/00.01.057_Add_PrefillingSource_table.sql index f65d6eb01..a6a0f390d 100644 --- a/dmp-db-scema/updates/00.01.057_Add_PrefillingSource_table.sql +++ b/dmp-db-scema/updates/00.01.057_Add_PrefillingSource_table.sql @@ -8,6 +8,7 @@ BEGIN ( id uuid NOT NULL, label character varying(250) NOT NULL, + code character varying(100) NOT NULL, definition xml NOT NULL, is_active smallint NOT NULL, created_at timestamp without time zone NOT NULL, diff --git a/dmp-db-scema/updates/00.01.060_Insert_values.sql b/dmp-db-scema/updates/00.01.060_Insert_values.sql index f2eba512e..ca54824ce 100644 --- a/dmp-db-scema/updates/00.01.060_Insert_values.sql +++ b/dmp-db-scema/updates/00.01.060_Insert_values.sql @@ -16,8 +16,8 @@ BEGIN INSERT INTO public."Language" VALUES ('110d2e49-1580-4ee3-b1df-84da966f97a8', 'pt', null, '2024-02-29 16:35:18.114652', '2024-02-29 16:35:18.114652', 1, 9, null); INSERT INTO public."Language" VALUES ('3b865f61-a863-43de-98cd-da86fc3f5940', 'pl', null, '2024-02-29 16:35:18.114652', '2024-02-29 16:35:18.114652', 1, 10, null); - INSERT INTO public."PrefillingSource" VALUES ('7a1ef5db-8833-45e1-85d8-476cea3d4f7a', 'OpenAIRE', 'openaire10falseapplication/jsonremote00$[''meta''][''pagination''][''page'',''pages'',''count'']{like}likereference_idoriginalId.first()labeltitle..content.first()descriptiondescriptiontitle.content[''title''][''content'']children.instance.license[''children''][''instance''][''license'']subject.content[''subject''][*][''content'']publisherpublisherlanguage.classid[''language''][''classid'']issued.content[''issued''][''content'']bestaccessright.classid[''bestaccessright''][''classid'']pid.content[''pid''][0][''content'']pid.classid[''pid''][0][''classid'']$[''results''][*][''result''][''metadata''][''oaf:entity''][''oaf:result'']https://services.openaire.eu/search/v2/api/datasets/?q={like}&page={page}&size={pageSize}&format=jsontitle.contentrda.dataset.distribution.titlelabeldescriptionrda.dataset.distribution.descriptiondescriptionchildren.instance.licenserda.dataset.distribution.license.license_refsubject.contentrda.dataset.keyworddescriptionTagspublisherrda.dataset.distribution.host.titlelanguage.classidrda.dataset.metadata.languageissued.contentrda.dataset.issuedbestaccessright.classidrda.dataset.distribution.data_accesspid.contentrda.dataset.dataset_idpid.contentrda.dataset.dataset_id.identifierpid.classidrda.dataset.dataset_id.type', 1, '2024-02-28 09:12:41.051733', '2024-05-01 13:12:52.96103', NULL); - INSERT INTO public."PrefillingSource" VALUES ('d79952bf-cfd9-4af4-b7b4-5a83d68890a5', 'Zenodo', 'zenodo search20falseapplication/jsonremote10$[''hits''][''total'']{like}likereference_ididlabeltitledescription[''metadata''][''description'']$[''hits''][''hits'']https://zenodo.org/api/records/?page={page}&size={pageSize}&q=title:"{like}" doi:"{like}" conceptdoi:"{like}"zenodo get10falseapplication/jsonremote0${like}likemetadata.title[''metadata''][''title'']metadata.description[''metadata''][''description'']metadata.license.id[''metadata''][''license''][''id'']metadata.keywords[''metadata''][''keywords'']metadata.filesize[''metadata''][''files''][0][''size'']metadata.language[''metadata''][''language'']metadata.dates.valid[''metadata''][''dates''][''type'']metadata.license.created[''metadata''][''license''][''created'']metadata.embargo_date[''metadata''][''embargo_date'']metadata.publication_date[''metadata''][''publication_date'']metadata.access_right[''metadata''][''access_right'']files[''files''][0][''key'']doidoi$https://zenodo.org/api/records/{like}metadata.titlerda.dataset.distribution.titlelabelmetadata.descriptionrda.dataset.distribution.descriptiondescriptionmetadata.license.idrda.dataset.distribution.license.license_refmetadata.keywordsrda.dataset.keyworddescriptionTagsmetadata.filesizerda.dataset.distribution.byte_sizemetadata.languagerda.dataset.metadata.languagemetadata.dates.validrda.dataset.distribution.available_untilmetadata.license.createdrda.dataset.distribution.license.start_datemetadata.embargo_daterda.dataset.distribution.license.start_datemetadata.publication_daterda.dataset.issuedmetadata.access_rightrda.dataset.distribution.data_accessfilesrda.dataset.distribution.format^.*\.doirda.dataset.dataset_iddoirda.dataset.dataset_id.identifierZenodorda.dataset.distribution.host.titleMore than 99% uptime yearlyrda.dataset.distribution.host.availabilityCHrda.dataset.distribution.host.geo_locationAll files uploaded to Zenodo are stored in CERN’s EOS service in an 18 petabytes disk cluster.rda.dataset.distribution.host.storage_typedoirda.dataset.dataset_id.typehttps://schema.datacite.org/meta/kernel-4.4/rda.dataset.metadata.metadata_standard_id.identifierurlrda.dataset.metadata.metadata_standard_id.typeengrda.dataset.metadata.languageDataCite Metadata Schemarda.dataset.metadata.descriptionHourlyrda.dataset.distribution.host.backup_frequencyIncremental backuprda.dataset.distribution.host.backup_typeRepository hosted by Zenodorda.dataset.distribution.host.descriptionhttps://zenodo.orgrda.dataset.distribution.host.urldoirda.dataset.distribution.host.pid_system', 1, '2024-02-28 10:20:50.570055', '2024-05-01 13:11:21.83541', NULL); + INSERT INTO public."PrefillingSource" VALUES ('7a1ef5db-8833-45e1-85d8-476cea3d4f7a', 'OpenAIRE', 'openaire', 'openaire10falseapplication/jsonremote00$[''meta''][''pagination''][''page'',''pages'',''count'']{like}likereference_idoriginalId.first()labeltitle..content.first()descriptiondescriptiontitle.content[''title''][''content'']children.instance.license[''children''][''instance''][''license'']subject.content[''subject''][*][''content'']publisherpublisherlanguage.classid[''language''][''classid'']issued.content[''issued''][''content'']bestaccessright.classid[''bestaccessright''][''classid'']pid.content[''pid''][0][''content'']pid.classid[''pid''][0][''classid'']$[''results''][*][''result''][''metadata''][''oaf:entity''][''oaf:result'']https://services.openaire.eu/search/v2/api/datasets/?q={like}&page={page}&size={pageSize}&format=jsontitle.contentrda.dataset.distribution.titlelabeldescriptionrda.dataset.distribution.descriptiondescriptionchildren.instance.licenserda.dataset.distribution.license.license_refsubject.contentrda.dataset.keyworddescriptionTagspublisherrda.dataset.distribution.host.titlelanguage.classidrda.dataset.metadata.languageissued.contentrda.dataset.issuedbestaccessright.classidrda.dataset.distribution.data_accesspid.contentrda.dataset.dataset_idpid.contentrda.dataset.dataset_id.identifierpid.classidrda.dataset.dataset_id.type', 1, '2024-02-28 09:12:41.051733', '2024-05-01 13:12:52.96103', NULL); + INSERT INTO public."PrefillingSource" VALUES ('d79952bf-cfd9-4af4-b7b4-5a83d68890a5', 'Zenodo', 'zenodo', 'zenodo search20falseapplication/jsonremote10$[''hits''][''total'']{like}likereference_ididlabeltitledescription[''metadata''][''description'']$[''hits''][''hits'']https://zenodo.org/api/records/?page={page}&size={pageSize}&q=title:"{like}" doi:"{like}" conceptdoi:"{like}"zenodo get10falseapplication/jsonremote0${like}likemetadata.title[''metadata''][''title'']metadata.description[''metadata''][''description'']metadata.license.id[''metadata''][''license''][''id'']metadata.keywords[''metadata''][''keywords'']metadata.filesize[''metadata''][''files''][0][''size'']metadata.language[''metadata''][''language'']metadata.dates.valid[''metadata''][''dates''][''type'']metadata.license.created[''metadata''][''license''][''created'']metadata.embargo_date[''metadata''][''embargo_date'']metadata.publication_date[''metadata''][''publication_date'']metadata.access_right[''metadata''][''access_right'']files[''files''][0][''key'']doidoi$https://zenodo.org/api/records/{like}metadata.titlerda.dataset.distribution.titlelabelmetadata.descriptionrda.dataset.distribution.descriptiondescriptionmetadata.license.idrda.dataset.distribution.license.license_refmetadata.keywordsrda.dataset.keyworddescriptionTagsmetadata.filesizerda.dataset.distribution.byte_sizemetadata.languagerda.dataset.metadata.languagemetadata.dates.validrda.dataset.distribution.available_untilmetadata.license.createdrda.dataset.distribution.license.start_datemetadata.embargo_daterda.dataset.distribution.license.start_datemetadata.publication_daterda.dataset.issuedmetadata.access_rightrda.dataset.distribution.data_accessfilesrda.dataset.distribution.format^.*\.doirda.dataset.dataset_iddoirda.dataset.dataset_id.identifierZenodorda.dataset.distribution.host.titleMore than 99% uptime yearlyrda.dataset.distribution.host.availabilityCHrda.dataset.distribution.host.geo_locationAll files uploaded to Zenodo are stored in CERN’s EOS service in an 18 petabytes disk cluster.rda.dataset.distribution.host.storage_typedoirda.dataset.dataset_id.typehttps://schema.datacite.org/meta/kernel-4.4/rda.dataset.metadata.metadata_standard_id.identifierurlrda.dataset.metadata.metadata_standard_id.typeengrda.dataset.metadata.languageDataCite Metadata Schemarda.dataset.metadata.descriptionHourlyrda.dataset.distribution.host.backup_frequencyIncremental backuprda.dataset.distribution.host.backup_typeRepository hosted by Zenodorda.dataset.distribution.host.descriptionhttps://zenodo.orgrda.dataset.distribution.host.urldoirda.dataset.distribution.host.pid_system', 1, '2024-02-28 10:20:50.570055', '2024-05-01 13:11:21.83541', NULL); INSERT INTO public."ReferenceType" VALUES ('2baab1e8-561f-4c15-84c3-571b811c52f6', 'Licenses', 'licenses', 'opendefinition100falseapplication/vnd.api+json; charset=utf-8local10$[*]reference_ididlabeltitledescriptionmaintaineruriurl$[*]https://licenses.opendefinition.org/licenses/groups/all.json', 1, '2023-11-16 16:24:12.162675', '2024-04-29 08:41:29.944368', NULL); INSERT INTO public."ReferenceType" VALUES ('2beacaad-3223-43ad-ad99-1e5f21328e7b', 'Registries', 'registries', 'rda-metadata-schemes100falseapplication/json; charset=utf-8remote10$[''meta''][''pagination''][''page'',''pages'',''count'']{like}likereference_idmscidlabeltitledescriptiondescriptionurluri$[''data''][''items''][*]https://rdamsc.bath.ac.uk/api2/m?q={like}&start=1&pageSize={pageSize}', 1, '2023-11-16 10:08:21.240804', '2024-02-16 09:16:50.456347', NULL); diff --git a/dmp-frontend/src/app/core/common/enum/respone-error-code.ts b/dmp-frontend/src/app/core/common/enum/respone-error-code.ts index 24ed73f81..ef94dfcb2 100644 --- a/dmp-frontend/src/app/core/common/enum/respone-error-code.ts +++ b/dmp-frontend/src/app/core/common/enum/respone-error-code.ts @@ -37,6 +37,8 @@ export enum ResponseErrorCode { DuplicateDmpUser = 137, DescriptionTemplateNewVersionAlreadyCreatedDraft = 138, DmpBlueprintNewVersionAlreadyCreatedDraft = 139, + ReferenceTypeCodeExists = 140, + PrefillingSourceCodeExists = 141, // Notification & Annotation Errors InvalidApiKey = 200, @@ -138,9 +140,13 @@ export class ResponseErrorCodeHelper { case ResponseErrorCode.OverlappingTenantConfigurationNotifierList: return language.instant("GENERAL.BACKEND-ERRORS.OVERLAPPING-TENANT-CONFIGURATION-NOTIFIER-LIST"); case ResponseErrorCode.DescriptionTemplateNewVersionAlreadyCreatedDraft: - return language.instant("DESCRIPTION-TEMPLATE-NEW-VERSION-ALREADY-CREATED-DRAFT"); + return language.instant("GENERAL.BACKEND-ERRORS.DESCRIPTION-TEMPLATE-NEW-VERSION-ALREADY-CREATED-DRAFT"); case ResponseErrorCode.DmpBlueprintNewVersionAlreadyCreatedDraft: return language.instant("GENERAL.BACKEND-ERRORS.DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT"); + case ResponseErrorCode.ReferenceTypeCodeExists: + return language.instant("GENERAL.BACKEND-ERRORS.REFERENCE-TYPE-CODE-EXISTS"); + case ResponseErrorCode.PrefillingSourceCodeExists: + return language.instant("GENERAL.BACKEND-ERRORS.PREFILLING-SOURCE-CODE-EXISTS"); default: return language.instant("GENERAL.SNACK-BAR.NOT-FOUND"); } diff --git a/dmp-frontend/src/app/core/model/prefilling-source/prefilling-source.ts b/dmp-frontend/src/app/core/model/prefilling-source/prefilling-source.ts index 4b888c7a8..7ad9186e6 100644 --- a/dmp-frontend/src/app/core/model/prefilling-source/prefilling-source.ts +++ b/dmp-frontend/src/app/core/model/prefilling-source/prefilling-source.ts @@ -3,6 +3,7 @@ import { ExternalFetcherBaseSourceConfiguration, ExternalFetcherBaseSourceConfig export interface PrefillingSource extends BaseEntity{ label: string; + code: string; definition: PrefillingSourceDefinition; } @@ -39,6 +40,7 @@ export interface Prefilling { export interface PrefillingSourcePersist extends BaseEntityPersist{ label: string; + code: string; definition: PrefillingSourceDefinitionPersist; } diff --git a/dmp-frontend/src/app/core/query/prefilling-source.lookup.ts b/dmp-frontend/src/app/core/query/prefilling-source.lookup.ts index 154fb871d..2c6db104b 100644 --- a/dmp-frontend/src/app/core/query/prefilling-source.lookup.ts +++ b/dmp-frontend/src/app/core/query/prefilling-source.lookup.ts @@ -7,6 +7,7 @@ export class PrefillingSourceLookup extends Lookup implements PrefillingSourceFi excludedIds: Guid[]; like: string; isActive: IsActive[]; + codes: string[]; constructor() { super(); @@ -18,4 +19,5 @@ export interface PrefillingSourceFilter { excludedIds: Guid[]; like: string; isActive: IsActive[]; -} \ No newline at end of file + codes: string[]; +} diff --git a/dmp-frontend/src/app/ui/admin/dmp-blueprint/editor/dmp-blueprint-editor.resolver.ts b/dmp-frontend/src/app/ui/admin/dmp-blueprint/editor/dmp-blueprint-editor.resolver.ts index 67be7678a..aee5fab9d 100644 --- a/dmp-frontend/src/app/ui/admin/dmp-blueprint/editor/dmp-blueprint-editor.resolver.ts +++ b/dmp-frontend/src/app/ui/admin/dmp-blueprint/editor/dmp-blueprint-editor.resolver.ts @@ -51,6 +51,7 @@ export class DmpBlueprintEditorResolver extends BaseEditorResolver { [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.prefillingSources), nameof(x => x.id)].join('.'), [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.prefillingSources), nameof(x => x.label)].join('.'), + [nameof(x => x.definition), nameof(x => x.sections), nameof(x => x.prefillingSources), nameof(x => x.code)].join('.'), nameof(x => x.createdAt), nameof(x => x.hash), diff --git a/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.html b/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.html index 2f68fc21e..69fbe4abe 100644 --- a/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.html +++ b/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.html @@ -30,7 +30,7 @@
-
+
{{'PREFILLING-SOURCE-EDITOR.FIELDS.LABEL' | translate}} @@ -38,6 +38,14 @@ {{'GENERAL.VALIDATION.REQUIRED' | translate}}
+
+ + {{'REFILLING-SOURCE-EDITOR.FIELDS.CODE' | translate}} + + {{formGroup.get('code').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
diff --git a/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.model.ts b/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.model.ts index a399ce34e..4ac23f4a5 100644 --- a/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.model.ts +++ b/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.model.ts @@ -9,6 +9,7 @@ import { Validation, ValidationContext } from "@common/forms/validation/validati export class PrefillingSourceEditorModel extends BaseEditorModel implements PrefillingSourcePersist { label: string; + code: string; definition: PrefillingSourceDefinitionEditorModel = new PrefillingSourceDefinitionEditorModel(this.validationErrorModel); permissions: string[]; @@ -21,7 +22,8 @@ export class PrefillingSourceEditorModel extends BaseEditorModel implements Pref if (item) { super.fromModel(item); this.label = item.label; - if (item.definition) this.definition = new PrefillingSourceDefinitionEditorModel(this.validationErrorModel).fromModel(item.definition); + this.code = item.code; + if (item.definition) this.definition = new PrefillingSourceDefinitionEditorModel(this.validationErrorModel).fromModel(item.definition); } return this; } @@ -32,9 +34,10 @@ export class PrefillingSourceEditorModel extends BaseEditorModel implements Pref return this.formBuilder.group({ id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators], label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators], + code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators], definition: this.definition.buildForm({ rootPath: `definition.`, - }), + }), hash: [{ value: this.hash, disabled: disabled }, context.getValidation('hash').validators] }); } @@ -44,6 +47,7 @@ export class PrefillingSourceEditorModel extends BaseEditorModel implements Pref const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'id', validators: [BackendErrorValidator(this.validationErrorModel, 'id')] }); baseValidationArray.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'label')] }); + baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'code')] }); baseValidationArray.push({ key: 'definition', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'definition')] }); baseValidationArray.push({ key: 'hash', validators: [] }); @@ -93,9 +97,9 @@ export class PrefillingSourceDefinitionEditorModel implements PrefillingSourceDe if (item) { if (item.fields) { item.fields.map(x => this.fields.push(new PrefillingSourceDefinitionFieldEditorModel(this.validationErrorModel).fromModel(x))); } if (item.fixedValueFields) { item.fixedValueFields.map(x => this.fixedValueFields.push(new PrefillingSourceDefinitionFixedValueFieldEditorModel(this.validationErrorModel).fromModel(x))); } - if (item.searchConfiguration) this.searchConfiguration = new ExternalFetcherBaseSourceConfigurationEditorModel(this.validationErrorModel).fromModel(item.searchConfiguration); + if (item.searchConfiguration) this.searchConfiguration = new ExternalFetcherBaseSourceConfigurationEditorModel(this.validationErrorModel).fromModel(item.searchConfiguration); if (item.getConfiguration) { - this.getConfiguration = new ExternalFetcherBaseSourceConfigurationEditorModel(this.validationErrorModel).fromModel(item.getConfiguration); + this.getConfiguration = new ExternalFetcherBaseSourceConfigurationEditorModel(this.validationErrorModel).fromModel(item.getConfiguration); this.getEnabled = true; } } @@ -152,7 +156,7 @@ export class PrefillingSourceDefinitionEditorModel implements PrefillingSourceDe .buildForm({ rootPath: `${rootPath}getConfiguration.` })); - + } static createValidationContext(params: { diff --git a/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.resolver.ts b/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.resolver.ts index 0a31316a4..fe5e2a0f8 100644 --- a/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.resolver.ts +++ b/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.resolver.ts @@ -21,12 +21,13 @@ export class PrefillingSourceEditorResolver extends BaseEditorResolver { ...BaseEditorResolver.lookupFields(), nameof(x => x.id), nameof(x => x.label), + nameof(x => x.code), [nameof(x => x.definition), nameof(x => x.fields), nameof(x => x.code)].join('.'), [nameof(x => x.definition), nameof(x => x.fields), nameof(x => x.systemFieldTarget)].join('.'), [nameof(x => x.definition), nameof(x => x.fields), nameof(x => x.semanticTarget)].join('.'), [nameof(x => x.definition), nameof(x => x.fields), nameof(x => x.trimRegex)].join('.'), - + [nameof(x => x.definition), nameof(x => x.fixedValueFields), nameof(x => x.systemFieldTarget)].join('.'), [nameof(x => x.definition), nameof(x => x.fixedValueFields), nameof(x => x.semanticTarget)].join('.'), [nameof(x => x.definition), nameof(x => x.fixedValueFields), nameof(x => x.trimRegex)].join('.'), diff --git a/dmp-frontend/src/app/ui/admin/prefilling-source/listing/prefilling-source-listing.component.ts b/dmp-frontend/src/app/ui/admin/prefilling-source/listing/prefilling-source-listing.component.ts index 3f23fae68..06e7064fc 100644 --- a/dmp-frontend/src/app/ui/admin/prefilling-source/listing/prefilling-source-listing.component.ts +++ b/dmp-frontend/src/app/ui/admin/prefilling-source/listing/prefilling-source-listing.component.ts @@ -39,6 +39,7 @@ export class PrefillingSourceListingComponent extends BaseListingComponent(x => x.id), nameof(x => x.label), + nameof(x => x.code), nameof(x => x.updatedAt), nameof(x => x.createdAt), nameof(x => x.hash), @@ -91,6 +92,10 @@ export class PrefillingSourceListingComponent extends BaseListingComponent(x => x.label), sortable: true, languageName: 'PREFILLING-SOURCE-LISTING.FIELDS.LABEL' + },{ + prop: nameof(x => x.code), + sortable: true, + languageName: 'PREFILLING-SOURCE-LISTING.FIELDS.CODE' }, { prop: nameof(x => x.createdAt), diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index 227576285..4b9d9c26c 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -79,6 +79,8 @@ "DMP-MISSING-USER-CONTACT-INFO": "This plan contains users that don't have contact info", "DESCRIPTION-TEMPLATE-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this description template.", "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", + "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", + "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" }, "FORM-VALIDATION-DISPLAY-DIALOG": { @@ -1068,6 +1070,7 @@ "CREATE": "Create Prefilling Source", "FIELDS": { "LABEL": "Label", + "CODE": "Code", "UPDATED-AT": "Updated", "CREATED-AT": "Created", "IS-ACTIVE": "Is Active"