Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOSIP-31715,MOSIP-31940,MOSIP-31570 #944

Merged
merged 5 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
ase-101 marked this conversation as resolved.
Show resolved Hide resolved

DYNAMIC_FIELD_VALUE_JSON_INVALID("KER-DYN-001", "Dynamic field is invalid, must contain code and value keys");

private final String errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,33 @@ 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);
identitySchemaService.deleteSchema("test-test");
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 testDeleteIdentitySchemaFailed() 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");
}

@Test(expected = MasterDataServiceException.class)
@WithUserDetails("global-admin")
public void testDeleteIdentitySchemaFailedUpdate() throws Exception {
ase-101 marked this conversation as resolved.
Show resolved Hide resolved
Mockito.when(identitySchemaRepository.deleteIdentitySchema(Mockito.anyString(), Mockito.any(LocalDateTime.class),
Mockito.anyString())).thenThrow(DataAccessLayerException.class);
public void deleteIdentitySchema_withDbException_failedToDelete() throws Exception {
Mockito.when(identitySchemaRepository.findIdentitySchemaById(
Mockito.anyString())).thenThrow(DataAccessLayerException.class);
identitySchemaService.deleteSchema("test-test");
}

@Test(expected = RequestException.class)
@WithUserDetails("global-admin")
public void deleteIdentitySchema_publishedSchema_Failed() throws Exception {
Mockito.when(identitySchemaRepository.findIdentitySchemaById(
Mockito.anyString())).thenReturn(publishedSchema);
identitySchemaService.deleteSchema("test-test");
}

Expand Down
Loading