From c4a7d975f78df0fdf77eaa33cb840156872b54d5 Mon Sep 17 00:00:00 2001 From: dhanendra06 Date: Fri, 15 Mar 2024 07:30:01 +0530 Subject: [PATCH 1/4] MOSIP-31715 Signed-off-by: dhanendra06 --- .../masterdata/constant/SchemaErrorCode.java | 3 +++ .../impl/IdentitySchemaServiceImpl.java | 12 +++++++----- .../test/service/SchemaServiceTest.java | 19 +++++++++++++------ db_scripts/mosip_master/dml.sql | 3 +++ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/constant/SchemaErrorCode.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/constant/SchemaErrorCode.java index 758761105b2..020e367c627 100644 --- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/constant/SchemaErrorCode.java +++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/constant/SchemaErrorCode.java @@ -32,6 +32,9 @@ public enum SchemaErrorCode { SUB_TYPE_REQUIRED_EXCEPTION("KER-SCH-017", "SubType is required for field %s"), BIO_ATTRIBUTES_REQUIRED_EXCEPTION("KER-SCH-018", "BioAttributes are required for field %s"), BIO_ATTRIBUTES_DUPLICATED_EXCEPTION("KER-SCH-019", "Same BioAttributes used in field with same SubType : %s"), + + PUBLISHED_SCHEMA_EXCEPTION("KER-SCH-022", "Published identity schema can't be deleted"), + DYNAMIC_FIELD_VALUE_JSON_INVALID("KER-DYN-001", "Dynamic field is invalid, must contain code and value keys"); private final String errorCode; diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/IdentitySchemaServiceImpl.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/IdentitySchemaServiceImpl.java index d5cc8992eca..a656c2fb050 100644 --- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/IdentitySchemaServiceImpl.java +++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/IdentitySchemaServiceImpl.java @@ -276,14 +276,16 @@ public IdSchemaResponseDto updateSchema(String id, IdentitySchemaDto dto) { @Transactional public String deleteSchema(String id) { try { - int updatedRows = identitySchemaRepository.deleteIdentitySchema(id, MetaDataUtils.getCurrentDateTime(), - MetaDataUtils.getContextUser()); - - if (updatedRows < 1) { + IdentitySchema entity = identitySchemaRepository.findIdentitySchemaById(id); + if (entity == null) { throw new RequestException(SchemaErrorCode.SCHEMA_NOT_FOUND_EXCEPTION.getErrorCode(), SchemaErrorCode.SCHEMA_NOT_FOUND_EXCEPTION.getErrorMessage()); + } else if (STATUS_PUBLISHED.equalsIgnoreCase(entity.getStatus())) { + throw new RequestException(SchemaErrorCode.PUBLISHED_SCHEMA_EXCEPTION.getErrorCode(), + SchemaErrorCode.PUBLISHED_SCHEMA_EXCEPTION.getErrorMessage()); } - + identitySchemaRepository.deleteIdentitySchema(id, MetaDataUtils.getCurrentDateTime(), + MetaDataUtils.getContextUser()); } catch (DataAccessException | DataAccessLayerException e) { LOGGER.error("Error while deleting identity schema : " , ExceptionUtils.neutralizeParam(id), e); throw new MasterDataServiceException(SchemaErrorCode.SCHEMA_UPDATE_EXCEPTION.getErrorCode(), diff --git a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java index 0c60f6508bc..116a7a55b7c 100644 --- a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java +++ b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java @@ -306,9 +306,8 @@ public void testPublishIdentitySchemaWithException() throws Exception { @Test @WithUserDetails("global-admin") - public void testDeleteIdentitySchema() throws Exception { - Mockito.when(identitySchemaRepository.deleteIdentitySchema(Mockito.anyString(), Mockito.any(LocalDateTime.class), - Mockito.anyString())).thenReturn(1); + public void testDeleteIdentitySchema() throws Exception { + Mockito.when(identitySchemaRepository.findIdentitySchemaById(Mockito.anyString())).thenReturn(draftSchema); identitySchemaService.deleteSchema("test-test"); } @@ -322,9 +321,17 @@ public void testDeleteIdentitySchemaFailed() throws Exception { @Test(expected = MasterDataServiceException.class) @WithUserDetails("global-admin") - public void testDeleteIdentitySchemaFailedUpdate() throws Exception { - Mockito.when(identitySchemaRepository.deleteIdentitySchema(Mockito.anyString(), Mockito.any(LocalDateTime.class), - Mockito.anyString())).thenThrow(DataAccessLayerException.class); + public void testDeleteIdentitySchemaFailedUpdate() throws Exception { + Mockito.when(identitySchemaRepository.findIdentitySchemaById( + Mockito.anyString())).thenThrow(DataAccessLayerException.class); + identitySchemaService.deleteSchema("test-test"); + } + + @Test(expected = RequestException.class) + @WithUserDetails("global-admin") + public void testDeletePublishedIdentitySchema() throws Exception { + Mockito.when(identitySchemaRepository.findIdentitySchemaById( + Mockito.anyString())).thenReturn(publishedSchema); identitySchemaService.deleteSchema("test-test"); } diff --git a/db_scripts/mosip_master/dml.sql b/db_scripts/mosip_master/dml.sql index 9ac8db756ff..43cbfbafe86 100644 --- a/db_scripts/mosip_master/dml.sql +++ b/db_scripts/mosip_master/dml.sql @@ -104,6 +104,9 @@ TRUNCATE TABLE master.template cascade ; \COPY master.template (id,name,descr,file_format_code,model,file_txt,module_id,module_name,template_typ_code,lang_code,is_active,cr_by,cr_dtimes) FROM './dml/master-template.csv' delimiter ',' HEADER csv; +\COPY master.blocklisted_words (word,descr,lang_code,is_active,cr_by,cr_dtimes) FROM './dml/master-blacklisted_words.csv' delimiter ',' HEADER csv; + + -------------- Level 3 data load scripts ------------------------ ----- TRUNCATE master.screen_authorization TABLE Data and It's reference Data and COPY Data from CSV file ----- From 11e20257bd1c4d1d633efeef88b42cc16db773e0 Mon Sep 17 00:00:00 2001 From: dhanendra06 Date: Mon, 1 Apr 2024 09:13:45 +0530 Subject: [PATCH 2/4] updated the code based on review comments Signed-off-by: dhanendra06 --- .../masterdata/test/service/SchemaServiceTest.java | 13 +++++++------ db_scripts/mosip_master/dml.sql | 2 -- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java index 116a7a55b7c..948c3b56ed7 100644 --- a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java +++ b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java @@ -306,14 +306,15 @@ public void testPublishIdentitySchemaWithException() throws Exception { @Test @WithUserDetails("global-admin") - public void testDeleteIdentitySchema() throws Exception { - Mockito.when(identitySchemaRepository.findIdentitySchemaById(Mockito.anyString())).thenReturn(draftSchema); - identitySchemaService.deleteSchema("test-test"); + public void deleteIdentitySchema_withValidRid_recordDeleted() throws Exception { + String rid="123456789"; + Mockito.when(identitySchemaRepository.findIdentitySchemaById(rid)).thenReturn(draftSchema); + assertEquals(rid,identitySchemaService.deleteSchema(rid)); } @Test(expected = RequestException.class) @WithUserDetails("global-admin") - public void testDeleteIdentitySchemaFailed() throws Exception { + public void deleteIdentitySchema_invalidRid_failedToDelete() throws Exception { Mockito.when(identitySchemaRepository.deleteIdentitySchema(Mockito.anyString(), Mockito.any(LocalDateTime.class), Mockito.anyString())).thenReturn(0); identitySchemaService.deleteSchema("test-test"); @@ -321,7 +322,7 @@ public void testDeleteIdentitySchemaFailed() throws Exception { @Test(expected = MasterDataServiceException.class) @WithUserDetails("global-admin") - public void testDeleteIdentitySchemaFailedUpdate() throws Exception { + public void deleteIdentitySchema_withDbException_failedToDelete() throws Exception { Mockito.when(identitySchemaRepository.findIdentitySchemaById( Mockito.anyString())).thenThrow(DataAccessLayerException.class); identitySchemaService.deleteSchema("test-test"); @@ -329,7 +330,7 @@ public void testDeleteIdentitySchemaFailedUpdate() throws Exception { @Test(expected = RequestException.class) @WithUserDetails("global-admin") - public void testDeletePublishedIdentitySchema() throws Exception { + public void deleteIdentitySchema_publishedSchema_Failed() throws Exception { Mockito.when(identitySchemaRepository.findIdentitySchemaById( Mockito.anyString())).thenReturn(publishedSchema); identitySchemaService.deleteSchema("test-test"); diff --git a/db_scripts/mosip_master/dml.sql b/db_scripts/mosip_master/dml.sql index 43cbfbafe86..a48b157c6c8 100644 --- a/db_scripts/mosip_master/dml.sql +++ b/db_scripts/mosip_master/dml.sql @@ -104,8 +104,6 @@ TRUNCATE TABLE master.template cascade ; \COPY master.template (id,name,descr,file_format_code,model,file_txt,module_id,module_name,template_typ_code,lang_code,is_active,cr_by,cr_dtimes) FROM './dml/master-template.csv' delimiter ',' HEADER csv; -\COPY master.blocklisted_words (word,descr,lang_code,is_active,cr_by,cr_dtimes) FROM './dml/master-blacklisted_words.csv' delimiter ',' HEADER csv; - -------------- Level 3 data load scripts ------------------------ From fbde50d1c69ec4d1b975326b9dcce7cdbdb7a260 Mon Sep 17 00:00:00 2001 From: dhanendra06 Date: Mon, 1 Apr 2024 12:55:31 +0530 Subject: [PATCH 3/4] updated the code based on review comments Signed-off-by: dhanendra06 --- .../masterdata/test/service/SchemaServiceTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java index 948c3b56ed7..5ebbf39c5c9 100644 --- a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java +++ b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/service/SchemaServiceTest.java @@ -306,15 +306,15 @@ public void testPublishIdentitySchemaWithException() throws Exception { @Test @WithUserDetails("global-admin") - public void deleteIdentitySchema_withValidRid_recordDeleted() throws Exception { - String rid="123456789"; - Mockito.when(identitySchemaRepository.findIdentitySchemaById(rid)).thenReturn(draftSchema); - assertEquals(rid,identitySchemaService.deleteSchema(rid)); + public void deleteIdentitySchema_withValidId_recordDeleted() throws Exception { + String id="123456789"; + Mockito.when(identitySchemaRepository.findIdentitySchemaById(id)).thenReturn(draftSchema); + assertEquals(id,identitySchemaService.deleteSchema(id)); } @Test(expected = RequestException.class) @WithUserDetails("global-admin") - public void deleteIdentitySchema_invalidRid_failedToDelete() throws Exception { + public void deleteIdentitySchema_invalidId_failedToDelete() throws Exception { Mockito.when(identitySchemaRepository.deleteIdentitySchema(Mockito.anyString(), Mockito.any(LocalDateTime.class), Mockito.anyString())).thenReturn(0); identitySchemaService.deleteSchema("test-test"); From c157c82f92fce02d54b77e1c03b7b0bf2929b13d Mon Sep 17 00:00:00 2001 From: dhanendra06 Date: Mon, 1 Apr 2024 13:02:16 +0530 Subject: [PATCH 4/4] updated the code based on review comments Signed-off-by: dhanendra06 --- db_scripts/mosip_master/dml.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db_scripts/mosip_master/dml.sql b/db_scripts/mosip_master/dml.sql index a48b157c6c8..9ac8db756ff 100644 --- a/db_scripts/mosip_master/dml.sql +++ b/db_scripts/mosip_master/dml.sql @@ -104,7 +104,6 @@ TRUNCATE TABLE master.template cascade ; \COPY master.template (id,name,descr,file_format_code,model,file_txt,module_id,module_name,template_typ_code,lang_code,is_active,cr_by,cr_dtimes) FROM './dml/master-template.csv' delimiter ',' HEADER csv; - -------------- Level 3 data load scripts ------------------------ ----- TRUNCATE master.screen_authorization TABLE Data and It's reference Data and COPY Data from CSV file -----