From 639cbeba6036e9a1b685ff91457491c557e851e3 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Fri, 24 Mar 2023 17:25:29 +0530 Subject: [PATCH 01/23] fixed id version for document APIs --- .../controller/DocumentController.java | 60 +++++++++++++------ .../service/impl/DocumentServiceImpl.java | 4 +- .../service/impl/DocumentServiceImplTest.java | 4 +- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/DocumentController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/DocumentController.java index 188f135dc30..e3b0e7fc18c 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/DocumentController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/DocumentController.java @@ -25,7 +25,9 @@ import io.mosip.resident.dto.DocumentRequestDTO; import io.mosip.resident.dto.DocumentResponseDTO; import io.mosip.resident.dto.ResponseDTO; +import io.mosip.resident.exception.InvalidInputException; import io.mosip.resident.exception.ResidentServiceCheckedException; +import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.service.DocumentService; import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; @@ -93,6 +95,8 @@ public ResponseWrapper uploadDocuments(@PathVariable("trans audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.VALIDATE_REQUEST, "Document Upload API")); ResponseWrapper responseWrapper = new ResponseWrapper<>(); try { + responseWrapper.setId(residentUploadDocumentId); + responseWrapper.setVersion(residentDocumentResponseVersion); validator.validateRequest(transactionId,docCatCode,docTypCode,langCode); validator.validateFileName(file); validator.scanForViruses(file); @@ -105,8 +109,6 @@ public ResponseWrapper uploadDocuments(@PathVariable("trans audit.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.UPLOAD_DOCUMENT, transactionId)); DocumentResponseDTO uploadDocumentResponse = service.uploadDocument(transactionId, file, docRequest); - responseWrapper.setId(residentUploadDocumentId); - responseWrapper.setVersion(residentDocumentResponseVersion); responseWrapper.setResponse(uploadDocumentResponse); audit.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.UPLOAD_DOCUMENT_SUCCESS, transactionId)); @@ -115,10 +117,14 @@ public ResponseWrapper uploadDocuments(@PathVariable("trans EventEnum.getEventEnumWithValue(EventEnum.UPLOAD_DOCUMENT_FAILED, transactionId)); logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), ExceptionUtils.getStackTrace(e)); - responseWrapper.setId(residentUploadDocumentId); - responseWrapper.setVersion(residentDocumentResponseVersion); responseWrapper.setErrors(List.of(new ServiceError(e.getErrorCode(), e.getErrorText()))); - } + } catch (InvalidInputException | ResidentServiceException e) { + audit.setAuditRequestDto( + EventEnum.getEventEnumWithValue(EventEnum.UPLOAD_DOCUMENT_FAILED, transactionId)); + logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), + LoggerFileConstant.APPLICATIONID.toString(), ExceptionUtils.getStackTrace(e)); + responseWrapper.setErrors(List.of(new ServiceError(e.getErrorCode(), e.getErrorText()))); + } return responseWrapper; } @@ -134,12 +140,13 @@ public ResponseWrapper> getDocumentsByTransactionId( audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.VALIDATE_REQUEST, "Get documents API")); ResponseWrapper> responseWrapper = new ResponseWrapper<>(); try { + responseWrapper.setId(residentDocumentListId); + responseWrapper.setVersion(residentDocumentListVersion); + validator.validateTransactionIdForDocument(transactionId); + audit.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.GET_DOCUMENTS_METADATA, transactionId)); - validator.validateTransactionIdForDocument(transactionId); List documentResponse = service.fetchAllDocumentsMetadata(transactionId); - responseWrapper.setId(residentDocumentListId); - responseWrapper.setVersion(residentDocumentListVersion); responseWrapper.setResponse(documentResponse); audit.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.GET_DOCUMENTS_METADATA_SUCCESS, transactionId)); @@ -149,6 +156,12 @@ public ResponseWrapper> getDocumentsByTransactionId( logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), ExceptionUtils.getStackTrace(e)); responseWrapper.setErrors(List.of(new ServiceError(e.getErrorCode(), e.getErrorText()))); + } catch (InvalidInputException | ResidentServiceException e) { + audit.setAuditRequestDto( + EventEnum.getEventEnumWithValue(EventEnum.GET_DOCUMENTS_METADATA_FAILED, transactionId)); + logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), + LoggerFileConstant.APPLICATIONID.toString(), ExceptionUtils.getStackTrace(e)); + responseWrapper.setErrors(List.of(new ServiceError(e.getErrorCode(), e.getErrorText()))); } return responseWrapper; } @@ -167,13 +180,14 @@ public ResponseWrapper getDocumentByDocumentId( audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.VALIDATE_REQUEST, "Get document API")); ResponseWrapper responseWrapper = new ResponseWrapper<>(); try { + responseWrapper.setId(residentGetDocumentId); + responseWrapper.setVersion(residentGetDocumentVersion); + validator.validateDocumentIdAndTransactionId(documentId, transactionId); + audit.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.GET_DOCUMENT_BY_DOC_ID, transactionId)); - validator.validateDocumentIdAndTransactionId(documentId, transactionId); DocumentDTO documentResponse = service.fetchDocumentByDocId(transactionId, documentId); responseWrapper.setResponse(documentResponse); - responseWrapper.setId(residentGetDocumentId); - responseWrapper.setVersion(residentGetDocumentVersion); audit.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.GET_DOCUMENT_BY_DOC_ID_SUCCESS, transactionId)); } catch (ResidentServiceCheckedException e) { @@ -182,6 +196,12 @@ public ResponseWrapper getDocumentByDocumentId( logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), ExceptionUtils.getStackTrace(e)); responseWrapper.setErrors(List.of(new ServiceError(e.getErrorCode(), e.getErrorText()))); + } catch (InvalidInputException | ResidentServiceException e) { + audit.setAuditRequestDto( + EventEnum.getEventEnumWithValue(EventEnum.GET_DOCUMENT_BY_DOC_ID_FAILED, transactionId)); + logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), + LoggerFileConstant.APPLICATIONID.toString(), ExceptionUtils.getStackTrace(e)); + responseWrapper.setErrors(List.of(new ServiceError(e.getErrorCode(), e.getErrorText()))); } return responseWrapper; } @@ -200,13 +220,13 @@ public ResponseWrapper deleteDocument( audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.VALIDATE_REQUEST, "Delete document API")); ResponseWrapper responseWrapper = new ResponseWrapper<>(); try { - audit.setAuditRequestDto( - EventEnum.getEventEnumWithValue(EventEnum.DELETE_DOCUMENT, transactionId)); - validator.validateDocumentIdAndTransactionId(documentId, transactionId); responseWrapper.setId(residentDeleteId); responseWrapper.setVersion(residentDeleteVersion); - ResponseDTO documentResponse = service - .deleteDocument(transactionId, documentId); + validator.validateDocumentIdAndTransactionId(documentId, transactionId); + + audit.setAuditRequestDto( + EventEnum.getEventEnumWithValue(EventEnum.DELETE_DOCUMENT, transactionId)); + ResponseDTO documentResponse = service.deleteDocument(transactionId, documentId); responseWrapper.setResponse(documentResponse); audit.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.DELETE_DOCUMENT_SUCCESS, transactionId)); @@ -215,8 +235,12 @@ public ResponseWrapper deleteDocument( EventEnum.getEventEnumWithValue(EventEnum.DELETE_DOCUMENT_FAILED, transactionId)); logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), ExceptionUtils.getStackTrace(e)); - responseWrapper.setId(residentDeleteId); - responseWrapper.setVersion(residentDeleteVersion); + responseWrapper.setErrors(List.of(new ServiceError(e.getErrorCode(), e.getErrorText()))); + } catch (InvalidInputException | ResidentServiceException e) { + audit.setAuditRequestDto( + EventEnum.getEventEnumWithValue(EventEnum.DELETE_DOCUMENT_FAILED, transactionId)); + logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), + LoggerFileConstant.APPLICATIONID.toString(), ExceptionUtils.getStackTrace(e)); responseWrapper.setErrors(List.of(new ServiceError(e.getErrorCode(), e.getErrorText()))); } return responseWrapper; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DocumentServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DocumentServiceImpl.java index 7a0cf742fad..036389020fb 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DocumentServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DocumentServiceImpl.java @@ -98,7 +98,7 @@ public List fetchAllDocumentsMetadata(String transactionId) throws ResidentServiceCheckedException { List allObjects = objectStoreHelper.getAllObjects(transactionId); if(allObjects == null){ - throw new ResidentServiceException(ResidentErrorCode.NO_DOCUMENT_FOUND_FOR_TRANSACTION_ID.getErrorCode(), + throw new ResidentServiceCheckedException(ResidentErrorCode.NO_DOCUMENT_FOUND_FOR_TRANSACTION_ID.getErrorCode(), ResidentErrorCode.NO_DOCUMENT_FOUND_FOR_TRANSACTION_ID.getErrorMessage()+transactionId); } return allObjects.stream().map(object -> this.fetchDocumentMetadata(transactionId, object.getObjectName())) @@ -121,7 +121,7 @@ public DocumentDTO fetchDocumentByDocId(String transactionId, String documentId) }catch (ResidentServiceException | ObjectStoreAdapterException e){ logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), ExceptionUtils.getStackTrace(e)); - throw new ResidentServiceException(ResidentErrorCode.NO_DOCUMENT_FOUND_FOR_TRANSACTION_ID.getErrorCode(), + throw new ResidentServiceCheckedException(ResidentErrorCode.NO_DOCUMENT_FOUND_FOR_TRANSACTION_ID.getErrorCode(), ResidentErrorCode.NO_DOCUMENT_FOUND_FOR_TRANSACTION_ID.getErrorMessage()+transactionId+ " & documentId: "+documentId, e); } return document; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/service/impl/DocumentServiceImplTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/DocumentServiceImplTest.java index 80f83c1aacb..0c8c0d2058c 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/service/impl/DocumentServiceImplTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/DocumentServiceImplTest.java @@ -21,7 +21,7 @@ import io.mosip.commons.khazana.dto.ObjectDto; import io.mosip.resident.dto.DocumentRequestDTO; -import io.mosip.resident.exception.ResidentServiceException; +import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.helper.ObjectStoreHelper; /** @@ -68,7 +68,7 @@ public void fetchAllDocumentsMetadataTest() throws Exception { assertNotNull(documentServiceImpl.fetchAllDocumentsMetadata("transactionId")); } - @Test(expected = ResidentServiceException.class) + @Test(expected = ResidentServiceCheckedException.class) public void testFetchAllDocumentsMetadataFailure() throws Exception{ Map metaData = getMetaData(); Mockito.when(objectStoreHelper.getAllObjects("transactionId")).thenReturn(null); From 156541043b4dd80a8965d669035b1b2c49e0c5d6 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Mon, 27 Mar 2023 12:38:42 +0530 Subject: [PATCH 02/23] update constant names --- .../constant/CredentialUpdateStatus.java | 32 ------------ .../CredentialStatusUpdateBatchJobTest.java | 50 +++++++++---------- 2 files changed, 25 insertions(+), 57 deletions(-) delete mode 100644 resident/resident-service/src/main/java/io/mosip/resident/constant/CredentialUpdateStatus.java diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/CredentialUpdateStatus.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/CredentialUpdateStatus.java deleted file mode 100644 index a5f54939b64..00000000000 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/CredentialUpdateStatus.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.mosip.resident.constant; - -/** - * @author Manoj SP - * - */ -public class CredentialUpdateStatus { - - private CredentialUpdateStatus() { - } - - public static final String NEW = "NEW"; - - public static final String ISSUED = "ISSUED"; - - public static final String PRINTING = "PRINTING"; - - public static final String FAILED = "FAILED"; - - public static final String PROCESSING = "PROCESSING"; - - public static final String RECEIVED = "RECEIVED"; - - public static final String DELIVERED = "CARD_DELIVERED"; - - public static final String STORED = "STORED"; - - public static final String IN_TRANSIT = "IN_TRANSIT"; - - public static final String PAYMENT_CONFIRMED = "PAYMENT_CONFIRMED"; - -} diff --git a/resident/resident-service/src/test/java/io/mosip/resident/batch/CredentialStatusUpdateBatchJobTest.java b/resident/resident-service/src/test/java/io/mosip/resident/batch/CredentialStatusUpdateBatchJobTest.java index 9ace38f8d3a..f69a461fce9 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/batch/CredentialStatusUpdateBatchJobTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/batch/CredentialStatusUpdateBatchJobTest.java @@ -1,11 +1,11 @@ package io.mosip.resident.batch; -import static io.mosip.resident.constant.CredentialUpdateStatus.FAILED; -import static io.mosip.resident.constant.CredentialUpdateStatus.IN_TRANSIT; -import static io.mosip.resident.constant.CredentialUpdateStatus.ISSUED; -import static io.mosip.resident.constant.CredentialUpdateStatus.NEW; -import static io.mosip.resident.constant.CredentialUpdateStatus.PAYMENT_CONFIRMED; -import static io.mosip.resident.constant.CredentialUpdateStatus.PRINTING; +import static io.mosip.resident.constant.EventStatusFailure.FAILED; +import static io.mosip.resident.constant.EventStatusInProgress.IN_TRANSIT; +import static io.mosip.resident.constant.EventStatusInProgress.ISSUED; +import static io.mosip.resident.constant.EventStatusInProgress.NEW; +import static io.mosip.resident.constant.EventStatusInProgress.PAYMENT_CONFIRMED; +import static io.mosip.resident.constant.EventStatusInProgress.PRINTING; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.when; @@ -93,7 +93,7 @@ public void testTrackAndUpdateNewOrIssuedStatusWithoutRID() throws ResidentServi txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(NEW); + txn.setStatusCode(NEW.name()); txn.setRequestTypeCode(RequestType.DOWNLOAD_PERSONALIZED_CARD.name()); txn.setCredentialRequestId(UUID.randomUUID().toString()); ResponseWrapper> responseWrapper = new ResponseWrapper<>(); @@ -110,7 +110,7 @@ public void testTrackAndUpdateNewOrIssuedStatusWithoutRIDException() throws Resi txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(NEW); + txn.setStatusCode(NEW.name()); txn.setRequestTypeCode(RequestType.DOWNLOAD_PERSONALIZED_CARD.name()); txn.setCredentialRequestId(UUID.randomUUID().toString()); ResponseWrapper> responseWrapper = new ResponseWrapper<>(); @@ -126,7 +126,7 @@ public void testScheduleCredentialStatusUpdateJobVidCardDownload() throws ApisRe txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(ISSUED); + txn.setStatusCode(ISSUED.name()); txn.setRequestTypeCode(RequestType.VID_CARD_DOWNLOAD.name()); txn.setCredentialRequestId(UUID.randomUUID().toString()); ResponseWrapper> responseWrapper = new ResponseWrapper<>(); @@ -142,7 +142,7 @@ public void testScheduleCredentialStatusUpdateJobVidCardDownloadFailed() throws txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(ISSUED); + txn.setStatusCode(ISSUED.name()); txn.setRequestTypeCode(RequestType.VID_CARD_DOWNLOAD.name()); txn.setCredentialRequestId(UUID.randomUUID().toString()); ResponseWrapper> responseWrapper = new ResponseWrapper<>(); @@ -159,7 +159,7 @@ public void testScheduleCredentialStatusUpdateJobVidCardDownloadFailedApiResourc txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(NEW); + txn.setStatusCode(NEW.name()); txn.setRequestTypeCode(RequestType.VID_CARD_DOWNLOAD.name()); txn.setCredentialRequestId(UUID.randomUUID().toString()); ResponseWrapper> responseWrapper = new ResponseWrapper<>(); @@ -175,7 +175,7 @@ public void updateOrderPhysicalCardTxnStatusTest() throws ApisResourceAccessExce txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(PAYMENT_CONFIRMED); + txn.setStatusCode(PAYMENT_CONFIRMED.name()); txn.setRequestTypeCode(RequestType.ORDER_PHYSICAL_CARD.name()); txn.setCredentialRequestId(UUID.randomUUID().toString()); ResponseWrapper> responseWrapper = new ResponseWrapper<>(); @@ -191,7 +191,7 @@ public void updateOrderPhysicalCardTxnStatusCodePrintingTest() throws ApisResour txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(PRINTING); + txn.setStatusCode(PRINTING.name()); txn.setRequestTrnId("123"); txn.setIndividualId("123"); txn.setRequestTypeCode(RequestType.ORDER_PHYSICAL_CARD.name()); @@ -209,13 +209,13 @@ public void updateOrderPhysicalCardTxnStatusCodeFailedTest() throws ApisResource txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(FAILED); + txn.setStatusCode(FAILED.name()); txn.setRequestTrnId("123"); txn.setIndividualId("123"); txn.setRequestTypeCode(RequestType.ORDER_PHYSICAL_CARD.name()); txn.setCredentialRequestId(UUID.randomUUID().toString()); ResponseWrapper> responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(Map.of("requestId", "requestId", "id", "id", "statusCode", FAILED, "url", "url")); + responseWrapper.setResponse(Map.of("requestId", "requestId", "id", "id", "statusCode", FAILED.name(), "url", "url")); when(residentServiceRestClient.getApi(any(), anyList(), anyList(), anyList(), any())).thenReturn(responseWrapper); when(repo.findByStatusCodeInAndRequestTypeCodeInOrderByCrDtimesAsc(anyList(), anyList())).thenReturn(List.of(txn)); job.scheduleCredentialStatusUpdateJob(); @@ -227,13 +227,13 @@ public void updateOrderPhysicalCardTxnStatusCodeFailedTestApiResourceException() txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(FAILED); + txn.setStatusCode(FAILED.name()); txn.setRequestTrnId("123"); txn.setIndividualId("123"); txn.setRequestTypeCode(RequestType.ORDER_PHYSICAL_CARD.name()); txn.setCredentialRequestId(UUID.randomUUID().toString()); ResponseWrapper> responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(Map.of("requestId", "requestId", "id", "id", "statusCode", FAILED, "url", "url")); + responseWrapper.setResponse(Map.of("requestId", "requestId", "id", "id", "statusCode", FAILED.name(), "url", "url")); when(residentServiceRestClient.getApi(any(), anyList(), anyList(), anyList(), any())).thenThrow(new ApisResourceAccessException()); when(repo.findByStatusCodeInAndRequestTypeCodeInOrderByCrDtimesAsc(anyList(), anyList())).thenReturn(List.of(txn)); job.scheduleCredentialStatusUpdateJob(); @@ -245,7 +245,7 @@ public void updateOrderPhysicalCardTxnStatusCodeFailedTest1() throws ApisResourc txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(IN_TRANSIT); + txn.setStatusCode(IN_TRANSIT.name()); txn.setRequestTrnId("123"); txn.setIndividualId("123"); txn.setRequestTypeCode(RequestType.ORDER_PHYSICAL_CARD.name()); @@ -264,7 +264,7 @@ public void testUpdateShareCredentialWithPartnerTxnStatus() throws ApisResourceA txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(NEW); + txn.setStatusCode(NEW.name()); txn.setRequestTrnId("123"); txn.setIndividualId("123"); txn.setRequestTypeCode(RequestType.SHARE_CRED_WITH_PARTNER.name()); @@ -282,13 +282,13 @@ public void testUpdateShareCredentialWithPartnerTxnStatusFailed() throws ApisRes txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(FAILED); + txn.setStatusCode(FAILED.name()); txn.setRequestTrnId("123"); txn.setIndividualId("123"); txn.setRequestTypeCode(RequestType.SHARE_CRED_WITH_PARTNER.name()); txn.setCredentialRequestId(UUID.randomUUID().toString()); ResponseWrapper> responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(Map.of("requestId", "requestId", "id", "id", "statusCode", FAILED, "url", "url")); + responseWrapper.setResponse(Map.of("requestId", "requestId", "id", "id", "statusCode", FAILED.name(), "url", "url")); when(residentServiceRestClient.getApi(any(), anyList(), anyList(), anyList(), any())).thenReturn(responseWrapper); when(repo.findByStatusCodeInAndRequestTypeCodeInOrderByCrDtimesAsc(anyList(), anyList())).thenReturn(List.of(txn)); job.scheduleCredentialStatusUpdateJob(); @@ -300,13 +300,13 @@ public void testUpdateShareCredentialWithPartnerTxnStatusFailedApiResourceExcept txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(FAILED); + txn.setStatusCode(FAILED.name()); txn.setRequestTrnId("123"); txn.setIndividualId("123"); txn.setRequestTypeCode(RequestType.SHARE_CRED_WITH_PARTNER.name()); txn.setCredentialRequestId(UUID.randomUUID().toString()); ResponseWrapper> responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(Map.of("requestId", "requestId", "id", "id", "statusCode", FAILED, "url", "url")); + responseWrapper.setResponse(Map.of("requestId", "requestId", "id", "id", "statusCode", FAILED.name(), "url", "url")); when(residentServiceRestClient.getApi(any(), anyList(), anyList(), anyList(), any())).thenThrow(new ApisResourceAccessException()); when(repo.findByStatusCodeInAndRequestTypeCodeInOrderByCrDtimesAsc(anyList(), anyList())).thenReturn(List.of(txn)); job.scheduleCredentialStatusUpdateJob(); @@ -318,7 +318,7 @@ public void testUpdateUinDemoDataUpdateTxnStatus() throws ApisResourceAccessExce txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(NEW); + txn.setStatusCode(NEW.name()); txn.setRequestTrnId("123"); txn.setIndividualId("123"); txn.setAid("123"); @@ -340,7 +340,7 @@ public void testUpdateUinDemoDataUpdateTxnStatusNullAid() throws ApisResourceAcc txn.setAid("aid"); txn.setEventId("eventId"); txn.setRefIdType("UIN"); - txn.setStatusCode(NEW); + txn.setStatusCode(NEW.name()); txn.setRequestTrnId("123"); txn.setIndividualId("123"); txn.setAid("123"); From 3ccfc549d94f806db3a978b2a059efa2e15ceba1 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Mon, 27 Mar 2023 13:22:29 +0530 Subject: [PATCH 03/23] used constant file_text --- .../service/impl/DownLoadMasterDataServiceImpl.java | 5 ++--- .../service/impl/ProxyMasterdataServiceImpl.java | 3 ++- .../mosip/resident/service/impl/ResidentServiceImpl.java | 2 +- .../resident/test/service/AcknowledgmentServiceTest.java | 3 ++- .../test/service/DownloadmasterDataServiceImplTest.java | 3 ++- .../test/service/ResidentServiceDownloadCardTest.java | 9 +++++---- .../io/mosip/resident/test/util/TemplateUtilTest.java | 2 +- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownLoadMasterDataServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownLoadMasterDataServiceImpl.java index 0b502dddac5..7b3f9ca3e2b 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownLoadMasterDataServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownLoadMasterDataServiceImpl.java @@ -54,7 +54,6 @@ public class DownLoadMasterDataServiceImpl implements DownLoadMasterDataService private static final String CLASSPATH = "classpath"; private static final String ENCODE_TYPE = "UTF-8"; - public static final String FILE_TEXT = "fileText"; @Autowired Environment env; @@ -116,7 +115,7 @@ public InputStream getRegistrationCentrePdf(String langCode, ResponseWrapper logger.debug("template data from DB:" + proxyResponseWrapper.getResponse()); Map templateResponse = new LinkedHashMap<>( (Map) proxyResponseWrapper.getResponse()); - String fileText = (String) templateResponse.get(FILE_TEXT); + String fileText = (String) templateResponse.get(ResidentConstants.FILE_TEXT); InputStream downLoadRegCenterTemplate = new ByteArrayInputStream(fileText.getBytes(StandardCharsets.UTF_8)); InputStream downLoadRegCenterTemplateData = templateManager.merge(downLoadRegCenterTemplate, regCentersMap); @@ -147,7 +146,7 @@ public InputStream downloadSupportingDocsByLanguage(String langCode) throws Resi .getAllTemplateBylangCodeAndTemplateTypeCode(langCode, this.env.getProperty(ResidentConstants.SUPPORTING_DOCS_TEMPLATE_PROPERTY)); logger.debug("template data from DB:" + proxyResponseWrapper.getResponse()); Map templateResponse = new LinkedHashMap<>((Map) proxyResponseWrapper.getResponse()); - String fileText = (String) templateResponse.get(FILE_TEXT); + String fileText = (String) templateResponse.get(ResidentConstants.FILE_TEXT); Map supportingsDocsMap = new HashMap<>(); supportingsDocsMap.put("supportingsDocMap", supportingsDocsMap); InputStream supportingDocsTemplate = new ByteArrayInputStream(fileText.getBytes(StandardCharsets.UTF_8)); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyMasterdataServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyMasterdataServiceImpl.java index 3d0ad487890..c2f2af26814 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyMasterdataServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyMasterdataServiceImpl.java @@ -21,6 +21,7 @@ import io.mosip.resident.config.LoggerConfiguration; import io.mosip.resident.constant.ApiName; import io.mosip.resident.constant.OrderEnum; +import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.constant.ResidentErrorCode; import io.mosip.resident.dto.GenderCodeResponseDTO; import io.mosip.resident.dto.GenderTypeListDTO; @@ -420,7 +421,7 @@ public ResponseWrapper getAllTemplateBylangCodeAndTemplateTypeCode(String lan String template = templateResponse.getTemplates().get(0).getFileText(); ResponseWrapper responseWrapper = new ResponseWrapper<>(); Map responseMap = new HashMap<>(); - responseMap.put("fileText", template); + responseMap.put(ResidentConstants.FILE_TEXT, template); responseWrapper.setResponse(responseMap); logger.debug("ProxyMasterdataServiceImpl::getAllTemplateBylangCodeAndTemplateTypeCode()::exit"); return responseWrapper; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java index 3773135c5b1..176a7514f0c 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java @@ -2159,7 +2159,7 @@ public byte[] downLoadServiceHistory(ResponseWrapper templateResponse = new LinkedHashMap<>( (Map) proxyResponseWrapper.getResponse()); - String fileText = (String) templateResponse.get("fileText"); + String fileText = (String) templateResponse.get(ResidentConstants.FILE_TEXT); // for avoiding null values in PDF List serviceHistoryDtlsList = responseWrapper.getResponse().getData(); if (serviceHistoryDtlsList != null && !serviceHistoryDtlsList.isEmpty()) { diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/AcknowledgmentServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/AcknowledgmentServiceTest.java index cb8973b5599..1da772e60ad 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/AcknowledgmentServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/AcknowledgmentServiceTest.java @@ -33,6 +33,7 @@ import io.mosip.kernel.signature.dto.SignatureResponseDto; import io.mosip.kernel.templatemanager.velocity.builder.TemplateManagerBuilderImpl; import io.mosip.resident.constant.RequestType; +import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.entity.ResidentTransactionEntity; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.repository.ResidentTransactionRepository; @@ -105,7 +106,7 @@ public void setup() throws Exception { values.put("test", String.class); templateVariables.put("eventId", eventId); responseWrapper = new ResponseWrapper<>(); - templateResponse.put("fileText", "test"); + templateResponse.put(ResidentConstants.FILE_TEXT, "test"); responseWrapper.setResponse(templateResponse); result = "test".getBytes(StandardCharsets.UTF_8); eventId = "bf42d76e-b02e-48c8-a17a-6bb842d85ea9"; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadmasterDataServiceImplTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadmasterDataServiceImplTest.java index 35dbf7a153c..ae12ac79df4 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadmasterDataServiceImplTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadmasterDataServiceImplTest.java @@ -34,6 +34,7 @@ import io.mosip.kernel.core.templatemanager.spi.TemplateManager; import io.mosip.kernel.signature.dto.SignatureResponseDto; import io.mosip.kernel.templatemanager.velocity.builder.TemplateManagerBuilderImpl; +import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.dto.RegistrationCenterDto; import io.mosip.resident.dto.WorkingDaysDto; import io.mosip.resident.dto.WorkingDaysResponseDto; @@ -110,7 +111,7 @@ public void setup() throws Exception { values.put("test", String.class); templateVariables.put("eventId", eventId); responseWrapper = new ResponseWrapper<>(); - templateResponse.put("fileText", "test"); + templateResponse.put(ResidentConstants.FILE_TEXT, "test"); responseWrapper.setResponse(templateResponse); result = "test".getBytes(StandardCharsets.UTF_8); eventId = "bf42d76e-b02e-48c8-a17a-6bb842d85ea9"; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceDownloadCardTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceDownloadCardTest.java index 8249d75dac8..081d5e600db 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceDownloadCardTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceDownloadCardTest.java @@ -36,6 +36,7 @@ import io.mosip.kernel.core.templatemanager.spi.TemplateManager; import io.mosip.resident.constant.ApiName; import io.mosip.resident.constant.RequestType; +import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.dto.BellNotificationDto; import io.mosip.resident.dto.DigitalCardStatusResponseDto; import io.mosip.resident.dto.PageDto; @@ -229,7 +230,7 @@ public void testDownloadServiceHistory() throws ResidentServiceCheckedException, responseWrapper.setResponse(responseDtoPageDto); ResponseWrapper responseWrapper1 = new ResponseWrapper<>(); Map templateResponse = new LinkedHashMap<>(); - templateResponse.put("fileText", "test"); + templateResponse.put(ResidentConstants.FILE_TEXT, "test"); responseWrapper1.setResponse(templateResponse); Mockito.when(proxyMasterdataService.getAllTemplateBylangCodeAndTemplateTypeCode(Mockito.anyString(), Mockito.anyString())) .thenReturn(responseWrapper1); @@ -252,7 +253,7 @@ public void testDownloadServiceHistorySuccess() throws ResidentServiceCheckedExc responseWrapper.setResponse(responseDtoPageDto); ResponseWrapper responseWrapper1 = new ResponseWrapper<>(); Map templateResponse = new LinkedHashMap<>(); - templateResponse.put("fileText", "test"); + templateResponse.put(ResidentConstants.FILE_TEXT, "test"); responseWrapper1.setResponse(templateResponse); Mockito.when(proxyMasterdataService.getAllTemplateBylangCodeAndTemplateTypeCode(Mockito.anyString(), Mockito.anyString())) .thenReturn(responseWrapper1); @@ -274,7 +275,7 @@ public void testDownloadServiceHistoryFail() throws ResidentServiceCheckedExcept responseWrapper.setResponse(responseDtoPageDto); ResponseWrapper responseWrapper1 = new ResponseWrapper<>(); Map templateResponse = new LinkedHashMap<>(); - templateResponse.put("fileText", "test"); + templateResponse.put(ResidentConstants.FILE_TEXT, "test"); responseWrapper1.setResponse(templateResponse); Mockito.when(proxyMasterdataService.getAllTemplateBylangCodeAndTemplateTypeCode(Mockito.anyString(), Mockito.anyString())) .thenReturn(responseWrapper1); @@ -303,7 +304,7 @@ public void testGetUnreadNotifyList() throws ResidentServiceCheckedException, Ap responseWrapper.setResponse(responseDtoPageDto); ResponseWrapper responseWrapper1 = new ResponseWrapper<>(); Map templateResponse = new LinkedHashMap<>(); - templateResponse.put("fileText", "test"); + templateResponse.put(ResidentConstants.FILE_TEXT, "test"); responseWrapper1.setResponse(templateResponse); residentServiceImpl.getNotificationList(0,10,"123","eng",0); } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java index 75d29a0b120..3b343ca4bdf 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java @@ -114,7 +114,7 @@ public void setUp() throws ApisResourceAccessException, ResidentServiceCheckedEx values.put("test", String.class); templateVariables.put("eventId", eventId); responseWrapper = new ResponseWrapper<>(); - templateResponse.put("fileText", "otp"); + templateResponse.put(ResidentConstants.FILE_TEXT, "otp"); responseWrapper.setResponse(templateResponse); Mockito.when(proxyMasterdataService.getAllTemplateBylangCodeAndTemplateTypeCode(Mockito.anyString(), Mockito.anyString())).thenReturn( responseWrapper); From 6917022825f437ee6da3304a89af6d33e487832a Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Tue, 28 Mar 2023 17:30:35 +0530 Subject: [PATCH 04/23] added validation on req credential API --- .../java/io/mosip/resident/constant/ResidentConstants.java | 2 ++ .../resident/controller/ResidentCredentialController.java | 3 +++ .../service/impl/ResidentCredentialServiceImpl.java | 7 ------- .../java/io/mosip/resident/validator/RequestValidator.java | 7 +++++++ .../test/controller/ResidentCredentialControllerTest.java | 6 ++++-- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java index 5eb856a6ee4..dc30f7c6bd5 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java @@ -212,6 +212,8 @@ private ResidentConstants() { public static final String VID_ACTIVE_STATUS = "mosip.idrepo.vid.reactive-status"; public static final int UTC_TIMEZONE_OFFSET = 0; public static final String INDIVIDUAL_ID = "individualId"; + public static final String ISSUER = "issuer"; + public static final String CREDENTIAL_TYPE = "credentialType"; public static final String MUST_NOT_BE_EMPTY = " must not be empty."; public static final String ID = "id"; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java index 316a664f05b..cae4ea900fe 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java @@ -90,6 +90,9 @@ public class ResidentCredentialController { public ResponseEntity reqCredential(@RequestBody RequestWrapper requestDTO) throws ResidentServiceCheckedException { audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ); + validator.validateDataToCheckNullOrEmpty(requestDTO.getRequest().getIndividualId(), ResidentConstants.INDIVIDUAL_ID); + validator.validateDataToCheckNullOrEmpty(requestDTO.getRequest().getCredentialType(), ResidentConstants.CREDENTIAL_TYPE); + validator.validateDataToCheckNullOrEmpty(requestDTO.getRequest().getIssuer(), ResidentConstants.ISSUER); ResponseWrapper response = new ResponseWrapper<>(); response.setResponse(residentCredentialService.reqCredential(requestDTO.getRequest())); audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_SUCCESS); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentCredentialServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentCredentialServiceImpl.java index c52152499e0..3d2497d8388 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentCredentialServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentCredentialServiceImpl.java @@ -11,7 +11,6 @@ import java.util.UUID; import org.apache.commons.collections.map.HashedMap; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; @@ -79,7 +78,6 @@ public class ResidentCredentialServiceImpl implements ResidentCredentialService private static final String NULL = "null"; private static final String PARTNER_TYPE = "partnerType"; private static final String ORGANIZATION_NAME = "organizationName"; - private static final String INDIVIDUAL_ID = "individualId"; private static final String DATA = "data"; @Autowired @@ -148,11 +146,6 @@ public ResidentCredentialResponseDto reqCredential(ResidentCredentialRequestDto throws ResidentServiceCheckedException { Map additionalAttributes = new HashMap<>(); try { - if (StringUtils.isBlank(dto.getIndividualId())) { - throw new ResidentServiceException(ResidentErrorCode.INVALID_INPUT.getErrorCode(), - ResidentErrorCode.INVALID_INPUT.getErrorMessage() + INDIVIDUAL_ID); - } - if (idAuthService.validateOtp(dto.getTransactionID(), dto.getIndividualId(), dto.getOtp())) { return reqCredential(dto, null); } else { diff --git a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java index e1ce7eeea42..bf4daf0e154 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java @@ -1363,4 +1363,11 @@ public void validateName(List name) throws ResidentServiceCheckedExcepti } } + + public void validateDataToCheckNullOrEmpty(String variableValue, String variableName) { + if (StringUtils.isBlank(variableValue)) { + throw new ResidentServiceException(ResidentErrorCode.INVALID_INPUT.getErrorCode(), + ResidentErrorCode.INVALID_INPUT.getErrorMessage() + variableName); + } + } } \ No newline at end of file diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentCredentialControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentCredentialControllerTest.java index 0b7ead5fb4e..0d8a034ac30 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentCredentialControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentCredentialControllerTest.java @@ -33,11 +33,11 @@ import io.mosip.kernel.cbeffutil.impl.CbeffImpl; import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; -import io.mosip.kernel.core.http.RequestWrapper; import io.mosip.resident.controller.ResidentCredentialController; import io.mosip.resident.dto.CredentialCancelRequestResponseDto; import io.mosip.resident.dto.CredentialRequestStatusResponseDto; import io.mosip.resident.dto.PartnerCredentialTypePolicyDto; +import io.mosip.resident.dto.RequestWrapper; import io.mosip.resident.dto.ResidentCredentialRequestDto; import io.mosip.resident.dto.ResidentCredentialResponseDto; import io.mosip.resident.dto.ResidentCredentialResponseDtoV2; @@ -137,7 +137,9 @@ public void setup() throws Exception { this.mockMvc = MockMvcBuilders.standaloneSetup(residentCredentialController).build(); ResidentCredentialRequestDto credentialRequestDto = new ResidentCredentialRequestDto(); credentialRequestDto.setIndividualId("123456"); - reqJson = gson.toJson(credentialRequestDto); + RequestWrapper requestDTO = new RequestWrapper<>(); + requestDTO.setRequest(credentialRequestDto); + reqJson = gson.toJson(requestDTO); pdfbytes = "uin".getBytes(); } From ad40dff028130748fbc28963e8cd128749f8ee49 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Wed, 29 Mar 2023 16:38:18 +0530 Subject: [PATCH 05/23] added validation for req credential API --- .../resident/constant/ResidentConstants.java | 4 ++ .../ResidentCredentialController.java | 4 +- .../resident/validator/RequestValidator.java | 57 ++++++++++++------- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java index dc30f7c6bd5..52167daffed 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java @@ -211,9 +211,13 @@ private ResidentConstants() { public static final String VID_ACTIVE_STATUS = "mosip.idrepo.vid.reactive-status"; public static final int UTC_TIMEZONE_OFFSET = 0; + public static final String INDIVIDUAL_ID = "individualId"; public static final String ISSUER = "issuer"; public static final String CREDENTIAL_TYPE = "credentialType"; + public static final String OTP = "otp"; + public static final String TRANSACTION_ID_OLD = "transactionID"; + public static final String MUST_NOT_BE_EMPTY = " must not be empty."; public static final String ID = "id"; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java index cae4ea900fe..eb7fcd281e1 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java @@ -90,9 +90,7 @@ public class ResidentCredentialController { public ResponseEntity reqCredential(@RequestBody RequestWrapper requestDTO) throws ResidentServiceCheckedException { audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ); - validator.validateDataToCheckNullOrEmpty(requestDTO.getRequest().getIndividualId(), ResidentConstants.INDIVIDUAL_ID); - validator.validateDataToCheckNullOrEmpty(requestDTO.getRequest().getCredentialType(), ResidentConstants.CREDENTIAL_TYPE); - validator.validateDataToCheckNullOrEmpty(requestDTO.getRequest().getIssuer(), ResidentConstants.ISSUER); + validator.validateReqCredentialRequest(requestDTO); ResponseWrapper response = new ResponseWrapper<>(); response.setResponse(residentCredentialService.reqCredential(requestDTO.getRequest())); audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_SUCCESS); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java index bf4daf0e154..a84fa03a90b 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java @@ -61,6 +61,7 @@ import io.mosip.resident.dto.OtpRequestDTOV3; import io.mosip.resident.dto.RequestDTO; import io.mosip.resident.dto.RequestWrapper; +import io.mosip.resident.dto.ResidentCredentialRequestDto; import io.mosip.resident.dto.ResidentReprintRequestDto; import io.mosip.resident.dto.ResidentUpdateRequestDto; import io.mosip.resident.dto.SharableAttributesDTO; @@ -83,6 +84,7 @@ @Component public class RequestValidator { + private static final String REQUEST = "request"; private static final String VALIDATE_EVENT_ID = "Validating Event Id."; @Autowired private UinValidator uinValidator; @@ -286,7 +288,7 @@ public void validateVidCreateRequest(IVidRequestDto if (requestDto.getRequest() == null) { audit.setAuditRequestDto(EventEnum.INPUT_DOESNT_EXISTS); - throw new InvalidInputException("request"); + throw new InvalidInputException(REQUEST); } if (StringUtils.isEmpty(individualId) @@ -341,7 +343,7 @@ public void validateVidCreateV2Request(IVidRequestDto request,String msg } if (request.getRequest() == null) { audit.setAuditRequestDto(EventEnum.INPUT_DOESNT_EXISTS); - throw new InvalidInputException("request"); + throw new InvalidInputException(REQUEST); } } @@ -728,7 +730,7 @@ public void validateRevokeVidV2RequestWrapper(RequestWrapper request,String m } if (request.getRequest() == null) { audit.setAuditRequestDto(EventEnum.INPUT_DOESNT_EXISTS); - throw new InvalidInputException("request"); + throw new InvalidInputException(REQUEST); } } @@ -745,7 +747,7 @@ public boolean validateRequest(RequestWrapper request, RequestIdType requestI if (request.getRequest() == null) { audit.setAuditRequestDto(EventEnum.INPUT_DOESNT_EXISTS); - throw new InvalidInputException("request"); + throw new InvalidInputException(REQUEST); } return true; @@ -764,7 +766,7 @@ public boolean validateAidStatusRequest(RequestWrapper request, RequestIdType if (request.getRequest() == null) { audit.setAuditRequestDto(EventEnum.INPUT_DOESNT_EXISTS); - throw new InvalidInputException("request"); + throw new InvalidInputException(REQUEST); } return true; @@ -1249,22 +1251,44 @@ public void validateDownloadCardVid(String vid) { } } - public boolean validateRequestNewApi(RequestWrapper request, RequestIdType requestIdType) { - if (StringUtils.isEmpty(request.getId()) || !request.getId().equals(map.get(requestIdType))) + public boolean validateRequestNewApi(RequestWrapper requestWrapper, RequestIdType requestIdType) { + if (StringUtils.isEmpty(requestWrapper.getId()) || !requestWrapper.getId().equals(map.get(requestIdType))) throw new InvalidInputException("id"); try { - DateUtils.parseToLocalDateTime(request.getRequesttime()); + DateUtils.parseToLocalDateTime(requestWrapper.getRequesttime()); } catch (Exception e) { throw new InvalidInputException("requesttime"); } - if (StringUtils.isEmpty(request.getVersion()) || !request.getVersion().equals(reqResVersion)) + if (StringUtils.isEmpty(requestWrapper.getVersion()) || !requestWrapper.getVersion().equals(reqResVersion)) throw new InvalidInputException("version"); - if (request.getRequest() == null) { + validateAPIRequestToCheckNull(requestWrapper); + return true; + } + + private void validateAPIRequestToCheckNull(RequestWrapper requestWrapper) { + if (requestWrapper.getRequest() == null) { audit.setAuditRequestDto(EventEnum.INPUT_DOESNT_EXISTS); - throw new InvalidInputException("request"); + throw new InvalidInputException(REQUEST); + } + } + + public void validateReqCredentialRequest(RequestWrapper requestWrapper) { + validateAPIRequestToCheckNull(requestWrapper); + validateDataToCheckNullOrEmpty(requestWrapper.getRequest().getIndividualId(), ResidentConstants.INDIVIDUAL_ID); + validateDataToCheckNullOrEmpty(requestWrapper.getRequest().getCredentialType(), + ResidentConstants.CREDENTIAL_TYPE); + validateDataToCheckNullOrEmpty(requestWrapper.getRequest().getIssuer(), ResidentConstants.ISSUER); + validateDataToCheckNullOrEmpty(requestWrapper.getRequest().getOtp(), ResidentConstants.OTP); + validateDataToCheckNullOrEmpty(requestWrapper.getRequest().getTransactionID(), + ResidentConstants.TRANSACTION_ID_OLD); + } + + private void validateDataToCheckNullOrEmpty(String variableValue, String variableName) { + if (StringUtils.isBlank(variableValue)) { + throw new ResidentServiceException(ResidentErrorCode.INVALID_INPUT.getErrorCode(), + ResidentErrorCode.INVALID_INPUT.getErrorMessage() + variableName); } - return true; } public void validateGrievanceRequestDto(MainRequestDTO grievanceRequestDTOMainRequestDTO) throws ResidentServiceCheckedException, ApisResourceAccessException { @@ -1363,11 +1387,4 @@ public void validateName(List name) throws ResidentServiceCheckedExcepti } } - - public void validateDataToCheckNullOrEmpty(String variableValue, String variableName) { - if (StringUtils.isBlank(variableValue)) { - throw new ResidentServiceException(ResidentErrorCode.INVALID_INPUT.getErrorCode(), - ResidentErrorCode.INVALID_INPUT.getErrorMessage() + variableName); - } - } } \ No newline at end of file From 39838792ba169b26bf64e95e1571159283083646 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Wed, 29 Mar 2023 18:30:43 +0530 Subject: [PATCH 06/23] removed duplicate code --- .../resident/validator/RequestValidator.java | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java index a84fa03a90b..849a294a6de 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java @@ -711,27 +711,24 @@ public void validateVidRevokeV2Request(RequestWrapper request,String msg) { + public void validateRevokeVidV2RequestWrapper(RequestWrapper requestWrapper,String msg) { - if (StringUtils.isEmpty(request.getId()) || !request.getId().equalsIgnoreCase(revokeVidIdNew)) { + if (StringUtils.isEmpty(requestWrapper.getId()) || !requestWrapper.getId().equalsIgnoreCase(revokeVidIdNew)) { audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "revokeVidIdNew", msg)); throw new InvalidInputException("revokeVidIdNew"); } try { - DateUtils.parseToLocalDateTime(request.getRequesttime()); + DateUtils.parseToLocalDateTime(requestWrapper.getRequesttime()); } catch (Exception e) { audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "requesttime", msg)); throw new InvalidInputException("requesttime"); } - if (StringUtils.isEmpty(request.getVersion()) || !request.getVersion().equalsIgnoreCase(revokeVidVersion)) { + if (StringUtils.isEmpty(requestWrapper.getVersion()) || !requestWrapper.getVersion().equalsIgnoreCase(revokeVidVersion)) { audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "revokeVidVersion", msg)); throw new InvalidInputException("revokeVidVersion"); } - if (request.getRequest() == null) { - audit.setAuditRequestDto(EventEnum.INPUT_DOESNT_EXISTS); - throw new InvalidInputException(REQUEST); - } + validateAPIRequestToCheckNull(requestWrapper); } public boolean validateRequest(RequestWrapper request, RequestIdType requestIdType) { @@ -753,23 +750,19 @@ public boolean validateRequest(RequestWrapper request, RequestIdType requestI } - public boolean validateAidStatusRequest(RequestWrapper request, RequestIdType requestIdType) { - if (StringUtils.isEmpty(request.getId()) || !request.getId().equals(map.get(requestIdType))) + public boolean validateAidStatusRequest(RequestWrapper requestWrapper, RequestIdType requestIdType) { + if (StringUtils.isEmpty(requestWrapper.getId()) || !requestWrapper.getId().equals(map.get(requestIdType))) throw new InvalidInputException("id"); try { - DateUtils.parseToLocalDateTime(request.getRequesttime()); + DateUtils.parseToLocalDateTime(requestWrapper.getRequesttime()); } catch (Exception e) { throw new InvalidInputException("requesttime"); } - if (StringUtils.isEmpty(request.getVersion()) || !request.getVersion().equals(newVersion)) + if (StringUtils.isEmpty(requestWrapper.getVersion()) || !requestWrapper.getVersion().equals(newVersion)) throw new InvalidInputException("version"); - if (request.getRequest() == null) { - audit.setAuditRequestDto(EventEnum.INPUT_DOESNT_EXISTS); - throw new InvalidInputException(REQUEST); - } + validateAPIRequestToCheckNull(requestWrapper); return true; - } public boolean isNumeric(String strNum) { @@ -1358,7 +1351,6 @@ public void validateReqOtp(IndividualIdOtpRequestDTO individualIdRequestDto) { validateIndividualIdV2(individualIdRequestDto.getIndividualId()); validateTransactionId(individualIdRequestDto.getTransactionId()); } - public void validatePurpose(String purpose) { validateMissingInputParameter(purpose, TemplateVariablesConstants.PURPOSE, "Validating purpose"); @@ -1385,6 +1377,5 @@ public void validateName(List name) throws ResidentServiceCheckedExcepti throw new ResidentServiceCheckedException(ResidentErrorCode.INVALID_REG_CENTER_NAME.getErrorCode(), ResidentErrorCode.INVALID_REG_CENTER_NAME.getErrorMessage()); } - } } \ No newline at end of file From 900e57ca1b8b62a9cf4ab74a50859839706c481d Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Thu, 30 Mar 2023 19:05:35 +0530 Subject: [PATCH 07/23] fixed rid status issue --- .../mosip/resident/constant/PacketStatus.java | 54 +++++++----- .../resident/constant/TransactionStage.java | 83 ++++++++++--------- .../service/impl/DownloadCardServiceImpl.java | 3 +- .../io/mosip/resident/util/Utilities.java | 35 ++++---- .../resident/test/util/UtilitiesTest.java | 10 +-- 5 files changed, 99 insertions(+), 86 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/PacketStatus.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/PacketStatus.java index 0d730747375..00c3f4dc468 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/PacketStatus.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/PacketStatus.java @@ -2,29 +2,41 @@ import java.util.List; +import org.springframework.core.env.Environment; + /** -Enum to store the TransactionStage -@author Kamesh Shekhar Prasad + * Enum to store the TransactionStage + * + * @author Kamesh Shekhar Prasad */ public enum PacketStatus { - SUCCESS("SUCCESS", List.of("PROCESSED", "SUCCESS", "UIN_GENERATED")), - IN_PROGRESS("IN-PROGRESS", List.of("PROCESSING", "REREGISTER", "RESEND", "RECEIVED", "UPLOAD_PENDING", - "AWAITING_INFORMATION")), - FAILURE("FAILURE", List.of("REJECTED", "FAILURE", "REPROCESS_FAILED")); - private List listOfName; - private String name; - PacketStatus(String name, List listOfName) { - this.name = name; - this.listOfName = listOfName; - } - - public static String getStatusCode(String statusCode){ - for (PacketStatus packetStatus : values()) { - if(packetStatus.listOfName.contains(statusCode)){ - return packetStatus.name; - } - } - return ""; - } + SUCCESS("SUCCESS", "resident.success.packet-status-code.list"), + IN_PROGRESS("IN-PROGRESS", "resident.in-progress.packet-status-code.list"), + FAILURE("FAILURE", "resident.failure.packet-status-code.list"); + + private String name; + private String statusCodePropertyName; + + PacketStatus(String name, String statusCodePropertyName) { + this.name = name; + this.statusCodePropertyName = statusCodePropertyName; + } + + public String getName() { + return name; + } + + public static String getStatusCode(String statusCode, Environment env) { + for (PacketStatus packetStatus : values()) { + if (getStatusCodeList(packetStatus, env).contains(statusCode)) { + return packetStatus.name; + } + } + return ""; + } + + private static List getStatusCodeList(PacketStatus packetStatus, Environment env) { + return List.of(env.getProperty(packetStatus.statusCodePropertyName).split(",")); + } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java index 02a27b65f60..9eab0e6d004 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java @@ -2,45 +2,52 @@ import java.util.List; +import org.springframework.core.env.Environment; + /** -Enum to store the TransactionStage -@author Kamesh Shekhar Prasad + * Enum to store the TransactionStage + * + * @author Kamesh Shekhar Prasad */ public enum TransactionStage { - REQUEST_RECEIVED("Request received", List.of("PACKET_RECEIVER", "UPLOAD_PACKET", "VALIDATE_PACKET", "PACKET_CLASSIFICATION")), - VALIDATION_STAGE("Validation stage", List.of("CMD_VALIDATION", "OPERATOR_VALIDATION", "SUPERVISOR_VALIDATION", - "INTRODUCER_VALIDATION", "EXTERNAL_INTEGRATION")), - VERIFICATION_STAGE("Verification stage", List.of("DEMOGRAPHIC_VERIFICATION", "MANUAL_ADJUDICATION", - "VERIFICATION", "BIOGRAPHIC_VERIFICATION")), - UIN_GENERATION_STAGE("UIN generation stage", List.of("UIN_GENERATOR", "BIOMETRIC_EXTRACTION", "NOTIFICATION")), - CARD_READY_TO_DOWNLOAD("Card ready to download", List.of("PRINT_SERVICE", "PRINT_POSTAL_SERVICE", "PRINT")); - private List listOfName; - private String name; - TransactionStage(String name, List listOfName) { - this.name = name; - this.listOfName = listOfName; - } - - public String getName() { - return name; - } - - public static String getTypeCode(String transactionTypeCode){ - for (TransactionStage transactionStage : values()) { - if(transactionStage.listOfName.contains(transactionTypeCode)){ - return transactionStage.name; - } - } - return ""; - } - - public static boolean containsStatus(String status) { - for (TransactionStage transactionStage : - TransactionStage.values()) { - if (transactionStage.name().equals(status)) { - return true; - } - } - return false; - } + REQUEST_RECEIVED("Request received", "resident.REQUEST_RECEIVED.packet-transaction-type-code.list"), + VALIDATION_STAGE("Validation stage", "resident.VALIDATION_STAGE.packet-transaction-type-code.list"), + VERIFICATION_STAGE("Verification stage", "resident.VERIFICATION_STAGE.packet-transaction-type-code.list"), + UIN_GENERATION_STAGE("UIN generation stage", "resident.UIN_GENERATION_STAGE.packet-transaction-type-code.list"), + CARD_READY_TO_DOWNLOAD("Card ready to download", + "resident.CARD_READY_TO_DOWNLOAD.packet-transaction-type-code.list"); + + private String name; + private String transactionTypeCodePropertyName; + + TransactionStage(String name, String transactionTypeCodePropertyName) { + this.name = name; + this.transactionTypeCodePropertyName = transactionTypeCodePropertyName; + } + + public String getName() { + return name; + } + + public static String getTypeCode(String transactionTypeCode, Environment env) { + for (TransactionStage transactionStage : values()) { + if (getTransactionTypeCodeList(transactionStage, env).contains(transactionTypeCode)) { + return transactionStage.name; + } + } + return ""; + } + + private static List getTransactionTypeCodeList(TransactionStage transactionStage, Environment env) { + return List.of(env.getProperty(transactionStage.transactionTypeCodePropertyName).split(",")); + } + + public static boolean containsStatus(String status) { + for (TransactionStage transactionStage : TransactionStage.values()) { + if (transactionStage.name().equals(status)) { + return true; + } + } + return false; + } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java index 6cd2b53f3b4..5f681eab775 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java @@ -30,6 +30,7 @@ import io.mosip.resident.constant.EventStatusInProgress; import io.mosip.resident.constant.IdType; import io.mosip.resident.constant.LoggerFileConstant; +import io.mosip.resident.constant.PacketStatus; import io.mosip.resident.constant.RequestType; import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.constant.ResidentErrorCode; @@ -140,7 +141,7 @@ public Tuple2 getDownloadCardPDF(MainRequestDTO ridStatus = utilities.getPacketStatus(rid); String transactionTypeCode = ridStatus.get(ResidentConstants.TRANSACTION_TYPE_CODE); String aidStatus = ridStatus.get(ResidentConstants.AID_STATUS); - if (transactionTypeCode.equalsIgnoreCase(TransactionStage.CARD_READY_TO_DOWNLOAD.getName()) && aidStatus.equalsIgnoreCase(EventStatus.SUCCESS.name())) { + if (transactionTypeCode.equalsIgnoreCase(TransactionStage.CARD_READY_TO_DOWNLOAD.getName()) && aidStatus.equalsIgnoreCase(PacketStatus.SUCCESS.getName())) { pdfBytes = residentCredentialService.getCard(rid + ridSuffix, null, null); } else { throw new ResidentServiceException(ResidentErrorCode.CARD_NOT_READY.getErrorCode(), diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/Utilities.java b/resident/resident-service/src/main/java/io/mosip/resident/util/Utilities.java index 6d86b303bd9..b49253cd3ce 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/Utilities.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/Utilities.java @@ -254,18 +254,14 @@ public ArrayList getRidStatus(String rid) throws ApisResourceAccessException, IO } public HashMap getPacketStatus(String rid) throws ApisResourceAccessException, IOException { - String aidStatus=""; - String transactionTypeCode=""; HashMap packetStatusMap = new HashMap<>(); ArrayList regTransactionResponseDTO = getRidStatus(rid); - for(Object object : regTransactionResponseDTO){ - HashMap packetStatus = (HashMap) object; - String statusCode = (String) packetStatus.get(STATUS_CODE); - String packetStatusCode = PacketStatus.getStatusCode(statusCode); - if(!packetStatusCode.isEmpty()){ - aidStatus = packetStatusCode; - transactionTypeCode = getTransactionTypeCode(regTransactionResponseDTO); - packetStatusMap.put(AID_STATUS, aidStatus); + for (Object object : regTransactionResponseDTO) { + HashMap packetData = (HashMap) object; + String packetStatusCode = getPacketStatusCode(packetData); + String transactionTypeCode = getTransactionTypeCode(packetData); + if (!packetStatusCode.isEmpty() && !transactionTypeCode.isEmpty()) { + packetStatusMap.put(AID_STATUS, packetStatusCode); packetStatusMap.put(TRANSACTION_TYPE_CODE, transactionTypeCode); return packetStatusMap; } @@ -273,16 +269,15 @@ public HashMap getPacketStatus(String rid) throws ApisResourceAc return packetStatusMap; } - private String getTransactionTypeCode(ArrayList regTransactionResponseDTO) { - String typeCode=""; - for(Object object : regTransactionResponseDTO){ - HashMap packetStatus = (HashMap) object; - String transactionTypeCode = (String) packetStatus.get(TRANSACTION_TYPE_CODE); - typeCode = TransactionStage.getTypeCode(transactionTypeCode); - if(!typeCode.isEmpty()){ - break; - } - } + private String getPacketStatusCode(HashMap packetData) { + String statusCode = (String) packetData.get(STATUS_CODE); + String packetStatusCode = PacketStatus.getStatusCode(statusCode, env); + return packetStatusCode; + } + + private String getTransactionTypeCode(HashMap packetData) { + String transactionTypeCode = (String) packetData.get(TRANSACTION_TYPE_CODE); + String typeCode = TransactionStage.getTypeCode(transactionTypeCode, env); return typeCode; } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java index d10a576a1bd..7d602dbf840 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java @@ -315,21 +315,19 @@ public void testGetRidStatus() throws ApisResourceAccessException, IOException { @Test public void testGetTransactionTypeCode() throws ApisResourceAccessException, IOException { - ArrayList transactionTypeCode = new ArrayList<>(); + when(env.getProperty(any())).thenReturn("PACKET_UPLOAD,PACKET_RECEIVER"); HashMap packetStatus = new HashMap<>(); packetStatus.put(TRANSACTION_TYPE_CODE, "PACKET_RECEIVER"); - transactionTypeCode.add(packetStatus); assertEquals("Request received", - ReflectionTestUtils.invokeMethod(utilities, "getTransactionTypeCode", transactionTypeCode)); + ReflectionTestUtils.invokeMethod(utilities, "getTransactionTypeCode", packetStatus)); } @Test public void testGetTransactionTypeCodeFailed() throws ApisResourceAccessException, IOException { - ArrayList transactionTypeCode = new ArrayList<>(); + when(env.getProperty(any())).thenReturn("status,packet"); HashMap packetStatus = new HashMap<>(); packetStatus.put(TRANSACTION_TYPE_CODE, "test"); - transactionTypeCode.add(packetStatus); - ReflectionTestUtils.invokeMethod(utilities, "getTransactionTypeCode", transactionTypeCode); + ReflectionTestUtils.invokeMethod(utilities, "getTransactionTypeCode", packetStatus); } @Test From bb6bff3439aa6a07be40cd8b6c4fe68308f020db Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Thu, 30 Mar 2023 20:10:48 +0530 Subject: [PATCH 08/23] removed name from enum --- .../resident/constant/TransactionStage.java | 23 +++++++------------ .../service/impl/DownloadCardServiceImpl.java | 2 +- .../test/service/DownloadCardServiceTest.java | 2 +- .../resident/test/util/UtilitiesTest.java | 2 +- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java index 9eab0e6d004..84939f3bae3 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java @@ -10,29 +10,22 @@ * @author Kamesh Shekhar Prasad */ public enum TransactionStage { - REQUEST_RECEIVED("Request received", "resident.REQUEST_RECEIVED.packet-transaction-type-code.list"), - VALIDATION_STAGE("Validation stage", "resident.VALIDATION_STAGE.packet-transaction-type-code.list"), - VERIFICATION_STAGE("Verification stage", "resident.VERIFICATION_STAGE.packet-transaction-type-code.list"), - UIN_GENERATION_STAGE("UIN generation stage", "resident.UIN_GENERATION_STAGE.packet-transaction-type-code.list"), - CARD_READY_TO_DOWNLOAD("Card ready to download", - "resident.CARD_READY_TO_DOWNLOAD.packet-transaction-type-code.list"); - - private String name; + REQUEST_RECEIVED("resident.REQUEST_RECEIVED.packet-transaction-type-code.list"), + VALIDATION_STAGE("resident.VALIDATION_STAGE.packet-transaction-type-code.list"), + VERIFICATION_STAGE("resident.VERIFICATION_STAGE.packet-transaction-type-code.list"), + UIN_GENERATION_STAGE("resident.UIN_GENERATION_STAGE.packet-transaction-type-code.list"), + CARD_READY_TO_DOWNLOAD("resident.CARD_READY_TO_DOWNLOAD.packet-transaction-type-code.list"); + private String transactionTypeCodePropertyName; - TransactionStage(String name, String transactionTypeCodePropertyName) { - this.name = name; + TransactionStage(String transactionTypeCodePropertyName) { this.transactionTypeCodePropertyName = transactionTypeCodePropertyName; } - public String getName() { - return name; - } - public static String getTypeCode(String transactionTypeCode, Environment env) { for (TransactionStage transactionStage : values()) { if (getTransactionTypeCodeList(transactionStage, env).contains(transactionTypeCode)) { - return transactionStage.name; + return transactionStage.name(); } } return ""; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java index 5f681eab775..2db9386ee8d 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java @@ -141,7 +141,7 @@ public Tuple2 getDownloadCardPDF(MainRequestDTO ridStatus = utilities.getPacketStatus(rid); String transactionTypeCode = ridStatus.get(ResidentConstants.TRANSACTION_TYPE_CODE); String aidStatus = ridStatus.get(ResidentConstants.AID_STATUS); - if (transactionTypeCode.equalsIgnoreCase(TransactionStage.CARD_READY_TO_DOWNLOAD.getName()) && aidStatus.equalsIgnoreCase(PacketStatus.SUCCESS.getName())) { + if (transactionTypeCode.equalsIgnoreCase(TransactionStage.CARD_READY_TO_DOWNLOAD.name()) && aidStatus.equalsIgnoreCase(PacketStatus.SUCCESS.getName())) { pdfBytes = residentCredentialService.getCard(rid + ridSuffix, null, null); } else { throw new ResidentServiceException(ResidentErrorCode.CARD_NOT_READY.getErrorCode(), diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java index 50fd9c0c3e8..6ea5a3f8929 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java @@ -173,7 +173,7 @@ public void testGetDownloadCardPdfAID() throws ApisResourceAccessException, IOEx String rid = "7841261580"; HashMap hashMap = new HashMap<>(); hashMap.put(ResidentConstants.AID_STATUS, "SUCCESS"); - hashMap.put(ResidentConstants.TRANSACTION_TYPE_CODE, TransactionStage.CARD_READY_TO_DOWNLOAD.getName()); + hashMap.put(ResidentConstants.TRANSACTION_TYPE_CODE, TransactionStage.CARD_READY_TO_DOWNLOAD.name()); Mockito.when(utilities.getPacketStatus(rid)).thenReturn(hashMap); Mockito.when(identityService.getIndividualIdType(Mockito.anyString())).thenReturn("AID"); Tuple2 actualResult = downloadCardService.getDownloadCardPDF(downloadCardRequestDTOMainRequestDTO); diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java index 7d602dbf840..4c3f32da503 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java @@ -318,7 +318,7 @@ public void testGetTransactionTypeCode() throws ApisResourceAccessException, IOE when(env.getProperty(any())).thenReturn("PACKET_UPLOAD,PACKET_RECEIVER"); HashMap packetStatus = new HashMap<>(); packetStatus.put(TRANSACTION_TYPE_CODE, "PACKET_RECEIVER"); - assertEquals("Request received", + assertEquals("REQUEST_RECEIVED", ReflectionTestUtils.invokeMethod(utilities, "getTransactionTypeCode", packetStatus)); } From e98a73ce290a38677a3a4cde7fd1c3242a7f657b Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Fri, 31 Mar 2023 14:59:35 +0530 Subject: [PATCH 09/23] code fix for rid status issue --- .../mosip/resident/constant/PacketStatus.java | 7 +-- .../resident/constant/TransactionStage.java | 7 +-- .../resident/service/DownloadCardService.java | 3 +- .../service/impl/DownloadCardServiceImpl.java | 8 +-- .../io/mosip/resident/util/Utilities.java | 50 +++++++++++-------- .../test/service/DownloadCardServiceTest.java | 8 +-- .../resident/test/util/UtilitiesTest.java | 6 ++- 7 files changed, 52 insertions(+), 37 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/PacketStatus.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/PacketStatus.java index 00c3f4dc468..22f3fecd9cd 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/PacketStatus.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/PacketStatus.java @@ -1,6 +1,7 @@ package io.mosip.resident.constant; import java.util.List; +import java.util.Optional; import org.springframework.core.env.Environment; @@ -26,13 +27,13 @@ public String getName() { return name; } - public static String getStatusCode(String statusCode, Environment env) { + public static Optional getStatusCode(String statusCode, Environment env) { for (PacketStatus packetStatus : values()) { if (getStatusCodeList(packetStatus, env).contains(statusCode)) { - return packetStatus.name; + return Optional.of(packetStatus.name); } } - return ""; + return Optional.empty(); } private static List getStatusCodeList(PacketStatus packetStatus, Environment env) { diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java index 84939f3bae3..6df08669471 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/TransactionStage.java @@ -1,6 +1,7 @@ package io.mosip.resident.constant; import java.util.List; +import java.util.Optional; import org.springframework.core.env.Environment; @@ -22,13 +23,13 @@ public enum TransactionStage { this.transactionTypeCodePropertyName = transactionTypeCodePropertyName; } - public static String getTypeCode(String transactionTypeCode, Environment env) { + public static Optional getTypeCode(String transactionTypeCode, Environment env) { for (TransactionStage transactionStage : values()) { if (getTransactionTypeCodeList(transactionStage, env).contains(transactionTypeCode)) { - return transactionStage.name(); + return Optional.of(transactionStage.name()); } } - return ""; + return Optional.empty(); } private static List getTransactionTypeCodeList(TransactionStage transactionStage, Environment env) { diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java index 2327a62db07..06f6587bc52 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java @@ -10,6 +10,7 @@ import io.mosip.resident.dto.ResponseWrapper; import io.mosip.resident.dto.VidDownloadCardResponseDto; import io.mosip.resident.exception.ApisResourceAccessException; +import io.mosip.resident.exception.ResidentServiceCheckedException; import reactor.util.function.Tuple2; /** @@ -23,5 +24,5 @@ public interface DownloadCardService { Tuple2, String> getVidCardEventId(String vid, int timeZoneOffset) throws BaseCheckedException; - ResponseWrapper getIndividualIdStatus(String vid) throws ApisResourceAccessException, IOException; + ResponseWrapper getIndividualIdStatus(String vid) throws ApisResourceAccessException, IOException, ResidentServiceCheckedException; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java index 2db9386ee8d..d2a6b9cbc0b 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java @@ -138,7 +138,7 @@ public Tuple2 getDownloadCardPDF(MainRequestDTO ridStatus = utilities.getPacketStatus(rid); + Map ridStatus = utilities.getPacketStatus(rid); String transactionTypeCode = ridStatus.get(ResidentConstants.TRANSACTION_TYPE_CODE); String aidStatus = ridStatus.get(ResidentConstants.AID_STATUS); if (transactionTypeCode.equalsIgnoreCase(TransactionStage.CARD_READY_TO_DOWNLOAD.name()) && aidStatus.equalsIgnoreCase(PacketStatus.SUCCESS.getName())) { @@ -182,7 +182,7 @@ public Tuple2 getDownloadCardPDF(MainRequestDTO getCheckStatusResponse(HashMap packetStatusMap) { + private ResponseWrapper getCheckStatusResponse(Map packetStatusMap) { ResponseWrapper checkStatusResponseDTOResponseWrapper = new ResponseWrapper<>(); CheckStatusResponseDTO checkStatusResponseDTO = new CheckStatusResponseDTO(); String aidStatus = packetStatusMap.get(ResidentConstants.AID_STATUS); @@ -412,9 +412,9 @@ public Tuple2, String> getVidCardEve } @Override - public ResponseWrapper getIndividualIdStatus(String individualId) throws ApisResourceAccessException, IOException { + public ResponseWrapper getIndividualIdStatus(String individualId) throws ApisResourceAccessException, IOException, ResidentServiceCheckedException { individualId = getRidForIndividualId(individualId); - HashMap packetStatusMap = utilities.getPacketStatus(individualId); + Map packetStatusMap = utilities.getPacketStatus(individualId); return getCheckStatusResponse(packetStatusMap); } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/Utilities.java b/resident/resident-service/src/main/java/io/mosip/resident/util/Utilities.java index b49253cd3ce..3023530f42f 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/Utilities.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/Utilities.java @@ -237,47 +237,57 @@ public String getRidByIndividualId(String individualId) throws ApisResourceAcces return rid; } - public ArrayList getRidStatus(String rid) throws ApisResourceAccessException, IOException { + public ArrayList getRidStatus(String rid) throws ApisResourceAccessException, IOException, ResidentServiceCheckedException { logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), "", "Utilities::getRidStatus():: entry"); Map pathsegments = new HashMap(); pathsegments.put("rid", rid); logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), "", "Stage::methodname():: RETRIEVEIUINBYVID GET service call Started"); - ResponseWrapper response = (ResponseWrapper)residentServiceRestClient.getApi(ApiName.GET_RID_STATUS, + ResponseWrapper responseWrapper = (ResponseWrapper)residentServiceRestClient.getApi(ApiName.GET_RID_STATUS, pathsegments, ResponseWrapper.class); + if (responseWrapper.getErrors() != null && !responseWrapper.getErrors().isEmpty()) { + logger.debug(responseWrapper.getErrors().get(0).toString()); + throw new ResidentServiceCheckedException(ResidentErrorCode.RID_NOT_FOUND.getErrorCode(), + responseWrapper.getErrors().get(0).getMessage()); + } logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.UIN.toString(), "", "Utilities::getRidByIndividualId():: GET_RID_BY_INDIVIDUAL_ID GET service call ended successfully"); - ArrayList objectArrayList = objMapper.readValue( - objMapper.writeValueAsString(response.getResponse()), ArrayList.class); + ArrayList objectArrayList = objMapper.readValue( + objMapper.writeValueAsString(responseWrapper.getResponse()), ArrayList.class); return objectArrayList; } - public HashMap getPacketStatus(String rid) throws ApisResourceAccessException, IOException { - HashMap packetStatusMap = new HashMap<>(); - ArrayList regTransactionResponseDTO = getRidStatus(rid); - for (Object object : regTransactionResponseDTO) { - HashMap packetData = (HashMap) object; - String packetStatusCode = getPacketStatusCode(packetData); - String transactionTypeCode = getTransactionTypeCode(packetData); - if (!packetStatusCode.isEmpty() && !transactionTypeCode.isEmpty()) { - packetStatusMap.put(AID_STATUS, packetStatusCode); - packetStatusMap.put(TRANSACTION_TYPE_CODE, transactionTypeCode); - return packetStatusMap; + public Map getPacketStatus(String rid) + throws ApisResourceAccessException, IOException, ResidentServiceCheckedException { + Map packetStatusMap = new HashMap<>(); + ArrayList regTransactionList = getRidStatus(rid); + for (Object object : regTransactionList) { + if (object instanceof Map) { + Map packetData = (Map) object; + Optional packetStatusCode = getPacketStatusCode(packetData); + Optional transactionTypeCode = getTransactionTypeCode(packetData); + if (packetStatusCode.isPresent() && transactionTypeCode.isPresent()) { + packetStatusMap.put(AID_STATUS, packetStatusCode.get()); + packetStatusMap.put(TRANSACTION_TYPE_CODE, transactionTypeCode.get()); + return packetStatusMap; + } } } - return packetStatusMap; + throw new ResidentServiceCheckedException(ResidentErrorCode.UNKNOWN_EXCEPTION.getErrorCode(), + String.format("%s - Unable to get the RID status from Reg-proc", + ResidentErrorCode.UNKNOWN_EXCEPTION.getErrorMessage())); } - private String getPacketStatusCode(HashMap packetData) { + private Optional getPacketStatusCode(Map packetData) { String statusCode = (String) packetData.get(STATUS_CODE); - String packetStatusCode = PacketStatus.getStatusCode(statusCode, env); + Optional packetStatusCode = PacketStatus.getStatusCode(statusCode, env); return packetStatusCode; } - private String getTransactionTypeCode(HashMap packetData) { + private Optional getTransactionTypeCode(Map packetData) { String transactionTypeCode = (String) packetData.get(TRANSACTION_TYPE_CODE); - String typeCode = TransactionStage.getTypeCode(transactionTypeCode, env); + Optional typeCode = TransactionStage.getTypeCode(transactionTypeCode, env); return typeCode; } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java index 6ea5a3f8929..21dbf9c7d4b 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java @@ -169,9 +169,9 @@ public void testGetDownloadCardPdfVID(){ } @Test - public void testGetDownloadCardPdfAID() throws ApisResourceAccessException, IOException { + public void testGetDownloadCardPdfAID() throws ApisResourceAccessException, IOException, ResidentServiceCheckedException { String rid = "7841261580"; - HashMap hashMap = new HashMap<>(); + Map hashMap = new HashMap<>(); hashMap.put(ResidentConstants.AID_STATUS, "SUCCESS"); hashMap.put(ResidentConstants.TRANSACTION_TYPE_CODE, TransactionStage.CARD_READY_TO_DOWNLOAD.name()); Mockito.when(utilities.getPacketStatus(rid)).thenReturn(hashMap); @@ -355,8 +355,8 @@ public void testGetVidCardEventIdWithVidDetails() throws BaseCheckedException { } @Test - public void testGetIndividualIdStatus() throws ApisResourceAccessException, IOException { - HashMap packetStatusMap = new HashMap<>(); + public void testGetIndividualIdStatus() throws ApisResourceAccessException, IOException, ResidentServiceCheckedException { + Map packetStatusMap = new HashMap<>(); packetStatusMap.put(ResidentConstants.AID_STATUS, PacketStatus.SUCCESS.name()); packetStatusMap.put(ResidentConstants.TRANSACTION_TYPE_CODE, TransactionStage.CARD_READY_TO_DOWNLOAD.name()); Mockito.when(utilities.getPacketStatus(Mockito.anyString())).thenReturn(packetStatusMap); diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java index 4c3f32da503..8a7533f2366 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/util/UtilitiesTest.java @@ -18,6 +18,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import org.apache.commons.io.IOUtils; import org.json.simple.JSONObject; @@ -50,6 +51,7 @@ import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.IdRepoAppException; import io.mosip.resident.exception.IndividualIdNotFoundException; +import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.exception.VidCreationException; import io.mosip.resident.util.JsonUtil; import io.mosip.resident.util.ResidentServiceRestClient; @@ -304,7 +306,7 @@ public void testGetRidByIndividualIdFailed() throws ApisResourceAccessException } @Test - public void testGetRidStatus() throws ApisResourceAccessException, IOException { + public void testGetRidStatus() throws ApisResourceAccessException, IOException, ResidentServiceCheckedException { ResponseWrapper response = new ResponseWrapper<>(); ArrayList arrayList = new ArrayList<>(); arrayList.add("123"); @@ -318,7 +320,7 @@ public void testGetTransactionTypeCode() throws ApisResourceAccessException, IOE when(env.getProperty(any())).thenReturn("PACKET_UPLOAD,PACKET_RECEIVER"); HashMap packetStatus = new HashMap<>(); packetStatus.put(TRANSACTION_TYPE_CODE, "PACKET_RECEIVER"); - assertEquals("REQUEST_RECEIVED", + assertEquals(Optional.of("REQUEST_RECEIVED"), ReflectionTestUtils.invokeMethod(utilities, "getTransactionTypeCode", packetStatus)); } From 44057965d78efe6e4b24ba82302f078190ca2946 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Fri, 31 Mar 2023 16:56:08 +0530 Subject: [PATCH 10/23] update validate request body method --- .../resident/validator/RequestValidator.java | 77 ++++++++----------- 1 file changed, 32 insertions(+), 45 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java index c412728c8ba..bf64704a41c 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java @@ -1,8 +1,6 @@ package io.mosip.resident.validator; -import static io.mosip.resident.constant.RegistrationConstants.ID; import static io.mosip.resident.constant.RegistrationConstants.MESSAGE_CODE; -import static io.mosip.resident.constant.RegistrationConstants.VERSION; import static io.mosip.resident.service.impl.ResidentOtpServiceImpl.EMAIL_CHANNEL; import static io.mosip.resident.service.impl.ResidentOtpServiceImpl.PHONE_CHANNEL; @@ -84,8 +82,12 @@ @Component public class RequestValidator { + private static final String ID = "id"; + private static final String VERSION = "version"; + private static final String REQUESTTIME = "requesttime"; private static final String REQUEST = "request"; private static final String VALIDATE_EVENT_ID = "Validating Event Id."; + @Autowired private UinValidator uinValidator; @@ -267,23 +269,23 @@ public void validateVidCreateRequest(IVidRequestDto DateUtils.parseToLocalDateTime(requestDto.getRequesttime()); } catch (Exception e) { audit.setAuditRequestDto( - EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "requesttime", "Request to generate VID")); + EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, REQUESTTIME, "Request to generate VID")); - throw new InvalidInputException("requesttime"); + throw new InvalidInputException(REQUESTTIME); } if (StringUtils.isEmpty(requestDto.getId()) || !requestDto.getId().equalsIgnoreCase(id)) { audit.setAuditRequestDto( - EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "id", "Request to generate VID")); + EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, ID, "Request to generate VID")); - throw new InvalidInputException("id"); + throw new InvalidInputException(ID); } if (StringUtils.isEmpty(requestDto.getVersion()) || !requestDto.getVersion().equalsIgnoreCase(version)) { audit.setAuditRequestDto( - EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "version", "Request to generate VID")); + EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, VERSION, "Request to generate VID")); - throw new InvalidInputException("version"); + throw new InvalidInputException(VERSION); } if (requestDto.getRequest() == null) { @@ -322,9 +324,9 @@ public void validateVidCreateV2Request(IVidRequestDto request,String msg try { DateUtils.parseToLocalDateTime(request.getRequesttime()); } catch (Exception e) { - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "requesttime", msg)); - throw new InvalidInputException("requesttime"); + audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, REQUESTTIME, msg)); + throw new InvalidInputException(REQUESTTIME); } if (StringUtils.isEmpty(request.getVersion()) || !request.getVersion().equalsIgnoreCase(version)) { - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "version", msg)); - throw new InvalidInputException("version"); + audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, VERSION, msg)); + throw new InvalidInputException(VERSION); } if (request.getRequest() == null) { audit.setAuditRequestDto(EventEnum.INPUT_DOESNT_EXISTS); @@ -720,8 +722,8 @@ public void validateRevokeVidV2RequestWrapper(RequestWrapper requestWrapper,S try { DateUtils.parseToLocalDateTime(requestWrapper.getRequesttime()); } catch (Exception e) { - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "requesttime", msg)); - throw new InvalidInputException("requesttime"); + audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, REQUESTTIME, msg)); + throw new InvalidInputException(REQUESTTIME); } if (StringUtils.isEmpty(requestWrapper.getVersion()) || !requestWrapper.getVersion().equalsIgnoreCase(revokeVidVersion)) { @@ -733,14 +735,14 @@ public void validateRevokeVidV2RequestWrapper(RequestWrapper requestWrapper,S public boolean validateRequest(RequestWrapper request, RequestIdType requestIdType) { if (StringUtils.isEmpty(request.getId()) || !request.getId().equals(map.get(requestIdType))) - throw new InvalidInputException("id"); + throw new InvalidInputException(ID); try { DateUtils.parseToLocalDateTime(request.getRequesttime()); } catch (Exception e) { - throw new InvalidInputException("requesttime"); + throw new InvalidInputException(REQUESTTIME); } if (StringUtils.isEmpty(request.getVersion()) || !request.getVersion().equals(version)) - throw new InvalidInputException("version"); + throw new InvalidInputException(VERSION); if (request.getRequest() == null) { audit.setAuditRequestDto(EventEnum.INPUT_DOESNT_EXISTS); @@ -750,21 +752,6 @@ public boolean validateRequest(RequestWrapper request, RequestIdType requestI } - public boolean validateAidStatusRequest(RequestWrapper requestWrapper, RequestIdType requestIdType) { - if (StringUtils.isEmpty(requestWrapper.getId()) || !requestWrapper.getId().equals(map.get(requestIdType))) - throw new InvalidInputException("id"); - try { - DateUtils.parseToLocalDateTime(requestWrapper.getRequesttime()); - } catch (Exception e) { - throw new InvalidInputException("requesttime"); - } - if (StringUtils.isEmpty(requestWrapper.getVersion()) || !requestWrapper.getVersion().equals(newVersion)) - throw new InvalidInputException("version"); - - validateAPIRequestToCheckNull(requestWrapper); - return true; - } - public boolean isNumeric(String strNum) { return strNum.matches(numericDataRegex); } @@ -925,7 +912,7 @@ private boolean validateIndividualIdvIdWithoutIdType(String individualId) { } public void validateAidStatusRequestDto(RequestWrapper reqDto) throws ResidentServiceCheckedException { - validateAidStatusRequest(reqDto, RequestIdType.CHECK_STATUS); + validateRequestNewApi(reqDto, RequestIdType.CHECK_STATUS); validateTransactionId(reqDto.getRequest().getTransactionId()); if(reqDto.getRequest().getIndividualId() == null) { throw new InvalidInputException("individualId"); @@ -1093,12 +1080,12 @@ private void validateLanguageCode(String languageCode) { public void validateId(io.mosip.preregistration.core.common.dto.MainRequestDTO requestDTO) { if (Objects.nonNull(requestDTO.getId())) { if (!requestDTO.getId().equals(transliterateId)) { - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "id", "Invalid Transliterate id")); - throw new InvalidInputException("id"); + audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, ID, "Invalid Transliterate id")); + throw new InvalidInputException(ID); } } else { - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "id", "id is null")); - throw new InvalidInputException("id"); + audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, ID, "id is null")); + throw new InvalidInputException(ID); } if (requestDTO.getRequest().getFromFieldLang().equalsIgnoreCase(requestDTO.getRequest().getToFieldLang())) { throw new InvalidInputException("'from' and 'to' languages cannot be same"); @@ -1182,8 +1169,8 @@ public void validateRequestType(String inputRequestType, String requestTypeStore public void validateDate(Date requesttime) { if(requesttime==null) { audit.setAuditRequestDto( - EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "requesttime", "Request time invalid")); - throw new InvalidInputException("requesttime"); + EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, REQUESTTIME, "Request time invalid")); + throw new InvalidInputException(REQUESTTIME); } } @@ -1221,7 +1208,7 @@ private void validateAttributeList(List attributes) { public void validateVersion(String requestVersion) { if (StringUtils.isEmpty(requestVersion) || !requestVersion.equals(reqResVersion)) - throw new InvalidInputException("version"); + throw new InvalidInputException(VERSION); } private void validateEncodedString(String html) { @@ -1249,14 +1236,14 @@ public void validateDownloadCardVid(String vid) { public boolean validateRequestNewApi(RequestWrapper requestWrapper, RequestIdType requestIdType) { if (StringUtils.isEmpty(requestWrapper.getId()) || !requestWrapper.getId().equals(map.get(requestIdType))) - throw new InvalidInputException("id"); + throw new InvalidInputException(ID); try { DateUtils.parseToLocalDateTime(requestWrapper.getRequesttime()); } catch (Exception e) { - throw new InvalidInputException("requesttime"); + throw new InvalidInputException(REQUESTTIME); } if (StringUtils.isEmpty(requestWrapper.getVersion()) || !requestWrapper.getVersion().equals(reqResVersion)) - throw new InvalidInputException("version"); + throw new InvalidInputException(VERSION); validateAPIRequestToCheckNull(requestWrapper); return true; From c68783ba1a4032cdacc225e7c8f54dea4e8968e3 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Wed, 5 Apr 2023 21:01:32 +0530 Subject: [PATCH 11/23] fixed registration center issue --- .../resident/constant/ResidentConstants.java | 2 ++ .../DownLoadMasterDataController.java | 3 +- .../RegistrationCenterInfoResponseDto.java | 20 +++++++++++ .../service/DownLoadMasterDataService.java | 2 +- .../impl/DownLoadMasterDataServiceImpl.java | 34 ++++++++++++++----- .../service/impl/ProxyIdRepoServiceImpl.java | 3 +- .../resident/validator/RequestValidator.java | 4 +-- .../DownloadmasterDataServiceImplTest.java | 6 ++-- .../src/test/resources/application.properties | 1 + 9 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 resident/resident-service/src/main/java/io/mosip/resident/dto/RegistrationCenterInfoResponseDto.java diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java index 17732274234..25afe56feee 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java @@ -240,6 +240,8 @@ private ResidentConstants() { public static final String RESIDENT_VIEW_HISTORY_DEFAULT_PAGE_SIZE = "resident.view-history.default.page.size"; public static final String LANGUAGE = "language"; public static final String VALUE = "value"; + + public static final String RESIDENT_REGISTRATION_CENTERS_DOWNLOAD_MAX_COUNT = "resident.registration-centers.download.max.count"; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/DownLoadMasterDataController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/DownLoadMasterDataController.java index 9c185bb1d2b..fdeb88f110e 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/DownLoadMasterDataController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/DownLoadMasterDataController.java @@ -4,7 +4,6 @@ import java.io.InputStream; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.List; import java.util.Objects; import org.springframework.beans.factory.annotation.Autowired; @@ -73,7 +72,7 @@ public class DownLoadMasterDataController { */ @GetMapping("/download/registration-centers-list") public ResponseEntity downloadRegistrationCentersByHierarchyLevel(@RequestParam(name="langcode") String langCode, - @RequestParam(name="hierarchylevel") Short hierarchyLevel, @RequestParam("name") List name, + @RequestParam(name="hierarchylevel") Short hierarchyLevel, @RequestParam("name") String name, @RequestHeader(name = "time-zone-offset", required = false, defaultValue = "0") int timeZoneOffset) throws ResidentServiceCheckedException, IOException, Exception { logger.debug("DownLoadMasterDataController::getRegistrationCentersByHierarchyLevel()::entry"); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/RegistrationCenterInfoResponseDto.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/RegistrationCenterInfoResponseDto.java new file mode 100644 index 00000000000..2e7f7724fee --- /dev/null +++ b/resident/resident-service/src/main/java/io/mosip/resident/dto/RegistrationCenterInfoResponseDto.java @@ -0,0 +1,20 @@ +package io.mosip.resident.dto; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author Ritik Jain + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class RegistrationCenterInfoResponseDto extends RegistrationCenterResponseDto { + + /** The registration centers data. */ + private List data; + +} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/DownLoadMasterDataService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/DownLoadMasterDataService.java index 9f1e5d8d3f1..9f8c81bb2c8 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/DownLoadMasterDataService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/DownLoadMasterDataService.java @@ -25,7 +25,7 @@ public interface DownLoadMasterDataService { * @throws ResidentServiceCheckedException */ public InputStream downloadRegistrationCentersByHierarchyLevel(String langCode, Short hierarchyLevel, - List name) throws ResidentServiceCheckedException, IOException, Exception; + String name) throws ResidentServiceCheckedException, IOException, Exception; /** * diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownLoadMasterDataServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownLoadMasterDataServiceImpl.java index 7b3f9ca3e2b..6d0d4265bd6 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownLoadMasterDataServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownLoadMasterDataServiceImpl.java @@ -1,5 +1,7 @@ package io.mosip.resident.service.impl; +import static io.mosip.resident.constant.ResidentConstants.RESIDENT_REGISTRATION_CENTERS_DOWNLOAD_MAX_COUNT; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -22,6 +24,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @@ -32,10 +35,11 @@ import io.mosip.kernel.core.templatemanager.spi.TemplateManager; import io.mosip.kernel.core.templatemanager.spi.TemplateManagerBuilder; import io.mosip.resident.config.LoggerConfiguration; +import io.mosip.resident.constant.OrderEnum; import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.constant.ResidentErrorCode; import io.mosip.resident.dto.RegistrationCenterDto; -import io.mosip.resident.dto.RegistrationCenterResponseDto; +import io.mosip.resident.dto.RegistrationCenterInfoResponseDto; import io.mosip.resident.dto.WorkingDaysDto; import io.mosip.resident.dto.WorkingDaysResponseDto; import io.mosip.resident.exception.ResidentServiceCheckedException; @@ -73,6 +77,9 @@ public class DownLoadMasterDataServiceImpl implements DownLoadMasterDataService @Autowired private Utility utility; + @Value("${" + RESIDENT_REGISTRATION_CENTERS_DOWNLOAD_MAX_COUNT + "}") + private Integer maxRegistrationCenterPageSize; + private static final Logger logger = LoggerConfiguration.logConfig(ProxyMasterdataServiceImpl.class); @PostConstruct @@ -86,21 +93,21 @@ public void idTemplateManagerPostConstruct() { * center names */ public InputStream downloadRegistrationCentersByHierarchyLevel(String langCode, Short hierarchyLevel, - List name) throws ResidentServiceCheckedException, IOException, Exception { + String name) throws ResidentServiceCheckedException, IOException, Exception { logger.debug("DownLoadMasterDataService::downloadRegistrationCentersByHierarchyLevel()::entry"); - ResponseWrapper regCentResponseWrapper = proxyMasterdataService.getRegistrationCentersByHierarchyLevel(langCode, hierarchyLevel, name); - return getRegistrationCentrePdf(langCode, regCentResponseWrapper); + ResponseWrapper regCentResponseWrapper = proxyMasterdataService.getRegistrationCenterByHierarchyLevelAndTextPaginated(langCode, hierarchyLevel, name, 0, maxRegistrationCenterPageSize, OrderEnum.desc, null); + return getRegistrationCentersPdf(langCode, regCentResponseWrapper); } - public InputStream getRegistrationCentrePdf(String langCode, ResponseWrapper regCentResponseWrapper) throws ResidentServiceCheckedException, IOException { + public InputStream getRegistrationCentersPdf(String langCode, ResponseWrapper regCentResponseWrapper) throws ResidentServiceCheckedException, IOException { ResponseWrapper proxyResponseWrapper = proxyMasterdataService .getAllTemplateBylangCodeAndTemplateTypeCode(langCode, this.env.getProperty(ResidentConstants.REGISTRATION_CENTRE_TEMPLATE_PROPERTY)); Map regCentersMap = new LinkedHashMap<>(); if (regCentResponseWrapper != null) { - RegistrationCenterResponseDto registrationCentersDtls = mapper.readValue( + RegistrationCenterInfoResponseDto registrationCentersDtls = mapper.readValue( mapper.writeValueAsString(regCentResponseWrapper.getResponse()), - RegistrationCenterResponseDto.class); - List regCenterIntialList = registrationCentersDtls.getRegistrationCenters(); + RegistrationCenterInfoResponseDto.class); + List regCenterIntialList = getRegCenterList(registrationCentersDtls); if (regCenterIntialList != null && !regCenterIntialList.isEmpty()) { IntStream.range(0, regCenterIntialList.size()).forEach(i -> { try { @@ -123,6 +130,15 @@ public InputStream getRegistrationCentrePdf(String langCode, ResponseWrapper IOUtils.copy(downLoadRegCenterTemplateData, writer, "UTF-8"); return new ByteArrayInputStream(utility.signPdf(new ByteArrayInputStream(writer.toString().getBytes()), null)); } + + private List getRegCenterList(RegistrationCenterInfoResponseDto registrationCentersDtls) { + if (registrationCentersDtls.getData() != null && !registrationCentersDtls.getData().isEmpty()) { + return registrationCentersDtls.getData(); + } else if (registrationCentersDtls.getRegistrationCenters() != null && !registrationCentersDtls.getRegistrationCenters().isEmpty()) { + return registrationCentersDtls.getRegistrationCenters(); + } + return List.of(); + } /** * download the nearest registration centers @@ -132,7 +148,7 @@ public InputStream getNearestRegistrationcenters(String langCode, double longitu logger.debug("DownLoadMasterDataService::downloadRegistrationCentersByHierarchyLevel()::entry"); ResponseWrapper regCentResponseWrapper = proxyMasterdataService.getCoordinateSpecificRegistrationCenters(langCode, longitude, latitude, proximityDistance); - return getRegistrationCentrePdf(langCode, regCentResponseWrapper); + return getRegistrationCentersPdf(langCode, regCentResponseWrapper); } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyIdRepoServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyIdRepoServiceImpl.java index 4dbe08d53b7..a7cfe8aa9a2 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyIdRepoServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyIdRepoServiceImpl.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -49,7 +50,7 @@ public ResponseWrapper getRemainingUpdateCountByIndividualId(List att queryParamName.add("attribute_list"); List queryParamValue = new ArrayList<>(); - queryParamValue.add(attributeList.stream().collect(Collectors.joining(","))); + queryParamValue.add(Objects.isNull(attributeList) ? "" : attributeList.stream().collect(Collectors.joining(","))); ResponseWrapper responseWrapper = residentServiceRestClient.getApi(ApiName.IDREPO_IDENTITY_UPDATE_COUNT, pathsegements, queryParamName, queryParamValue, ResponseWrapper.class); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java index 29dec91978c..65ac43cf131 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java @@ -1415,8 +1415,8 @@ public void validateSharableAttributes(List sharableAttri } } - public void validateName(List name) throws ResidentServiceCheckedException { - if (name == null || name.isEmpty()) { + public void validateName(String name) throws ResidentServiceCheckedException { + if (StringUtils.isBlank(name)) { throw new ResidentServiceCheckedException(ResidentErrorCode.INVALID_REG_CENTER_NAME.getErrorCode(), ResidentErrorCode.INVALID_REG_CENTER_NAME.getErrorMessage()); } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadmasterDataServiceImplTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadmasterDataServiceImplTest.java index ae12ac79df4..fa575488644 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadmasterDataServiceImplTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadmasterDataServiceImplTest.java @@ -101,7 +101,7 @@ public class DownloadmasterDataServiceImplTest { private String langCode; private Short hierarchyLevel; - private List name; + private String name; @Before public void setup() throws Exception { @@ -133,12 +133,12 @@ public void setup() throws Exception { Mockito.when(environment.getProperty(Mockito.anyString())).thenReturn("supporting-docs-list"); langCode="eng"; hierarchyLevel=4; - name = new ArrayList<>(); - name.add("name1"); + name = "name1"; } @Test public void testDownloadRegistrationCentersByHierarchyLevel() throws Exception { + ReflectionTestUtils.setField(downLoadMasterDataService, "maxRegistrationCenterPageSize", 10); byte[] actualResult = downLoadMasterDataService.downloadRegistrationCentersByHierarchyLevel(langCode, hierarchyLevel, name).readAllBytes(); assertNotNull(actualResult); } diff --git a/resident/resident-service/src/test/resources/application.properties b/resident/resident-service/src/test/resources/application.properties index bcd9131f85f..8c3eba384ab 100644 --- a/resident/resident-service/src/test/resources/application.properties +++ b/resident/resident-service/src/test/resources/application.properties @@ -457,3 +457,4 @@ resident.otp.validation.transaction-id.regex=^[0-9]{10}$ resident.validation.event-id.regex=^[0-9]{16}$ mosip.registration.processor.rid.delimiter=-PDF +resident.registration-centers.download.max.count=10 From fb50ef100e65cdbda7e762ff9c50047d4f6ee695 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Wed, 12 Apr 2023 19:02:58 +0530 Subject: [PATCH 12/23] added notification in validate otp API --- .../resident/constant/ResidentConstants.java | 1 + .../resident/controller/IdAuthController.java | 4 +- .../service/impl/IdAuthServiceImpl.java | 57 ++++++++++++++----- .../service/impl/ResidentOtpServiceImpl.java | 4 +- .../test/service/IdAuthServiceTest.java | 4 ++ 5 files changed, 55 insertions(+), 15 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java index 166a76a20a9..195d31a64fc 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java @@ -158,6 +158,7 @@ private ResidentConstants() { public static final String AUTH_TYPE = "authType"; public static final String CHANNEL = "channel"; + public static final String CHANNEL_DELIMITER = ", "; public static final String MASK_PREFIX = "masked_"; public static final String MASK_PERPETUAL_VID = "masked_perpetualVID"; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/IdAuthController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/IdAuthController.java index 84ba70352ed..d0f208a6a40 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/IdAuthController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/IdAuthController.java @@ -81,7 +81,9 @@ public ResponseEntity validateOtp(@RequestBody RequestWrapper responseWrapper = new ResponseWrapper(); ValidateOtpResponseDto validateOtpResponseDto = new ValidateOtpResponseDto(); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/IdAuthServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/IdAuthServiceImpl.java index 47e6bf48fb4..7da03197e96 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/IdAuthServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/IdAuthServiceImpl.java @@ -1,5 +1,6 @@ package io.mosip.resident.service.impl; +import static io.mosip.resident.constant.ResidentConstants.CHANNEL_DELIMITER; import static io.mosip.resident.constant.ResidentConstants.RESIDENT_SERVICES; import java.io.ByteArrayInputStream; @@ -55,6 +56,7 @@ import io.mosip.resident.constant.RequestType; import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.constant.ResidentErrorCode; +import io.mosip.resident.constant.TemplateType; import io.mosip.resident.dto.AuthRequestDTO; import io.mosip.resident.dto.AuthResponseDTO; import io.mosip.resident.dto.AuthTxnDetailsDTO; @@ -63,6 +65,7 @@ import io.mosip.resident.dto.AuthTypeStatusResponseDto; import io.mosip.resident.dto.AutnTxnDto; import io.mosip.resident.dto.AutnTxnResponseDto; +import io.mosip.resident.dto.NotificationRequestDtoV2; import io.mosip.resident.dto.OtpAuthRequestDTO; import io.mosip.resident.dto.PublicKeyResponseDto; import io.mosip.resident.entity.ResidentTransactionEntity; @@ -72,6 +75,7 @@ import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.IdAuthService; +import io.mosip.resident.service.NotificationService; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.validator.RequestValidator; import reactor.util.function.Tuple2; @@ -117,7 +121,10 @@ public class IdAuthServiceImpl implements IdAuthService { @Autowired private IdentityServiceImpl identityService; - + + @Autowired + private NotificationService notificationService; + @Autowired RequestValidator requestValidator; @@ -132,27 +139,51 @@ public Tuple2 validateOtpV1(String transactionId, String indivi throws OtpValidationFailedException, ResidentServiceCheckedException { AuthResponseDTO response = null; String eventId = ResidentConstants.NOT_AVAILABLE; - ResidentTransactionEntity residentTransactionEntity = null; + boolean authStatus = false; try { response = internelOtpAuth(transactionId, individualId, otp); - residentTransactionEntity = updateResidentTransaction(response.getResponse().isAuthStatus(), transactionId, - individualId); - if (residentTransactionEntity != null) { - eventId = residentTransactionEntity.getEventId(); + if (response.getErrors() != null && !response.getErrors().isEmpty()) { + response.getErrors().stream().forEach(error -> logger.error(LoggerFileConstant.SESSIONID.toString(), + LoggerFileConstant.USERID.toString(), error.getErrorCode(), error.getErrorMessage())); + eventId = updateResidentTransactionAndSendNotification(transactionId, individualId, eventId, authStatus); + throw new OtpValidationFailedException(response.getErrors().get(0).getErrorMessage(), + Map.of(ResidentConstants.EVENT_ID, eventId)); + } + if (response.getResponse() != null) { + authStatus = response.getResponse().isAuthStatus(); + eventId = updateResidentTransactionAndSendNotification(transactionId, individualId, eventId, authStatus); } } catch (ApisResourceAccessException | InvalidKeySpecException | NoSuchAlgorithmException | IOException | JsonProcessingException | java.security.cert.CertificateException e) { logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), null, "IdAuthServiceImpl::validateOtp():: validate otp method call" + ExceptionUtils.getStackTrace(e)); + eventId = updateResidentTransactionAndSendNotification(transactionId, individualId, eventId, authStatus); throw new OtpValidationFailedException(e.getMessage(), Map.of(ResidentConstants.EVENT_ID, eventId)); } - if (response.getErrors() != null && !response.getErrors().isEmpty()) { - response.getErrors().stream().forEach(error -> logger.error(LoggerFileConstant.SESSIONID.toString(), - LoggerFileConstant.USERID.toString(), error.getErrorCode(), error.getErrorMessage())); - throw new OtpValidationFailedException(response.getErrors().get(0).getErrorMessage(), - Map.of(ResidentConstants.EVENT_ID, eventId)); + return Tuples.of(authStatus, eventId); + } + + private String updateResidentTransactionAndSendNotification(String transactionId, String individualId, + String eventId, boolean authStatus) throws ResidentServiceCheckedException { + ResidentTransactionEntity residentTransactionEntity = null; + residentTransactionEntity = updateResidentTransaction(authStatus, transactionId, individualId); + if (residentTransactionEntity != null) { + eventId = residentTransactionEntity.getEventId(); + TemplateType templateType = authStatus == true ? TemplateType.SUCCESS : TemplateType.FAILURE; + sendNotificationV2(individualId, templateType, eventId, residentTransactionEntity.getAttributeList()); } - return Tuples.of(response.getResponse().isAuthStatus(), eventId); + return eventId; + } + + private void sendNotificationV2(String id, TemplateType templateType, String eventId, String channels) + throws ResidentServiceCheckedException { + NotificationRequestDtoV2 notificationRequestDtoV2 = new NotificationRequestDtoV2(); + notificationRequestDtoV2.setId(id); + notificationRequestDtoV2.setRequestType(RequestType.VALIDATE_OTP); + notificationRequestDtoV2.setTemplateType(templateType); + notificationRequestDtoV2.setEventId(eventId); + notificationService.sendNotification(notificationRequestDtoV2, + channels != null ? List.of(channels.split(CHANNEL_DELIMITER)) : null, null, null); } @Override @@ -232,7 +263,7 @@ public Tuple2 validateOtpV2(String transactionId, String indivi return Tuples.of(response.getResponse().isAuthStatus(), eventId); } - private ResidentTransactionEntity updateResidentTransaction(boolean verified,String transactionId, String individualId) throws NoSuchAlgorithmException, ResidentServiceCheckedException { + private ResidentTransactionEntity updateResidentTransaction(boolean verified,String transactionId, String individualId) throws ResidentServiceCheckedException { ResidentTransactionEntity residentTransactionEntity = residentTransactionRepository. findTopByRequestTrnIdAndTokenIdAndStatusCodeOrderByCrDtimesDesc(transactionId, identityService.getIDATokenForIndividualId(individualId) , EventStatusInProgress.OTP_REQUESTED.toString()); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentOtpServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentOtpServiceImpl.java index e3cc0a915d5..32b9c9a0653 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentOtpServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentOtpServiceImpl.java @@ -1,5 +1,7 @@ package io.mosip.resident.service.impl; +import static io.mosip.resident.constant.ResidentConstants.CHANNEL_DELIMITER; + import java.security.NoSuchAlgorithmException; import java.util.stream.Collectors; @@ -92,7 +94,7 @@ public void insertData(OtpRequestDTO otpRequestDTO) throws ResidentServiceChecke residentTransactionEntity.setEventId(utility.createEventId()); residentTransactionEntity.setRequestTrnId(otpRequestDTO.getTransactionID()); residentTransactionEntity.setRequestTypeCode(RequestType.SEND_OTP.name()); - String attributeList = otpRequestDTO.getOtpChannel().stream().collect(Collectors.joining(", ")); + String attributeList = otpRequestDTO.getOtpChannel().stream().collect(Collectors.joining(CHANNEL_DELIMITER)); residentTransactionEntity.setAttributeList(attributeList); residentTransactionEntity.setAuthTypeCode(attributeList); residentTransactionEntity.setRequestSummary("OTP Generated"); diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/IdAuthServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/IdAuthServiceTest.java index 4f120ec9e03..6d26d9071f2 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/IdAuthServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/IdAuthServiceTest.java @@ -59,6 +59,7 @@ import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.IdAuthService; +import io.mosip.resident.service.NotificationService; import io.mosip.resident.service.ProxyIdRepoService; import io.mosip.resident.service.impl.IdAuthServiceImpl; import io.mosip.resident.service.impl.IdentityServiceImpl; @@ -101,6 +102,9 @@ public class IdAuthServiceTest { @Mock private IdentityServiceImpl identityService; + @Mock + private NotificationService notificationService; + @Before public void setup() { From 268016716ee2f6d422762d4ddc12f3edfb3310de Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Wed, 12 Apr 2023 19:03:46 +0530 Subject: [PATCH 13/23] fixed authentication request description --- .../src/main/java/io/mosip/resident/util/TemplateUtil.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java index cac35e2b264..c434a4d729d 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java @@ -174,7 +174,8 @@ public String getTemplateValueFromTemplateTypeCodeAndLangCode(String languageCod public String getDescriptionTemplateVariablesForAuthenticationRequest(String eventId, String fileText, String languageCode){ - return fileText; + ResidentTransactionEntity residentTransactionEntity = getEntityFromEventId(eventId); + return residentTransactionEntity.getStatusComment(); } public String getDescriptionTemplateVariablesForShareCredential(String eventId, String fileText, String languageCode) { From 361eb270cd11c65e0c7d08a782d61ccb1b54bc00 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Wed, 12 Apr 2023 20:12:13 +0530 Subject: [PATCH 14/23] removed space --- .../main/java/io/mosip/resident/constant/ResidentConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java index 195d31a64fc..738a0ef8863 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java @@ -158,7 +158,7 @@ private ResidentConstants() { public static final String AUTH_TYPE = "authType"; public static final String CHANNEL = "channel"; - public static final String CHANNEL_DELIMITER = ", "; + public static final String CHANNEL_DELIMITER = ","; public static final String MASK_PREFIX = "masked_"; public static final String MASK_PERPETUAL_VID = "masked_perpetualVID"; From ee70d2648a08e19b2da4546c8bed3b329fd67b21 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Wed, 12 Apr 2023 20:29:00 +0530 Subject: [PATCH 15/23] removed validate otp from auth request service type --- .../src/main/java/io/mosip/resident/constant/ServiceType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/ServiceType.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/ServiceType.java index d74ac60500a..e002e8c33a9 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/ServiceType.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/ServiceType.java @@ -10,7 +10,7 @@ */ public enum ServiceType { - AUTHENTICATION_REQUEST(List.of(RequestType.AUTHENTICATION_REQUEST, RequestType.VALIDATE_OTP)), + AUTHENTICATION_REQUEST(List.of(RequestType.AUTHENTICATION_REQUEST)), SERVICE_REQUEST(List.of(RequestType.DOWNLOAD_PERSONALIZED_CARD, RequestType.ORDER_PHYSICAL_CARD, RequestType.GET_MY_ID, RequestType.BOOK_AN_APPOINTMENT, RequestType.VID_CARD_DOWNLOAD)), DATA_UPDATE_REQUEST(List.of(RequestType.UPDATE_MY_UIN)), From 76ac174a6ffd10b7d20718e293c16f5dcfe4bcca Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Thu, 13 Apr 2023 14:44:07 +0530 Subject: [PATCH 16/23] added notification to get my uin API --- .../controller/DownloadCardController.java | 3 +- .../resident/service/DownloadCardService.java | 4 +- .../service/impl/DownloadCardServiceImpl.java | 169 +++++++++++------- .../test/service/DownloadCardServiceTest.java | 4 +- 4 files changed, 109 insertions(+), 71 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/DownloadCardController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/DownloadCardController.java index 1da6bababbe..44578469b80 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/DownloadCardController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/DownloadCardController.java @@ -32,6 +32,7 @@ import io.mosip.resident.dto.VidDownloadCardResponseDto; import io.mosip.resident.exception.CardNotReadyException; import io.mosip.resident.exception.InvalidInputException; +import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.service.DownloadCardService; import io.mosip.resident.util.AuditUtil; @@ -79,7 +80,7 @@ public class DownloadCardController { @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))), @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(hidden = true))) }) - public ResponseEntity downloadCard(@Validated @RequestBody MainRequestDTO downloadCardRequestDTOMainRequestDTO){ + public ResponseEntity downloadCard(@Validated @RequestBody MainRequestDTO downloadCardRequestDTOMainRequestDTO) throws ResidentServiceCheckedException{ logger.debug("DownloadCardController::downloadCard()::entry"); auditUtil.setAuditRequestDto(EventEnum.REQ_CARD); requestValidator.validateDownloadCardRequest(downloadCardRequestDTOMainRequestDTO); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java index 06f6587bc52..146f6bb2955 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java @@ -18,7 +18,9 @@ * @Author Kamesh Shekhar Prasad */ public interface DownloadCardService { - Tuple2 getDownloadCardPDF(MainRequestDTO downloadCardRequestDTOMainRequestDTO); + Tuple2 getDownloadCardPDF( + MainRequestDTO downloadCardRequestDTOMainRequestDTO) + throws ResidentServiceCheckedException; Tuple2 downloadPersonalizedCard(MainRequestDTO downloadPersonalizedCardMainRequestDTO, int timeZoneOffset); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java index 3a29e866b2f..e6e0ddfa8d0 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java @@ -25,9 +25,9 @@ import io.mosip.kernel.core.util.DateUtils; import io.mosip.resident.config.LoggerConfiguration; import io.mosip.resident.constant.ApiName; -import io.mosip.resident.constant.EventStatus; import io.mosip.resident.constant.EventStatusFailure; import io.mosip.resident.constant.EventStatusInProgress; +import io.mosip.resident.constant.EventStatusSuccess; import io.mosip.resident.constant.IdType; import io.mosip.resident.constant.LoggerFileConstant; import io.mosip.resident.constant.PacketStatus; @@ -126,61 +126,103 @@ public class DownloadCardServiceImpl implements DownloadCardService { private static final Logger logger = LoggerConfiguration.logConfig(DownloadCardServiceImpl.class); @Override - public Tuple2 getDownloadCardPDF(MainRequestDTO downloadCardRequestDTOMainRequestDTO) { - String rid = ""; - String eventId = utility.createEventId(); - byte[] pdfBytes = new byte[0]; - try { - if (idAuthService.validateOtpv2(downloadCardRequestDTOMainRequestDTO.getRequest().getTransactionId(), - getIndividualIdForAid(downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId()) - , downloadCardRequestDTOMainRequestDTO.getRequest().getOtp())) { - String individualId = downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId(); - String idType = identityService.getIndividualIdType(individualId); - if (idType.equalsIgnoreCase(AID)) { - rid = individualId; - Map ridStatus = utilities.getPacketStatus(rid); - String transactionTypeCode = ridStatus.get(ResidentConstants.TRANSACTION_TYPE_CODE); - String aidStatus = ridStatus.get(ResidentConstants.AID_STATUS); - if (transactionTypeCode.equalsIgnoreCase(TransactionStage.CARD_READY_TO_DOWNLOAD.name()) && aidStatus.equalsIgnoreCase(PacketStatus.SUCCESS.getName())) { - pdfBytes = residentCredentialService.getCard(rid + ridSuffix, null, null); - } else { - throw new ResidentServiceException(ResidentErrorCode.CARD_NOT_READY.getErrorCode(), - ResidentErrorCode.CARD_NOT_READY.getErrorMessage()); - } - }else { - rid = utilities.getRidByIndividualId(individualId); - pdfBytes = residentCredentialService.getCard(rid + ridSuffix, null, null); - } - if(pdfBytes.length==0){ - insertDataForDownloadCard(downloadCardRequestDTOMainRequestDTO, eventId, EventStatus.FAILED.name()); - } else { - insertDataForDownloadCard(downloadCardRequestDTOMainRequestDTO, eventId, EventStatus.SUCCESS.name()); - } - - } else { - logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), - LoggerFileConstant.APPLICATIONID.toString(), - ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); - audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_EXCEPTION); - throw new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorCode(), - ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); - } - } catch (ApisResourceAccessException e) { - audit.setAuditRequestDto(EventEnum.RID_DIGITAL_CARD_REQ_EXCEPTION); - throw new ResidentServiceException( - ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorCode(), - ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorMessage(), e); - } catch (OtpValidationFailedException e) { - audit.setAuditRequestDto(EventEnum.RID_DIGITAL_CARD_REQ_EXCEPTION); - throw new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorCode(), e.getErrorText(), - e); - } catch (Exception e) { + public Tuple2 getDownloadCardPDF( + MainRequestDTO downloadCardRequestDTOMainRequestDTO) + throws ResidentServiceCheckedException { + String rid = ""; + String individualId = ""; + String eventId = ResidentConstants.NOT_AVAILABLE; + ResidentTransactionEntity residentTransactionEntity = null; + byte[] pdfBytes = new byte[0]; + try { + individualId = downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId(); + String transactionId = downloadCardRequestDTOMainRequestDTO.getRequest().getTransactionId(); + residentTransactionEntity = insertDataForGetMyUin(individualId, transactionId); + if (residentTransactionEntity != null) { + eventId = residentTransactionEntity.getEventId(); + } + if (idAuthService.validateOtpv2(transactionId, getIndividualIdForAid(individualId), + downloadCardRequestDTOMainRequestDTO.getRequest().getOtp())) { + String idType = identityService.getIndividualIdType(individualId); + if (idType.equalsIgnoreCase(AID)) { + rid = individualId; + Map ridStatus = utilities.getPacketStatus(rid); + String transactionTypeCode = ridStatus.get(ResidentConstants.TRANSACTION_TYPE_CODE); + String aidStatus = ridStatus.get(ResidentConstants.AID_STATUS); + if (transactionTypeCode.equalsIgnoreCase(TransactionStage.CARD_READY_TO_DOWNLOAD.name()) + && aidStatus.equalsIgnoreCase(PacketStatus.SUCCESS.getName())) { + pdfBytes = residentCredentialService.getCard(rid + ridSuffix, null, null); + } else { + throw new ResidentServiceException(ResidentErrorCode.CARD_NOT_READY.getErrorCode(), + ResidentErrorCode.CARD_NOT_READY.getErrorMessage()); + } + } else { + rid = utilities.getRidByIndividualId(individualId); + pdfBytes = residentCredentialService.getCard(rid + ridSuffix, null, null); + } + if (pdfBytes.length == 0) { + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + residentTransactionEntity + .setStatusComment(ResidentErrorCode.CARD_NOT_READY.getErrorMessage() + " - zero length"); + residentTransactionEntity + .setRequestSummary(RequestType.GET_MY_ID.name() + " - " + ResidentConstants.FAILED); + } else { + residentTransactionEntity.setStatusCode(EventStatusSuccess.CARD_DOWNLOADED.name()); + residentTransactionEntity.setStatusComment(EventStatusSuccess.CARD_DOWNLOADED.name()); + residentTransactionEntity + .setRequestSummary(RequestType.GET_MY_ID.name() + " - " + ResidentConstants.SUCCESS); + } + } else { + logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), + LoggerFileConstant.APPLICATIONID.toString(), + ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); + audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_EXCEPTION); + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + residentTransactionEntity.setStatusComment(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); + throw new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorCode(), + ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); + } + } catch (ApisResourceAccessException e) { + audit.setAuditRequestDto(EventEnum.RID_DIGITAL_CARD_REQ_EXCEPTION); + throw new ResidentServiceException(ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorCode(), + ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorMessage(), e, + Map.of(ResidentConstants.EVENT_ID, eventId)); + } catch (OtpValidationFailedException e) { + audit.setAuditRequestDto(EventEnum.RID_DIGITAL_CARD_REQ_EXCEPTION); + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + residentTransactionEntity.setStatusComment(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); + throw new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorCode(), e.getErrorText(), + e, Map.of(ResidentConstants.EVENT_ID, eventId)); + } catch (Exception e) { audit.setAuditRequestDto(EventEnum.RID_DIGITAL_CARD_REQ_EXCEPTION); throw new ResidentServiceException(ResidentErrorCode.CARD_NOT_READY.getErrorCode(), - ResidentErrorCode.CARD_NOT_READY.getErrorMessage(), e); + ResidentErrorCode.CARD_NOT_READY.getErrorMessage(), e, Map.of(ResidentConstants.EVENT_ID, eventId)); + } finally { + if (residentTransactionEntity != null) { + /** + * Here we are setting RID in AID column. + */ + residentTransactionEntity.setAid(rid); + // if the status code will come as null, it will set it as failed. + if (residentTransactionEntity.getStatusCode() == null) { + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + residentTransactionEntity.setStatusComment(ResidentErrorCode.CARD_NOT_READY.getErrorMessage()); + } + if (residentTransactionEntity.getRequestSummary() == null) { + residentTransactionEntity + .setRequestSummary(RequestType.GET_MY_ID.name() + " - " + ResidentConstants.FAILED); + } + residentTransactionRepository.save(residentTransactionEntity); + + TemplateType templateType = (residentTransactionEntity.getStatusCode() + .equals(EventStatusSuccess.CARD_DOWNLOADED.name())) ? TemplateType.SUCCESS + : TemplateType.FAILURE; + + sendNotificationV2(individualId, RequestType.GET_MY_ID, templateType, eventId, null); + } + } + return Tuples.of(pdfBytes, eventId); } - return Tuples.of(pdfBytes, eventId); - } private ResponseWrapper getCheckStatusResponse(Map packetStatusMap) { ResponseWrapper checkStatusResponseDTOResponseWrapper = new ResponseWrapper<>(); @@ -196,23 +238,16 @@ private ResponseWrapper getCheckStatusResponse(Map downloadCardRequestDTOMainRequestDTO, - String eventId, String status) throws ApisResourceAccessException, ResidentServiceCheckedException { + private ResidentTransactionEntity insertDataForGetMyUin(String individualId, String transactionId) throws ResidentServiceCheckedException { ResidentTransactionEntity residentTransactionEntity = utility.createEntity(); - residentTransactionEntity.setEventId(eventId); + residentTransactionEntity.setEventId(utility.createEventId()); residentTransactionEntity.setRequestTypeCode(RequestType.GET_MY_ID.name()); - residentTransactionEntity.setRequestSummary(RequestType.GET_MY_ID.name()); - residentTransactionEntity.setStatusCode(status); residentTransactionEntity.setAuthTypeCode(OTP); - residentTransactionEntity.setStatusComment(String.valueOf(CARD_DOWNLOADED)); - residentTransactionEntity.setRefId(utility.convertToMaskDataFormat( - downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId())); - residentTransactionEntity.setIndividualId(downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId()); - residentTransactionEntity.setTokenId(identityService.getIDATokenForIndividualId( - getIndividualIdForAid(downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId()))); - residentTransactionEntity.setRequestTrnId(downloadCardRequestDTOMainRequestDTO.getRequest().getTransactionId()); - residentTransactionRepository.save(residentTransactionEntity); - + residentTransactionEntity.setRefId(utility.convertToMaskDataFormat(individualId)); + residentTransactionEntity.setIndividualId(individualId); + residentTransactionEntity.setTokenId(identityService.getIDATokenForIndividualId(getIndividualIdForAid(individualId))); + residentTransactionEntity.setRequestTrnId(transactionId); + return residentTransactionEntity; } @Override diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java index 21dbf9c7d4b..980166c4817 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/DownloadCardServiceTest.java @@ -156,13 +156,13 @@ public void setup() throws Exception { } @Test - public void testDownloadCardServiceTest() { + public void testDownloadCardServiceTest() throws ResidentServiceCheckedException { Tuple2 actualResult = downloadCardService.getDownloadCardPDF(downloadCardRequestDTOMainRequestDTO); assertEquals(pdfbytes, actualResult.getT1()); } @Test - public void testGetDownloadCardPdfVID(){ + public void testGetDownloadCardPdfVID() throws ResidentServiceCheckedException{ Mockito.when(identityService.getIndividualIdType(Mockito.anyString())).thenReturn("VID"); Tuple2 actualResult = downloadCardService.getDownloadCardPDF(downloadCardRequestDTOMainRequestDTO); assertNotNull(actualResult); From 758d76f3ae7693cf404de495af1b53971aed0089 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Thu, 13 Apr 2023 17:21:23 +0530 Subject: [PATCH 17/23] added notification in personalised card API --- .../resident/constant/ResidentConstants.java | 2 +- .../controller/DownloadCardController.java | 6 +- .../resident/service/DownloadCardService.java | 4 +- .../service/impl/DownloadCardServiceImpl.java | 93 ++++++++++++------- .../service/impl/IdAuthServiceImpl.java | 4 +- .../service/impl/ResidentOtpServiceImpl.java | 4 +- .../test/service/DownloadCardServiceTest.java | 6 +- 7 files changed, 72 insertions(+), 47 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java index 738a0ef8863..6f6e5ce62e2 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java @@ -158,7 +158,7 @@ private ResidentConstants() { public static final String AUTH_TYPE = "authType"; public static final String CHANNEL = "channel"; - public static final String CHANNEL_DELIMITER = ","; + public static final String ATTRIBUTE_lIST_DELIMITER = ","; public static final String MASK_PREFIX = "masked_"; public static final String MASK_PERPETUAL_VID = "masked_perpetualVID"; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/DownloadCardController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/DownloadCardController.java index 44578469b80..71c64261543 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/DownloadCardController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/DownloadCardController.java @@ -101,8 +101,10 @@ public ResponseEntity downloadCard(@Validated @RequestBody MainRequestDT @PreAuthorize("@scopeValidator.hasAllScopes(" + "@authorizedScopes.getPostPersonalizedCard()" + ")") @PostMapping("/download/personalized-card") - public ResponseEntity downloadPersonalizedCard(@Validated @RequestBody MainRequestDTO downloadPersonalizedCardMainRequestDTO, - @RequestHeader(name = "time-zone-offset", required = false, defaultValue = "0") int timeZoneOffset){ + public ResponseEntity downloadPersonalizedCard( + @Validated @RequestBody MainRequestDTO downloadPersonalizedCardMainRequestDTO, + @RequestHeader(name = "time-zone-offset", required = false, defaultValue = "0") int timeZoneOffset) + throws ResidentServiceCheckedException { logger.debug("DownloadCardController::downloadPersonalizedCard()::entry"); auditUtil.setAuditRequestDto(EventEnum.DOWNLOAD_PERSONALIZED_CARD); try { diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java index 146f6bb2955..f5c7a012aba 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/DownloadCardService.java @@ -22,7 +22,9 @@ Tuple2 getDownloadCardPDF( MainRequestDTO downloadCardRequestDTOMainRequestDTO) throws ResidentServiceCheckedException; - Tuple2 downloadPersonalizedCard(MainRequestDTO downloadPersonalizedCardMainRequestDTO, int timeZoneOffset); + Tuple2 downloadPersonalizedCard( + MainRequestDTO downloadPersonalizedCardMainRequestDTO, int timeZoneOffset) + throws ResidentServiceCheckedException; Tuple2, String> getVidCardEventId(String vid, int timeZoneOffset) throws BaseCheckedException; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java index e6e0ddfa8d0..d1add483315 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java @@ -1,6 +1,7 @@ package io.mosip.resident.service.impl; import static io.mosip.resident.constant.EventStatusSuccess.CARD_DOWNLOADED; +import static io.mosip.resident.constant.ResidentConstants.ATTRIBUTE_lIST_DELIMITER; import static io.mosip.resident.constant.TemplateVariablesConstants.OTP; import static io.mosip.resident.constant.TemplateVariablesConstants.VID; import static io.mosip.resident.constant.TemplateVariablesConstants.VID_TYPE; @@ -27,7 +28,6 @@ import io.mosip.resident.constant.ApiName; import io.mosip.resident.constant.EventStatusFailure; import io.mosip.resident.constant.EventStatusInProgress; -import io.mosip.resident.constant.EventStatusSuccess; import io.mosip.resident.constant.IdType; import io.mosip.resident.constant.LoggerFileConstant; import io.mosip.resident.constant.PacketStatus; @@ -160,25 +160,29 @@ public Tuple2 getDownloadCardPDF( rid = utilities.getRidByIndividualId(individualId); pdfBytes = residentCredentialService.getCard(rid + ridSuffix, null, null); } - if (pdfBytes.length == 0) { - residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); - residentTransactionEntity - .setStatusComment(ResidentErrorCode.CARD_NOT_READY.getErrorMessage() + " - zero length"); - residentTransactionEntity - .setRequestSummary(RequestType.GET_MY_ID.name() + " - " + ResidentConstants.FAILED); - } else { - residentTransactionEntity.setStatusCode(EventStatusSuccess.CARD_DOWNLOADED.name()); - residentTransactionEntity.setStatusComment(EventStatusSuccess.CARD_DOWNLOADED.name()); - residentTransactionEntity - .setRequestSummary(RequestType.GET_MY_ID.name() + " - " + ResidentConstants.SUCCESS); + if (residentTransactionEntity != null) { + if (pdfBytes.length == 0) { + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + residentTransactionEntity + .setStatusComment(ResidentErrorCode.CARD_NOT_READY.getErrorMessage() + " - zero length"); + residentTransactionEntity + .setRequestSummary(RequestType.GET_MY_ID.name() + " - " + ResidentConstants.FAILED); + } else { + residentTransactionEntity.setStatusCode(CARD_DOWNLOADED.name()); + residentTransactionEntity.setStatusComment(CARD_DOWNLOADED.name()); + residentTransactionEntity + .setRequestSummary(RequestType.GET_MY_ID.name() + " - " + ResidentConstants.SUCCESS); + } } } else { logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_EXCEPTION); - residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); - residentTransactionEntity.setStatusComment(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); + if (residentTransactionEntity != null) { + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + residentTransactionEntity.setStatusComment(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); + } throw new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorCode(), ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); } @@ -189,8 +193,10 @@ public Tuple2 getDownloadCardPDF( Map.of(ResidentConstants.EVENT_ID, eventId)); } catch (OtpValidationFailedException e) { audit.setAuditRequestDto(EventEnum.RID_DIGITAL_CARD_REQ_EXCEPTION); - residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); - residentTransactionEntity.setStatusComment(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); + if (residentTransactionEntity != null) { + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + residentTransactionEntity.setStatusComment(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); + } throw new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorCode(), e.getErrorText(), e, Map.of(ResidentConstants.EVENT_ID, eventId)); } catch (Exception e) { @@ -215,7 +221,7 @@ public Tuple2 getDownloadCardPDF( residentTransactionRepository.save(residentTransactionEntity); TemplateType templateType = (residentTransactionEntity.getStatusCode() - .equals(EventStatusSuccess.CARD_DOWNLOADED.name())) ? TemplateType.SUCCESS + .equals(CARD_DOWNLOADED.name())) ? TemplateType.SUCCESS : TemplateType.FAILURE; sendNotificationV2(individualId, RequestType.GET_MY_ID, templateType, eventId, null); @@ -251,14 +257,18 @@ private ResidentTransactionEntity insertDataForGetMyUin(String individualId, Str } @Override - public Tuple2 downloadPersonalizedCard(MainRequestDTO downloadPersonalizedCardMainRequestDTO, int timeZoneOffset) { + public Tuple2 downloadPersonalizedCard( + MainRequestDTO downloadPersonalizedCardMainRequestDTO, int timeZoneOffset) + throws ResidentServiceCheckedException { String encodeHtml = downloadPersonalizedCardMainRequestDTO.getRequest().getHtml(); byte[] decodedData; String password=null; + String individualId = ""; String eventId = ResidentConstants.NOT_AVAILABLE; ResidentTransactionEntity residentTransactionEntity = null; try { - residentTransactionEntity = createResidentTransactionEntity(); + individualId = identityService.getResidentIndvidualIdFromSession(); + residentTransactionEntity = createResidentTransactionEntity(individualId, downloadPersonalizedCardMainRequestDTO.getRequest()); if (residentTransactionEntity != null) { eventId = residentTransactionEntity.getEventId(); } @@ -267,20 +277,19 @@ public Tuple2 downloadPersonalizedCard(MainRequestDTO attributes = downloadPersonalizedCardMainRequestDTO.getRequest().getAttributes(); - if(attributes != null){ - String attributeList = attributes. - stream().collect(Collectors.joining(", ")); - residentTransactionEntity.setAttributeList(attributeList); - } - residentTransactionEntity.setRequestSummary(ResidentConstants.SUCCESS); - residentTransactionEntity.setStatusCode(CARD_DOWNLOADED.name()); - residentTransactionEntity.setStatusComment(CARD_DOWNLOADED.name()); + if (residentTransactionEntity != null) { + residentTransactionEntity.setRequestSummary( + RequestType.DOWNLOAD_PERSONALIZED_CARD.name() + " - " + ResidentConstants.SUCCESS); + residentTransactionEntity.setStatusCode(CARD_DOWNLOADED.name()); + residentTransactionEntity.setStatusComment(CARD_DOWNLOADED.name()); + } } catch (Exception e) { if (residentTransactionEntity != null) { - residentTransactionEntity.setRequestSummary(ResidentConstants.FAILED); - residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + residentTransactionEntity.setRequestSummary( + RequestType.DOWNLOAD_PERSONALIZED_CARD.name() + " - " + ResidentConstants.FAILED); + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + residentTransactionEntity.setStatusComment(ResidentErrorCode.DOWNLOAD_PERSONALIZED_CARD.getErrorMessage()); } audit.setAuditRequestDto(EventEnum.DOWNLOAD_PERSONALIZED_CARD); logger.error("Unable to convert html to pdf RootCause- "+e); @@ -289,26 +298,38 @@ public Tuple2 downloadPersonalizedCard(MainRequestDTO actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO, 0); assertEquals(pdfbytes, actualResult.getT1()); } @@ -239,14 +239,14 @@ public void testDownloadPersonalizedCardSuccessWithListAttributes() throws Resid } @Test - public void testDownloadPersonalizedCardPassword(){ + public void testDownloadPersonalizedCardPassword() throws ResidentServiceCheckedException{ Mockito.when(environment.getProperty(ResidentConstants.IS_PASSWORD_FLAG_ENABLED)).thenReturn(String.valueOf(true)); Tuple2 actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO, 0); assertEquals(pdfbytes, actualResult.getT1()); } @Test(expected = ResidentServiceException.class) - public void testDownloadPersonalizedCardPasswordFailed(){ + public void testDownloadPersonalizedCardPasswordFailed() throws ResidentServiceCheckedException{ Mockito.when(environment.getProperty(ResidentConstants.IS_PASSWORD_FLAG_ENABLED)).thenReturn(String.valueOf(true)); Mockito.when(utility.getPassword(Mockito.anyList())).thenThrow( new ResidentServiceException(ResidentErrorCode.DOWNLOAD_PERSONALIZED_CARD)); From a7d6f51d884efa9a74530123c35cc7814d6776a9 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Thu, 13 Apr 2023 18:14:10 +0530 Subject: [PATCH 18/23] fixed null check --- .../main/java/io/mosip/resident/validator/RequestValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java index 65ac43cf131..c2d108bfe93 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/validator/RequestValidator.java @@ -1254,7 +1254,7 @@ public void validateDownloadPersonalizedCard(MainRequestDTO attributes) { - if(attributes.isEmpty()){ + if (attributes == null || attributes.isEmpty()) { throw new InvalidInputException(TemplateVariablesConstants.ATTRIBUTES); } } From 1a5d6f917f476d6621daf1dc54191514793997ac Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Thu, 13 Apr 2023 19:46:02 +0530 Subject: [PATCH 19/23] refactor code --- .../resident/constant/ResidentConstants.java | 2 +- .../service/impl/DownloadCardServiceImpl.java | 87 +++++++++---------- .../service/impl/IdAuthServiceImpl.java | 4 +- .../service/impl/ResidentOtpServiceImpl.java | 4 +- 4 files changed, 46 insertions(+), 51 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java index 6f6e5ce62e2..c3400c37d13 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentConstants.java @@ -158,7 +158,7 @@ private ResidentConstants() { public static final String AUTH_TYPE = "authType"; public static final String CHANNEL = "channel"; - public static final String ATTRIBUTE_lIST_DELIMITER = ","; + public static final String ATTRIBUTE_LIST_DELIMITER = ","; public static final String MASK_PREFIX = "masked_"; public static final String MASK_PERPETUAL_VID = "masked_perpetualVID"; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java index d1add483315..5821de82b28 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java @@ -1,7 +1,7 @@ package io.mosip.resident.service.impl; import static io.mosip.resident.constant.EventStatusSuccess.CARD_DOWNLOADED; -import static io.mosip.resident.constant.ResidentConstants.ATTRIBUTE_lIST_DELIMITER; +import static io.mosip.resident.constant.ResidentConstants.ATTRIBUTE_LIST_DELIMITER; import static io.mosip.resident.constant.TemplateVariablesConstants.OTP; import static io.mosip.resident.constant.TemplateVariablesConstants.VID; import static io.mosip.resident.constant.TemplateVariablesConstants.VID_TYPE; @@ -130,41 +130,38 @@ public Tuple2 getDownloadCardPDF( MainRequestDTO downloadCardRequestDTOMainRequestDTO) throws ResidentServiceCheckedException { String rid = ""; - String individualId = ""; + String individualId = downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId(); String eventId = ResidentConstants.NOT_AVAILABLE; ResidentTransactionEntity residentTransactionEntity = null; byte[] pdfBytes = new byte[0]; try { - individualId = downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId(); String transactionId = downloadCardRequestDTOMainRequestDTO.getRequest().getTransactionId(); residentTransactionEntity = insertDataForGetMyUin(individualId, transactionId); if (residentTransactionEntity != null) { eventId = residentTransactionEntity.getEventId(); - } - if (idAuthService.validateOtpv2(transactionId, getIndividualIdForAid(individualId), - downloadCardRequestDTOMainRequestDTO.getRequest().getOtp())) { - String idType = identityService.getIndividualIdType(individualId); - if (idType.equalsIgnoreCase(AID)) { - rid = individualId; - Map ridStatus = utilities.getPacketStatus(rid); - String transactionTypeCode = ridStatus.get(ResidentConstants.TRANSACTION_TYPE_CODE); - String aidStatus = ridStatus.get(ResidentConstants.AID_STATUS); - if (transactionTypeCode.equalsIgnoreCase(TransactionStage.CARD_READY_TO_DOWNLOAD.name()) - && aidStatus.equalsIgnoreCase(PacketStatus.SUCCESS.getName())) { - pdfBytes = residentCredentialService.getCard(rid + ridSuffix, null, null); + if (idAuthService.validateOtpv2(transactionId, getIndividualIdForAid(individualId), + downloadCardRequestDTOMainRequestDTO.getRequest().getOtp())) { + String idType = identityService.getIndividualIdType(individualId); + if (idType.equalsIgnoreCase(AID)) { + rid = individualId; + Map ridStatus = utilities.getPacketStatus(rid); + String transactionTypeCode = ridStatus.get(ResidentConstants.TRANSACTION_TYPE_CODE); + String aidStatus = ridStatus.get(ResidentConstants.AID_STATUS); + if (transactionTypeCode.equalsIgnoreCase(TransactionStage.CARD_READY_TO_DOWNLOAD.name()) + && aidStatus.equalsIgnoreCase(PacketStatus.SUCCESS.getName())) { + pdfBytes = residentCredentialService.getCard(rid + ridSuffix, null, null); + } else { + throw new ResidentServiceException(ResidentErrorCode.CARD_NOT_READY.getErrorCode(), + ResidentErrorCode.CARD_NOT_READY.getErrorMessage()); + } } else { - throw new ResidentServiceException(ResidentErrorCode.CARD_NOT_READY.getErrorCode(), - ResidentErrorCode.CARD_NOT_READY.getErrorMessage()); + rid = utilities.getRidByIndividualId(individualId); + pdfBytes = residentCredentialService.getCard(rid + ridSuffix, null, null); } - } else { - rid = utilities.getRidByIndividualId(individualId); - pdfBytes = residentCredentialService.getCard(rid + ridSuffix, null, null); - } - if (residentTransactionEntity != null) { if (pdfBytes.length == 0) { residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); - residentTransactionEntity - .setStatusComment(ResidentErrorCode.CARD_NOT_READY.getErrorMessage() + " - zero length"); + residentTransactionEntity.setStatusComment( + ResidentErrorCode.CARD_NOT_READY.getErrorMessage() + " - zero length"); residentTransactionEntity .setRequestSummary(RequestType.GET_MY_ID.name() + " - " + ResidentConstants.FAILED); } else { @@ -173,18 +170,17 @@ public Tuple2 getDownloadCardPDF( residentTransactionEntity .setRequestSummary(RequestType.GET_MY_ID.name() + " - " + ResidentConstants.SUCCESS); } - } - } else { - logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), - LoggerFileConstant.APPLICATIONID.toString(), - ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); - audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_EXCEPTION); - if (residentTransactionEntity != null) { + } else { + logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), + LoggerFileConstant.APPLICATIONID.toString(), + ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); + audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_EXCEPTION); residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); - residentTransactionEntity.setStatusComment(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); + residentTransactionEntity + .setStatusComment(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); + throw new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorCode(), + ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); } - throw new ResidentServiceException(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorCode(), - ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorMessage()); } } catch (ApisResourceAccessException e) { audit.setAuditRequestDto(EventEnum.RID_DIGITAL_CARD_REQ_EXCEPTION); @@ -261,23 +257,22 @@ public Tuple2 downloadPersonalizedCard( MainRequestDTO downloadPersonalizedCardMainRequestDTO, int timeZoneOffset) throws ResidentServiceCheckedException { String encodeHtml = downloadPersonalizedCardMainRequestDTO.getRequest().getHtml(); - byte[] decodedData; + byte[] decodedData = new byte[0]; String password=null; String individualId = ""; String eventId = ResidentConstants.NOT_AVAILABLE; ResidentTransactionEntity residentTransactionEntity = null; try { - individualId = identityService.getResidentIndvidualIdFromSession(); - residentTransactionEntity = createResidentTransactionEntity(individualId, downloadPersonalizedCardMainRequestDTO.getRequest()); - if (residentTransactionEntity != null) { - eventId = residentTransactionEntity.getEventId(); - } - decodedData = CryptoUtil.decodePlainBase64(encodeHtml); - List attributeValues = getAttributeList(); - if(Boolean.parseBoolean(this.environment.getProperty(ResidentConstants.IS_PASSWORD_FLAG_ENABLED))){ - password = utility.getPassword(attributeValues); - } + individualId = identityService.getResidentIndvidualIdFromSession(); + residentTransactionEntity = createResidentTransactionEntity(individualId, + downloadPersonalizedCardMainRequestDTO.getRequest()); if (residentTransactionEntity != null) { + eventId = residentTransactionEntity.getEventId(); + decodedData = CryptoUtil.decodePlainBase64(encodeHtml); + List attributeValues = getAttributeList(); + if (Boolean.parseBoolean(this.environment.getProperty(ResidentConstants.IS_PASSWORD_FLAG_ENABLED))) { + password = utility.getPassword(attributeValues); + } residentTransactionEntity.setRequestSummary( RequestType.DOWNLOAD_PERSONALIZED_CARD.name() + " - " + ResidentConstants.SUCCESS); residentTransactionEntity.setStatusCode(CARD_DOWNLOADED.name()); @@ -328,7 +323,7 @@ private ResidentTransactionEntity createResidentTransactionEntity(String individ residentTransactionEntity.setTokenId(identityService.getResidentIdaToken()); if (downloadPersonalizedCardDto.getAttributes() != null) { residentTransactionEntity.setAttributeList( - downloadPersonalizedCardDto.getAttributes().stream().collect(Collectors.joining(ATTRIBUTE_lIST_DELIMITER))); + downloadPersonalizedCardDto.getAttributes().stream().collect(Collectors.joining(ATTRIBUTE_LIST_DELIMITER))); } return residentTransactionEntity; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/IdAuthServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/IdAuthServiceImpl.java index b313bc09d22..975e492c04b 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/IdAuthServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/IdAuthServiceImpl.java @@ -1,6 +1,6 @@ package io.mosip.resident.service.impl; -import static io.mosip.resident.constant.ResidentConstants.ATTRIBUTE_lIST_DELIMITER; +import static io.mosip.resident.constant.ResidentConstants.ATTRIBUTE_LIST_DELIMITER; import static io.mosip.resident.constant.ResidentConstants.RESIDENT_SERVICES; import java.io.ByteArrayInputStream; @@ -183,7 +183,7 @@ private void sendNotificationV2(String id, TemplateType templateType, String eve notificationRequestDtoV2.setTemplateType(templateType); notificationRequestDtoV2.setEventId(eventId); notificationService.sendNotification(notificationRequestDtoV2, - channels != null ? List.of(channels.split(ATTRIBUTE_lIST_DELIMITER)) : null, null, null); + channels != null ? List.of(channels.split(ATTRIBUTE_LIST_DELIMITER)) : null, null, null); } @Override diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentOtpServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentOtpServiceImpl.java index cb4f82683f9..3e9ec64b61d 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentOtpServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentOtpServiceImpl.java @@ -1,6 +1,6 @@ package io.mosip.resident.service.impl; -import static io.mosip.resident.constant.ResidentConstants.ATTRIBUTE_lIST_DELIMITER; +import static io.mosip.resident.constant.ResidentConstants.ATTRIBUTE_LIST_DELIMITER; import java.security.NoSuchAlgorithmException; import java.util.stream.Collectors; @@ -94,7 +94,7 @@ public void insertData(OtpRequestDTO otpRequestDTO) throws ResidentServiceChecke residentTransactionEntity.setEventId(utility.createEventId()); residentTransactionEntity.setRequestTrnId(otpRequestDTO.getTransactionID()); residentTransactionEntity.setRequestTypeCode(RequestType.SEND_OTP.name()); - String attributeList = otpRequestDTO.getOtpChannel().stream().collect(Collectors.joining(ATTRIBUTE_lIST_DELIMITER)); + String attributeList = otpRequestDTO.getOtpChannel().stream().collect(Collectors.joining(ATTRIBUTE_LIST_DELIMITER)); residentTransactionEntity.setAttributeList(attributeList); residentTransactionEntity.setAuthTypeCode(attributeList); residentTransactionEntity.setRequestSummary("OTP Generated"); From ceccca09a03eb737c7786d863b7b1fe072308061 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Fri, 14 Apr 2023 19:39:47 +0530 Subject: [PATCH 20/23] fixed code for notify --- .../resident/constant/AttributeNameEnum.java | 5 +++ .../constant/TemplateVariablesConstants.java | 1 + .../service/impl/ResidentServiceImpl.java | 3 +- .../io/mosip/resident/util/TemplateUtil.java | 44 ++++++------------- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java index bbba7f13bb8..8cf4f7377ba 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java @@ -11,6 +11,11 @@ public enum AttributeNameEnum { PHONE("phone", "mosip.phone.template.property"), EMAIL("email", "mosip.email.template.property"), ADDRESS("addressLine1", "mosip.address.template.property"), + PROVINCE("province", "mosip.province.template.property"), + CITY("city", "mosip.city.template.property"), + ZONE("zone", "mosip.zone.template.property"), + POSTAL_CODE("postalCode", "mosip.postal.code.template.property"), + REGION("region", "mosip.region.template.property"), GENDER("gender", "mosip.gender.template.property"), DEFAULT("Default", "mosip.defualt.template.property"); private String attributeValue; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/TemplateVariablesConstants.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/TemplateVariablesConstants.java index da8baeb2098..168fe7cae91 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/TemplateVariablesConstants.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/TemplateVariablesConstants.java @@ -16,6 +16,7 @@ public class TemplateVariablesConstants { public static final String SUMMARY = "summary"; public static final String TRACKING_ID = "trackingId"; public static final String ORDER_TRACKING_LINK = "orderTrackingLink"; + public static final String PARTNER_ID = "partner"; public static final String PARTNER_NAME = "partnerName"; public static final String PARTNER_LOGO = "partnerLogo"; public static final String ATTRIBUTE_LIST = "attributeList"; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java index 5861b2047bb..8d761c56d86 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java @@ -3,6 +3,7 @@ import static io.mosip.resident.constant.EventStatusSuccess.CARD_DOWNLOADED; import static io.mosip.resident.constant.EventStatusSuccess.LOCKED; import static io.mosip.resident.constant.EventStatusSuccess.UNLOCKED; +import static io.mosip.resident.constant.ResidentConstants.ATTRIBUTE_LIST_DELIMITER; import static io.mosip.resident.constant.ResidentConstants.RESIDENT; import static io.mosip.resident.constant.ResidentConstants.RESIDENT_NOTIFICATIONS_DEFAULT_PAGE_SIZE; import static io.mosip.resident.constant.ResidentErrorCode.MACHINE_MASTER_CREATE_EXCEPTION; @@ -1162,7 +1163,7 @@ private ResidentTransactionEntity createResidentTransEntity(ResidentUpdateReques HashSet keys = new HashSet(identityMap.keySet()); keys.remove("IDSchemaVersion"); keys.remove("UIN"); - String attributeList = keys.stream().collect(Collectors.joining(AUTH_TYPE_LIST_DELIMITER)); + String attributeList = keys.stream().collect(Collectors.joining(ATTRIBUTE_LIST_DELIMITER)); residentTransactionEntity.setAttributeList(attributeList); residentTransactionEntity.setConsent(dto.getConsent()); residentTransactionEntity.setStatusCode(EventStatusInProgress.NEW.name()); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java index c434a4d729d..5992a5734e4 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -18,10 +19,10 @@ import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.core.util.DateUtils; +import io.mosip.kernel.core.util.StringUtils; import io.mosip.resident.config.LoggerConfiguration; import io.mosip.resident.constant.AttributeNameEnum; import io.mosip.resident.constant.AuthenticationModeEnum; -import io.mosip.resident.constant.EventStatus; import io.mosip.resident.constant.EventStatusFailure; import io.mosip.resident.constant.EventStatusInProgress; import io.mosip.resident.constant.EventStatusSuccess; @@ -100,9 +101,9 @@ public Tuple2, ResidentTransactionEntity> getCommonTemplateV templateVariables.put(TemplateVariablesConstants.EVENT_ID, eventId); ResidentTransactionEntity residentTransactionEntity = getEntityFromEventId(eventId); templateVariables.put(TemplateVariablesConstants.EVENT_TYPE, - RequestType.valueOf(residentTransactionEntity.getRequestTypeCode()).getName()); + RequestType.getRequestTypeFromString(residentTransactionEntity.getRequestTypeCode()).getName()); templateVariables.put(TemplateVariablesConstants.EVENT_STATUS, - getEventStatusForRequestType(residentTransactionEntity.getStatusCode())); + residentService.getEventStatusCode(residentTransactionEntity.getStatusCode())); templateVariables.put(TemplateVariablesConstants.SUMMARY, replaceNullWithEmptyString( residentTransactionEntity.getRequestSummary())); templateVariables.put(TemplateVariablesConstants.TIMESTAMP, @@ -133,13 +134,13 @@ public Tuple2, ResidentTransactionEntity> getCommonTemplateV * @return attribute value stored in the template. */ private String getAttributesDisplayText(String attributes, String languageCode) { - String phoneAttributeName = this.env.getProperty(ResidentConstants.PHOTO_ATTRIBUTE_NAME); + String photoAttributeName = this.env.getProperty(ResidentConstants.PHOTO_ATTRIBUTE_NAME); List attributeListTemplateValue = new ArrayList<>(); - if (attributes != null && attributes.contains(Objects.requireNonNull(phoneAttributeName))) { - attributes = attributes.replace(phoneAttributeName, ""); + if (attributes != null && attributes.contains(Objects.requireNonNull(photoAttributeName))) { + attributes = attributes.replace(photoAttributeName, ""); } - if (attributes != null) { - List attributeList = List.of(attributes.trim().split(ResidentConstants.COMMA)); + if (!StringUtils.isBlank(attributes)) { + List attributeList = List.of(attributes.split(ResidentConstants.ATTRIBUTE_LIST_DELIMITER)); for (String attribute : attributeList) { attribute = attribute.trim(); attributeListTemplateValue.add(getTemplateValueFromTemplateTypeCodeAndLangCode(languageCode, @@ -149,7 +150,7 @@ private String getAttributesDisplayText(String attributes, String languageCode) if(attributeListTemplateValue.isEmpty()){ return ""; } else { - return String.join(ResidentConstants.COMMA, attributeListTemplateValue); + return attributeListTemplateValue.stream().collect(Collectors.joining(ResidentConstants.ATTRIBUTE_LIST_DELIMITER)); } } @@ -267,18 +268,6 @@ public String getIndividualIdType() throws ApisResourceAccessException { return identityServiceImpl.getIndividualIdType(individualId); } - private String getEventStatusForRequestType(String requestType) { - String eventStatus = ""; - if(EventStatusSuccess.containsStatus(requestType)){ - eventStatus = EventStatus.SUCCESS.getStatus(); - } else if(EventStatusFailure.containsStatus(requestType)){ - eventStatus = EventStatus.FAILED.getStatus(); - } else { - eventStatus = EventStatus.IN_PROGRESS.getStatus(); - } - return eventStatus; - } - public Tuple2, String> getAckTemplateVariablesForCredentialShare(String eventId, String languageCode, Integer timeZoneOffset) { Tuple2, ResidentTransactionEntity> tupleResponse = getCommonTemplateVariables(eventId, languageCode, timeZoneOffset); Map templateVariables = tupleResponse.getT1(); @@ -513,9 +502,6 @@ public Map getNotificationTemplateVariablesForAuthTypeLockUnlock public Map getNotificationTemplateVariablesForUpdateMyUin(NotificationTemplateVariableDTO dto) { Map templateVariables = getNotificationCommonTemplateVariables(dto); - if(TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) { - templateVariables.put(TemplateVariablesConstants.DOWNLOAD_LINK, utility.createTrackServiceRequestLink(dto.getEventId())); - } return templateVariables; } @@ -531,22 +517,20 @@ public Map getNotificationTemplateVariablesForGetMyId(Notificati public Map getNotificationTemplateVariablesForDownloadPersonalizedCard(NotificationTemplateVariableDTO dto) { Map templateVariables = getNotificationCommonTemplateVariables(dto); - if(TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) { - templateVariables.put(TemplateVariablesConstants.DOWNLOAD_LINK, utility.createTrackServiceRequestLink(dto.getEventId())); - } return templateVariables; } public Map getNotificationTemplateVariablesForOrderPhysicalCard(NotificationTemplateVariableDTO dto) { Map templateVariables = getNotificationCommonTemplateVariables(dto); - if(TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) { - templateVariables.put(TemplateVariablesConstants.DOWNLOAD_LINK, utility.createTrackServiceRequestLink(dto.getEventId())); - } return templateVariables; } public Map getNotificationTemplateVariablesForShareCredentialWithPartner(NotificationTemplateVariableDTO dto) { Map templateVariables = getNotificationCommonTemplateVariables(dto); + if (TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) { + templateVariables.put(TemplateVariablesConstants.PARTNER_ID, + getEntityFromEventId(dto.getEventId()).getRequestedEntityId()); + } return templateVariables; } From 296cc0f02000f443507d75e06fa558c86a591341 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Sat, 15 Apr 2023 18:46:08 +0530 Subject: [PATCH 21/23] code refactoring --- .../resident/service/impl/ResidentServiceImpl.java | 13 +++---------- .../java/io/mosip/resident/util/TemplateUtil.java | 4 ++-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java index 8d761c56d86..4f3504501fe 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java @@ -1904,11 +1904,7 @@ private String getDescriptionForLangCode(String langCode, String statusCode, Req templateType = TemplateType.FAILURE; } String templateTypeCode = templateUtil.getPurposeTemplateTypeCode(requestType, templateType); - ResponseWrapper proxyResponseWrapper = proxyMasterdataService - .getAllTemplateBylangCodeAndTemplateTypeCode(langCode, templateTypeCode); - Map templateResponse = new LinkedHashMap<>( - (Map) proxyResponseWrapper.getResponse()); - String fileText = templateResponse.get(ResidentConstants.FILE_TEXT); + String fileText = templateUtil.getTemplateValueFromTemplateTypeCodeAndLangCode(langCode, templateTypeCode); return replacePlaceholderValueInTemplate(fileText, eventId, requestType, langCode); } @@ -1922,11 +1918,8 @@ public String getSummaryForLangCode(String langCode, String statusCode, RequestT if (statusCode.equalsIgnoreCase(EventStatus.SUCCESS.toString())) { templateType = TemplateType.SUCCESS; String templateTypeCode = templateUtil.getSummaryTemplateTypeCode(requestType, templateType); - ResponseWrapper proxyResponseWrapper = proxyMasterdataService - .getAllTemplateBylangCodeAndTemplateTypeCode(langCode, templateTypeCode); - Map templateResponse = new LinkedHashMap<>( - (Map) proxyResponseWrapper.getResponse()); - return replacePlaceholderValueInTemplate(templateResponse.get(ResidentConstants.FILE_TEXT), eventId, requestType, langCode); + String fileText = templateUtil.getTemplateValueFromTemplateTypeCodeAndLangCode(langCode, templateTypeCode); + return replacePlaceholderValueInTemplate(fileText, eventId, requestType, langCode); } else { return getDescriptionForLangCode(langCode, statusCode, requestType, eventId); } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java index 5992a5734e4..055295844db 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java @@ -293,7 +293,7 @@ public Tuple2, String> getAckTemplateVariablesForDownloadPer Map templateVariables = tupleResponse.getT1(); ResidentTransactionEntity residentTransactionEntity = tupleResponse.getT2(); templateVariables.put(TemplateVariablesConstants.PURPOSE, addAttributeInPurpose(getPurposeFromResidentTransactionEntityLangCode( - residentTransactionEntity, languageCode), getEntityFromEventId(eventId).getPurpose(), languageCode)); + residentTransactionEntity, languageCode), residentTransactionEntity.getPurpose(), languageCode)); return Tuples.of(templateVariables, Objects.requireNonNull( this.env.getProperty(ResidentConstants.ACK_DOWNLOAD_PERSONALIZED_CARD_TEMPLATE_PROPERTY))); } @@ -381,7 +381,7 @@ public String getPurposeFromResidentTransactionEntityLangCode(ResidentTransactio try { purpose = residentService.getSummaryForLangCode(languageCode, residentService.getEventStatusCode( residentTransactionEntity.getStatusCode()), - RequestType.valueOf(residentTransactionEntity.getRequestTypeCode().trim()), residentTransactionEntity.getEventId()); + RequestType.getRequestTypeFromString(residentTransactionEntity.getRequestTypeCode()), residentTransactionEntity.getEventId()); } catch (ResidentServiceCheckedException e) { return ""; } From 8f12ec9f758847cec3ce072e8681c1bed99c19c6 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Sat, 15 Apr 2023 19:34:25 +0530 Subject: [PATCH 22/23] fixed test case failure --- .../java/io/mosip/resident/test/util/TemplateUtilTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java index 9cc8ee5ec5f..90002917bc7 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java @@ -118,6 +118,7 @@ public void setUp() throws ApisResourceAccessException, ResidentServiceCheckedEx responseWrapper.setResponse(templateResponse); Mockito.when(proxyMasterdataService.getAllTemplateBylangCodeAndTemplateTypeCode(Mockito.anyString(), Mockito.anyString())).thenReturn( responseWrapper); + Mockito.when(residentService.getEventStatusCode(Mockito.anyString())).thenReturn(EventStatus.SUCCESS.getStatus()); } @Test @@ -203,7 +204,7 @@ public void getCommonTemplateVariablesTestBadEventId() { @Test public void getCommonTemplateVariablesTestFailedEventStatus() { residentTransactionEntity.setStatusCode(EventStatusFailure.AUTHENTICATION_FAILED.name()); - Mockito.when(residentTransactionRepository.findById(eventId)).thenReturn(java.util.Optional.ofNullable(residentTransactionEntity)); + Mockito.when(residentService.getEventStatusCode(Mockito.anyString())).thenReturn(EventStatus.FAILED.getStatus()); assertEquals(EventStatus.FAILED.getStatus(),templateUtil.getCommonTemplateVariables(eventId, "eng", 0).getT1().get( TemplateVariablesConstants.EVENT_STATUS )); @@ -212,7 +213,7 @@ public void getCommonTemplateVariablesTestFailedEventStatus() { @Test public void getCommonTemplateVariablesTestInProgressEventStatus() { residentTransactionEntity.setStatusCode(EventStatusInProgress.OTP_REQUESTED.name()); - Mockito.when(residentTransactionRepository.findById(eventId)).thenReturn(java.util.Optional.ofNullable(residentTransactionEntity)); + Mockito.when(residentService.getEventStatusCode(Mockito.anyString())).thenReturn(EventStatus.IN_PROGRESS.getStatus()); assertEquals(EventStatus.IN_PROGRESS.getStatus(),templateUtil.getCommonTemplateVariables(eventId, "eng", 0).getT1().get( TemplateVariablesConstants.EVENT_STATUS )); From 127b1dabb9dee0c238c575765385045cf0c5aa83 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Mon, 17 Apr 2023 15:29:43 +0530 Subject: [PATCH 23/23] take templatetype code from properties --- .../resident/constant/AttributeNameEnum.java | 40 ++++++++++--------- .../service/impl/ResidentServiceImpl.java | 10 +++-- .../io/mosip/resident/util/TemplateUtil.java | 2 +- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java index 8cf4f7377ba..99882f376fe 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java @@ -1,23 +1,25 @@ package io.mosip.resident.constant; +import org.springframework.core.env.Environment; + /** * @author Kamesh Shekhar Prasad */ public enum AttributeNameEnum { - FULL_NAME("fullName", "mosip.full.name.template.property"), - DATE_OF_BIRTH("dateOfBirth", "mosip.date.of.birth.template.property"), - UIN("UIN", "mosip.uin.template.property"), - PERPETUAL_VID("perpetualVID", "mosip.perpetual.vid.template.property"), - PHONE("phone", "mosip.phone.template.property"), - EMAIL("email", "mosip.email.template.property"), - ADDRESS("addressLine1", "mosip.address.template.property"), - PROVINCE("province", "mosip.province.template.property"), - CITY("city", "mosip.city.template.property"), - ZONE("zone", "mosip.zone.template.property"), - POSTAL_CODE("postalCode", "mosip.postal.code.template.property"), - REGION("region", "mosip.region.template.property"), - GENDER("gender", "mosip.gender.template.property"), - DEFAULT("Default", "mosip.defualt.template.property"); + FULL_NAME("fullName", "mosip.full.name.template.property.attribute.list"), + DATE_OF_BIRTH("dateOfBirth", "mosip.date.of.birth.template.property.attribute.list"), + UIN("UIN", "mosip.uin.template.property.attribute.list"), + PERPETUAL_VID("perpetualVID", "mosip.perpetual.vid.template.property.attribute.list"), + PHONE("phone", "mosip.phone.template.property.attribute.list"), + EMAIL("email", "mosip.email.template.property.attribute.list"), + ADDRESS("addressLine1", "mosip.address.template.property.attribute.list"), + PROVINCE("province", "mosip.province.template.property.attribute.list"), + CITY("city", "mosip.city.template.property.attribute.list"), + ZONE("zone", "mosip.zone.template.property.attribute.list"), + POSTAL_CODE("postalCode", "mosip.postal.code.template.property.attribute.list"), + REGION("region", "mosip.region.template.property.attribute.list"), + GENDER("gender", "mosip.gender.template.property.attribute.list"), + DEFAULT("Default", "mosip.defualt.template.property.attribute.list"); private String attributeValue; private String templatePropertyName; AttributeNameEnum(String name, String templatePropertyName){ @@ -25,13 +27,13 @@ public enum AttributeNameEnum { this.templatePropertyName = templatePropertyName; } - public static String getTemplatePropertyName(String attributeName) { - for (AttributeNameEnum authenticationModeEnum : values()) { - if (authenticationModeEnum.attributeValue.equalsIgnoreCase(attributeName)) { - return authenticationModeEnum.templatePropertyName; + public static String getTemplatePropertyName(String attributeName, Environment env) { + for (AttributeNameEnum attributeNameEnum : values()) { + if (attributeNameEnum.attributeValue.equalsIgnoreCase(attributeName)) { + return env.getProperty(attributeNameEnum.templatePropertyName); } } - return AttributeNameEnum.DEFAULT.templatePropertyName; + return env.getProperty(AttributeNameEnum.DEFAULT.templatePropertyName); } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java index 4f3504501fe..98bfebbd2eb 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java @@ -3,6 +3,8 @@ import static io.mosip.resident.constant.EventStatusSuccess.CARD_DOWNLOADED; import static io.mosip.resident.constant.EventStatusSuccess.LOCKED; import static io.mosip.resident.constant.EventStatusSuccess.UNLOCKED; +import static io.mosip.resident.constant.MappingJsonConstants.IDSCHEMA_VERSION; +import static io.mosip.resident.constant.RegistrationConstants.UIN_LABEL; import static io.mosip.resident.constant.ResidentConstants.ATTRIBUTE_LIST_DELIMITER; import static io.mosip.resident.constant.ResidentConstants.RESIDENT; import static io.mosip.resident.constant.ResidentConstants.RESIDENT_NOTIFICATIONS_DEFAULT_PAGE_SIZE; @@ -1160,10 +1162,10 @@ private ResidentTransactionEntity createResidentTransEntity(ResidentUpdateReques } else { identityMap = dto.getIdentity(); } - HashSet keys = new HashSet(identityMap.keySet()); - keys.remove("IDSchemaVersion"); - keys.remove("UIN"); - String attributeList = keys.stream().collect(Collectors.joining(ATTRIBUTE_LIST_DELIMITER)); + + String attributeList = identityMap.keySet().stream() + .filter(key -> !key.equals(IDSCHEMA_VERSION) && !key.equals(UIN_LABEL)) + .collect(Collectors.joining(ATTRIBUTE_LIST_DELIMITER)); residentTransactionEntity.setAttributeList(attributeList); residentTransactionEntity.setConsent(dto.getConsent()); residentTransactionEntity.setStatusCode(EventStatusInProgress.NEW.name()); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java index 055295844db..6aeff89fa21 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java @@ -144,7 +144,7 @@ private String getAttributesDisplayText(String attributes, String languageCode) for (String attribute : attributeList) { attribute = attribute.trim(); attributeListTemplateValue.add(getTemplateValueFromTemplateTypeCodeAndLangCode(languageCode, - AttributeNameEnum.getTemplatePropertyName(attribute))); + AttributeNameEnum.getTemplatePropertyName(attribute, env))); } } if(attributeListTemplateValue.isEmpty()){