add code to prefilling source

This commit is contained in:
Efstratios Giannopoulos 2024-06-12 12:42:53 +03:00
parent 89fe30df30
commit 41583745be
24 changed files with 229 additions and 68 deletions

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -58,6 +58,7 @@ public class PrefillingSourceBuilder extends BaseBuilder<PrefillingSource, Prefi
for (PrefillingSourceEntity d : data) {
PrefillingSource m = new PrefillingSource();
if (fields.hasField(this.asIndexer(PrefillingSource._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(PrefillingSource._code))) m.setCode(d.getCode());
if (fields.hasField(this.asIndexer(PrefillingSource._label))) m.setLabel(d.getLabel());
if (!definitionFields.isEmpty() && d.getDefinition() != null){
PrefillingSourceDefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(PrefillingSourceDefinitionEntity.class, d.getDefinition());

View File

@ -1,11 +1,12 @@
package org.opencdmp.model.persist;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.model.persist.prefillingsourcedefinition.PrefillingSourceDefinitionPersist;
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;
import org.opencdmp.model.persist.prefillingsourcedefinition.PrefillingSourceDefinitionPersist;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
@ -24,6 +25,10 @@ public class PrefillingSourcePersist {
public static final String _label = "label";
private String code;
public static final String _code = "code";
private PrefillingSourceDefinitionPersist definition;
public static final String _definition = "definition";
@ -33,15 +38,23 @@ public class PrefillingSourcePersist {
public static final String _hash = "hash";
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 +62,7 @@ public class PrefillingSourcePersist {
}
public PrefillingSourceDefinitionPersist getDefinition() {
return definition;
return this.definition;
}
public void setDefinition(PrefillingSourceDefinitionPersist definition) {
@ -57,7 +70,7 @@ public class PrefillingSourcePersist {
}
public String getHash() {
return hash;
return this.hash;
}
public void setHash(String hash) {
@ -91,17 +104,24 @@ public class PrefillingSourcePersist {
this.spec()
.iff(() -> 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)

View File

@ -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)

View File

@ -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) {

View File

@ -31,6 +31,7 @@ public class PrefillingSourceQuery extends QueryBase<PrefillingSourceEntity> {
private Collection<IsActive> isActives;
private Collection<UUID> excludedIds;
private Collection<String> codes;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@ -55,6 +56,21 @@ public class PrefillingSourceQuery extends QueryBase<PrefillingSourceEntity> {
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<String> 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<PrefillingSourceEntity> {
@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<PrefillingSourceEntity> {
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<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(PrefillingSourceEntity._isActive));
@ -148,6 +166,12 @@ public class PrefillingSourceQuery extends QueryBase<PrefillingSourceEntity> {
notInClause.value(item);
predicates.add(notInClause.not());
}
if (this.codes != null) {
CriteriaBuilder.In<String> 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<PrefillingSourceEntity> {
protected PrefillingSourceEntity convert(Tuple tuple, Set<String> 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<PrefillingSourceEntity> {
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;

View File

@ -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<UUID> excludedIds;
private List<String> 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<IsActive> getIsActive() {
return isActive;
return this.isActive;
}
public void setIsActive(List<IsActive> isActive) {
@ -35,7 +37,7 @@ public class PrefillingSourceLookup extends Lookup {
}
public List<UUID> getIds() {
return ids;
return this.ids;
}
public void setIds(List<UUID> ids) {
@ -43,7 +45,7 @@ public class PrefillingSourceLookup extends Lookup {
}
public List<UUID> getExcludedIds() {
return excludedIds;
return this.excludedIds;
}
public void setExcludedIds(List<UUID> 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);

View File

@ -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) {
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();
}

View File

@ -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);
}

View File

@ -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) {
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;
}
@ -104,6 +107,9 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
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);
}

View File

@ -107,3 +107,9 @@ error-thesaurus:
dmpBlueprintNewVersionAlreadyCreatedDraft:
code: 139
message: Already created draft for this blueprint
referenceTypeCodeExists:
code: 140
message: Reference type exists
prefillingSourceCodeExists:
code: 141
message: Prefilling source code exists

View File

@ -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,

File diff suppressed because one or more lines are too long

View File

@ -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");
}

View File

@ -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;
}

View File

@ -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[];
codes: string[];
}

View File

@ -51,6 +51,7 @@ export class DmpBlueprintEditorResolver extends BaseEditorResolver {
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.prefillingSources), nameof<PrefillingSource>(x => x.id)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.prefillingSources), nameof<PrefillingSource>(x => x.label)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.prefillingSources), nameof<PrefillingSource>(x => x.code)].join('.'),
nameof<DmpBlueprint>(x => x.createdAt),
nameof<DmpBlueprint>(x => x.hash),

View File

@ -30,7 +30,7 @@
<div class="col-12">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'PREFILLING-SOURCE-EDITOR.FIELDS.LABEL' | translate}}</mat-label>
<input matInput type="text" name="label" [formControl]="formGroup.get('label')" required>
@ -38,6 +38,14 @@
<mat-error *ngIf="formGroup.get('label').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFILLING-SOURCE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<input matInput type="text" name="code" [formControl]="formGroup.get('code')" required>
<mat-error *ngIf="formGroup.get('code').hasError('backendError')">{{formGroup.get('code').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('code').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
</div>
</div>

View File

@ -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,6 +22,7 @@ export class PrefillingSourceEditorModel extends BaseEditorModel implements Pref
if (item) {
super.fromModel(item);
this.label = item.label;
this.code = item.code;
if (item.definition) this.definition = new PrefillingSourceDefinitionEditorModel(this.validationErrorModel).fromModel(item.definition);
}
return this;
@ -32,6 +34,7 @@ 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.`,
}),
@ -44,6 +47,7 @@ export class PrefillingSourceEditorModel extends BaseEditorModel implements Pref
const baseValidationArray: Validation[] = new Array<Validation>();
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: [] });

View File

@ -21,6 +21,7 @@ export class PrefillingSourceEditorResolver extends BaseEditorResolver {
...BaseEditorResolver.lookupFields(),
nameof<PrefillingSource>(x => x.id),
nameof<PrefillingSource>(x => x.label),
nameof<PrefillingSource>(x => x.code),
[nameof<PrefillingSource>(x => x.definition), nameof<PrefillingSourceDefinition>(x => x.fields), nameof<PrefillingSourceDefinitionField>(x => x.code)].join('.'),
[nameof<PrefillingSource>(x => x.definition), nameof<PrefillingSourceDefinition>(x => x.fields), nameof<PrefillingSourceDefinitionField>(x => x.systemFieldTarget)].join('.'),

View File

@ -39,6 +39,7 @@ export class PrefillingSourceListingComponent extends BaseListingComponent<Prefi
private readonly lookupFields: string[] = [
nameof<PrefillingSource>(x => x.id),
nameof<PrefillingSource>(x => x.label),
nameof<PrefillingSource>(x => x.code),
nameof<PrefillingSource>(x => x.updatedAt),
nameof<PrefillingSource>(x => x.createdAt),
nameof<PrefillingSource>(x => x.hash),
@ -91,6 +92,10 @@ export class PrefillingSourceListingComponent extends BaseListingComponent<Prefi
prop: nameof<PrefillingSource>(x => x.label),
sortable: true,
languageName: 'PREFILLING-SOURCE-LISTING.FIELDS.LABEL'
},{
prop: nameof<PrefillingSource>(x => x.code),
sortable: true,
languageName: 'PREFILLING-SOURCE-LISTING.FIELDS.CODE'
},
{
prop: nameof<PrefillingSource>(x => x.createdAt),

View File

@ -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"