diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/importexport/fielddata/ReferenceTypeDataImportExport.java b/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/importexport/fielddata/ReferenceTypeDataImportExport.java index 45940cd93..e8bdd5e20 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/importexport/fielddata/ReferenceTypeDataImportExport.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/importexport/fielddata/ReferenceTypeDataImportExport.java @@ -17,6 +17,9 @@ public class ReferenceTypeDataImportExport extends BaseFieldDataImportExport { @XmlElement(name = "referenceTypeId") private UUID referenceTypeId; + @XmlElement(name = "referenceTypeName") + private String referenceTypeName; + @XmlElement(name = "referenceTypeCode") private String referenceTypeCode; @@ -43,4 +46,12 @@ public class ReferenceTypeDataImportExport extends BaseFieldDataImportExport { public void setReferenceTypeCode(String referenceTypeCode) { this.referenceTypeCode = referenceTypeCode; } + + public String getReferenceTypeName() { + return referenceTypeName; + } + + public void setReferenceTypeName(String referenceTypeName) { + this.referenceTypeName = referenceTypeName; + } } 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 0273b3bda..aad918df2 100644 --- a/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java +++ b/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java @@ -428,4 +428,14 @@ public class ErrorThesaurusProperties { public void setDescriptionTemplateTypeImportNotFound(ErrorDescription descriptionTemplateTypeImportNotFound) { this.descriptionTemplateTypeImportNotFound = descriptionTemplateTypeImportNotFound; } + + private ErrorDescription referenceTypeImportNotFound; + + public ErrorDescription getReferenceTypeImportNotFound() { + return referenceTypeImportNotFound; + } + + public void setReferenceTypeImportNotFound(ErrorDescription referenceTypeImportNotFound) { + this.referenceTypeImportNotFound = referenceTypeImportNotFound; + } } diff --git a/backend/core/src/main/java/org/opencdmp/service/fielddatahelper/ReferenceTypeFieldDataHelperService.java b/backend/core/src/main/java/org/opencdmp/service/fielddatahelper/ReferenceTypeFieldDataHelperService.java index 767df771e..dc1f6d93d 100644 --- a/backend/core/src/main/java/org/opencdmp/service/fielddatahelper/ReferenceTypeFieldDataHelperService.java +++ b/backend/core/src/main/java/org/opencdmp/service/fielddatahelper/ReferenceTypeFieldDataHelperService.java @@ -3,6 +3,7 @@ package org.opencdmp.service.fielddatahelper; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyNotFoundException; +import gr.cite.tools.exception.MyValidationException; import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.validation.Validator; @@ -13,6 +14,7 @@ import org.opencdmp.commons.types.descriptiontemplate.fielddata.ReferenceTypeDat import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.ReferenceTypeDataImportExport; import org.opencdmp.convention.ConventionService; import org.opencdmp.data.ReferenceTypeEntity; +import org.opencdmp.errorcode.ErrorThesaurusProperties; import org.opencdmp.model.builder.commonmodels.descriptiontemplate.fielddata.ReferenceTypeDataCommonModelBuilder; import org.opencdmp.model.builder.descriptiontemplate.fielddata.ReferenceTypeDataBuilder; import org.opencdmp.model.descriptiontemplate.fielddata.ReferenceTypeData; @@ -33,14 +35,16 @@ public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperServ private final QueryFactory queryFactory; private final ConventionService conventionService; private final MessageSource messageSource; + private final ErrorThesaurusProperties errors; private final ValidatorFactory validatorFactory; - public ReferenceTypeFieldDataHelperService(BuilderFactory builderFactory, QueryFactory queryFactory, ConventionService conventionService, MessageSource messageSource, ValidatorFactory validatorFactory) { + public ReferenceTypeFieldDataHelperService(BuilderFactory builderFactory, QueryFactory queryFactory, ConventionService conventionService, MessageSource messageSource, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory) { this.builderFactory = builderFactory; this.queryFactory = queryFactory; this.conventionService = conventionService; this.messageSource = messageSource; - this.validatorFactory = validatorFactory; + this.errors = errors; + this.validatorFactory = validatorFactory; } @Override @@ -118,7 +122,7 @@ public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperServ ReferenceTypeEntity referenceTypeEntity = data.getReferenceTypeId() != null ? this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().ids(data.getReferenceTypeId()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._id)) : null; if (referenceTypeEntity == null){ if (!this.conventionService.isNullOrEmpty(data.getReferenceTypeCode())) referenceTypeEntity = this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().codes(data.getReferenceTypeCode()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._id)); - if (referenceTypeEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getReferenceTypeId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (referenceTypeEntity == null) throw new MyValidationException(this.errors.getReferenceTypeImportNotFound().getCode(), !this.conventionService.isNullOrEmpty(data.getReferenceTypeCode()) ? data.getReferenceTypeCode() : data.getReferenceTypeName()); } persist.setMultipleSelect(data.getMultipleSelect()); persist.setReferenceTypeId(referenceTypeEntity.getId()); @@ -130,7 +134,7 @@ public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperServ ReferenceTypeEntity referenceTypeEntity = data.getReferenceType() != null && data.getReferenceType().getId() != null ? this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().ids(data.getReferenceType().getId()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._id)) : null; if (referenceTypeEntity == null){ if (!this.conventionService.isNullOrEmpty(data.getReferenceType().getCode())) referenceTypeEntity = this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().codes(data.getReferenceType().getCode()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._id)); - if (referenceTypeEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getReferenceType().getId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (referenceTypeEntity == null) throw new MyValidationException(this.errors.getReferenceTypeImportNotFound().getCode(), data.getReferenceType() != null ? data.getReferenceType().getCode() : this.errors.getReferenceTypeImportNotFound().getMessage()); } persist.setMultipleSelect(data.getMultipleSelect()); persist.setReferenceTypeId(referenceTypeEntity.getId()); @@ -139,11 +143,12 @@ public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperServ @Override protected ReferenceTypeDataImportExport dataToImportExportXmlInternal(ReferenceTypeDataEntity data, ReferenceTypeDataImportExport xml) { - ReferenceTypeEntity referenceTypeEntity = this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().ids(data.getReferenceTypeId()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._code)); + ReferenceTypeEntity referenceTypeEntity = this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().ids(data.getReferenceTypeId()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._code).ensure(ReferenceType._name)); if (referenceTypeEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getReferenceTypeId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale())); xml.setMultipleSelect(data.getMultipleSelect()); xml.setReferenceTypeCode(referenceTypeEntity.getCode()); + xml.setReferenceTypeName(referenceTypeEntity.getName()); xml.setReferenceTypeId(data.getReferenceTypeId()); return xml; } diff --git a/backend/web/src/main/resources/config/errors.yml b/backend/web/src/main/resources/config/errors.yml index e3c437efb..105b1ea6d 100644 --- a/backend/web/src/main/resources/config/errors.yml +++ b/backend/web/src/main/resources/config/errors.yml @@ -133,4 +133,7 @@ error-thesaurus: message: Description template type code exists descriptionTemplateTypeImportNotFound: code: 148 - message: Description template type not found \ No newline at end of file + message: Description template type not found + referenceTypeImportNotFound: + code: 149 + message: Reference type not found \ No newline at end of file diff --git a/frontend/src/app/core/common/enum/respone-error-code.ts b/frontend/src/app/core/common/enum/respone-error-code.ts index 1d8032689..02164ba42 100644 --- a/frontend/src/app/core/common/enum/respone-error-code.ts +++ b/frontend/src/app/core/common/enum/respone-error-code.ts @@ -44,6 +44,7 @@ export enum ResponseErrorCode { UsageLimitMetricAlreadyExists = 146, DescriptionTemplateTypeCodeExists = 147, descriptionTemplateTypeImportNotFound = 148, + referenceTypeImportNotFound = 149, // Notification & Annotation Errors InvalidApiKey = 200, @@ -166,6 +167,8 @@ export class ResponseErrorCodeHelper { return language.instant("GENERAL.BACKEND-ERRORS.DESCRIPTION-TEMPLATE-TYPE-CODE-EXISTS"); case ResponseErrorCode.descriptionTemplateTypeImportNotFound: return language.instant("GENERAL.BACKEND-ERRORS.DESCRIPTION-TEMPLATE-TYPE-IMPORT-NOT-FOUND"); + case ResponseErrorCode.referenceTypeImportNotFound: + return language.instant("GENERAL.BACKEND-ERRORS.REFERENCE-TYPE-IMPORT-NOT-FOUND"); default: return language.instant("GENERAL.SNACK-BAR.NOT-FOUND"); } diff --git a/frontend/src/assets/i18n/en.json b/frontend/src/assets/i18n/en.json index 0b959ce66..65a6ac402 100644 --- a/frontend/src/assets/i18n/en.json +++ b/frontend/src/assets/i18n/en.json @@ -83,7 +83,8 @@ "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant.", "DESCRIPTION-TEMPLATE-TYPE-CODE-EXISTS": "The description template type code you provided already exists. Please choose a different code.", - "DESCRIPTION-TEMPLATE-TYPE-IMPORT-NOT-FOUND": "Description template type {{descriptionTemplateTypeLabel}} not found." + "DESCRIPTION-TEMPLATE-TYPE-IMPORT-NOT-FOUND": "Description template type {{descriptionTemplateTypeLabel}} not found.", + "REFERENCE-TYPE-IMPORT-NOT-FOUND": "Reference type {{referenceTypeCode}} not found." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Warning!", diff --git a/frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts b/frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts index ce3437b6f..542a5a881 100644 --- a/frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts +++ b/frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts @@ -21,6 +21,8 @@ export class HttpErrorHandlingService { this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.BACKEND-ERRORS.USAGE-LIMIT-EXCEPTION', { 'usageLimitLabel': errorResponse.error.error }), SnackBarNotificationLevel.Error); } if (errorResponse.error.code === ResponseErrorCode.descriptionTemplateTypeImportNotFound){ this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.BACKEND-ERRORS.DESCRIPTION-TEMPLATE-TYPE-IMPORT-NOT-FOUND', { 'descriptionTemplateTypeLabel': errorResponse.error.error }), SnackBarNotificationLevel.Error); + } if (errorResponse.error.code === ResponseErrorCode.referenceTypeImportNotFound){ + this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.BACKEND-ERRORS.REFERENCE-TYPE-IMPORT-NOT-FOUND', { 'referenceTypeCode': errorResponse.error.error }), SnackBarNotificationLevel.Error); } else { this.uiNotificationService.snackBarNotification(ResponseErrorCodeHelper.getErrorMessageByBackendStatusCode(errorResponse.error.code, this.language), SnackBarNotificationLevel.Error); }