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 6d9e7a570..0273b3bda 100644 --- a/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java +++ b/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java @@ -418,4 +418,14 @@ public class ErrorThesaurusProperties { public void setDescriptionTemplateTypeCodeExists(ErrorDescription descriptionTemplateTypeCodeExists) { this.descriptionTemplateTypeCodeExists = descriptionTemplateTypeCodeExists; } + + private ErrorDescription descriptionTemplateTypeImportNotFound; + + public ErrorDescription getDescriptionTemplateTypeImportNotFound() { + return descriptionTemplateTypeImportNotFound; + } + + public void setDescriptionTemplateTypeImportNotFound(ErrorDescription descriptionTemplateTypeImportNotFound) { + this.descriptionTemplateTypeImportNotFound = descriptionTemplateTypeImportNotFound; + } } diff --git a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java index 8136f7cfb..db19c37b5 100644 --- a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java @@ -730,7 +730,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic persist.setStatus(DescriptionTemplateStatus.Draft); persist.setDescription(importXml.getDescription()); persist.setLanguage(importXml.getLanguage()); - persist.setType(this.xmlDescriptionTemplateTypeToPersist(importXml.getDescriptionTemplateType())); + persist.setType(this.xmlDescriptionTemplateTypeToPersist(importXml.getDescriptionTemplateType(), label)); persist.setDefinition(this.xmlDefinitionToPersist(importXml)); this.validatorFactory.validator(DescriptionTemplatePersist.DescriptionTemplatePersistValidator.class).validateForce(persist); return this.persist(persist, groupId, fields); @@ -750,7 +750,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic persist.setDescription(importXml.getDescription()); persist.setLanguage(importXml.getLanguage()); persist.setDefinition(this.xmlDefinitionToPersist(importXml)); - persist.setType(this.xmlDescriptionTemplateTypeToPersist(importXml.getDescriptionTemplateType())); + persist.setType(this.xmlDescriptionTemplateTypeToPersist(importXml.getDescriptionTemplateType(), label)); persist.setHash(this.conventionService.hashValue(latestVersionDescriptionTemplate.getUpdatedAt())); this.validatorFactory.validator(NewVersionDescriptionTemplatePersist.NewVersionDescriptionTemplatePersistValidator.class).validateForce(persist); @@ -759,28 +759,28 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic } } - private UUID xmlDescriptionTemplateTypeToPersist(DescriptionTemplateTypeImportExport importXml) { + private UUID xmlDescriptionTemplateTypeToPersist(DescriptionTemplateTypeImportExport importXml, String label) { if (importXml == null) return null; DescriptionTemplateTypeQuery query = null; if (importXml.getId() != null) { // search by id - query = this.queryFactory.query(DescriptionTemplateTypeQuery.class).ids(importXml.getId()); - if (query != null && query.count() > 0 ) { - return query.firstAs(new BaseFieldSet().ensure(DescriptionTemplate._id)).getId(); + DescriptionTemplateTypeEntity entity = this.queryFactory.query(DescriptionTemplateTypeQuery.class).ids(importXml.getId()).firstAs(new BaseFieldSet().ensure(DescriptionTemplate._id)); + if (entity != null ) { + return entity.getId(); } else { if (!this.conventionService.isNullOrEmpty(importXml.getCode())){ // search by code - query = this.queryFactory.query(DescriptionTemplateTypeQuery.class).codes(importXml.getCode()); - if (query != null && query.count() > 0) { - return query.firstAs(new BaseFieldSet().ensure(DescriptionTemplate._id)).getId(); + entity = this.queryFactory.query(DescriptionTemplateTypeQuery.class).codes(importXml.getCode()).firstAs(new BaseFieldSet().ensure(DescriptionTemplate._id)); + if (entity != null) { + return entity.getId(); } } } } - return null; + throw new MyValidationException(this.errors.getDescriptionTemplateTypeImportNotFound().getCode(), !this.conventionService.isNullOrEmpty(importXml.getCode()) ? importXml.getCode() : importXml.getName()); } @Override diff --git a/backend/web/src/main/resources/config/errors.yml b/backend/web/src/main/resources/config/errors.yml index 716f33773..e3c437efb 100644 --- a/backend/web/src/main/resources/config/errors.yml +++ b/backend/web/src/main/resources/config/errors.yml @@ -130,4 +130,7 @@ error-thesaurus: message: Usage limit metric is already selected as target descriptionTemplateTypeCodeExists: code: 147 - message: Description template type code exists \ No newline at end of file + message: Description template type code exists + descriptionTemplateTypeImportNotFound: + code: 148 + message: Description template 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 4c5529b2e..1d8032689 100644 --- a/frontend/src/app/core/common/enum/respone-error-code.ts +++ b/frontend/src/app/core/common/enum/respone-error-code.ts @@ -43,6 +43,7 @@ export enum ResponseErrorCode { UsageLimitException = 145, UsageLimitMetricAlreadyExists = 146, DescriptionTemplateTypeCodeExists = 147, + descriptionTemplateTypeImportNotFound = 148, // Notification & Annotation Errors InvalidApiKey = 200, @@ -163,6 +164,8 @@ export class ResponseErrorCodeHelper { return language.instant("GENERAL.BACKEND-ERRORS.USAGE-LIMIT-METRIC-ALLREADY-EXISTS"); case ResponseErrorCode.DescriptionTemplateTypeCodeExists: 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"); default: return language.instant("GENERAL.SNACK-BAR.NOT-FOUND"); } diff --git a/frontend/src/app/ui/admin/description-template/listing/description-template-listing.component.ts b/frontend/src/app/ui/admin/description-template/listing/description-template-listing.component.ts index 94dc487f3..651f0ba65 100644 --- a/frontend/src/app/ui/admin/description-template/listing/description-template-listing.component.ts +++ b/frontend/src/app/ui/admin/description-template/listing/description-template-listing.component.ts @@ -302,9 +302,7 @@ export class DescriptionTemplateListingComponent extends BaseListingComponent { - this.uiNotificationService.snackBarNotification(error.error.error, SnackBarNotificationLevel.Error); - }); + error => this.httpErrorHandlingService.handleBackedRequestError(error)); } }); } diff --git a/frontend/src/assets/i18n/en.json b/frontend/src/assets/i18n/en.json index 82798b827..0b959ce66 100644 --- a/frontend/src/assets/i18n/en.json +++ b/frontend/src/assets/i18n/en.json @@ -82,7 +82,8 @@ "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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-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." }, "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 d0803e9ed..ce3437b6f 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 @@ -19,6 +19,8 @@ export class HttpErrorHandlingService { if(errorResponse.error && ResponseErrorCodeHelper.isBackendError(errorResponse.error?.code)){ if (errorResponse.error.code === ResponseErrorCode.UsageLimitException && errorResponse.error.error){ 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); } else { this.uiNotificationService.snackBarNotification(ResponseErrorCodeHelper.getErrorMessageByBackendStatusCode(errorResponse.error.code, this.language), SnackBarNotificationLevel.Error); }