From 82565a892a23ef5caf65719422f4eb0b22293775 Mon Sep 17 00:00:00 2001 From: Neha2365 <110969715+Neha2365@users.noreply.github.com> Date: Wed, 14 Dec 2022 17:01:33 +0530 Subject: [PATCH 01/11] added masked VID (#612) * email and phone added in profile info * validation added when claim is not available * Changes done in identityservice * log added * sysout removed * method changed * Added masked VID Co-authored-by: Neha Farheen --- .../service/impl/ResidentVidServiceImpl.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentVidServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentVidServiceImpl.java index 48118cdf319..00dcfa5c7ed 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentVidServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentVidServiceImpl.java @@ -80,6 +80,12 @@ @Component public class ResidentVidServiceImpl implements ResidentVidService { + private static final String TRANSACTIONS_LEFT_COUNT = "transactionsLeftCount"; + + private static final String TRANSACTION_LIMIT = "transactionLimit"; + + private static final String MASKED_VID = "maskedVid"; + private static final String HASH_ATTRIBUTES = "hashAttributes"; private static final Logger logger = LoggerConfiguration.logConfig(ResidentVidServiceImpl.class); @@ -683,6 +689,7 @@ public ResponseWrapper>> retrieveVids(String residentIndividu List> filteredList = ((List>) response.getResponse()).stream() .map(map -> new LinkedHashMap(map)) + .map(lhm2 -> getMaskedVid(lhm2)) .map(lhm1 -> getRefIdHash(lhm1)) .map(lhm -> { return lhm; @@ -697,19 +704,25 @@ public ResponseWrapper>> retrieveVids(String residentIndividu } + private Map getMaskedVid(Map map) { + String maskedvid = utility.convertToMaskDataFormat(map.get(VID).toString()); + map.put(MASKED_VID, maskedvid); + return map; + } + private Map getRefIdHash(Map map) { try { - String hashrefid = HMACUtils2.digestAsPlainText(map.get("vid").toString().getBytes()); + String hashrefid = HMACUtils2.digestAsPlainText(map.get(VID).toString().getBytes()); int countdb = residentTransactionRepository.findByrefIdandauthtype(hashrefid); - if(map.get("transactionLimit") != null) { - int limitCount = (int) map.get("transactionLimit"); + if(map.get(TRANSACTION_LIMIT) != null) { + int limitCount = (int) map.get(TRANSACTION_LIMIT); int leftcount = limitCount - countdb; - map.put("transactionsLeftCount", leftcount); + map.put(TRANSACTIONS_LEFT_COUNT, leftcount); if(leftcount < 0) { - map.put("transactionsLeftCount", 0); + map.put(TRANSACTIONS_LEFT_COUNT, 0); } }else { - map.put("transactionsLeftCount", map.get("transactionLimit")); + map.put(TRANSACTIONS_LEFT_COUNT, map.get(TRANSACTION_LIMIT)); } map.remove(HASH_ATTRIBUTES); } catch (NoSuchAlgorithmException e) { From e4e12d35386d0d62c056ca7dfca6fb56747aa3c4 Mon Sep 17 00:00:00 2001 From: RitikJain4108 <99730411+RitikJain4108@users.noreply.github.com> Date: Wed, 14 Dec 2022 17:51:40 +0530 Subject: [PATCH 02/11] Mosip 24879 add event id in the response of the below stories (#613) * added error for invalid user * added status in 2 apis * changed response of auth-lock-unlock api * updated response of validate otp * added eventid and status in response * added eventId in response header for download eventid api * fixed service history pdf file name * added eventid in response of download card api * convert eventId to constant * added eventId for error scenarios Co-authored-by: Ritik Jain --- .../resident/constant/ResidentConstants.java | 1 + .../controller/DownloadCardController.java | 23 +++- .../exception/ApiExceptionHandler.java | 12 ++ .../exception/ResidentServiceException.java | 20 +++- .../resident/service/DownloadCardService.java | 4 +- .../service/impl/DownloadCardServiceImpl.java | 107 +++++++++--------- .../resident/util/ObjectWithMetadata.java | 14 +++ .../DownloadCardControllerTest.java | 12 +- .../test/service/DownloadCardServiceTest.java | 57 +++------- 9 files changed, 143 insertions(+), 107 deletions(-) create mode 100644 resident/resident-service/src/main/java/io/mosip/resident/util/ObjectWithMetadata.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 e2c8fc96241..81e19118520 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 @@ -139,6 +139,7 @@ private ResidentConstants() { public static final String UIN_CARD_NAMING_CONVENTION_PROPERTY = "mosip.resident.uin.card.name.convention"; public static final String VID_CARD_NAMING_CONVENTION_PROPERTY = "mosip.resident.vid.card.name.convention"; public static final String SUCCESS = "Success"; + public static final String FAILED = "Failed"; public static final String REGISTRATION_CENTRE_TEMPLATE_PROPERTY = "resident.template.registration.centers.list"; public static final String SUPPORTING_DOCS_TEMPLATE_PROPERTY = "resident.template.support-docs-list"; public static final String FROM_DATE_TIME = "fromDateTime"; 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 6209fed73d0..e70743c3bbf 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 @@ -13,11 +13,13 @@ import io.mosip.resident.service.DownloadCardService; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.EventEnum; +import io.mosip.resident.util.Utilitiy; import io.mosip.resident.validator.RequestValidator; import io.swagger.v3.oas.annotations.tags.Tag; import reactor.util.function.Tuple2; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.core.io.InputStreamResource; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -31,6 +33,7 @@ import org.springframework.web.bind.annotation.RestController; import java.io.ByteArrayInputStream; +import java.util.Objects; /** * @author Kamesh Shekhar Prasad @@ -49,6 +52,12 @@ public class DownloadCardController { @Autowired DownloadCardService downloadCardService; + + @Autowired + private Utilitiy utilitiy; + + @Autowired + private Environment environment; private static final Logger logger = LoggerConfiguration.logConfig(DownloadCardController.class); @@ -77,14 +86,18 @@ public ResponseEntity downloadPersonalizedCard(@Validated @RequestBody M logger.debug("DownloadCardController::downloadPersonalizedCard()::entry"); auditUtil.setAuditRequestDto(EventEnum.DOWNLOAD_PERSONALIZED_CARD); requestValidator.validateDownloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); - byte[] pdfBytes = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); - InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(pdfBytes)); - if(pdfBytes.length==0){ + Tuple2 tupleResponse = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); + InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(tupleResponse.getT1())); + if(tupleResponse.getT1().length==0){ return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } return ResponseEntity.ok().contentType(MediaType.parseMediaType("application/pdf")) - .header("Content-Disposition", "attachment; filename=\"" + - downloadCardService.getFileName() + ".pdf\"") + .header("Content-Disposition", "attachment; filename=\"" + + utilitiy.getFileName(tupleResponse.getT2(), + Objects.requireNonNull(this.environment.getProperty( + ResidentConstants.DOWNLOAD_PERSONALIZED_CARD_NAMING_CONVENTION_PROPERTY))) + + ".pdf\"") + .header(ResidentConstants.EVENT_ID, tupleResponse.getT2()) .body(resource); } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/exception/ApiExceptionHandler.java b/resident/resident-service/src/main/java/io/mosip/resident/exception/ApiExceptionHandler.java index c4a4645d114..43cee75ef6b 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/exception/ApiExceptionHandler.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/exception/ApiExceptionHandler.java @@ -13,13 +13,17 @@ import io.mosip.resident.mock.exception.PaymentCanceledException; import io.mosip.resident.mock.exception.PaymentFailedException; import io.mosip.resident.mock.exception.TechnicalErrorException; +import io.mosip.resident.util.ObjectWithMetadata; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.core.env.Environment; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.util.MultiValueMap; import org.springframework.validation.FieldError; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -40,6 +44,7 @@ import io.mosip.kernel.core.util.DateUtils; import io.mosip.kernel.core.util.EmptyCheckUtils; import io.mosip.resident.config.LoggerConfiguration; +import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.constant.ResidentErrorCode; @RestControllerAdvice @@ -102,6 +107,13 @@ private ResponseEntity> getErrorResponseEntity(Htt ServiceError error = new ServiceError(e.getErrorCode(), e.getErrorText()); ResponseWrapper errorResponse = setErrors(httpServletRequest); errorResponse.getErrors().add(error); + if (e instanceof ObjectWithMetadata && ((ObjectWithMetadata) e).getMetadata() != null + && ((ObjectWithMetadata) e).getMetadata().containsKey(ResidentConstants.EVENT_ID)) { + MultiValueMap headers = new HttpHeaders(); + headers.add(ResidentConstants.EVENT_ID, + (String) ((ObjectWithMetadata) e).getMetadata().get(ResidentConstants.EVENT_ID)); + return new ResponseEntity<>(errorResponse, headers, httpStatus); + } return new ResponseEntity<>(errorResponse, httpStatus); } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java index d274c144d77..085e7ce1822 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java @@ -1,15 +1,20 @@ package io.mosip.resident.exception; +import java.util.Map; + import io.mosip.kernel.core.exception.BaseUncheckedException; import io.mosip.resident.constant.ResidentErrorCode; +import io.mosip.resident.util.ObjectWithMetadata; /** * The Class ResidentServiceException. */ -public class ResidentServiceException extends BaseUncheckedException { +public class ResidentServiceException extends BaseUncheckedException implements ObjectWithMetadata { /** Generated serial version id. */ private static final long serialVersionUID = 8621530697947108810L; + + private Map metadata; /** * Constructor the initialize Handler exception. @@ -54,5 +59,18 @@ public ResidentServiceException(String errorCode, String errorMessage, Throwable public ResidentServiceException(ResidentErrorCode err, Throwable rootCause) { this(err.getErrorCode(), err.getErrorMessage(), rootCause); } + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + public ResidentServiceException(ResidentErrorCode err, Throwable rootCause, Map metadata) { + this(err, rootCause); + this.metadata=metadata; + } } 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 da16b7074f4..a59863b95cc 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 @@ -15,9 +15,7 @@ public interface DownloadCardService { Tuple2 getDownloadCardPDF(MainRequestDTO downloadCardRequestDTOMainRequestDTO); - byte[] downloadPersonalizedCard(MainRequestDTO downloadPersonalizedCardMainRequestDTO); - - String getFileName(); + Tuple2 downloadPersonalizedCard(MainRequestDTO downloadPersonalizedCardMainRequestDTO); ResponseWrapper getVidCardEventId(String vid) 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 cbb2cd78bfa..eb86b09b24e 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,12 +1,32 @@ package io.mosip.resident.service.impl; +import static io.mosip.resident.constant.RegistrationConstants.SUCCESS; +import static io.mosip.resident.constant.TemplateVariablesConstants.NAME; +import static io.mosip.resident.constant.TemplateVariablesConstants.VID; +import static io.mosip.resident.constant.TemplateVariablesConstants.VID_TYPE; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Service; + import com.fasterxml.jackson.databind.ObjectMapper; + import io.mosip.kernel.core.exception.BaseCheckedException; import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.core.util.CryptoUtil; import io.mosip.kernel.core.util.DateUtils; import io.mosip.resident.config.LoggerConfiguration; import io.mosip.resident.constant.ApiName; +import io.mosip.resident.constant.EventStatusFailure; +import io.mosip.resident.constant.EventStatusInProgress; import io.mosip.resident.constant.IdType; import io.mosip.resident.constant.LoggerFileConstant; import io.mosip.resident.constant.RequestType; @@ -41,25 +61,6 @@ import reactor.util.function.Tuple2; import reactor.util.function.Tuples; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Service; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import static io.mosip.resident.constant.RegistrationConstants.SUCCESS; -import static io.mosip.resident.constant.TemplateVariablesConstants.NAME; -import static io.mosip.resident.constant.TemplateVariablesConstants.VID; -import static io.mosip.resident.constant.TemplateVariablesConstants.VID_TYPE; - /** * @author Kamesh Shekhar Prasad * This class is used to create service class implementation of download card api. @@ -163,26 +164,53 @@ public Tuple2 getDownloadCardPDF(MainRequestDTO downloadPersonalizedCardMainRequestDTO) { + public Tuple2 downloadPersonalizedCard(MainRequestDTO downloadPersonalizedCardMainRequestDTO) { String encodeHtml = downloadPersonalizedCardMainRequestDTO.getRequest().getHtml(); byte[] decodedData; String password=null; + String eventId = null; + ResidentTransactionEntity residentTransactionEntity = null; try { + residentTransactionEntity = createResidentTransactionEntity(); + 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 = utilitiy.getPassword(attributeValues); } + residentTransactionEntity.setRequestSummary(SUCCESS); + residentTransactionEntity.setStatusCode(EventStatusInProgress.NEW.name()); } catch (Exception e) { + residentTransactionEntity.setRequestSummary(ResidentConstants.FAILED); + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); audit.setAuditRequestDto(EventEnum.DOWNLOAD_PERSONALIZED_CARD); logger.error("Unable to convert html to pdf RootCause- "+e); - throw new ResidentServiceException(ResidentErrorCode.DOWNLOAD_PERSONALIZED_CARD, e); - } - return utilitiy.signPdf(new ByteArrayInputStream(decodedData), password); + throw new ResidentServiceException(ResidentErrorCode.DOWNLOAD_PERSONALIZED_CARD, e, Map.of(ResidentConstants.EVENT_ID, eventId)); + } finally { + //if the status code will come as null, it will set it as failed. + if(residentTransactionEntity.getStatusCode()==null) { + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + residentTransactionEntity.setRequestSummary(ResidentConstants.FAILED); + } + residentTransactionRepository.save(residentTransactionEntity); + } + return Tuples.of(utilitiy.signPdf(new ByteArrayInputStream(decodedData), password), eventId); } - private List getAttributeList() throws ApisResourceAccessException, IOException { + private ResidentTransactionEntity createResidentTransactionEntity() throws ApisResourceAccessException, ResidentServiceCheckedException { + ResidentTransactionEntity residentTransactionEntity = utilitiy.createEntity(); + String eventId = utilitiy.createEventId(); + residentTransactionEntity.setEventId(eventId); + residentTransactionEntity.setRequestTypeCode(RequestType.DOWNLOAD_PERSONALIZED_CARD.name()); + residentTransactionEntity.setRefId(utilitiy.convertToMaskDataFormat(identityService.getResidentIndvidualId())); + residentTransactionEntity.setTokenId(identityService.getResidentIdaToken()); + return residentTransactionEntity; + } + + private List getAttributeList() throws ApisResourceAccessException, IOException { return getAttributeList(identityService.getResidentIndvidualId()); } @@ -227,35 +255,6 @@ private List getAttributeList(String individualId) throws IOException, A return attributeValues; } - @Override - public String getFileName() { - ResidentTransactionEntity residentTransactionEntity = utilitiy.createEntity(); - String eventId = utilitiy.createEventId(); - residentTransactionEntity.setEventId(eventId); - residentTransactionEntity.setRequestTypeCode(RequestType.DOWNLOAD_PERSONALIZED_CARD.name()); - try { - residentTransactionEntity.setRefId(utilitiy.convertToMaskDataFormat(identityService.getResidentIndvidualId())); - residentTransactionEntity.setTokenId(identityService.getResidentIdaToken()); - } catch (ApisResourceAccessException e) { - logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), - LoggerFileConstant.APPLICATIONID.toString(), - ResidentErrorCode.API_RESOURCE_UNAVAILABLE.getErrorCode() - + ResidentErrorCode.API_RESOURCE_UNAVAILABLE.getErrorMessage() - + ExceptionUtils.getStackTrace(e)); - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.API_NOT_AVAILABLE, - eventId, "Download personalized card")); - throw new ResidentServiceException(ResidentErrorCode.API_RESOURCE_UNAVAILABLE.getErrorCode(), - ResidentErrorCode.API_RESOURCE_UNAVAILABLE.getErrorMessage(), e); - } catch (ResidentServiceCheckedException e) { - throw new RuntimeException(e); - } - residentTransactionEntity.setRequestSummary(SUCCESS); - residentTransactionEntity.setStatusCode(NEW); - residentTransactionRepository.save(residentTransactionEntity); - return utilitiy.getFileName(eventId, Objects.requireNonNull(this.environment.getProperty - (ResidentConstants.DOWNLOAD_PERSONALIZED_CARD_NAMING_CONVENTION_PROPERTY))); - } - @Override public ResponseWrapper getVidCardEventId(String vid) throws BaseCheckedException { ResponseWrapper responseWrapper= new ResponseWrapper<>(); @@ -314,7 +313,7 @@ private String insertDataForVidCard(ResidentCredentialResponseDto responseDto, S residentTransactionEntity.setRefId(utilitiy.convertToMaskDataFormat(uin)); residentTransactionEntity.setTokenId(identityService.getIDAToken(uin)); residentTransactionEntity.setCredentialRequestId(responseDto.getRequestId()); - residentTransactionEntity.setStatusCode(NEW); + residentTransactionEntity.setStatusCode(EventStatusInProgress.NEW.name()); residentTransactionEntity.setRequestSummary(RequestType.VID_CARD_DOWNLOAD.name()); /** * Here we are setting vid in aid column. diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/ObjectWithMetadata.java b/resident/resident-service/src/main/java/io/mosip/resident/util/ObjectWithMetadata.java new file mode 100644 index 00000000000..b74859e43de --- /dev/null +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/ObjectWithMetadata.java @@ -0,0 +1,14 @@ +package io.mosip.resident.util; + +import java.util.Map; + +/** + * @author Ritik Jain + */ +public interface ObjectWithMetadata { + + public Map getMetadata(); + + public void setMetadata(Map metadata); + +} diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadCardControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadCardControllerTest.java index 8fa3622e6e7..a636500b2b8 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadCardControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadCardControllerTest.java @@ -19,6 +19,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.core.env.Environment; import org.springframework.http.MediaType; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -42,6 +43,7 @@ import io.mosip.resident.service.impl.IdentityServiceImpl; import io.mosip.resident.test.ResidentTestBootApplication; import io.mosip.resident.util.AuditUtil; +import io.mosip.resident.util.Utilitiy; import io.mosip.resident.validator.RequestValidator; import reactor.util.function.Tuples; @@ -60,6 +62,12 @@ public class DownloadCardControllerTest { @Mock private AuditUtil audit; + + @Mock + private Environment environment; + + @Mock + private Utilitiy utilitiy; @MockBean private ObjectStoreHelper objectStore; @@ -106,6 +114,8 @@ public void setup() throws Exception { downloadCardRequestDTOMainRequestDTO.setId("mosip.resident.download.uin.card"); reqJson = gson.toJson(downloadCardRequestDTOMainRequestDTO); pdfbytes = "uin".getBytes(); + Mockito.when(utilitiy.getFileName(Mockito.anyString(), Mockito.anyString())).thenReturn("file"); + Mockito.when(environment.getProperty(Mockito.anyString())).thenReturn("property"); } @Test @@ -117,7 +127,7 @@ public void testGetCardSuccess() throws Exception { @Test public void testDownloadPersonalizedCard() throws Exception { - Mockito.when(downloadCardService.downloadPersonalizedCard(Mockito.any())).thenReturn(pdfbytes); + Mockito.when(downloadCardService.downloadPersonalizedCard(Mockito.any())).thenReturn(Tuples.of(pdfbytes, "12345")); MainRequestDTO downloadPersonalizedCardMainRequestDTO = new MainRequestDTO<>(); DownloadPersonalizedCardDto downloadPersonalizedCardDto = 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 d90519c93df..7c45a65cfa6 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 @@ -125,6 +125,8 @@ public void setup() throws Exception { Mockito.when(residentService.getUINCard(Mockito.anyString())).thenReturn(pdfbytes); Mockito.when(identityService.getIndividualIdType(Mockito.anyString())).thenReturn("UIN"); Mockito.when(identityService.getIndividualIdForAid(Mockito.anyString())).thenReturn("7841261580"); + Mockito.when(utilitiy.createEntity()).thenReturn(new ResidentTransactionEntity()); + Mockito.when(utilitiy.createEventId()).thenReturn("123"); ResidentTransactionEntity residentTransactionEntity = new ResidentTransactionEntity(); residentTransactionEntity.setEventId("12345"); @@ -138,7 +140,6 @@ public void setup() throws Exception { Mockito.when(environment.getProperty(ResidentConstants.IS_PASSWORD_FLAG_ENABLED)).thenReturn(String.valueOf(false)); Mockito.when(environment.getProperty(ResidentConstants.RESIDENT_IDENTITY_SCHEMATYPE)).thenReturn("personalized-card"); Mockito.when(environment.getProperty(ResidentConstants.PASSWORD_ATTRIBUTE)).thenReturn("dateOfBirth"); - Mockito.when(environment.getProperty(ResidentConstants.DOWNLOAD_PERSONALIZED_CARD_NAMING_CONVENTION_PROPERTY)).thenReturn("dateOfBirth"); Mockito.when(environment.getProperty(ResidentConstants.MOSIP_CREDENTIAL_TYPE_PROPERTY)).thenReturn("credentialType"); Mockito.when(environment.getProperty(ResidentConstants.CREDENTIAL_ISSUER)).thenReturn("credentialType"); Mockito.when(environment.getProperty(ResidentConstants.CREDENTIAL_ENCRYPTION_FLAG)).thenReturn("true"); @@ -216,33 +217,27 @@ public void testGetDownloadCardPdfOtpValidationException() throws OtpValidationF @Test public void testDownloadPersonalizedCardSuccess() { - byte[] actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); - assertEquals(pdfbytes, actualResult); + Tuple2 actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); + assertEquals(pdfbytes, actualResult.getT1()); } @Test public void testDownloadPersonalizedCardSuccessWithListAttributes() throws ResidentServiceCheckedException, IOException { Mockito.when(environment.getProperty(ResidentConstants.PASSWORD_ATTRIBUTE)).thenReturn("firstName"); - identityMap = new LinkedHashMap(); Map name = new HashMap<>(); name.put("language", "eng"); name.put("value", "kamesh"); - identityMap.put("UIN", "8251649601"); - identityMap.put("email", "manojvsp12@gmail.com"); - identityMap.put("phone", "9395910872"); - identityMap.put("dateOfBirth", "1970"); identityMap.put("firstName", List.of(name)); Mockito.when(utilities.getLanguageCode()).thenReturn("eng"); - Mockito.when(identityService.getIdentityAttributes(Mockito.anyString(),Mockito.anyString())).thenReturn(identityMap); - byte[] actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); - assertEquals(pdfbytes, actualResult); + Tuple2 actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); + assertEquals(pdfbytes, actualResult.getT1()); } @Test public void testDownloadPersonalizedCardPassword(){ Mockito.when(environment.getProperty(ResidentConstants.IS_PASSWORD_FLAG_ENABLED)).thenReturn(String.valueOf(true)); - byte[] actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); - assertEquals(pdfbytes, actualResult); + Tuple2 actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); + assertEquals(pdfbytes, actualResult.getT1()); } @Test(expected = ResidentServiceException.class) @@ -250,48 +245,24 @@ public void testDownloadPersonalizedCardPasswordFailed(){ Mockito.when(environment.getProperty(ResidentConstants.IS_PASSWORD_FLAG_ENABLED)).thenReturn(String.valueOf(true)); Mockito.when(utilitiy.getPassword(Mockito.anyList())).thenThrow( new ResidentServiceException(ResidentErrorCode.DOWNLOAD_PERSONALIZED_CARD)); - byte[] actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); - assertEquals(pdfbytes, actualResult); + Tuple2 actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); + assertEquals(pdfbytes, actualResult.getT1()); } @Test(expected = ResidentServiceException.class) public void testDownloadPersonalizedCardResidentServiceCheckedException() throws ResidentServiceCheckedException, IOException { Mockito.when(identityService.getIdentityAttributes(Mockito.anyString(), Mockito.anyString())).thenThrow( new ResidentServiceCheckedException()); - byte[] actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); - assertEquals(pdfbytes, actualResult); + Tuple2 actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); + assertEquals(pdfbytes, actualResult.getT1()); } @Test(expected = ResidentServiceException.class) public void testDownloadPersonalizedCardIOException() throws ResidentServiceCheckedException, IOException { Mockito.when(identityService.getIdentityAttributes(Mockito.anyString(), Mockito.anyString())).thenThrow( new IOException()); - byte[] actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); - assertEquals(pdfbytes, actualResult); - } - - @Test - public void testGetFileNameSuccess(){ - Mockito.when(utilitiy.createEntity()).thenReturn(new ResidentTransactionEntity()); - Mockito.when(utilitiy.createEventId()).thenReturn("123"); - Mockito.when(utilitiy.getFileName(Mockito.anyString(), Mockito.anyString())).thenReturn("file"); - assertEquals("file", downloadCardService.getFileName()); - } - - @Test(expected = ResidentServiceException.class) - public void testGetFileNameApiResourceException() throws ResidentServiceCheckedException, ApisResourceAccessException { - Mockito.when(utilitiy.createEntity()).thenReturn(new ResidentTransactionEntity()); - Mockito.when(utilitiy.createEventId()).thenReturn("123"); - Mockito.when(identityService.getResidentIdaToken()).thenThrow(new ApisResourceAccessException()); - assertEquals("file", downloadCardService.getFileName()); - } - - @Test(expected = RuntimeException.class) - public void testGetFileNameResidentServiceCheckedException() throws ResidentServiceCheckedException, ApisResourceAccessException { - Mockito.when(utilitiy.createEntity()).thenReturn(new ResidentTransactionEntity()); - Mockito.when(utilitiy.createEventId()).thenReturn("123"); - Mockito.when(identityService.getResidentIdaToken()).thenThrow(new ResidentServiceCheckedException()); - assertEquals("file", downloadCardService.getFileName()); + Tuple2 actualResult = downloadCardService.downloadPersonalizedCard(downloadPersonalizedCardMainRequestDTO); + assertEquals(pdfbytes, actualResult.getT1()); } @Test From 19aab32ae9c1811ecd74eac86d08534634bb4b8d Mon Sep 17 00:00:00 2001 From: RitikJain4108 <99730411+RitikJain4108@users.noreply.github.com> Date: Thu, 15 Dec 2022 19:43:53 +0530 Subject: [PATCH 03/11] Mosip 24879 add event id in the response of the below stories (#614) * added error for invalid user * added status in 2 apis * changed response of auth-lock-unlock api * updated response of validate otp * added eventid and status in response * added eventId in response header for download eventid api * fixed service history pdf file name * added eventid in response of download card api * convert eventId to constant * added eventId for error scenarios * fixed reliability bug * fixed response of share credential API * fixed test failure * updated response for auth lock unlock API * covered code for one method Co-authored-by: Ritik Jain --- .../controller/ResidentController.java | 11 +++- .../ResidentCredentialController.java | 12 +++- .../dto/AuthLockUnlockResponseDto.java | 17 ----- .../dto/ResidentCredentialResponseDtoV2.java | 1 - .../ResidentCredentialServiceException.java | 21 ++++++- .../exception/ResidentServiceException.java | 7 ++- .../service/ResidentCredentialService.java | 5 +- .../resident/service/ResidentService.java | 3 +- .../service/impl/DownloadCardServiceImpl.java | 23 ++++--- .../impl/ResidentCredentialServiceImpl.java | 27 ++++---- .../service/impl/ResidentServiceImpl.java | 24 ++++--- .../controller/ResidentControllerTest.java | 5 +- .../ResidentCredentialControllerTest.java | 19 +++++- .../ResidentCredentialServiceTest.java | 62 ++++++++++--------- ...esidentServiceRequestTypeAuthLockTest.java | 18 +++--- 15 files changed, 154 insertions(+), 101 deletions(-) delete mode 100644 resident/resident-service/src/main/java/io/mosip/resident/dto/AuthLockUnlockResponseDto.java diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java index c3d4012dbb4..c3b92924d92 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java @@ -51,6 +51,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import reactor.util.function.Tuple2; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; @@ -228,7 +230,7 @@ public ResponseWrapper reqAuthUnlock( @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 ResponseWrapper reqAauthTypeStatusUpdateV2( + public ResponseEntity reqAauthTypeStatusUpdateV2( @Valid @RequestBody RequestWrapper requestDTO) throws ResidentServiceCheckedException, ApisResourceAccessException { audit.setAuditRequestDto( @@ -237,11 +239,14 @@ public ResponseWrapper reqAauthTypeStatusUpdateV2( validator.validateAuthLockOrUnlockRequestV2(requestDTO); audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.REQ_AUTH_LOCK, individualId)); ResponseWrapper response = new ResponseWrapper<>(); - response.setResponse(residentService.reqAauthTypeStatusUpdateV2(requestDTO.getRequest())); + Tuple2 tupleResponse = residentService.reqAauthTypeStatusUpdateV2(requestDTO.getRequest()); + response.setResponse(tupleResponse.getT1()); response.setId(authLockStatusUpdateV2Id); response.setVersion(authLockStatusUpdateV2Version); audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.REQ_AUTH_LOCK_SUCCESS, individualId)); - return response; + return ResponseEntity.ok() + .header(ResidentConstants.EVENT_ID, tupleResponse.getT2()) + .body(response); } @ResponseFilter 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 bddb9c2ad8b..fd2e46c819b 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 @@ -29,6 +29,7 @@ import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.resident.constant.RequestIdType; import io.mosip.resident.constant.RequestType; +import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.dto.CredentialCancelRequestResponseDto; import io.mosip.resident.dto.CredentialRequestStatusResponseDto; import io.mosip.resident.dto.CredentialTypeResponse; @@ -52,6 +53,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import reactor.util.function.Tuple2; @RestController @Tag(name = "resident-credential-controller", description = "Resident Credential Controller") @@ -116,15 +118,19 @@ public ResponseEntity requestShareCredWithPartner( request.setRequest(credentialRequestDto); buildAdditionalMetadata(requestDTO, request); ResponseWrapper response = new ResponseWrapper<>(); + Tuple2 tupleResponse; if(purpose != null) { - response.setResponse(residentCredentialService.shareCredential(request.getRequest(), RequestType.SHARE_CRED_WITH_PARTNER.name(),purpose)); + tupleResponse = residentCredentialService.shareCredential(request.getRequest(), RequestType.SHARE_CRED_WITH_PARTNER.name(),purpose); }else { - response.setResponse(residentCredentialService.shareCredential(request.getRequest(), RequestType.SHARE_CRED_WITH_PARTNER.name())); + tupleResponse = residentCredentialService.shareCredential(request.getRequest(), RequestType.SHARE_CRED_WITH_PARTNER.name()); } response.setId(shareCredentialId); response.setVersion(shareCredentialVersion); + response.setResponse(tupleResponse.getT1()); audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_SUCCESS); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.status(HttpStatus.OK) + .header(ResidentConstants.EVENT_ID, tupleResponse.getT2()) + .body(response); } @GetMapping(value = "req/credential/status/{requestId}") diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/AuthLockUnlockResponseDto.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/AuthLockUnlockResponseDto.java deleted file mode 100644 index 26f0ea6aff6..00000000000 --- a/resident/resident-service/src/main/java/io/mosip/resident/dto/AuthLockUnlockResponseDto.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.mosip.resident.dto; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * The Auth Lock Unlock response dto. - * - * @author Ritik Jain - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class AuthLockUnlockResponseDto extends ResponseDTO { - - private String eventId; - -} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/ResidentCredentialResponseDtoV2.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/ResidentCredentialResponseDtoV2.java index bc07aeea7d0..e736ee6761e 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/dto/ResidentCredentialResponseDtoV2.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/dto/ResidentCredentialResponseDtoV2.java @@ -10,7 +10,6 @@ @Data public class ResidentCredentialResponseDtoV2 { - private String eventId; private String status; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentCredentialServiceException.java b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentCredentialServiceException.java index 984666a0a43..3eb00bdf0dc 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentCredentialServiceException.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentCredentialServiceException.java @@ -1,13 +1,19 @@ package io.mosip.resident.exception; +import java.util.Map; + import io.mosip.kernel.core.exception.BaseUncheckedException; +import io.mosip.resident.constant.ResidentErrorCode; +import io.mosip.resident.util.ObjectWithMetadata; -public class ResidentCredentialServiceException extends BaseUncheckedException { +public class ResidentCredentialServiceException extends BaseUncheckedException implements ObjectWithMetadata { /** * Generated serial version id */ private static final long serialVersionUID = 8621530697947108810L; + + private Map metadata; /** * Constructor the initialize Handler exception @@ -29,4 +35,17 @@ public ResidentCredentialServiceException(String errorCode, String errorMessage) public ResidentCredentialServiceException(String errorCode, String errorMessage, Throwable rootCause) { super(errorCode, errorMessage, rootCause); } + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + public ResidentCredentialServiceException(ResidentErrorCode err, Throwable rootCause, Map metadata) { + this(err.getErrorCode(), err.getErrorMessage(), rootCause); + this.metadata = metadata; + } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java index 085e7ce1822..1e7cd04f676 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java @@ -70,7 +70,12 @@ public void setMetadata(Map metadata) { public ResidentServiceException(ResidentErrorCode err, Throwable rootCause, Map metadata) { this(err, rootCause); - this.metadata=metadata; + this.metadata = metadata; + } + + public ResidentServiceException(ResidentErrorCode err, Map metadata) { + this(err); + this.metadata = metadata; } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentCredentialService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentCredentialService.java index b2f0399c7a5..f339f806418 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentCredentialService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentCredentialService.java @@ -10,6 +10,7 @@ import io.mosip.resident.dto.ResponseWrapper; import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.ResidentServiceCheckedException; +import reactor.util.function.Tuple2; public interface ResidentCredentialService { @@ -17,9 +18,9 @@ public interface ResidentCredentialService { public ResidentCredentialResponseDto reqCredential(ResidentCredentialRequestDto request, String id) throws ResidentServiceCheckedException; - public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequestDto request, String requestType) throws ResidentServiceCheckedException, ApisResourceAccessException; + public Tuple2 shareCredential(ResidentCredentialRequestDto request, String requestType) throws ResidentServiceCheckedException, ApisResourceAccessException; - public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequestDto request, String requestType, String purpose) throws ResidentServiceCheckedException, ApisResourceAccessException; + public Tuple2 shareCredential(ResidentCredentialRequestDto request, String requestType, String purpose) throws ResidentServiceCheckedException, ApisResourceAccessException; public CredentialRequestStatusResponseDto getStatus(String requestId) throws ResidentServiceCheckedException; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java index 80e2f369cc3..caf1dbc5603 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java @@ -32,6 +32,7 @@ import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.OtpValidationFailedException; import io.mosip.resident.exception.ResidentServiceCheckedException; +import reactor.util.function.Tuple2; public interface ResidentService { @@ -50,7 +51,7 @@ public ResponseDTO reqAauthTypeStatusUpdate(AuthLockOrUnLockRequestDto dto, Auth public Object reqUinUpdate(ResidentUpdateRequestDto dto, JSONObject demographicJsonObject) throws ResidentServiceCheckedException; - ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 request) + public Tuple2 reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 request) throws ResidentServiceCheckedException, ApisResourceAccessException; public ResponseWrapper getAuthLockStatus(String individualId) throws 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 eb86b09b24e..95e8bc5ce10 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 @@ -184,18 +184,23 @@ public Tuple2 downloadPersonalizedCard(MainRequestDTO shareCredential(ResidentCredentialRequestDto dto, String requestType) throws ResidentServiceCheckedException, ApisResourceAccessException { return shareCredential(dto, requestType, null); } @Override - public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequestDto dto, String requestType, + public Tuple2 shareCredential(ResidentCredentialRequestDto dto, String requestType, String purpose) throws ResidentServiceCheckedException, ApisResourceAccessException { ResidentCredentialResponseDto residentCredentialResponseDto = new ResidentCredentialResponseDto(); ResidentCredentialResponseDtoV2 residentCredentialResponseDtoV2=new ResidentCredentialResponseDtoV2(); @@ -239,10 +241,14 @@ public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequest String partnerUrl = env.getProperty(ApiName.PARTNER_API_URL.name()) + "/" + dto.getIssuer(); URI partnerUri = URI.create(partnerUrl); String individualId = identityServiceImpl.getResidentIndvidualId(); + String eventId = null; ResidentTransactionEntity residentTransactionEntity = null; try { residentTransactionEntity = createResidentTransactionEntity(dto, requestType, individualId); + if (residentTransactionEntity != null) { + eventId = residentTransactionEntity.getEventId(); + } if (dto.getConsent() == null || dto.getConsent().equalsIgnoreCase(ConsentStatusType.DENIED.name()) || dto.getConsent().trim().isEmpty() || dto.getConsent().equals("null") || !dto.getConsent().equalsIgnoreCase(ConsentStatusType.ACCEPTED.name())) { residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); @@ -273,27 +279,26 @@ public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequest } additionalAttributes.put("RID", residentCredentialResponseDto.getRequestId()); sendNotificationV2(individualId, RequestType.valueOf(requestType), TemplateType.REQUEST_RECEIVED, - residentTransactionEntity.getEventId(), additionalAttributes); + eventId, additionalAttributes); updateResidentTransaction(dto, residentCredentialResponseDto, residentTransactionEntity); - residentCredentialResponseDtoV2.setEventId(residentTransactionEntity.getEventId()); residentCredentialResponseDtoV2.setStatus(ResidentConstants.SUCCESS); } catch (ResidentServiceCheckedException | ApisResourceAccessException e) { if (residentTransactionEntity != null) { residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); sendNotificationV2(individualId, RequestType.valueOf(requestType), TemplateType.FAILURE, - residentTransactionEntity.getEventId(), additionalAttributes); + eventId, additionalAttributes); } audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_EXCEPTION); - throw new ResidentCredentialServiceException(ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorCode(), - ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorMessage(), e); + throw new ResidentCredentialServiceException(ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION, e, + Map.of(ResidentConstants.EVENT_ID, eventId)); } catch (IOException e) { residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); sendNotificationV2(individualId, RequestType.valueOf(requestType), TemplateType.FAILURE, - residentTransactionEntity.getEventId(), additionalAttributes); + eventId, additionalAttributes); audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_EXCEPTION); - throw new ResidentCredentialServiceException(ResidentErrorCode.IO_EXCEPTION.getErrorCode(), - ResidentErrorCode.IO_EXCEPTION.getErrorMessage(), e); + throw new ResidentCredentialServiceException(ResidentErrorCode.IO_EXCEPTION, e, + Map.of(ResidentConstants.EVENT_ID, eventId)); } finally { if (Utilitiy.isSecureSession() && residentTransactionEntity != null) { //if the status code will come as null, it will set it as failed. @@ -304,7 +309,7 @@ public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequest residentTransactionRepository.save(residentTransactionEntity); } } - return residentCredentialResponseDtoV2; + return Tuples.of(residentCredentialResponseDtoV2, eventId); } private ResidentTransactionEntity createResidentTransactionEntity(ResidentCredentialRequestDto dto, 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 840a9aa11e9..56c56cc5817 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 @@ -78,7 +78,6 @@ import io.mosip.resident.dto.AuthLockOrUnLockRequestDto; import io.mosip.resident.dto.AuthLockOrUnLockRequestDtoV2; import io.mosip.resident.dto.AuthLockStatusResponseDtoV2; -import io.mosip.resident.dto.AuthLockUnlockResponseDto; import io.mosip.resident.dto.AuthTxnDetailsDTO; import io.mosip.resident.dto.AuthTypeStatusDtoV2; import io.mosip.resident.dto.AuthUnLockRequestDTO; @@ -152,6 +151,8 @@ import io.mosip.resident.util.UINCardDownloadService; import io.mosip.resident.util.Utilities; import io.mosip.resident.util.Utilitiy; +import reactor.util.function.Tuple2; +import reactor.util.function.Tuples; @Service public class ResidentServiceImpl implements ResidentService { @@ -1122,14 +1123,15 @@ private List getResidentDocuments(ResidentUpdateRequestDto dt } @Override - public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authLockOrUnLockRequestDtoV2) + public Tuple2 reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authLockOrUnLockRequestDtoV2) throws ResidentServiceCheckedException, ApisResourceAccessException { logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), "ResidentServiceImpl::reqAauthTypeStatusUpdate():: entry"); - AuthLockUnlockResponseDto response = new AuthLockUnlockResponseDto(); + ResponseDTO response = new ResponseDTO(); String individualId = identityServiceImpl.getResidentIndvidualId(); boolean isTransactionSuccessful = false; List residentTransactionEntities = List.of(); + String eventId = null; try { audit.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.REQ_AUTH_TYPE_LOCK, "Request for Auth Type Lock")); @@ -1144,6 +1146,9 @@ public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authL throw new RuntimeException(e); } }).collect(Collectors.toList()); + if (!residentTransactionEntities.isEmpty()) { + eventId = residentTransactionEntities.get(0).getEventId(); + } List authTypesStatusList = authLockOrUnLockRequestDtoV2.getAuthTypes(); String authType = authTypesStatusList.stream().map(ResidentServiceImpl::getAuthTypeBasedOnConfigV2) @@ -1176,8 +1181,8 @@ public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authL } else { audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.REQUEST_FAILED, "Request for auth " + authLockOrUnLockRequestDtoV2.getAuthTypes() + " lock failed")); - throw new ResidentServiceException(ResidentErrorCode.REQUEST_FAILED.getErrorCode(), - ResidentErrorCode.REQUEST_FAILED.getErrorMessage()); + throw new ResidentServiceException(ResidentErrorCode.REQUEST_FAILED, + Map.of(ResidentConstants.EVENT_ID, eventId)); } } catch (ApisResourceAccessException e) { @@ -1193,8 +1198,8 @@ public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authL + ExceptionUtils.getStackTrace(e)); audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.API_NOT_AVAILABLE, "Request for auth" + authLockOrUnLockRequestDtoV2.getAuthTypes() + " lock failed")); - throw new ResidentServiceException(ResidentErrorCode.API_RESOURCE_UNAVAILABLE.getErrorCode(), - ResidentErrorCode.API_RESOURCE_UNAVAILABLE.getErrorMessage(), e); + throw new ResidentServiceException(ResidentErrorCode.API_RESOURCE_UNAVAILABLE, e, + Map.of(ResidentConstants.EVENT_ID, eventId)); } finally { residentTransactionRepository.saveAll(residentTransactionEntities); @@ -1202,7 +1207,7 @@ public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authL TemplateType templateType = isTransactionSuccessful ? TemplateType.REQUEST_RECEIVED : TemplateType.FAILURE; NotificationResponseDTO notificationResponseDTO = sendNotificationV2(individualId, requestType, - templateType, residentTransactionEntities.get(0).getEventId(), null); + templateType, eventId, null); if (isTransactionSuccessful) audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.SEND_NOTIFICATION_SUCCESS, @@ -1213,12 +1218,11 @@ public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authL if (notificationResponseDTO != null) { response.setMessage(notificationResponseDTO.getMessage()); response.setStatus(ResidentConstants.SUCCESS); - response.setEventId(residentTransactionEntities.get(0).getEventId()); } } logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), "ResidentServiceImpl::reqAauthTypeStatusUpdate():: exit"); - return response; + return Tuples.of(response, eventId); } private ResidentTransactionEntity createResidentTransactionEntity(String individualId, String partnerId) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java index a310b134651..33e019b9c3d 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java @@ -93,6 +93,7 @@ import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.JsonUtil; import io.mosip.resident.validator.RequestValidator; +import reactor.util.function.Tuples; /** * @author Sowmya Ujjappa Banakar @@ -235,7 +236,7 @@ public void testReqAuthTypeLock() throws Exception { ResponseDTO responseDto = new ResponseDTO(); responseDto.setStatus("success"); doNothing().when(validator).validateAuthLockOrUnlockRequestV2(Mockito.any()); - Mockito.doReturn(responseDto).when(residentService).reqAauthTypeStatusUpdateV2(Mockito.any()); + Mockito.doReturn(Tuples.of(responseDto, "12345")).when(residentService).reqAauthTypeStatusUpdateV2(Mockito.any()); residentController.reqAauthTypeStatusUpdateV2(authTypeStatusRequest); validator.validateAuthLockOrUnlockRequestV2(authTypeStatusRequest); this.mockMvc.perform( @@ -248,7 +249,7 @@ public void testReqAuthTypeLock() throws Exception { public void testReqAuthTypeLockBadRequest() throws Exception { ResponseDTO responseDto = new ResponseDTO(); doNothing().when(validator).validateAuthLockOrUnlockRequest(Mockito.any(), Mockito.any()); - Mockito.doReturn(responseDto).when(residentService).reqAauthTypeStatusUpdateV2(Mockito.any()); + Mockito.doReturn(Tuples.of(responseDto, "12345")).when(residentService).reqAauthTypeStatusUpdateV2(Mockito.any()); MvcResult result = this.mockMvc .perform(post("/auth-lock-unlock").contentType(MediaType.APPLICATION_JSON).content("")) 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 881a2407dd2..52ed3ede3c6 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 @@ -53,6 +53,7 @@ import io.mosip.resident.test.ResidentTestBootApplication; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.validator.RequestValidator; +import reactor.util.function.Tuples; @RunWith(SpringRunner.class) @SpringBootTest(classes = ResidentTestBootApplication.class) @@ -114,6 +115,8 @@ public class ResidentCredentialControllerTest { CredentialRequestStatusResponseDto credentialReqStatusResponse; PartnerCredentialTypePolicyDto partnerCredentialTypeReqResponse; + + ResidentCredentialResponseDtoV2 dtoV2; String reqCredentialEventJson; @@ -125,6 +128,7 @@ public void setup() throws Exception { credentialCancelReqResponse = new CredentialCancelRequestResponseDto(); credentialReqResponse = new ResidentCredentialResponseDto(); partnerCredentialTypeReqResponse = new PartnerCredentialTypePolicyDto(); + dtoV2 = new ResidentCredentialResponseDtoV2(); MockitoAnnotations.initMocks(this); this.mockMvc = MockMvcBuilders.standaloneSetup(residentCredentialController).build(); ResidentCredentialRequestDto credentialRequestDto = new ResidentCredentialRequestDto(); @@ -193,7 +197,8 @@ public void testPartnerIdCredentialType() throws Exception { @Test public void testRequestShareCredWithPartner() throws Exception { - Mockito.when(residentCredentialService.shareCredential(Mockito.any(),Mockito.anyString())).thenReturn(new ResidentCredentialResponseDtoV2()); + Mockito.when(residentCredentialService.shareCredential(Mockito.any(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(Tuples.of(dtoV2, "12345")); ShareCredentialRequestDto request = new ShareCredentialRequestDto(); SharableAttributesDTO attr = new SharableAttributesDTO(); attr.setAttributeName("name"); @@ -205,4 +210,16 @@ public void testRequestShareCredWithPartner() throws Exception { mockMvc.perform(MockMvcRequestBuilders.post("/share-credential").contentType(MediaType.APPLICATION_JSON_VALUE) .content(gson.toJson(requestWrapper).getBytes())).andExpect(status().isOk()); } + + @Test + public void testRequestShareCredWithPartnerWithoutPurpose() throws Exception { + Mockito.when(residentCredentialService.shareCredential(Mockito.any(), Mockito.anyString())) + .thenReturn(Tuples.of(dtoV2, "12345")); + ShareCredentialRequestDto request = new ShareCredentialRequestDto(); + request.setSharableAttributes(null); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setRequest(request); + mockMvc.perform(MockMvcRequestBuilders.post("/share-credential").contentType(MediaType.APPLICATION_JSON_VALUE) + .content(gson.toJson(requestWrapper).getBytes())).andExpect(status().isOk()); + } } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentCredentialServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentCredentialServiceTest.java index 3d016dd68b0..5c918df93cb 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentCredentialServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentCredentialServiceTest.java @@ -1,6 +1,31 @@ package io.mosip.resident.test.service; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.net.URI; +import java.security.SecureRandom; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.util.ReflectionTestUtils; + import com.fasterxml.jackson.databind.ObjectMapper; + import io.mosip.kernel.core.exception.ServiceError; import io.mosip.kernel.core.util.CryptoUtil; import io.mosip.kernel.core.util.DateUtils; @@ -38,30 +63,7 @@ import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utilitiy; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.core.env.Environment; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.util.ReflectionTestUtils; - -import java.io.IOException; -import java.net.URI; -import java.security.SecureRandom; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; +import reactor.util.function.Tuple2; @RunWith(MockitoJUnitRunner.class) @RefreshScope @@ -260,8 +262,8 @@ public void testShareCredential() throws IOException, ApisResourceAccessExceptio when(residentServiceRestClient.getApi(partnerUri, ResponseWrapper.class)).thenReturn(partnerResponseDtoResponseWrapper); when(residentServiceRestClient.postApi(any(), any(), any(), any())).thenReturn(response); - ResidentCredentialResponseDtoV2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER"); - assertNotNull(credentialResponseDto.getEventId()); + Tuple2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER"); + assertNotNull(credentialResponseDto.getT1().getStatus()); } @Test @@ -289,8 +291,8 @@ public void testShareCredentialPurpose() throws IOException, ApisResourceAccessE when(residentServiceRestClient.getApi(partnerUri, ResponseWrapper.class)).thenReturn(partnerResponseDtoResponseWrapper); when(residentServiceRestClient.postApi(any(), any(), any(), any())).thenReturn(response); - ResidentCredentialResponseDtoV2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER","Banking"); - assertNotNull(credentialResponseDto.getEventId()); + Tuple2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER","Banking"); + assertNotNull(credentialResponseDto.getT1().getStatus()); } @Test @@ -319,8 +321,8 @@ public void testShareCredentialWithEncryptionKeyNull() throws IOException, ApisR when(residentServiceRestClient.getApi(partnerUri, ResponseWrapper.class)).thenReturn(partnerResponseDtoResponseWrapper); when(residentServiceRestClient.postApi(any(), any(), any(), any())).thenReturn(response); - ResidentCredentialResponseDtoV2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER"); - assertNotNull(credentialResponseDto.getEventId()); + Tuple2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER"); + assertNotNull(credentialResponseDto.getT1().getStatus()); } @Test(expected = ResidentCredentialServiceException.class) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestTypeAuthLockTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestTypeAuthLockTest.java index 209828069e6..14dbe0fe52e 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestTypeAuthLockTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestTypeAuthLockTest.java @@ -28,6 +28,8 @@ import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.UINCardDownloadService; import io.mosip.resident.util.Utilitiy; +import reactor.util.function.Tuple2; + import org.json.simple.JSONObject; import org.junit.Before; import org.junit.Test; @@ -35,14 +37,13 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.util.ReflectionTestUtils; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -110,15 +111,17 @@ public class ResidentServiceRequestTypeAuthLockTest { public void setup() throws ApisResourceAccessException, ResidentServiceCheckedException { notificationResponseDTO = new NotificationResponseDTO(); - notificationResponseDTO.setStatus("Notification success"); + notificationResponseDTO.setStatus("success"); + notificationResponseDTO.setMessage("Notification success"); Mockito.doNothing().when(audit).setAuditRequestDto(Mockito.any()); individualId = identityServiceImpl.getResidentIndvidualId(); List residentTransactionEntities=new ArrayList<>(); ResidentTransactionEntity residentTransactionEntity = new ResidentTransactionEntity(); - residentTransactionEntity.setEventId(UUID.randomUUID().toString()); + residentTransactionEntity.setEventId("12345"); when(utility.createEntity()).thenReturn(residentTransactionEntity); residentTransactionEntities.add(residentTransactionEntity); + Mockito.when(utility.createEventId()).thenReturn("12345"); ArrayList partnerIds = new ArrayList<>(); partnerIds.add("m-partner-default-auth"); when(partnerService.getPartnerDetails(Mockito.anyString())).thenReturn(partnerIds); @@ -139,13 +142,10 @@ public void testReqAuthTypeStatusUpdateSuccess() authLockOrUnLockRequestDtoV2.setAuthTypes(authTypeStatusDtoList); for (AuthTypeStatusDto authTypeStatusDto1 : authLockOrUnLockRequestDtoV2.getAuthTypes()) { Mockito.when(idAuthService.authTypeStatusUpdateForRequestId(any(), any(), any())).thenReturn("123"); - ResponseDTO response = new ResponseDTO(); - response.setMessage("Notification success"); Mockito.when(notificationService.sendNotification(Mockito.any())).thenReturn(notificationResponseDTO); - ResponseDTO authLockResponse = residentService.reqAauthTypeStatusUpdateV2(authLockOrUnLockRequestDtoV2); - assertEquals(authLockResponse.getMessage(), authLockResponse.getMessage()); + Tuple2 authLockResponse = residentService.reqAauthTypeStatusUpdateV2(authLockOrUnLockRequestDtoV2); + assertEquals(notificationResponseDTO.getMessage(), authLockResponse.getT1().getMessage()); } - } @Test(expected = ResidentServiceException.class) From b3d1710b7db39f13fce4148c054fe0bd99d0f77b Mon Sep 17 00:00:00 2001 From: kameshsr <47484458+kameshsr@users.noreply.github.com> Date: Fri, 16 Dec 2022 15:31:07 +0530 Subject: [PATCH 04/11] MOSIP-25310 MOSIP-24730 MOSIP-25312 MOSIP-24731 Added grievance api (#615) * Fixed service history issue. * MOSIP-25310 Added resident_grievance_ticket.sql * MOSIP-25310 Added hasAttachment column to grievance table. * MOSIP-25310 Added hasAttachment column to grievance table. * MOSIP-25310 Added hasAttachment column to grievance table. * MOSIP-25310 Added service class of GrievanceController * MOSIP-25310 Added entity and repository class of grievance table. * MOSIP-25310 Added status in resident entity. * MOSIP-25310 Fixed test case failure. * MOSIP-25310 Get default name from profile. * MOSIP-25310 Added card format to vid card. * MOSIP-25310 made message max length configurable. --- .../ddl/resident_grievance_ticket.sql | 50 ++++++++ .../ddl/resident_grievance_ticket.sql | 50 ++++++++ .../resident/constant/ResidentConstants.java | 9 ++ .../resident/constant/ResidentErrorCode.java | 4 +- .../mosip/resident/constant/ServiceType.java | 2 +- .../controller/AcknowledgementController.java | 3 - .../controller/GrievanceController.java | 52 ++++++++ .../controller/PinStatusController.java | 4 +- .../controller/ProxyOtpController.java | 4 +- .../controller/ResidentController.java | 2 +- .../resident/dto/GrievanceRequestDTO.java | 18 +++ .../entity/ResidentGrievanceEntity.java | 89 ++++++++++++++ .../ResidentGrievanceRepository.java | 15 +++ .../resident/service/GrievanceService.java | 16 +++ .../service/impl/DownloadCardServiceImpl.java | 99 ++++++++++----- .../service/impl/GrievanceServiceImpl.java | 114 ++++++++++++++++++ .../service/impl/ResidentServiceImpl.java | 11 +- .../io/mosip/resident/util/EventEnum.java | 10 ++ .../resident/validator/RequestValidator.java | 108 ++++++++++++++--- .../test/service/DownloadCardServiceTest.java | 3 +- .../test/validator/RequestValidatorTest.java | 17 +-- 21 files changed, 611 insertions(+), 69 deletions(-) create mode 100644 db_release_scripts/mosip_resident/ddl/resident_grievance_ticket.sql create mode 100644 db_scripts/mosip_resident/ddl/resident_grievance_ticket.sql create mode 100644 resident/resident-service/src/main/java/io/mosip/resident/controller/GrievanceController.java create mode 100644 resident/resident-service/src/main/java/io/mosip/resident/dto/GrievanceRequestDTO.java create mode 100644 resident/resident-service/src/main/java/io/mosip/resident/entity/ResidentGrievanceEntity.java create mode 100644 resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentGrievanceRepository.java create mode 100644 resident/resident-service/src/main/java/io/mosip/resident/service/GrievanceService.java create mode 100644 resident/resident-service/src/main/java/io/mosip/resident/service/impl/GrievanceServiceImpl.java diff --git a/db_release_scripts/mosip_resident/ddl/resident_grievance_ticket.sql b/db_release_scripts/mosip_resident/ddl/resident_grievance_ticket.sql new file mode 100644 index 00000000000..d2ca532ae0e --- /dev/null +++ b/db_release_scripts/mosip_resident/ddl/resident_grievance_ticket.sql @@ -0,0 +1,50 @@ +-- ------------------------------------------------------------------------------------------------- +-- Database Name: resident_grievance_ticket +-- Release Version : 1.2.1 +-- Purpose : Database scripts for Resident Service DB. +-- Create By : Kamesh Shekhar Prasad +-- Created Date : December-2022 +-- +-- Modified Date Modified By Comments / Remarks +-- -------------------------------------------------------------------------------------------------- +-- +----------------------------------------------------------------------------------------------------- + +-- This Table is used to save the resident_grievance_ticket table values. +CREATE TABLE resident.resident_grievance_ticket( + id VARCHAR(64) NOT NULL, + eventId VARCHAR(64) NOT NULL, + name VARCHAR(256) NOT NULL, + emailId VARCHAR(128), + alternateEmailId VARCHAR(128), + phoneNo VARCHAR(64), + alternatePhoneNo VARCHAR(64), + message character varying(1024) NOT NULL, + hasAttachment boolean NOT NULL DEFAULT false, + status character varying(64) NOT NULL, + cr_by character varying(256) NOT NULL, + cr_dtimes timestamp NOT NULL, + upd_by character varying(256), + upd_dtimes timestamp, + is_deleted boolean NOT NULL DEFAULT false, + del_dtimes timestamp, + CONSTRAINT pk_resgrev_id PRIMARY KEY (id) +); + +COMMENT ON TABLE resident.resident_grievance_ticket IS 'This Table is used to save the resident_grievance_ticket table values.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.id IS 'Unique Id.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.event_id IS 'Unique event id.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.emailId IS 'Unique email id.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.alternateEmailId IS 'Alternate email id.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.phoneNo IS 'Phone number.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.altrenatePhoneNo IS 'Alternate Phone number.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.message IS 'Message.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.status IS 'status.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.cr_by IS 'created by.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.cr_dtimes IS 'created date and time.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.upd_by IS 'updated by.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.upd_dtimes IS 'updated date and time.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.is_deleted IS 'is deleted.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.del_dtimes IS 'Deleted time-stamp.'; + +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/db_scripts/mosip_resident/ddl/resident_grievance_ticket.sql b/db_scripts/mosip_resident/ddl/resident_grievance_ticket.sql new file mode 100644 index 00000000000..d2ca532ae0e --- /dev/null +++ b/db_scripts/mosip_resident/ddl/resident_grievance_ticket.sql @@ -0,0 +1,50 @@ +-- ------------------------------------------------------------------------------------------------- +-- Database Name: resident_grievance_ticket +-- Release Version : 1.2.1 +-- Purpose : Database scripts for Resident Service DB. +-- Create By : Kamesh Shekhar Prasad +-- Created Date : December-2022 +-- +-- Modified Date Modified By Comments / Remarks +-- -------------------------------------------------------------------------------------------------- +-- +----------------------------------------------------------------------------------------------------- + +-- This Table is used to save the resident_grievance_ticket table values. +CREATE TABLE resident.resident_grievance_ticket( + id VARCHAR(64) NOT NULL, + eventId VARCHAR(64) NOT NULL, + name VARCHAR(256) NOT NULL, + emailId VARCHAR(128), + alternateEmailId VARCHAR(128), + phoneNo VARCHAR(64), + alternatePhoneNo VARCHAR(64), + message character varying(1024) NOT NULL, + hasAttachment boolean NOT NULL DEFAULT false, + status character varying(64) NOT NULL, + cr_by character varying(256) NOT NULL, + cr_dtimes timestamp NOT NULL, + upd_by character varying(256), + upd_dtimes timestamp, + is_deleted boolean NOT NULL DEFAULT false, + del_dtimes timestamp, + CONSTRAINT pk_resgrev_id PRIMARY KEY (id) +); + +COMMENT ON TABLE resident.resident_grievance_ticket IS 'This Table is used to save the resident_grievance_ticket table values.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.id IS 'Unique Id.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.event_id IS 'Unique event id.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.emailId IS 'Unique email id.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.alternateEmailId IS 'Alternate email id.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.phoneNo IS 'Phone number.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.altrenatePhoneNo IS 'Alternate Phone number.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.message IS 'Message.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.status IS 'status.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.cr_by IS 'created by.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.cr_dtimes IS 'created date and time.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.upd_by IS 'updated by.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.upd_dtimes IS 'updated date and time.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.is_deleted IS 'is deleted.'; +COMMENT ON COLUMN resident.resident_grievance_ticket.del_dtimes IS 'Deleted time-stamp.'; + +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 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 81e19118520..79b2ec2e736 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 @@ -145,5 +145,14 @@ private ResidentConstants() { public static final String FROM_DATE_TIME = "fromDateTime"; public static final String TO_DATE_TIME = "toDateTime"; public static final String DOWNLOAD_SERVICE_HISTORY_FILE_NAME_CONVENTION_PROPERTY = "mosip.resident.download.service.history.file.name.convention"; + public static final String GRIEVANCE_REQUEST_ID = "mosip.resident.grievance.ticket.request.id"; + public static final String GRIEVANCE_REQUEST_VERSION = "mosip.resident.grievance.ticket.request.version"; + + public static final String NAME_FROM_PROFILE = "mosip.resident.name.token.claim-name"; + + public static final String EMAIL_FROM_PROFILE = "mosip.resident.email.token.claim-email"; + public static final String PHONE_FROM_PROFILE = "mosip.resident.phone.token.claim-phone"; + + public static final String MESSAGE_CODE_MAXIMUM_LENGTH = "mosip.resident.message.code.maximum.length"; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentErrorCode.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentErrorCode.java index be5e52acf9d..6a8891e5c32 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentErrorCode.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/ResidentErrorCode.java @@ -111,7 +111,9 @@ public enum ResidentErrorCode { REDIRECT_URL_NOT_FOUND("RES-SER-482","Redirect url not found."), CARD_NOT_READY("RES_SER_509", "The card is not ready for download."), OTP_REQUEST_FLOODED("RES_SER_510", "Innumerous OTP requests received"), - EID_NOT_BELONG_TO_SESSION("RES-SER-511", "The entered EID is not associated with the UIN/VID used to log in."); + EID_NOT_BELONG_TO_SESSION("RES-SER-511", "The entered EID is not associated with the UIN/VID used to log in."), + GRIEVANCE_TICKET_GENERATION_FAILED("RES-SER-512", "Unable to Generate Ticket of grievance"), + MISSING_INPUT_PARAMETER("RES-SER-414", "Missing input Parameter- "); private final String errorCode; private final String errorMessage; 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 3d8b360e088..da8ad2e43df 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)), + AUTHENTICATION_REQUEST(List.of(RequestType.AUTHENTICATION_REQUEST, RequestType.SEND_OTP, RequestType.VALIDATE_OTP)), SERVICE_REQUEST(List.of(RequestType.DOWNLOAD_PERSONALIZED_CARD, RequestType.ORDER_PHYSICAL_CARD, RequestType.GET_MY_ID, RequestType.BOOK_AN_APPOINTMENT)), DATA_UPDATE_REQUEST(List.of(RequestType.UPDATE_MY_UIN)), diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/AcknowledgementController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/AcknowledgementController.java index 0f480143029..122d4512598 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/AcknowledgementController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/AcknowledgementController.java @@ -14,7 +14,6 @@ import org.springframework.core.io.InputStreamResource; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; @@ -22,8 +21,6 @@ import java.io.ByteArrayInputStream; import java.io.IOException; -import static io.mosip.resident.constant.RegistrationConstants.UNDER_SCORE; - /** * This class is used to create api for getting acknowledgement. * @Author Kamesh Shekhar Prasad diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/GrievanceController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/GrievanceController.java new file mode 100644 index 00000000000..0d65b80f62d --- /dev/null +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/GrievanceController.java @@ -0,0 +1,52 @@ +package io.mosip.resident.controller; + +import io.mosip.kernel.core.http.ResponseWrapper; +import io.mosip.kernel.core.logger.spi.Logger; +import io.mosip.resident.config.LoggerConfiguration; +import io.mosip.resident.dto.GrievanceRequestDTO; +import io.mosip.resident.dto.MainRequestDTO; +import io.mosip.resident.exception.ApisResourceAccessException; +import io.mosip.resident.exception.ResidentServiceCheckedException; +import io.mosip.resident.service.GrievanceService; +import io.mosip.resident.util.AuditUtil; +import io.mosip.resident.util.EventEnum; +import io.mosip.resident.validator.RequestValidator; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; + +/** + * @author Kamesh Shekhar Prasad + * This class is used to generate ticket of grievance. + */ + +@RestController +@Tag(name = "GrievanceController", description = "Grievance-Controller") +public class GrievanceController { + + @Autowired + AuditUtil auditUtil; + + @Autowired + RequestValidator requestValidator; + + @Autowired + GrievanceService grievanceService; + + private static final Logger logger = LoggerConfiguration.logConfig(GrievanceController.class); + + @PostMapping("/grievance/ticket") + public ResponseWrapper grievanceTicket(@Validated @RequestBody MainRequestDTO + grievanceRequestDTOMainRequestDTO) throws ResidentServiceCheckedException, + ApisResourceAccessException, IOException { + logger.debug("DownloadCardController::grievanceTicket()::entry"); + auditUtil.setAuditRequestDto(EventEnum.GRIEVANCE_TICKET_REQUEST); + requestValidator.validateGrievanceRequestDto(grievanceRequestDTOMainRequestDTO); + return grievanceService.getGrievanceTicket(grievanceRequestDTOMainRequestDTO); + } +} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/PinStatusController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/PinStatusController.java index b3cecf7e28a..90708c9e09c 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/PinStatusController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/PinStatusController.java @@ -37,7 +37,7 @@ public class PinStatusController { @PostMapping(path = "pinned/{eventId}") public ResponseWrapper pinStatus(@PathVariable("eventId") String eventId){ audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.VALIDATE_REQUEST, "Pin Status API")); - requestValidator.validateIndividualId(eventId); + requestValidator.validateEventId(eventId); audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.PIN_STATUS, eventId)); return pinUnpinStatusService.pinStatus(eventId, true); } @@ -48,7 +48,7 @@ public ResponseWrapper pinStatus(@PathVariable("eventId") String ev @PostMapping(path = "unpinned/{eventId}") public ResponseWrapper unPinStatus(@PathVariable("eventId") String eventId){ audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.VALIDATE_REQUEST, "Pin Status API")); - requestValidator.validateIndividualId(eventId); + requestValidator.validateEventId(eventId); audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.UN_PIN_STATUS, eventId)); return pinUnpinStatusService.pinStatus(eventId, false); } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyOtpController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyOtpController.java index b904c0bf3df..fa2dcc48f35 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyOtpController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyOtpController.java @@ -27,6 +27,8 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import static io.mosip.resident.constant.RegistrationConstants.ID; + /** * This class provides different api to perform operation for login * @@ -67,7 +69,7 @@ public class ProxyOtpController { @ResponseStatus(value = HttpStatus.OK) public ResponseEntity> sendOTP( @Validated @RequestBody MainRequestDTO userOtpRequest) { - requestValidator.validateRequestId(userOtpRequest.getId(), this.environment.getProperty(ResidentConstants.RESIDENT_CONTACT_DETAILS_SEND_OTP_ID)); + requestValidator.validateRequestType(userOtpRequest.getId(), this.environment.getProperty(ResidentConstants.RESIDENT_CONTACT_DETAILS_SEND_OTP_ID), ID); requestValidator.validateDate(userOtpRequest.getRequesttime()); return proxyOtpService.sendOtp(userOtpRequest); } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java index c3b92924d92..4a2aaf2cc9a 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java @@ -408,7 +408,7 @@ public ResponseEntity downloadCard( @PathVariable("eventId") String eventId) throws ResidentServiceCheckedException { audit.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.VALIDATE_REQUEST, "request download card API")); - validator.validateIndividualId(eventId); + validator.validateEventId(eventId); ResponseWrapper> response = new ResponseWrapper<>(); audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.RID_DIGITAL_CARD_REQ, eventId)); byte[] pdfBytes = residentService.downloadCard(eventId, getIdType(eventId)); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/GrievanceRequestDTO.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/GrievanceRequestDTO.java new file mode 100644 index 00000000000..38606ea6a8b --- /dev/null +++ b/resident/resident-service/src/main/java/io/mosip/resident/dto/GrievanceRequestDTO.java @@ -0,0 +1,18 @@ +package io.mosip.resident.dto; + +import lombok.Data; + +/** + * @author Kamesh Shekhar Prasad + * This class is used a request DTO for grievance tiket API. + */ +@Data +public class GrievanceRequestDTO { + private String eventId; + private String name; + private String emailId; + private String alternateEmailId; + private String phoneNo; + private String alternatePhoneNo; + private String message; +} \ No newline at end of file diff --git a/resident/resident-service/src/main/java/io/mosip/resident/entity/ResidentGrievanceEntity.java b/resident/resident-service/src/main/java/io/mosip/resident/entity/ResidentGrievanceEntity.java new file mode 100644 index 00000000000..623fffc3a3c --- /dev/null +++ b/resident/resident-service/src/main/java/io/mosip/resident/entity/ResidentGrievanceEntity.java @@ -0,0 +1,89 @@ +package io.mosip.resident.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + +/** + * This entity class defines the database table details for resident_grievance_ticket + * table. + * + * @author Kamesh Shekhar Prasad + * @since 1.2.0.1 + * + */ + +@Data +@Table(name = "resident_grievance_ticket", schema = "resident") +@Entity +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ResidentGrievanceEntity { + + @Id + @Column(name = "id") + private String id; + + @NotNull + @Column(name = "eventId") + private String eventId; + + @NotNull + @Column(name = "name") + private String name; + + @Column(name = "emailId") + private String emailId; + + @Column(name = "alternateEmailId") + private String alternateEmailId; + + @Column(name = "phoneNo") + private String phoneNo; + + @Column(name = "alternatePhoneNo") + private String alternatePhoneNo; + + @NotNull + @Column(name = "message") + private String message; + + @NotNull + @Column(name = "hasAttachment") + private boolean hasAttachment = false; + + @NotNull + @Column(name = "status") + private String status; + + @NotNull + @Column(name = "cr_by") + private String crBy; + + @NotNull + @Column(name = "cr_dtimes") + private LocalDateTime crDtimes; + + @Column(name = "upd_by") + private String updBy; + + @Column(name = "upd_dtimes") + private LocalDateTime updDtimes; + + @NotNull + @Column(name = "is_deleted") + private Boolean isDeleted = false; + + @Column(name = "del_dtimes") + private LocalDateTime delDtimes; + +} \ No newline at end of file diff --git a/resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentGrievanceRepository.java b/resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentGrievanceRepository.java new file mode 100644 index 00000000000..307ac648fa6 --- /dev/null +++ b/resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentGrievanceRepository.java @@ -0,0 +1,15 @@ +package io.mosip.resident.repository; + +import io.mosip.resident.entity.ResidentGrievanceEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * The Interface ResidentGrievanceRepository. + * + * @author Kamesh Shekhar Prasad. + * @since 1.2.0.1 + */ +@Repository +public interface ResidentGrievanceRepository extends JpaRepository { +} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/GrievanceService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/GrievanceService.java new file mode 100644 index 00000000000..265a84e91b6 --- /dev/null +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/GrievanceService.java @@ -0,0 +1,16 @@ +package io.mosip.resident.service; + +import io.mosip.kernel.core.http.ResponseWrapper; +import io.mosip.resident.dto.GrievanceRequestDTO; +import io.mosip.resident.dto.MainRequestDTO; +import io.mosip.resident.exception.ApisResourceAccessException; + +import java.io.IOException; + +/** + * This class is used to create service class for getting Grievance Service API. + * @Author Kamesh Shekhar Prasad + */ +public interface GrievanceService { + ResponseWrapper getGrievanceTicket(MainRequestDTO grievanceRequestDTOMainRequestDTO) throws IOException, ApisResourceAccessException; +} 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 95e8bc5ce10..2e59388b158 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,30 +1,13 @@ package io.mosip.resident.service.impl; -import static io.mosip.resident.constant.RegistrationConstants.SUCCESS; -import static io.mosip.resident.constant.TemplateVariablesConstants.NAME; -import static io.mosip.resident.constant.TemplateVariablesConstants.VID; -import static io.mosip.resident.constant.TemplateVariablesConstants.VID_TYPE; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Service; - import com.fasterxml.jackson.databind.ObjectMapper; - import io.mosip.kernel.core.exception.BaseCheckedException; import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.core.util.CryptoUtil; 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.IdType; @@ -50,6 +33,7 @@ import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.DownloadCardService; import io.mosip.resident.service.IdAuthService; +import io.mosip.resident.service.ResidentCredentialService; import io.mosip.resident.service.ResidentVidService; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.EventEnum; @@ -58,9 +42,26 @@ import io.mosip.resident.util.TemplateUtil; import io.mosip.resident.util.Utilities; import io.mosip.resident.util.Utilitiy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Service; import reactor.util.function.Tuple2; import reactor.util.function.Tuples; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static io.mosip.resident.constant.EventStatusSuccess.CARD_DOWNLOADED; +import static io.mosip.resident.constant.RegistrationConstants.SUCCESS; +import static io.mosip.resident.constant.TemplateVariablesConstants.NAME; +import static io.mosip.resident.constant.TemplateVariablesConstants.VID; +import static io.mosip.resident.constant.TemplateVariablesConstants.VID_TYPE; + /** * @author Kamesh Shekhar Prasad * This class is used to create service class implementation of download card api. @@ -76,9 +77,8 @@ public class DownloadCardServiceImpl implements DownloadCardService { private static final String GENERATED_ON_TIMESTAMP = "genratedOnTimestamp"; private static final String TRANSACTION_LIMIT = "transactionLimit"; private static final String TRANSACTION_COUNT = "transactionCount"; - private static final String NEW = "NEW"; - private static final String FIRST_NAME = "firstName"; - private static final String DATE_OF_BIRTH = "dateOfBirth"; + private static final String CARD_FORMAT = "cardFormat"; + private static final Object VID_CARD = "vidCard"; @Autowired private ResidentController residentController; @@ -121,12 +121,16 @@ public class DownloadCardServiceImpl implements DownloadCardService { @Autowired private ResidentVidService vidService; + @Autowired + private ResidentCredentialService residentCredentialService; + private static final Logger logger = LoggerConfiguration.logConfig(DownloadCardServiceImpl.class); @Override public Tuple2 getDownloadCardPDF(MainRequestDTO downloadCardRequestDTOMainRequestDTO) { - String rid = null; - String eventId = ""; + String rid = ""; + String eventId = utilitiy.createEventId(); + byte[] pdfBytes = new byte[0]; try { if (idAuthService.validateOtp(downloadCardRequestDTOMainRequestDTO.getRequest().getTransactionId(), getUINForIndividualId(downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId()) @@ -135,13 +139,26 @@ public Tuple2 getDownloadCardPDF(MainRequestDTO getDownloadCardPDF(MainRequestDTO downloadCardRequestDTOMainRequestDTO, + String eventId, String status) throws ApisResourceAccessException, ResidentServiceCheckedException { + ResidentTransactionEntity residentTransactionEntity = utilitiy.createEntity(); + residentTransactionEntity.setEventId(eventId); + residentTransactionEntity.setRequestTypeCode(RequestType.GET_MY_ID.name()); + residentTransactionEntity.setRequestSummary(RequestType.GET_MY_ID.name()); + residentTransactionEntity.setStatusCode(status); + residentTransactionEntity.setStatusComment(String.valueOf(CARD_DOWNLOADED)); + residentTransactionEntity.setRefId(utilitiy.convertToMaskDataFormat( + downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId())); + residentTransactionEntity.setTokenId(identityService.getIDAToken( + downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId())); + residentTransactionEntity.setRequestTrnId(downloadCardRequestDTOMainRequestDTO.getRequest().getTransactionId()); + residentTransactionRepository.save(residentTransactionEntity); + } @Override @@ -349,6 +389,7 @@ private Map getVidDetails(String vid) throws ResidentServiceChec additionalAttributes.put(GENERATED_ON_TIMESTAMP, vidData.get(GENERATED_ON_TIMESTAMP)); additionalAttributes.put(TRANSACTION_LIMIT, vidData.get(TRANSACTION_LIMIT)); additionalAttributes.put(TRANSACTION_COUNT, vidData.get(TRANSACTION_COUNT)); + additionalAttributes.put(CARD_FORMAT, VID_CARD); if(name!=null){ additionalAttributes.put(NAME, name); } @@ -370,7 +411,7 @@ private String getFullName(String uin) throws IOException, ApisResourceAccessExc private String getUINForIndividualId(String individualId) { String idType = identityService.getIndividualIdType(individualId); - if(idType.equalsIgnoreCase(IdType.UIN.toString()) || idType.equalsIgnoreCase(IdType.VID.toString())){ + if(idType.equalsIgnoreCase(IdType.UIN.toString())){ return individualId; } else { try { diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/GrievanceServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/GrievanceServiceImpl.java new file mode 100644 index 00000000000..b96d6a356e7 --- /dev/null +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/GrievanceServiceImpl.java @@ -0,0 +1,114 @@ +package io.mosip.resident.service.impl; + +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.resident.config.LoggerConfiguration; +import io.mosip.resident.constant.ResidentConstants; +import io.mosip.resident.constant.ResidentErrorCode; +import io.mosip.resident.dto.GrievanceRequestDTO; +import io.mosip.resident.dto.MainRequestDTO; +import io.mosip.resident.entity.ResidentGrievanceEntity; +import io.mosip.resident.exception.ApisResourceAccessException; +import io.mosip.resident.exception.ResidentServiceCheckedException; +import io.mosip.resident.exception.ResidentServiceException; +import io.mosip.resident.repository.ResidentGrievanceRepository; +import io.mosip.resident.service.GrievanceService; +import io.mosip.resident.util.AuditUtil; +import io.mosip.resident.util.EventEnum; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.HashMap; +import java.util.UUID; + +import static io.mosip.resident.constant.RegistrationConstants.SUCCESS; + +/** + * @author Kamesh Shekhar Prasad + * This class is used to implement service class of grievance api. + */ +@Service +public class GrievanceServiceImpl implements GrievanceService { + + private static final String TICKET_ID = "ticketId"; + @Autowired + private IdentityServiceImpl identityService; + + @Autowired + private Environment environment; + + @Autowired + private AuditUtil auditUtil; + + @Autowired + private ResidentGrievanceRepository residentGrievanceRepository; + + private static final Logger logger = LoggerConfiguration.logConfig(GrievanceServiceImpl.class); + + @Override + public ResponseWrapper getGrievanceTicket(MainRequestDTO grievanceRequestDTOMainRequestDTO) throws IOException, ApisResourceAccessException { + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + responseWrapper.setId(grievanceRequestDTOMainRequestDTO.getId()); + responseWrapper.setVersion(grievanceRequestDTOMainRequestDTO.getVersion()); + responseWrapper.setResponsetime(DateUtils.getUTCCurrentDateTime()); + try { + grievanceRequestDTOMainRequestDTO = fillDefaultValueFromProfile(grievanceRequestDTOMainRequestDTO); + String ticketId = UUID.randomUUID().toString(); + insertDataInGrievanceTable(ticketId, grievanceRequestDTOMainRequestDTO); + HashMap response = new HashMap<>(); + response.put(TICKET_ID, ticketId); + responseWrapper.setResponse(response); + } + catch (ResidentServiceCheckedException e) { + auditUtil.setAuditRequestDto(EventEnum.GRIEVANCE_TICKET_REQUEST); + logger.error("Unable to get attributes- "+e); + throw new ResidentServiceException(ResidentErrorCode.GRIEVANCE_TICKET_GENERATION_FAILED, e); + } catch (IOException e) { + auditUtil.setAuditRequestDto(EventEnum.GRIEVANCE_TICKET_REQUEST); + logger.error("Unable to get attributes- "+e); + throw new IOException(ResidentErrorCode.GRIEVANCE_TICKET_GENERATION_FAILED.getErrorCode(), e); + } catch (ApisResourceAccessException e) { + throw new ApisResourceAccessException(ResidentErrorCode.GRIEVANCE_TICKET_GENERATION_FAILED.getErrorCode(), e); + } + return responseWrapper; + } + + private void insertDataInGrievanceTable(String ticketId, MainRequestDTO grievanceRequestDTOMainRequestDTO) { + ResidentGrievanceEntity residentGrievanceEntity = new ResidentGrievanceEntity(); + residentGrievanceEntity.setId(ticketId); + residentGrievanceEntity.setEventId(grievanceRequestDTOMainRequestDTO.getRequest().getEventId()); + residentGrievanceEntity.setName(grievanceRequestDTOMainRequestDTO.getRequest().getName()); + residentGrievanceEntity.setEmailId(grievanceRequestDTOMainRequestDTO.getRequest().getEmailId()); + residentGrievanceEntity.setAlternateEmailId(grievanceRequestDTOMainRequestDTO.getRequest().getAlternateEmailId()); + residentGrievanceEntity.setPhoneNo(grievanceRequestDTOMainRequestDTO.getRequest().getPhoneNo()); + residentGrievanceEntity.setAlternatePhoneNo(grievanceRequestDTOMainRequestDTO.getRequest().getAlternatePhoneNo()); + residentGrievanceEntity.setMessage(grievanceRequestDTOMainRequestDTO.getRequest().getMessage()); + residentGrievanceEntity.setStatus(SUCCESS); + residentGrievanceEntity.setCrBy(this.environment.getProperty(ResidentConstants.RESIDENT_APP_ID)); + residentGrievanceEntity.setCrDtimes(DateUtils.getUTCCurrentDateTime()); + residentGrievanceRepository.save(residentGrievanceEntity); + } + + private MainRequestDTO fillDefaultValueFromProfile(MainRequestDTO + grievanceRequestDTOMainRequestDTO) + throws ResidentServiceCheckedException, ApisResourceAccessException, IOException { + if (grievanceRequestDTOMainRequestDTO.getRequest().getName() == null) { + grievanceRequestDTOMainRequestDTO.getRequest().setName(identityService.getAvailableclaimValue( + this.environment.getProperty(ResidentConstants.NAME_FROM_PROFILE))); + } + if(grievanceRequestDTOMainRequestDTO.getRequest().getPhoneNo() == null){ + grievanceRequestDTOMainRequestDTO.getRequest().setPhoneNo(identityService.getAvailableclaimValue( + this.environment.getProperty(ResidentConstants.PHONE_FROM_PROFILE) + )); + } + if(grievanceRequestDTOMainRequestDTO.getRequest().getEmailId() == null){ + grievanceRequestDTOMainRequestDTO.getRequest().setEmailId(identityService.getAvailableclaimValue( + this.environment.getProperty(ResidentConstants.EMAIL_FROM_PROFILE))); + } + return grievanceRequestDTOMainRequestDTO; + } + +} 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 56c56cc5817..78f6b9d5bcb 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 @@ -174,7 +174,6 @@ public class ResidentServiceImpl implements ResidentService { private static final String DOCUMENT = "documents"; private static final String SERVER_PROFILE_SIGN_KEY = "PROD"; private static final String UIN = "uin"; - private static final String NAME = "mosip.resident.name.token.claim-name"; private static final String IMAGE = "mosip.resident.photo.token.claim-photo"; private static final Logger logger = LoggerConfiguration.logConfig(ResidentServiceImpl.class); private static final Integer DEFAULT_PAGE_START = 0; @@ -183,8 +182,6 @@ public class ResidentServiceImpl implements ResidentService { private static final String CLASSPATH = "classpath"; private static final String ENCODE_TYPE = "UTF-8"; private static String cardType = "UIN"; - private static final String EMAIL = "mosip.resident.email.token.claim-email"; - private static final String PHONE = "mosip.resident.phone.token.claim-phone"; @Autowired private UINCardDownloadService uinCardDownloadService; @@ -1954,7 +1951,7 @@ public ResponseWrapper getEventStatus(String eventId, St eventStatusMap.remove(TemplateVariablesConstants.TIMESTAMP); eventStatusMap.remove(TemplateVariablesConstants.TRACK_SERVICE_REQUEST_LINK); - String name = identityServiceImpl.getClaimFromIdToken(env.getProperty(NAME)); + String name = identityServiceImpl.getClaimFromIdToken(env.getProperty(ResidentConstants.NAME_FROM_PROFILE)); eventStatusMap.put(env.getProperty(ResidentConstants.APPLICANT_NAME_PROPERTY), name); if (serviceType.isPresent()) { @@ -2091,10 +2088,10 @@ public byte[] downLoadServiceHistory(ResponseWrapper getUserinfo(String Id) throws ApisResourceAccessException { - String name = identityServiceImpl.getAvailableclaimValue(env.getProperty(NAME)); + String name = identityServiceImpl.getAvailableclaimValue(env.getProperty(ResidentConstants.NAME_FROM_PROFILE)); String photo = identityServiceImpl.getAvailableclaimValue(env.getProperty(IMAGE)); - String email = identityServiceImpl.getAvailableclaimValue(env.getProperty(EMAIL)); - String phone = identityServiceImpl.getAvailableclaimValue(env.getProperty(PHONE)); + String email = identityServiceImpl.getAvailableclaimValue(env.getProperty(ResidentConstants.EMAIL_FROM_PROFILE)); + String phone = identityServiceImpl.getAvailableclaimValue(env.getProperty(ResidentConstants.PHONE_FROM_PROFILE)); ResponseWrapper responseWrapper = new ResponseWrapper(); UserInfoDto user = new UserInfoDto(); Map data = new HashMap<>(); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java b/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java index fb6c7790e08..18ebc54a77a 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java @@ -689,6 +689,16 @@ public enum EventEnum { "download registration center success", "download registration center success based on language code,longitude,latitude and distance", "RES-SER", "Resident service", "NO_ID", "NO_ID_TYPE", RegistrationConstants.APPLICATION_ID, + RegistrationConstants.APPLICATION_NAME), + GRIEVANCE_TICKET_REQUEST("RES-SER-273", RegistrationConstants.SYSTEM, + "Grievance ticket request", + "Grievance ticket request", "RES-SER", + "Resident service", "NO_ID", "NO_ID_TYPE", RegistrationConstants.APPLICATION_ID, + RegistrationConstants.APPLICATION_NAME), + GRIEVANCE_TICKET_REQUEST_SUCCESS("RES-SER-273", RegistrationConstants.SYSTEM, + "Grievance ticket request success", + "Grievance ticket request success", "RES-SER", + "Resident service", "NO_ID", "NO_ID_TYPE", RegistrationConstants.APPLICATION_ID, RegistrationConstants.APPLICATION_NAME) ; 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 42660123e98..89a1cb75080 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 @@ -13,7 +13,9 @@ import io.mosip.resident.constant.IdType; import io.mosip.resident.constant.RequestIdType; import io.mosip.resident.constant.ResidentConstants; +import io.mosip.resident.constant.ResidentErrorCode; import io.mosip.resident.constant.ServiceType; +import io.mosip.resident.constant.TemplateVariablesConstants; import io.mosip.resident.dto.AidStatusRequestDTO; import io.mosip.resident.dto.AuthHistoryRequestDTO; import io.mosip.resident.dto.AuthLockOrUnLockRequestDto; @@ -25,6 +27,7 @@ import io.mosip.resident.dto.DownloadCardRequestDTO; import io.mosip.resident.dto.DownloadPersonalizedCardDto; import io.mosip.resident.dto.EuinRequestDTO; +import io.mosip.resident.dto.GrievanceRequestDTO; import io.mosip.resident.dto.IVidRequestDto; import io.mosip.resident.dto.MainRequestDTO; import io.mosip.resident.dto.OtpRequestDTOV3; @@ -35,8 +38,12 @@ import io.mosip.resident.dto.SortType; import io.mosip.resident.dto.VidRequestDto; import io.mosip.resident.dto.VidRevokeRequestDTO; +import io.mosip.resident.entity.ResidentTransactionEntity; +import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.InvalidInputException; import io.mosip.resident.exception.ResidentServiceCheckedException; +import io.mosip.resident.exception.ResidentServiceException; +import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.impl.IdentityServiceImpl; import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; @@ -58,12 +65,17 @@ import java.util.Objects; import java.util.Optional; +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; @Component public class RequestValidator { + private static final int EVENT_ID_LENGTH = 16; + private static final String VALIDATE_EVENT_ID = "Validating Event Id."; @Autowired private UinValidator uinValidator; @@ -79,6 +91,9 @@ public class RequestValidator { @Autowired private IdentityServiceImpl identityService; + @Autowired + private ResidentTransactionRepository residentTransactionRepository; + private String euinId; private String reprintId; @@ -929,15 +944,26 @@ private void validateServiceType(String serviceType, String requestServiceHistor } } - public void validateIndividualId(String eventId) { - if (eventId==null ||StringUtils.isEmpty(eventId)) { - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "eventId", "Request service history API")); - throw new InvalidInputException("eventId"); + public void validateEventId(String eventId) { + validateMissingInputParameter(eventId, TemplateVariablesConstants.EVENT_ID); + if (isNumeric(eventId) || eventId.length()!=EVENT_ID_LENGTH) { + audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, + TemplateVariablesConstants.EVENT_ID, VALIDATE_EVENT_ID)); + throw new InvalidInputException(TemplateVariablesConstants.EVENT_ID); + } + } + + private void validateMissingInputParameter(String variableValue, String variableName) { + if (variableValue==null || StringUtils.isEmpty(variableValue)) { + audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, + variableName, VALIDATE_EVENT_ID)); + throw new ResidentServiceException(ResidentErrorCode.MISSING_INPUT_PARAMETER, + ResidentErrorCode.MISSING_INPUT_PARAMETER.getErrorMessage()+variableName); } } public void validateEventIdLanguageCode(String eventId, String languageCode) { - validateIndividualId(eventId); + validateEventId(eventId); validateLanguageCode(languageCode); } @@ -1002,7 +1028,7 @@ public void validateTransactionId(String transactionID) { public void validateUpdateDataRequest(MainRequestDTO userIdOtpRequest) { String inputRequestId = userIdOtpRequest.getId(); String requestIdStoredInProperty = this.environment.getProperty(ResidentConstants.RESIDENT_CONTACT_DETAILS_UPDATE_ID); - validateRequestId(inputRequestId, requestIdStoredInProperty); + validateRequestType(inputRequestId, requestIdStoredInProperty, ID); validateDate(userIdOtpRequest.getRequesttime()); validateUserIdAndTransactionId(userIdOtpRequest.getRequest().getUserId(), userIdOtpRequest.getRequest().getTransactionID()); validateOTP(userIdOtpRequest.getRequest().getOtp()); @@ -1020,15 +1046,15 @@ public void validateOTP(String otp) { } } - public void validateRequestId(String inputRequestId, String requestIdStoredInProperty) { - if(inputRequestId==null){ + public void validateRequestType(String inputRequestType, String requestTypeStoredInProperty, String type) { + if(inputRequestType==null){ audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, - "request id", "Id must not be null")); - throw new InvalidInputException("Id"); - } else if(!inputRequestId.equalsIgnoreCase(requestIdStoredInProperty)){ + "request "+type, type+" must not be null")); + throw new InvalidInputException(type); + } else if(!inputRequestType.equalsIgnoreCase(requestTypeStoredInProperty)){ audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, - "request id", "Id is invalid")); - throw new InvalidInputException("Id"); + "request "+type, type+" is invalid")); + throw new InvalidInputException(type); } } @@ -1041,7 +1067,7 @@ public void validateDate(Date requesttime) { } public void validateDownloadCardRequest(MainRequestDTO downloadCardRequestDTOMainRequestDTO) { - validateRequestId(downloadCardRequestDTOMainRequestDTO.getId(), this.environment.getProperty(ResidentConstants.DOWNLOAD_UIN_CARD_ID)); + validateRequestType(downloadCardRequestDTOMainRequestDTO.getId(), this.environment.getProperty(ResidentConstants.DOWNLOAD_UIN_CARD_ID), ID); validateDate(downloadCardRequestDTOMainRequestDTO.getRequesttime()); validateTransactionId(downloadCardRequestDTOMainRequestDTO.getRequest().getTransactionId()); validateOTP(downloadCardRequestDTOMainRequestDTO.getRequest().getOtp()); @@ -1057,7 +1083,8 @@ private void validateIndividualIdV2(String individualId) { } public void validateDownloadPersonalizedCard(MainRequestDTO downloadPersonalizedCardMainRequestDTO) { - validateRequestId(downloadPersonalizedCardMainRequestDTO.getId(), this.environment.getProperty(ResidentConstants.MOSIP_RESIDENT_DOWNLOAD_PERSONALIZED_CARD)); + validateRequestType(downloadPersonalizedCardMainRequestDTO.getId(), + this.environment.getProperty(ResidentConstants.MOSIP_RESIDENT_DOWNLOAD_PERSONALIZED_CARD), ID); validateDate(downloadPersonalizedCardMainRequestDTO.getRequesttime()); validateString(downloadPersonalizedCardMainRequestDTO.getRequest().getHtml(), "html"); validateEncodedString(downloadPersonalizedCardMainRequestDTO.getRequest().getHtml()); @@ -1103,4 +1130,55 @@ public boolean validateRequestNewApi(RequestWrapper request, RequestIdType re } return true; } + + public void validateGrievanceRequestDto(MainRequestDTO grievanceRequestDTOMainRequestDTO) throws ResidentServiceCheckedException, ApisResourceAccessException { + validateRequestType(grievanceRequestDTOMainRequestDTO.getId(), + this.environment.getProperty(ResidentConstants.GRIEVANCE_REQUEST_ID), ID); + validateRequestType(grievanceRequestDTOMainRequestDTO.getVersion(), + this.environment.getProperty(ResidentConstants.GRIEVANCE_REQUEST_VERSION), VERSION); + validateDate(grievanceRequestDTOMainRequestDTO.getRequesttime()); + validateEventId(grievanceRequestDTOMainRequestDTO.getRequest().getEventId()); + validateEventIdBelongToSameSession(grievanceRequestDTOMainRequestDTO.getRequest().getEventId()); + validateEmailId(grievanceRequestDTOMainRequestDTO.getRequest().getEmailId()); + validateEmailId(grievanceRequestDTOMainRequestDTO.getRequest().getAlternateEmailId()); + validatePhoneNumber(grievanceRequestDTOMainRequestDTO.getRequest().getPhoneNo()); + validatePhoneNumber(grievanceRequestDTOMainRequestDTO.getRequest().getAlternatePhoneNo()); + validateMessage(grievanceRequestDTOMainRequestDTO.getRequest().getMessage()); + } + + private void validateMessage(String message) { + validateMissingInputParameter(message, MESSAGE_CODE); + if(message.length()>Integer.parseInt(Objects.requireNonNull(this.environment.getProperty( + ResidentConstants.MESSAGE_CODE_MAXIMUM_LENGTH)))){ + throw new InvalidInputException(MESSAGE_CODE); + } + } + + private void validatePhoneNumber(String phoneNo) { + if(phoneNo!=null){ + if(!phoneValidator(phoneNo)){ + throw new InvalidInputException(PHONE_CHANNEL); + } + } + } + + private void validateEmailId(String emailId) { + if(emailId!=null){ + if(!emailValidator(emailId)){ + throw new InvalidInputException(EMAIL_CHANNEL); + } + } + } + + private void validateEventIdBelongToSameSession(String eventId) throws ResidentServiceCheckedException, ApisResourceAccessException { + Optional residentTransactionEntity = residentTransactionRepository.findById(eventId); + if(residentTransactionEntity.isPresent()){ + String tokenId = residentTransactionEntity.get().getTokenId(); + String sessionToken = identityService.getResidentIdaToken(); + if(!tokenId.equals(sessionToken)){ + throw new ResidentServiceException(ResidentErrorCode.EID_NOT_BELONG_TO_SESSION, + ResidentErrorCode.EID_NOT_BELONG_TO_SESSION.getErrorMessage()); + } + } + } } 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 7c45a65cfa6..e8f7aee8cc6 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 @@ -49,6 +49,7 @@ import java.util.Map; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; /** @@ -164,7 +165,7 @@ public void testDownloadCardServiceTest() { public void testGetDownloadCardPdfVID(){ Mockito.when(identityService.getIndividualIdType(Mockito.anyString())).thenReturn("VID"); Tuple2 actualResult = downloadCardService.getDownloadCardPDF(downloadCardRequestDTOMainRequestDTO); - assertEquals(pdfbytes, actualResult.getT1()); + assertNotNull(actualResult); } @Test diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestValidatorTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestValidatorTest.java index 5459957332f..6de6768beec 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestValidatorTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestValidatorTest.java @@ -14,6 +14,7 @@ import io.mosip.resident.constant.ResidentErrorCode; import io.mosip.resident.dto.*; import io.mosip.resident.exception.InvalidInputException; +import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.service.ResidentService; import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; @@ -1501,16 +1502,16 @@ public void testValidateServiceHistoryRequestServiceHistorySuccess() throws Exce } - @Test(expected = InvalidInputException.class) + @Test(expected = ResidentServiceException.class) public void testValidateIndividualId() throws Exception{ String individualId = ""; - requestValidator.validateIndividualId(individualId); + requestValidator.validateEventId(individualId); } @Test public void testValidateIndividualIdSuccess() throws Exception { - String individualId = "123456789"; - requestValidator.validateIndividualId(individualId); + String individualId = "1234567897777777"; + requestValidator.validateEventId(individualId); } @Test @@ -1984,10 +1985,10 @@ public void testValidateOnlyInvalidLanguageCodeSuccess(){ @Test public void testValidateEventIdLanguageCodeSuccess(){ - requestValidator.validateEventIdLanguageCode("3434343434","ara"); + requestValidator.validateEventIdLanguageCode("3434343434777777","ara"); } - @Test(expected = InvalidInputException.class) + @Test(expected = ResidentServiceException.class) public void testValidateEmptyEventIdLanguageCodeSuccess(){ requestValidator.validateEventIdLanguageCode("","ara"); } @@ -2073,9 +2074,9 @@ public void testValidateRequestNewApiSuccess() throws Exception{ assertEquals(true,requestValidator.validateRequestNewApi(request, requestIdType)); } - @Test(expected = InvalidInputException.class) + @Test(expected = ResidentServiceException.class) public void testValidateNullIndividualId() throws Exception{ - requestValidator.validateIndividualId(null); + requestValidator.validateEventId(null); } @Test(expected = InvalidInputException.class) From 025b09b280f88cbfa204707ce1c48616d14f6661 Mon Sep 17 00:00:00 2001 From: Neha2365 <110969715+Neha2365@users.noreply.github.com> Date: Fri, 16 Dec 2022 16:28:02 +0530 Subject: [PATCH 05/11] MOSIP-25307 Created API to get DocumentType from masterdata (#617) * MOSIP-25307 Created API to get DocumentType from masterdata * JUNIT added for document API Co-authored-by: Neha Farheen --- .../io/mosip/resident/constant/ApiName.java | 3 +- .../controller/ProxyMasterdataController.java | 27 ++++++++++++++ .../service/ProxyMasterdataService.java | 2 + .../impl/ProxyMasterdataServiceImpl.java | 24 ++++++++++++ .../io/mosip/resident/util/EventEnum.java | 12 +++++- .../ProxyMasterdataControllerTest.java | 7 ++++ .../service/ProxyMasterdataServiceTest.java | 37 +++++++++++++++++++ 7 files changed, 110 insertions(+), 2 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/ApiName.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/ApiName.java index 345051cfbcb..cce6e68f28c 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/ApiName.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/ApiName.java @@ -81,6 +81,7 @@ public enum ApiName { GENDER_TYPE_BY_LANGCODE, GET_RID_BY_INDIVIDUAL_ID, PDFSIGN, - PARTNER_DETAILS_NEW_URL; + PARTNER_DETAILS_NEW_URL, + DOCUMENT_TYPE_BY_DOCUMENT_CATEGORY_AND_LANG_CODE; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyMasterdataController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyMasterdataController.java index ad2649877be..5761343c7dd 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyMasterdataController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyMasterdataController.java @@ -393,4 +393,31 @@ public ResponseWrapper getGenderTypesByLangCode(@PathVariable("langcode") Str logger.debug("ProxyMasterdataController::getGenderTypesByLangCode()::exit"); return responseWrapper; } + + /** + * Get document types by document category code & language code. + * + * @param langCode + * @param documentcategorycode + * @return ResponseWrapper object + * @throws ResidentServiceCheckedException + */ + @ResponseFilter + @GetMapping("/proxy/masterdata/documenttypes/{documentcategorycode}/{langcode}") + @Operation(summary = "getDocumentTypesByDocumentCategoryLangCode", description = "getDocumentTypesByDocumentCategoryLangCode", tags = { + "proxy-masterdata-controller" }) + @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(hidden = true))), + @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 ResponseWrapper getDocumentTypesByDocumentCategoryAndLangCode(@PathVariable("documentcategorycode") String documentcategorycode,@PathVariable("langcode") String langCode) + throws ResidentServiceCheckedException { + logger.debug("ProxyMasterdataController::getDocumentTypesByDocumentCategoryLangCode::entry"); + auditUtil.setAuditRequestDto(EventEnum.GET_DOCUMENT_TYPES); + ResponseWrapper responseWrapper = proxyMasterdataService.getDocumentTypesByDocumentCategoryAndLangCode(documentcategorycode,langCode); + auditUtil.setAuditRequestDto(EventEnum.GET_DOCUMENT_TYPES_SUCCESS); + logger.debug("ProxyMasterdataController::getDocumentTypesByDocumentCategoryLangCode::exit"); + return responseWrapper; + } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/ProxyMasterdataService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/ProxyMasterdataService.java index 93310221b08..cb328981e71 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/ProxyMasterdataService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/ProxyMasterdataService.java @@ -153,5 +153,7 @@ public ResponseWrapper getAllTemplateBylangCodeAndTemplateTypeCode(String lan * @throws ResidentServiceCheckedException */ public ResponseWrapper getGenderTypesByLangCode(String langCode) throws ResidentServiceCheckedException; + + public ResponseWrapper getDocumentTypesByDocumentCategoryAndLangCode(String documentcategorycode, String langCode) throws ResidentServiceCheckedException; } \ No newline at end of file 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 8c01d1a1f1d..7cdddf58bf0 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 @@ -413,5 +413,29 @@ public ResponseWrapper getGenderTypesByLangCode(String langCode) throws Resid logger.debug("ProxyMasterdataServiceImpl::getGenderTypesByLangCode()::exit"); return responseWrapper; } + + @Override + public ResponseWrapper getDocumentTypesByDocumentCategoryAndLangCode(String documentcategorycode, String langCode) throws ResidentServiceCheckedException { + logger.debug("ProxyMasterdataServiceImpl::getDocumentTypesByDocumentCategoryAndLangCode()::entry"); + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + Map pathsegments = new HashMap(); + pathsegments.put("documentcategorycode", documentcategorycode); + pathsegments.put("langcode", langCode); + try { + responseWrapper=residentServiceRestClient.getApi(ApiName.DOCUMENT_TYPE_BY_DOCUMENT_CATEGORY_AND_LANG_CODE, pathsegments, ResponseWrapper.class); + if (responseWrapper.getErrors() != null && !responseWrapper.getErrors().isEmpty()) { + logger.debug(responseWrapper.getErrors().get(0).toString()); + throw new ResidentServiceCheckedException(ResidentErrorCode.BAD_REQUEST.getErrorCode(), + responseWrapper.getErrors().get(0).getMessage()); + } + } catch (ApisResourceAccessException e) { + auditUtil.setAuditRequestDto(EventEnum.GET_DOCUMENT_TYPES_EXCEPTION); + logger.error("Error occured in accessing document types %s", e.getMessage()); + throw new ResidentServiceCheckedException(ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorCode(), + ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorMessage(), e); + } + logger.debug("ProxyMasterdataServiceImpl::getDocumentTypesByDocumentCategoryAndLangCode()::exit"); + return responseWrapper; + } } \ No newline at end of file diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java b/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java index 18ebc54a77a..413c4012dd7 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java @@ -690,6 +690,7 @@ public enum EventEnum { "download registration center success based on language code,longitude,latitude and distance", "RES-SER", "Resident service", "NO_ID", "NO_ID_TYPE", RegistrationConstants.APPLICATION_ID, RegistrationConstants.APPLICATION_NAME), + GRIEVANCE_TICKET_REQUEST("RES-SER-273", RegistrationConstants.SYSTEM, "Grievance ticket request", "Grievance ticket request", "RES-SER", @@ -699,7 +700,16 @@ public enum EventEnum { "Grievance ticket request success", "Grievance ticket request success", "RES-SER", "Resident service", "NO_ID", "NO_ID_TYPE", RegistrationConstants.APPLICATION_ID, - RegistrationConstants.APPLICATION_NAME) + RegistrationConstants.APPLICATION_NAME), + GET_DOCUMENT_TYPES("RES-SER-274", RegistrationConstants.SYSTEM, "get document types", + "get document types by documentCode and langCode", "RES-SER", "Residence service", "NO_ID", "NO_ID_TYPE", + RegistrationConstants.APPLICATIONID, RegistrationConstants.APPLICATIONNAME), + GET_DOCUMENT_TYPES_SUCCESS("RES-SER-275", RegistrationConstants.SYSTEM, "get document types success", + "get document types by documentCode and langCode is succeeded", "RES-SER", "Residence service", "NO_ID", + "NO_ID_TYPE", RegistrationConstants.APPLICATIONID, RegistrationConstants.APPLICATIONNAME), + GET_DOCUMENT_TYPES_EXCEPTION("RES-SER-276", RegistrationConstants.SYSTEM, "get document types failure", + "get document types by documentCode and langCode is failed", "RES-SER", "Residence service", "NO_ID", + "NO_ID_TYPE", RegistrationConstants.APPLICATIONID, RegistrationConstants.APPLICATIONNAME) ; private final String eventId; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyMasterdataControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyMasterdataControllerTest.java index 880af79706f..a755d02ab23 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyMasterdataControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyMasterdataControllerTest.java @@ -198,5 +198,12 @@ public void testGetGenderTypesByLangCode() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/auth-proxy/masterdata/gendertypes/langcode")) .andExpect(status().isOk()); } + + @Test + public void testGetDocumentTypesByDocumentCategoryCodeAndLangCode() throws Exception { + Mockito.when(proxyMasterdataService.getDocumentTypesByDocumentCategoryAndLangCode(Mockito.anyString(),Mockito.anyString())).thenReturn(responseWrapper); + mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/documenttypes/documentcategorycode/langcode")) + .andExpect(status().isOk()); + } } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyMasterdataServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyMasterdataServiceTest.java index 464078d26c8..7e1b987758c 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyMasterdataServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyMasterdataServiceTest.java @@ -573,5 +573,42 @@ public void testGetGenderTypesByLangCodeWithApisResourceAccessException() .thenThrow(new ApisResourceAccessException()); proxyMasterdataService.getGenderTypesByLangCode("eng"); } + + @Test + public void testGetDocumentTypesByDocumentCategoryAndLangCode() throws ApisResourceAccessException, ResidentServiceCheckedException { + when(residentServiceRestClient.getApi((ApiName) any(), any(), any())).thenReturn(responseWrapper); + ResponseWrapper result = proxyMasterdataService.getDocumentTypesByDocumentCategoryAndLangCode("DOC","eng"); + assertNotNull(result); + } + @Test(expected = ResidentServiceCheckedException.class) + public void testGetDocumentTypesByDocumentCategoryAndLangCodeIf() throws ApisResourceAccessException, ResidentServiceCheckedException { + when(residentServiceRestClient.getApi((ApiName) any(), any(), any())).thenReturn(responseWrapper); + ServiceError error = new ServiceError(); + error.setErrorCode("101"); + error.setMessage("errors"); + + List errorList = new ArrayList(); + errorList.add(error); + + responseWrapper.setErrors(errorList); + proxyMasterdataService.getDocumentTypesByDocumentCategoryAndLangCode("DOC","xyz"); + } + + @Test + public void testGetDocumentTypesByDocumentCategoryAndLangCodeElse() throws ApisResourceAccessException, ResidentServiceCheckedException { + when(residentServiceRestClient.getApi((ApiName) any(), any(), any())).thenReturn(responseWrapper); + responseWrapper.setErrors(null); + ResponseWrapper result = proxyMasterdataService.getDocumentTypesByDocumentCategoryAndLangCode("DOC","eng"); + assertNotNull(result); + } + + @Test(expected = ResidentServiceCheckedException.class) + public void testGetDocumentTypesByDocumentCategoryAndLangCodeWithApisResourceAccessException() + throws ApisResourceAccessException, ResidentServiceCheckedException { + when(residentServiceRestClient.getApi((ApiName) any(), any(), any())) + .thenThrow(new ApisResourceAccessException()); + proxyMasterdataService.getDocumentTypesByDocumentCategoryAndLangCode("DOC","eng"); + } + } From 3c1f9b22cb66fb398616b0d494c4f0c596768cf4 Mon Sep 17 00:00:00 2001 From: kameshsr <47484458+kameshsr@users.noreply.github.com> Date: Fri, 16 Dec 2022 16:53:08 +0530 Subject: [PATCH 06/11] MOSIP-24784 Fixed download card api. (#619) * Fixed service history issue. * MOSIP-24784 Fixed download card api. --- .../main/java/io/mosip/resident/constant/RequestType.java | 7 +++---- .../main/java/io/mosip/resident/constant/ServiceType.java | 2 +- .../resident/repository/ResidentTransactionRepository.java | 2 +- .../resident/service/impl/DownloadCardServiceImpl.java | 2 +- .../resident/test/service/DownloadCardServiceTest.java | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/RequestType.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/RequestType.java index df8773280b8..2c90319543c 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/RequestType.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/RequestType.java @@ -1,14 +1,13 @@ package io.mosip.resident.constant; +import io.mosip.resident.dto.NotificationTemplateVariableDTO; +import io.mosip.resident.util.TemplateUtil; + import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.function.BiFunction; -import io.mosip.resident.dto.NotificationTemplateVariableDTO; -import io.mosip.resident.util.TemplateUtil; - /** * The Enum RequestType. * 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 da8ad2e43df..30d2a8d324b 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 @@ -12,7 +12,7 @@ public enum ServiceType { AUTHENTICATION_REQUEST(List.of(RequestType.AUTHENTICATION_REQUEST, RequestType.SEND_OTP, RequestType.VALIDATE_OTP)), SERVICE_REQUEST(List.of(RequestType.DOWNLOAD_PERSONALIZED_CARD, RequestType.ORDER_PHYSICAL_CARD, - RequestType.GET_MY_ID, RequestType.BOOK_AN_APPOINTMENT)), + RequestType.GET_MY_ID, RequestType.BOOK_AN_APPOINTMENT, RequestType.VID_CARD_DOWNLOAD)), DATA_UPDATE_REQUEST(List.of(RequestType.UPDATE_MY_UIN)), ID_MANAGEMENT_REQUEST(List.of(RequestType.GENERATE_VID, RequestType.REVOKE_VID, RequestType.VALIDATE_OTP, RequestType.AUTH_TYPE_LOCK_UNLOCK)), diff --git a/resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentTransactionRepository.java b/resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentTransactionRepository.java index 4dce5816cb2..e7b1f639d5d 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentTransactionRepository.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentTransactionRepository.java @@ -28,7 +28,7 @@ public interface ResidentTransactionRepository extends JpaRepository getDownloadCardPDF(MainRequestDTO(); From 5b269e39c12b5a5a1204b49578820b1e6d4e857e Mon Sep 17 00:00:00 2001 From: RitikJain4108 <99730411+RitikJain4108@users.noreply.github.com> Date: Fri, 16 Dec 2022 18:36:19 +0530 Subject: [PATCH 07/11] Mosip 24879 add event id in the response of the below stories (#618) * added error for invalid user * added status in 2 apis * changed response of auth-lock-unlock api * updated response of validate otp * added eventid and status in response * added eventId in response header for download eventid api * fixed service history pdf file name * added eventid in response of download card api * convert eventId to constant * added eventId for error scenarios * fixed reliability bug * fixed response of share credential API * fixed test failure * updated response for auth lock unlock API * covered code for one method * updated response of request vid card * updated response of validate otp API * created contant for NA Co-authored-by: Ritik Jain --- .../resident/constant/ResidentConstants.java | 1 + .../controller/DownloadCardController.java | 8 +- .../resident/controller/IdAuthController.java | 8 +- .../resident/dto/ValidateOtpResponseDto.java | 1 - .../dto/VidDownloadCardResponseDto.java | 1 - .../exception/ApiExceptionHandler.java | 19 ++- .../ApisResourceAccessException.java | 20 ++- .../OtpValidationFailedException.java | 22 +++- .../ResidentServiceCheckedException.java | 21 ++- .../exception/ResidentServiceException.java | 2 +- .../resident/service/DownloadCardService.java | 2 +- .../service/impl/DownloadCardServiceImpl.java | 122 ++++++++++-------- .../service/impl/IdAuthServiceImpl.java | 12 +- .../impl/ResidentCredentialServiceImpl.java | 2 +- .../service/impl/ResidentServiceImpl.java | 2 +- .../DownloadCardControllerTest.java | 9 +- .../test/service/DownloadCardServiceTest.java | 64 +++------ 17 files changed, 185 insertions(+), 131 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 79b2ec2e736..b795d1085ec 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 @@ -140,6 +140,7 @@ private ResidentConstants() { public static final String VID_CARD_NAMING_CONVENTION_PROPERTY = "mosip.resident.vid.card.name.convention"; public static final String SUCCESS = "Success"; public static final String FAILED = "Failed"; + public static final String NOT_AVAILABLE = "NA"; public static final String REGISTRATION_CENTRE_TEMPLATE_PROPERTY = "resident.template.registration.centers.list"; public static final String SUPPORTING_DOCS_TEMPLATE_PROPERTY = "resident.template.support-docs-list"; public static final String FROM_DATE_TIME = "fromDateTime"; 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 e70743c3bbf..ba81ca78b4f 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 @@ -102,9 +102,11 @@ public ResponseEntity downloadPersonalizedCard(@Validated @RequestBody M } @GetMapping("/request-card/vid/{VID}") - public ResponseWrapper requestVidCard(@PathVariable("VID") String vid) throws BaseCheckedException { + public ResponseEntity requestVidCard(@PathVariable("VID") String vid) throws BaseCheckedException { requestValidator.validateDownloadCardVid(vid); - ResponseWrapper downloadCardResponseDtoResponseWrapper = downloadCardService.getVidCardEventId(vid); - return downloadCardResponseDtoResponseWrapper; + Tuple2, String> tupleResponse = downloadCardService.getVidCardEventId(vid); + return ResponseEntity.ok() + .header(ResidentConstants.EVENT_ID, tupleResponse.getT2()) + .body(tupleResponse.getT1()); } } 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 75b1cefd6c3..dd62431a6b7 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 @@ -1,6 +1,7 @@ package io.mosip.resident.controller; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @@ -58,7 +59,7 @@ public class IdAuthController { @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 ResponseWrapper validateOtp(@RequestBody RequestWrapper requestWrapper) + public ResponseEntity validateOtp(@RequestBody RequestWrapper requestWrapper) throws OtpValidationFailedException { logger.debug("IdAuthController::validateOtp()::entry"); auditUtil.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.VALIDATE_OTP, requestWrapper.getRequest().getTransactionId(), @@ -71,11 +72,12 @@ public ResponseWrapper validateOtp(@RequestBody RequestWrappe ValidateOtpResponseDto validateOtpResponseDto = new ValidateOtpResponseDto(); validateOtpResponseDto.setAuthStatus(tupleResponse.getT1()); validateOtpResponseDto.setTransactionId(requestWrapper.getRequest().getTransactionId()); - validateOtpResponseDto.setEventId(tupleResponse.getT2()); validateOtpResponseDto.setStatus(ResidentConstants.SUCCESS); responseWrapper.setResponse(validateOtpResponseDto); logger.debug("IdAuthController::validateOtp()::exit"); - return responseWrapper; + return ResponseEntity.ok() + .header(ResidentConstants.EVENT_ID, tupleResponse.getT2()) + .body(responseWrapper); } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/ValidateOtpResponseDto.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/ValidateOtpResponseDto.java index e1df37b6ea2..6b3788a3e2a 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/dto/ValidateOtpResponseDto.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/dto/ValidateOtpResponseDto.java @@ -12,7 +12,6 @@ @EqualsAndHashCode(callSuper = true) public class ValidateOtpResponseDto extends IdAuthResponseDto { - private String eventId; private String status; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/VidDownloadCardResponseDto.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/VidDownloadCardResponseDto.java index 8345b07e5bf..d4f8b005a0f 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/dto/VidDownloadCardResponseDto.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/dto/VidDownloadCardResponseDto.java @@ -9,6 +9,5 @@ @Data public class VidDownloadCardResponseDto { - String eventId; String status; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/exception/ApiExceptionHandler.java b/resident/resident-service/src/main/java/io/mosip/resident/exception/ApiExceptionHandler.java index 43cee75ef6b..20d32238406 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/exception/ApiExceptionHandler.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/exception/ApiExceptionHandler.java @@ -122,6 +122,13 @@ private ResponseEntity> getCheckedErrorEntity(Http ServiceError error = new ServiceError(e.getErrorCode(), e.getErrorText()); ResponseWrapper errorResponse = setErrors(httpServletRequest); errorResponse.getErrors().add(error); + if (e instanceof ObjectWithMetadata && ((ObjectWithMetadata) e).getMetadata() != null + && ((ObjectWithMetadata) e).getMetadata().containsKey(ResidentConstants.EVENT_ID)) { + MultiValueMap headers = new HttpHeaders(); + headers.add(ResidentConstants.EVENT_ID, + (String) ((ObjectWithMetadata) e).getMetadata().get(ResidentConstants.EVENT_ID)); + return new ResponseEntity<>(errorResponse, headers, httpStatus); + } return new ResponseEntity<>(errorResponse, httpStatus); } @@ -256,12 +263,9 @@ public ResponseEntity> getRidStackTraceHandler( @ExceptionHandler(ResidentServiceCheckedException.class) public ResponseEntity> getResidentServiceStackTraceHandler( final HttpServletRequest httpServletRequest, final ResidentServiceCheckedException e) throws IOException { - ResponseWrapper errorResponse = setErrors(httpServletRequest); - ServiceError error = new ServiceError(e.getErrorCode(), e.getErrorText()); - errorResponse.getErrors().add(error); ExceptionUtils.logRootCause(e); logStackTrace(e); - return new ResponseEntity<>(errorResponse, HttpStatus.OK); + return getCheckedErrorEntity(httpServletRequest, e, HttpStatus.OK); } @ExceptionHandler(ApisResourceAccessException.class) @@ -276,6 +280,13 @@ public ResponseEntity> getApiResourceStackTraceHan errorResponse.getErrors().add(error); ExceptionUtils.logRootCause(e); logStackTrace(e); + if (e instanceof ObjectWithMetadata && ((ObjectWithMetadata) e).getMetadata() != null + && ((ObjectWithMetadata) e).getMetadata().containsKey(ResidentConstants.EVENT_ID)) { + MultiValueMap headers = new HttpHeaders(); + headers.add(ResidentConstants.EVENT_ID, + (String) ((ObjectWithMetadata) e).getMetadata().get(ResidentConstants.EVENT_ID)); + return new ResponseEntity<>(errorResponse, headers, HttpStatus.OK); + } return new ResponseEntity<>(errorResponse, HttpStatus.OK); } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/exception/ApisResourceAccessException.java b/resident/resident-service/src/main/java/io/mosip/resident/exception/ApisResourceAccessException.java index 6765ff3cf55..3b89cd48af2 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/exception/ApisResourceAccessException.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/exception/ApisResourceAccessException.java @@ -1,16 +1,21 @@ package io.mosip.resident.exception; +import java.util.Map; + import io.mosip.kernel.core.exception.BaseCheckedException; import io.mosip.resident.constant.ResidentErrorCode; +import io.mosip.resident.util.ObjectWithMetadata; /** * The Class ApisResourceAccessException. * */ -public class ApisResourceAccessException extends BaseCheckedException { +public class ApisResourceAccessException extends BaseCheckedException implements ObjectWithMetadata { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; + + private Map metadata; /** * Instantiates a new apis resource access exception. @@ -37,4 +42,17 @@ public ApisResourceAccessException(String message) { public ApisResourceAccessException(String message, Throwable cause) { super(ResidentErrorCode.API_RESOURCE_UNAVAILABLE.getErrorCode(), message, cause); } + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + public ApisResourceAccessException(String err, Throwable rootCause, Map metadata) { + this(err, rootCause); + this.metadata = metadata; + } } \ No newline at end of file diff --git a/resident/resident-service/src/main/java/io/mosip/resident/exception/OtpValidationFailedException.java b/resident/resident-service/src/main/java/io/mosip/resident/exception/OtpValidationFailedException.java index 05deb459551..ef5bab77581 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/exception/OtpValidationFailedException.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/exception/OtpValidationFailedException.java @@ -1,14 +1,17 @@ package io.mosip.resident.exception; +import java.util.Map; + import io.mosip.kernel.core.exception.BaseCheckedException; import io.mosip.resident.constant.ResidentErrorCode; +import io.mosip.resident.util.ObjectWithMetadata; -import static io.mosip.kernel.core.exception.BaseUncheckedException.EMPTY_SPACE; - -public class OtpValidationFailedException extends BaseCheckedException { +public class OtpValidationFailedException extends BaseCheckedException implements ObjectWithMetadata { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; + + private Map metadata; /** * Instantiates a new otp validation failed exception. @@ -46,4 +49,17 @@ public OtpValidationFailedException(String errorCode, String errorMessage) { public OtpValidationFailedException(String message, Throwable cause) { super(ResidentErrorCode.OTP_VALIDATION_FAILED.getErrorCode(), message, cause); } + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + public OtpValidationFailedException(String errorMessage, Map metadata) { + this(errorMessage); + this.metadata = metadata; + } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceCheckedException.java b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceCheckedException.java index 9d157edf174..c4705bc0555 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceCheckedException.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceCheckedException.java @@ -1,14 +1,20 @@ package io.mosip.resident.exception; +import java.util.Map; + import io.mosip.kernel.core.exception.BaseCheckedException; import io.mosip.resident.constant.ResidentErrorCode; +import io.mosip.resident.util.ObjectWithMetadata; /** * * @author Girish Yarru * */ -public class ResidentServiceCheckedException extends BaseCheckedException { +public class ResidentServiceCheckedException extends BaseCheckedException implements ObjectWithMetadata { + private static final long serialVersionUID = -1561461793874550645L; + + private Map metadata; public ResidentServiceCheckedException() { super(); @@ -29,5 +35,18 @@ public ResidentServiceCheckedException(String errorCode, String errorMessage, Th public ResidentServiceCheckedException(ResidentErrorCode error, ApisResourceAccessException e) { this(error.getErrorCode(), error.getErrorMessage(), e); } + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + public ResidentServiceCheckedException(ResidentErrorCode err, Map metadata) { + this(err.getErrorCode(), err.getErrorMessage()); + this.metadata = metadata; + } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java index 1e7cd04f676..2fe6d919659 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java @@ -68,7 +68,7 @@ public void setMetadata(Map metadata) { this.metadata = metadata; } - public ResidentServiceException(ResidentErrorCode err, Throwable rootCause, Map metadata) { + public ResidentServiceException(ResidentErrorCode err, Throwable rootCause, Map metadata) { this(err, rootCause); this.metadata = metadata; } 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 a59863b95cc..ff8f7d78823 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 @@ -17,5 +17,5 @@ public interface DownloadCardService { Tuple2 downloadPersonalizedCard(MainRequestDTO downloadPersonalizedCardMainRequestDTO); - ResponseWrapper getVidCardEventId(String vid) throws BaseCheckedException; + Tuple2, String> getVidCardEventId(String vid) 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 3599ee2e2d1..5b2ee4b0c81 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,22 @@ package io.mosip.resident.service.impl; -import com.fasterxml.jackson.databind.ObjectMapper; +import static io.mosip.resident.constant.EventStatusSuccess.CARD_DOWNLOADED; +import static io.mosip.resident.constant.TemplateVariablesConstants.NAME; +import static io.mosip.resident.constant.TemplateVariablesConstants.VID; +import static io.mosip.resident.constant.TemplateVariablesConstants.VID_TYPE; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Service; + import io.mosip.kernel.core.exception.BaseCheckedException; import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.core.util.CryptoUtil; @@ -15,7 +31,6 @@ import io.mosip.resident.constant.RequestType; import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.constant.ResidentErrorCode; -import io.mosip.resident.controller.ResidentController; import io.mosip.resident.dto.CredentialReqestDto; import io.mosip.resident.dto.DownloadCardRequestDTO; import io.mosip.resident.dto.DownloadPersonalizedCardDto; @@ -29,7 +44,6 @@ import io.mosip.resident.exception.OtpValidationFailedException; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.exception.ResidentServiceException; -import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.repository.ResidentTransactionRepository; import io.mosip.resident.service.DownloadCardService; import io.mosip.resident.service.IdAuthService; @@ -39,29 +53,11 @@ import io.mosip.resident.util.EventEnum; import io.mosip.resident.util.JsonUtil; import io.mosip.resident.util.ResidentServiceRestClient; -import io.mosip.resident.util.TemplateUtil; import io.mosip.resident.util.Utilities; import io.mosip.resident.util.Utilitiy; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Service; import reactor.util.function.Tuple2; import reactor.util.function.Tuples; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static io.mosip.resident.constant.EventStatusSuccess.CARD_DOWNLOADED; -import static io.mosip.resident.constant.RegistrationConstants.SUCCESS; -import static io.mosip.resident.constant.TemplateVariablesConstants.NAME; -import static io.mosip.resident.constant.TemplateVariablesConstants.VID; -import static io.mosip.resident.constant.TemplateVariablesConstants.VID_TYPE; - /** * @author Kamesh Shekhar Prasad * This class is used to create service class implementation of download card api. @@ -79,8 +75,6 @@ public class DownloadCardServiceImpl implements DownloadCardService { private static final String TRANSACTION_COUNT = "transactionCount"; private static final String CARD_FORMAT = "cardFormat"; private static final Object VID_CARD = "vidCard"; - @Autowired - private ResidentController residentController; @Autowired private Utilities utilities; @@ -88,9 +82,6 @@ public class DownloadCardServiceImpl implements DownloadCardService { @Autowired private AuditUtil audit; - @Autowired - private ObjectStoreHelper objectStoreHelper; - @Autowired private ResidentServiceRestClient residentServiceRestClient; @@ -106,12 +97,6 @@ public class DownloadCardServiceImpl implements DownloadCardService { @Autowired private IdentityServiceImpl identityService; - @Autowired - private TemplateUtil templateUtil; - - @Autowired - private ObjectMapper objectMapper; - @Autowired private Environment environment; @@ -208,7 +193,7 @@ public Tuple2 downloadPersonalizedCard(MainRequestDTO downloadPersonalizedCard(MainRequestDTO getAttributeList(String individualId) throws IOException, A } @Override - public ResponseWrapper getVidCardEventId(String vid) throws BaseCheckedException { + public Tuple2, String> getVidCardEventId(String vid) throws BaseCheckedException { ResponseWrapper responseWrapper= new ResponseWrapper<>(); VidDownloadCardResponseDto vidDownloadCardResponseDto = new VidDownloadCardResponseDto(); - String eventId=""; + String eventId = ResidentConstants.NOT_AVAILABLE; + ResidentTransactionEntity residentTransactionEntity = null; try{ + residentTransactionEntity = insertDataForVidCard(vid); + if (residentTransactionEntity != null) { + eventId = residentTransactionEntity.getEventId(); + } RequestWrapper requestDto = new RequestWrapper<>(); CredentialReqestDto credentialReqestDto = new CredentialReqestDto(); credentialReqestDto.setId(vid); @@ -327,45 +317,67 @@ public ResponseWrapper getVidCardEventId(String vid) ResidentCredentialResponseDto residentCredentialResponseDto = JsonUtil.readValue(JsonUtil.writeValueAsString(responseDto.getResponse()), ResidentCredentialResponseDto.class); - eventId =insertDataForVidCard(residentCredentialResponseDto, vid); - vidDownloadCardResponseDto.setEventId(eventId); + residentTransactionEntity.setCredentialRequestId(residentCredentialResponseDto.getRequestId()); vidDownloadCardResponseDto.setStatus(ResidentConstants.SUCCESS); - }else{ - throw new ResidentServiceCheckedException(String.valueOf(ResidentErrorCode.VID_REQUEST_CARD_FAILED), - ResidentErrorCode.VID_REQUEST_CARD_FAILED.getErrorMessage()); + } else { + if (residentTransactionEntity != null) { + residentTransactionEntity.setRequestSummary(ResidentConstants.FAILED); + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + } + throw new ResidentServiceCheckedException(ResidentErrorCode.VID_REQUEST_CARD_FAILED, + Map.of(ResidentConstants.EVENT_ID, eventId)); } - }catch (ApisResourceAccessException e){ - throw new ApisResourceAccessException(ResidentErrorCode.VID_REQUEST_CARD_FAILED.toString(), e); - }catch (ResidentServiceCheckedException exception){ - throw new ResidentServiceException(ResidentErrorCode.VID_REQUEST_CARD_FAILED.getErrorCode(), - ResidentErrorCode.VID_REQUEST_CARD_FAILED.getErrorMessage(), exception); - }catch (IOException exception){ + } catch (ApisResourceAccessException e) { + if (residentTransactionEntity != null) { + residentTransactionEntity.setRequestSummary(ResidentConstants.FAILED); + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + } + throw new ApisResourceAccessException(ResidentErrorCode.VID_REQUEST_CARD_FAILED.toString(), e, + Map.of(ResidentConstants.EVENT_ID, eventId)); + } catch (ResidentServiceCheckedException exception) { + if (residentTransactionEntity != null) { + residentTransactionEntity.setRequestSummary(ResidentConstants.FAILED); + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + } + throw new ResidentServiceException(ResidentErrorCode.VID_REQUEST_CARD_FAILED, exception, + Map.of(ResidentConstants.EVENT_ID, eventId)); + } catch (IOException exception) { + if (residentTransactionEntity != null) { + residentTransactionEntity.setRequestSummary(ResidentConstants.FAILED); + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + } throw new BaseCheckedException(ResidentErrorCode.BASE_EXCEPTION.getErrorCode(), exception.getMessage(), exception); - } + } finally { + if(residentTransactionEntity != null) { + //if the status code will come as null, it will set it as failed. + if(residentTransactionEntity.getStatusCode()==null) { + residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); + residentTransactionEntity.setRequestSummary(ResidentConstants.FAILED); + } + residentTransactionRepository.save(residentTransactionEntity); + } + } responseWrapper.setId(environment.getProperty(ResidentConstants.VID_DOWNLOAD_CARD_ID)); responseWrapper.setVersion(environment.getProperty(ResidentConstants.VID_DOWNLOAD_CARD_VERSION)); responseWrapper.setResponsetime(DateUtils.getUTCCurrentDateTimeString()); responseWrapper.setResponse(vidDownloadCardResponseDto); - return responseWrapper; + return Tuples.of(responseWrapper, eventId); } - private String insertDataForVidCard(ResidentCredentialResponseDto responseDto, String vid) throws ApisResourceAccessException, IOException { + private ResidentTransactionEntity insertDataForVidCard(String vid) throws ApisResourceAccessException, IOException { ResidentTransactionEntity residentTransactionEntity = utilitiy.createEntity(); - String eventId = utilitiy.createEventId(); String uin = utilities.getUinByVid(vid); - residentTransactionEntity.setEventId(eventId); + residentTransactionEntity.setEventId(utilitiy.createEventId()); residentTransactionEntity.setRequestTypeCode(RequestType.VID_CARD_DOWNLOAD.name()); residentTransactionEntity.setRefId(utilitiy.convertToMaskDataFormat(uin)); residentTransactionEntity.setTokenId(identityService.getIDAToken(uin)); - residentTransactionEntity.setCredentialRequestId(responseDto.getRequestId()); residentTransactionEntity.setStatusCode(EventStatusInProgress.NEW.name()); residentTransactionEntity.setRequestSummary(RequestType.VID_CARD_DOWNLOAD.name()); /** * Here we are setting vid in aid column. */ residentTransactionEntity.setAid(vid); - residentTransactionRepository.save(residentTransactionEntity); - return eventId; + return residentTransactionEntity; } private Map getVidDetails(String vid) throws ResidentServiceCheckedException, ApisResourceAccessException, IOException { 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 aed11371eac..51ac9fe09e4 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 @@ -51,6 +51,7 @@ import io.mosip.resident.constant.EventStatusInProgress; import io.mosip.resident.constant.LoggerFileConstant; import io.mosip.resident.constant.RequestType; +import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.constant.ResidentErrorCode; import io.mosip.resident.constant.ServiceType; import io.mosip.resident.dto.AuthRequestDTO; @@ -128,7 +129,7 @@ public boolean validateOtp(String transactionId, String individualId, String otp public Tuple2 validateOtpV1(String transactionId, String individualId, String otp) throws OtpValidationFailedException { AuthResponseDTO response = null; - String eventId = null; + String eventId = ResidentConstants.NOT_AVAILABLE; ResidentTransactionEntity residentTransactionEntity = null; try { response = internelOtpAuth(transactionId, individualId, otp); @@ -137,17 +138,16 @@ public Tuple2 validateOtpV1(String transactionId, String indivi | JsonProcessingException | java.security.cert.CertificateException e) { logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), null, "IdAuthServiceImpl::validateOtp():: validate otp method call" + ExceptionUtils.getStackTrace(e)); - throw new OtpValidationFailedException(e.getMessage()); + 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()); - + throw new OtpValidationFailedException(response.getErrors().get(0).getErrorMessage(), + Map.of(ResidentConstants.EVENT_ID, eventId)); } if (residentTransactionEntity != null) { - eventId = residentTransactionEntity.getEventId(); + eventId = residentTransactionEntity.getEventId(); } return Tuples.of(response.getResponse().isAuthStatus(), eventId); } 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 0251dec1bc5..5ff57752991 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 @@ -241,7 +241,7 @@ public Tuple2 shareCredential(ResidentC String partnerUrl = env.getProperty(ApiName.PARTNER_API_URL.name()) + "/" + dto.getIssuer(); URI partnerUri = URI.create(partnerUrl); String individualId = identityServiceImpl.getResidentIndvidualId(); - String eventId = null; + String eventId = ResidentConstants.NOT_AVAILABLE; ResidentTransactionEntity residentTransactionEntity = null; try { 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 78f6b9d5bcb..c4c7b11a5da 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 @@ -1128,7 +1128,7 @@ public Tuple2 reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRe String individualId = identityServiceImpl.getResidentIndvidualId(); boolean isTransactionSuccessful = false; List residentTransactionEntities = List.of(); - String eventId = null; + String eventId = ResidentConstants.NOT_AVAILABLE; try { audit.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.REQ_AUTH_TYPE_LOCK, "Request for Auth Type Lock")); diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadCardControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadCardControllerTest.java index a636500b2b8..bfdcc2767d1 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadCardControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/DownloadCardControllerTest.java @@ -36,6 +36,7 @@ import io.mosip.resident.dto.DownloadCardRequestDTO; import io.mosip.resident.dto.DownloadPersonalizedCardDto; import io.mosip.resident.dto.MainRequestDTO; +import io.mosip.resident.dto.ResponseWrapper; import io.mosip.resident.dto.VidDownloadCardResponseDto; import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.service.DownloadCardService; @@ -141,12 +142,12 @@ public void testDownloadPersonalizedCard() throws Exception { @Test public void testRequestVidCard() throws Exception { - io.mosip.resident.dto.ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = - new io.mosip.resident.dto.ResponseWrapper<>(); + ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = new ResponseWrapper<>(); VidDownloadCardResponseDto vidDownloadCardResponseDto = new VidDownloadCardResponseDto(); - vidDownloadCardResponseDto.setEventId("123"); + vidDownloadCardResponseDto.setStatus("success"); vidDownloadCardResponseDtoResponseWrapper.setResponse(vidDownloadCardResponseDto); - Mockito.when(downloadCardService.getVidCardEventId(Mockito.any())).thenReturn(vidDownloadCardResponseDtoResponseWrapper); + Mockito.when(downloadCardService.getVidCardEventId(Mockito.any())) + .thenReturn(Tuples.of(vidDownloadCardResponseDtoResponseWrapper, "12345")); mockMvc.perform(MockMvcRequestBuilders.get("/request-card/vid/9086273859467431")).andExpect(status().isOk()); } 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 d8c01e1db4b..f3dce75f6c9 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 @@ -2,7 +2,6 @@ import io.mosip.kernel.core.exception.BaseCheckedException; import io.mosip.kernel.core.exception.ServiceError; -import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.constant.ResidentErrorCode; import io.mosip.resident.dto.DigitalCardStatusResponseDto; @@ -10,6 +9,7 @@ import io.mosip.resident.dto.DownloadPersonalizedCardDto; import io.mosip.resident.dto.MainRequestDTO; import io.mosip.resident.dto.ResidentCredentialResponseDto; +import io.mosip.resident.dto.ResponseWrapper; import io.mosip.resident.dto.VidDownloadCardResponseDto; import io.mosip.resident.entity.ResidentTransactionEntity; import io.mosip.resident.exception.ApisResourceAccessException; @@ -25,7 +25,6 @@ import io.mosip.resident.service.impl.ResidentServiceImpl; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; -import io.mosip.resident.util.TemplateUtil; import io.mosip.resident.util.Utilities; import io.mosip.resident.util.Utilitiy; import reactor.util.function.Tuple2; @@ -82,9 +81,6 @@ public class DownloadCardServiceTest { @Mock private ResidentServiceImpl residentService; - @Mock - private TemplateUtil templateUtil; - @Mock private IdentityServiceImpl identityService; @@ -103,7 +99,6 @@ public class DownloadCardServiceTest { byte[] pdfbytes; - private ResponseWrapper responseDto; DigitalCardStatusResponseDto digitalCardStatusResponseDto; private MainRequestDTO downloadPersonalizedCardMainRequestDTO; @@ -127,7 +122,7 @@ public void setup() throws Exception { Mockito.when(identityService.getIndividualIdType(Mockito.anyString())).thenReturn("UIN"); Mockito.when(identityService.getIndividualIdForAid(Mockito.anyString())).thenReturn("7841261580"); Mockito.when(utilitiy.createEntity()).thenReturn(new ResidentTransactionEntity()); - Mockito.when(utilitiy.createEventId()).thenReturn("123"); + Mockito.when(utilitiy.createEventId()).thenReturn("12345"); ResidentTransactionEntity residentTransactionEntity = new ResidentTransactionEntity(); residentTransactionEntity.setEventId("12345"); @@ -268,33 +263,25 @@ public void testDownloadPersonalizedCardIOException() throws ResidentServiceChec @Test public void testGetVidCardEventId() throws BaseCheckedException { - io.mosip.resident.dto.ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = - new io.mosip.resident.dto.ResponseWrapper<>(); + ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = new ResponseWrapper<>(); VidDownloadCardResponseDto vidDownloadCardResponseDto = new VidDownloadCardResponseDto(); - vidDownloadCardResponseDto.setEventId("123"); + vidDownloadCardResponseDto.setStatus("success"); vidDownloadCardResponseDtoResponseWrapper.setResponse(vidDownloadCardResponseDto); - io.mosip.resident.dto.ResponseWrapper responseWrapper = - new io.mosip.resident.dto.ResponseWrapper<>(); + ResponseWrapper responseWrapper = new ResponseWrapper<>(); ResidentCredentialResponseDto residentCredentialResponseDto = new ResidentCredentialResponseDto(); residentCredentialResponseDto.setId("123"); residentCredentialResponseDto.setRequestId("123"); responseWrapper.setResponse(residentCredentialResponseDto); Mockito.when(residentServiceRestClient.postApi(any(), any(), any(), any())).thenReturn(responseWrapper); - Mockito.when(utilitiy.createEntity()).thenReturn(new ResidentTransactionEntity()); - Mockito.when(utilitiy.createEventId()).thenReturn("123"); - assertEquals(vidDownloadCardResponseDtoResponseWrapper.getResponse().getEventId(), - downloadCardService.getVidCardEventId("123").getResponse().getEventId()); + assertEquals("12345", downloadCardService.getVidCardEventId("123").getT2()); } @Test(expected = ResidentServiceException.class) public void testGetVidCardEventIdFailed() throws BaseCheckedException { - io.mosip.resident.dto.ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = - new io.mosip.resident.dto.ResponseWrapper<>(); + ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = new ResponseWrapper<>(); VidDownloadCardResponseDto vidDownloadCardResponseDto = new VidDownloadCardResponseDto(); - vidDownloadCardResponseDto.setEventId("123"); vidDownloadCardResponseDtoResponseWrapper.setResponse(vidDownloadCardResponseDto); - io.mosip.resident.dto.ResponseWrapper responseWrapper = - new io.mosip.resident.dto.ResponseWrapper<>(); + ResponseWrapper responseWrapper = new ResponseWrapper<>(); ResidentCredentialResponseDto residentCredentialResponseDto = new ResidentCredentialResponseDto(); residentCredentialResponseDto.setId("123"); residentCredentialResponseDto.setRequestId("123"); @@ -302,55 +289,45 @@ public void testGetVidCardEventIdFailed() throws BaseCheckedException { ResidentErrorCode.VID_REQUEST_CARD_FAILED.getErrorMessage()))); responseWrapper.setResponse(residentCredentialResponseDto); Mockito.when(residentServiceRestClient.postApi(any(), any(), any(), any())).thenReturn(responseWrapper); - assertEquals(vidDownloadCardResponseDtoResponseWrapper.getResponse().getEventId(), - downloadCardService.getVidCardEventId("123").getResponse().getEventId()); + downloadCardService.getVidCardEventId("123"); } @Test(expected = ApisResourceAccessException.class) public void testGetVidCardEventIdApisResourceAccessException() throws BaseCheckedException { - io.mosip.resident.dto.ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = - new io.mosip.resident.dto.ResponseWrapper<>(); + ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = new ResponseWrapper<>(); VidDownloadCardResponseDto vidDownloadCardResponseDto = new VidDownloadCardResponseDto(); - vidDownloadCardResponseDto.setEventId("123"); vidDownloadCardResponseDtoResponseWrapper.setResponse(vidDownloadCardResponseDto); Mockito.when(residentServiceRestClient.postApi(any(), any(), any(), any())).thenThrow(new ApisResourceAccessException()); - assertEquals(vidDownloadCardResponseDtoResponseWrapper.getResponse().getEventId(), - downloadCardService.getVidCardEventId("123").getResponse().getEventId()); + downloadCardService.getVidCardEventId("123"); } @Test(expected = BaseCheckedException.class) public void testGetVidCardEventIdResidentServiceCheckedException() throws BaseCheckedException, IOException { - io.mosip.resident.dto.ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = - new io.mosip.resident.dto.ResponseWrapper<>(); + ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = new ResponseWrapper<>(); VidDownloadCardResponseDto vidDownloadCardResponseDto = new VidDownloadCardResponseDto(); - vidDownloadCardResponseDto.setEventId("123"); vidDownloadCardResponseDtoResponseWrapper.setResponse(vidDownloadCardResponseDto); - io.mosip.resident.dto.ResponseWrapper responseWrapper = - new io.mosip.resident.dto.ResponseWrapper<>(); + ResponseWrapper responseWrapper = new ResponseWrapper<>(); ResidentCredentialResponseDto residentCredentialResponseDto = new ResidentCredentialResponseDto(); residentCredentialResponseDto.setId("123"); residentCredentialResponseDto.setRequestId("123"); responseWrapper.setResponse(residentCredentialResponseDto); Mockito.when(utilities.getUinByVid(Mockito.anyString())).thenThrow(new IOException()); - assertEquals(vidDownloadCardResponseDtoResponseWrapper.getResponse().getEventId(), - downloadCardService.getVidCardEventId("123").getResponse().getEventId()); + downloadCardService.getVidCardEventId("123"); } @Test public void testGetVidCardEventIdWithVidDetails() throws BaseCheckedException, IOException { - io.mosip.resident.dto.ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = - new io.mosip.resident.dto.ResponseWrapper<>(); + ResponseWrapper vidDownloadCardResponseDtoResponseWrapper = new ResponseWrapper<>(); VidDownloadCardResponseDto vidDownloadCardResponseDto = new VidDownloadCardResponseDto(); - vidDownloadCardResponseDto.setEventId("123"); + vidDownloadCardResponseDto.setStatus("success"); vidDownloadCardResponseDtoResponseWrapper.setResponse(vidDownloadCardResponseDto); - io.mosip.resident.dto.ResponseWrapper responseWrapper = - new io.mosip.resident.dto.ResponseWrapper<>(); + ResponseWrapper responseWrapper = new ResponseWrapper<>(); ResidentCredentialResponseDto residentCredentialResponseDto = new ResidentCredentialResponseDto(); residentCredentialResponseDto.setId("123"); residentCredentialResponseDto.setRequestId("123"); responseWrapper.setResponse(residentCredentialResponseDto); Mockito.when(residentServiceRestClient.postApi(any(), any(), any(), any())).thenReturn(responseWrapper); - io.mosip.resident.dto.ResponseWrapper>> vidResponse = new io.mosip.resident.dto.ResponseWrapper<>(); + ResponseWrapper>> vidResponse = new ResponseWrapper<>(); Map vidDetails = new HashMap<>(); vidDetails.put("vidType", "perpetual"); List> vidList = new ArrayList<>(); @@ -365,10 +342,7 @@ public void testGetVidCardEventIdWithVidDetails() throws BaseCheckedException, I vidResponse.setResponse(vidList); Mockito.when(vidService.retrieveVids(Mockito.anyString())).thenReturn(vidResponse); Mockito.when(utilities.getUinByVid(Mockito.anyString())).thenReturn("3425636374"); - Mockito.when(utilitiy.createEntity()).thenReturn(new ResidentTransactionEntity()); - Mockito.when(utilitiy.createEventId()).thenReturn("123"); - assertEquals(vidDownloadCardResponseDtoResponseWrapper.getResponse().getEventId(), - downloadCardService.getVidCardEventId("123").getResponse().getEventId()); + assertEquals("12345", downloadCardService.getVidCardEventId("123").getT2()); } } \ No newline at end of file From 8bf439b97b620690407e1f6f1c1293bad5b49e41 Mon Sep 17 00:00:00 2001 From: RitikJain4108 <99730411+RitikJain4108@users.noreply.github.com> Date: Mon, 19 Dec 2022 14:35:36 +0530 Subject: [PATCH 08/11] Mosip 24879 add event id in the response of the below stories (#620) * added error for invalid user * added status in 2 apis * changed response of auth-lock-unlock api * updated response of validate otp * added eventid and status in response * added eventId in response header for download eventid api * fixed service history pdf file name * added eventid in response of download card api * convert eventId to constant * added eventId for error scenarios * fixed reliability bug * fixed response of share credential API * fixed test failure * updated response for auth lock unlock API * covered code for one method * updated response of request vid card * updated response of validate otp API * created contant for NA * updated response of generate and revoke vid Co-authored-by: Ritik Jain --- .../controller/ResidentVidController.java | 15 ++++--- .../resident/dto/GenerateVidResponseDto.java | 1 - .../resident/dto/RevokeVidResponseDto.java | 1 - .../resident/service/ResidentVidService.java | 8 ++++ .../service/impl/IdAuthServiceImpl.java | 6 +-- .../service/impl/ResidentVidServiceImpl.java | 44 ++++++++++++++----- 6 files changed, 53 insertions(+), 22 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentVidController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentVidController.java index a49d9576b95..9220c14fead 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentVidController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentVidController.java @@ -20,6 +20,7 @@ import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.core.util.DateUtils; import io.mosip.resident.config.LoggerConfiguration; +import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.constant.ResidentErrorCode; import io.mosip.resident.dto.BaseVidRevokeRequestDTO; import io.mosip.resident.dto.IVidRequestDto; @@ -48,6 +49,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import reactor.util.function.Tuple2; /** * Resident VID controller class. @@ -159,10 +161,12 @@ private ResponseEntity generateVidV2Version(IVidRequestDto requestDto validator.validateVidCreateV2Request(requestDto, isOtpValidationRequired, residentIndividualId); auditUtil.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.GENERATE_VID, residentIndividualId)); - ResponseWrapper vidResponseDto = residentVidService.generateVid(requestDto.getRequest(), residentIndividualId); + Tuple2, String> tupleResponse = residentVidService.generateVidV2(requestDto.getRequest(), residentIndividualId); auditUtil.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.GENERATE_VID_SUCCESS, residentIndividualId)); - return ResponseEntity.ok().body(vidResponseDto); + return ResponseEntity.ok() + .header(ResidentConstants.EVENT_ID, tupleResponse.getT2()) + .body(tupleResponse.getT1()); } @PatchMapping(path = "/vid/{vid}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @@ -237,14 +241,15 @@ private ResponseEntity revokeVidV2Version(RequestWrapper vidResponseDto = residentVidService.revokeVid(requestDto.getRequest(), + Tuple2, String> tupleResponse = residentVidService.revokeVidV2(requestDto.getRequest(), vid, residentIndividualId); auditUtil.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.REVOKE_VID_SUCCESS, residentIndividualId)); - return ResponseEntity.ok().body(vidResponseDto); + return ResponseEntity.ok() + .header(ResidentConstants.EVENT_ID, tupleResponse.getT2()) + .body(tupleResponse.getT1()); } - private String getResidentIndividualId() throws ApisResourceAccessException { return identityServiceImpl.getResidentIndvidualId(); } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/GenerateVidResponseDto.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/GenerateVidResponseDto.java index 7c23b23ce90..180bb12a5b1 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/dto/GenerateVidResponseDto.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/dto/GenerateVidResponseDto.java @@ -16,7 +16,6 @@ public class GenerateVidResponseDto extends VidResponseDtoV2 { * */ private static final long serialVersionUID = 5728940858748492895L; - private String eventId; private String status; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/RevokeVidResponseDto.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/RevokeVidResponseDto.java index 1cf69c68e9b..b0e02df6aab 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/dto/RevokeVidResponseDto.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/dto/RevokeVidResponseDto.java @@ -16,7 +16,6 @@ public class RevokeVidResponseDto extends VidRevokeResponseDTO { * */ private static final long serialVersionUID = 1973880019812497700L; - private String eventId; private String status; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentVidService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentVidService.java index 71600d9e676..eee42c4979c 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentVidService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentVidService.java @@ -14,6 +14,7 @@ import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.OtpValidationFailedException; import io.mosip.resident.exception.ResidentServiceCheckedException; +import reactor.util.function.Tuple2; @Service public interface ResidentVidService { @@ -28,4 +29,11 @@ public interface ResidentVidService { public Optional getPerpatualVid(String uin) throws ResidentServiceCheckedException, ApisResourceAccessException; + public Tuple2, String> generateVidV2(BaseVidRequestDto requestDto, + String individualId) throws OtpValidationFailedException, ResidentServiceCheckedException; + + public Tuple2, String> revokeVidV2(BaseVidRevokeRequestDTO requestDto, + String vid, String indivudalId) + throws OtpValidationFailedException, ResidentServiceCheckedException, ApisResourceAccessException; + } 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 51ac9fe09e4..9ad34dd3cc2 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 @@ -134,6 +134,9 @@ public Tuple2 validateOtpV1(String transactionId, String indivi try { response = internelOtpAuth(transactionId, individualId, otp); residentTransactionEntity = updateResidentTransaction(response.getResponse().isAuthStatus(), transactionId, individualId); + if (residentTransactionEntity != null) { + eventId = residentTransactionEntity.getEventId(); + } } catch (ApisResourceAccessException | InvalidKeySpecException | NoSuchAlgorithmException | IOException | JsonProcessingException | java.security.cert.CertificateException e) { logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), null, @@ -146,9 +149,6 @@ public Tuple2 validateOtpV1(String transactionId, String indivi throw new OtpValidationFailedException(response.getErrors().get(0).getErrorMessage(), Map.of(ResidentConstants.EVENT_ID, eventId)); } - if (residentTransactionEntity != null) { - eventId = residentTransactionEntity.getEventId(); - } return Tuples.of(response.getResponse().isAuthStatus(), eventId); } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentVidServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentVidServiceImpl.java index 00dcfa5c7ed..2df86d176cd 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentVidServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentVidServiceImpl.java @@ -76,6 +76,8 @@ import io.mosip.resident.util.EventEnum; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utilitiy; +import reactor.util.function.Tuple2; +import reactor.util.function.Tuples; @Component public class ResidentVidServiceImpl implements ResidentVidService { @@ -163,6 +165,12 @@ public class ResidentVidServiceImpl implements ResidentVidService { @Override public ResponseWrapper generateVid(BaseVidRequestDto requestDto, String individualId) throws OtpValidationFailedException, ResidentServiceCheckedException { + return generateVidV2(requestDto, individualId).getT1(); + } + + @Override + public Tuple2, String> generateVidV2(BaseVidRequestDto requestDto, + String individualId) throws OtpValidationFailedException, ResidentServiceCheckedException { boolean isV2Request = requestDto instanceof VidRequestDtoV2; ResponseWrapper responseDto = new ResponseWrapper<>(); NotificationRequestDto notificationRequestDto = isV2Request? new NotificationRequestDtoV2() : new NotificationRequestDto(); @@ -192,10 +200,14 @@ public ResponseWrapper generateVid(BaseVidRequestDto requestDto, IdentityDTO identityDTO = identityServiceImpl.getIdentity(individualId); String email = identityDTO.getEmail(); String phone = identityDTO.getPhone(); + String eventId = ResidentConstants.NOT_AVAILABLE; ResidentTransactionEntity residentTransactionEntity=null; try { if(Utilitiy.isSecureSession()){ residentTransactionEntity = createResidentTransactionEntity(requestDto); + if (residentTransactionEntity != null) { + eventId = residentTransactionEntity.getEventId(); + } } String uin = identityDTO.getUIN(); // generate vid @@ -213,7 +225,7 @@ public ResponseWrapper generateVid(BaseVidRequestDto requestDto, NotificationRequestDtoV2 notificationRequestDtoV2=(NotificationRequestDtoV2) notificationRequestDto; notificationRequestDtoV2.setTemplateType(TemplateType.SUCCESS); notificationRequestDtoV2.setRequestType(RequestType.GENERATE_VID); - notificationRequestDtoV2.setEventId(residentTransactionEntity.getEventId()); + notificationRequestDtoV2.setEventId(eventId); notificationResponseDTO=notificationService .sendNotification(notificationRequestDto, vidRequestDtoV2.getChannels(), email, phone); @@ -230,7 +242,6 @@ public ResponseWrapper generateVid(BaseVidRequestDto requestDto, vidResponseDto = generateVidResponseDto; generateVidResponseDto.setMaskedEmail(notificationResponseDTO.getMaskedEmail()); generateVidResponseDto.setMaskedPhone(notificationResponseDTO.getMaskedPhone()); - generateVidResponseDto.setEventId(residentTransactionEntity.getEventId()); generateVidResponseDto.setStatus(ResidentConstants.SUCCESS); } else { vidResponseDto = new VidResponseDto(); @@ -255,7 +266,7 @@ public ResponseWrapper generateVid(BaseVidRequestDto requestDto, NotificationRequestDtoV2 notificationRequestDtoV2=(NotificationRequestDtoV2) notificationRequestDto; notificationRequestDtoV2.setTemplateType(TemplateType.FAILURE); notificationRequestDtoV2.setRequestType(RequestType.GENERATE_VID); - notificationRequestDtoV2.setEventId(residentTransactionEntity.getEventId()); + notificationRequestDtoV2.setEventId(eventId); notificationService.sendNotification(notificationRequestDto, vidRequestDtoV2.getChannels(), email, phone); } else { @@ -276,7 +287,7 @@ public ResponseWrapper generateVid(BaseVidRequestDto requestDto, NotificationRequestDtoV2 notificationRequestDtoV2=(NotificationRequestDtoV2) notificationRequestDto; notificationRequestDtoV2.setTemplateType(TemplateType.FAILURE); notificationRequestDtoV2.setRequestType(RequestType.GENERATE_VID); - notificationRequestDtoV2.setEventId(residentTransactionEntity.getEventId()); + notificationRequestDtoV2.setEventId(eventId); notificationService.sendNotification(notificationRequestDto, vidRequestDtoV2.getChannels(), email, phone); } else { @@ -297,7 +308,7 @@ public ResponseWrapper generateVid(BaseVidRequestDto requestDto, NotificationRequestDtoV2 notificationRequestDtoV2=(NotificationRequestDtoV2) notificationRequestDto; notificationRequestDtoV2.setTemplateType(TemplateType.FAILURE); notificationRequestDtoV2.setRequestType(RequestType.GENERATE_VID); - notificationRequestDtoV2.setEventId(residentTransactionEntity.getEventId()); + notificationRequestDtoV2.setEventId(eventId); notificationService.sendNotification(notificationRequestDto, vidRequestDtoV2.getChannels(), email, phone); } else { @@ -329,7 +340,7 @@ public ResponseWrapper generateVid(BaseVidRequestDto requestDto, } responseDto.setResponsetime(DateUtils.formatToISOString(DateUtils.getUTCCurrentDateTime())); - return responseDto; + return Tuples.of(responseDto, eventId); } private ResidentTransactionEntity createResidentTransactionEntity(BaseVidRequestDto requestDto) throws ApisResourceAccessException, ResidentServiceCheckedException { @@ -397,6 +408,12 @@ private VidGeneratorResponseDto vidGenerator(BaseVidRequestDto requestDto, Strin @Override public ResponseWrapper revokeVid(BaseVidRevokeRequestDTO requestDto, String vid, String indivudalId) throws OtpValidationFailedException, ResidentServiceCheckedException, ApisResourceAccessException { + return revokeVidV2(requestDto, vid, indivudalId).getT1(); + } + + @Override + public Tuple2, String> revokeVidV2(BaseVidRevokeRequestDTO requestDto, String vid, String indivudalId) + throws OtpValidationFailedException, ResidentServiceCheckedException, ApisResourceAccessException { boolean isV2Request = requestDto instanceof VidRevokeRequestDTOV2; ResponseWrapper responseDto = new ResponseWrapper<>(); NotificationRequestDto notificationRequestDto = isV2Request? new NotificationRequestDtoV2() : new NotificationRequestDto(); @@ -426,9 +443,13 @@ public ResponseWrapper revokeVid(BaseVidRevokeRequestDTO r } } } + String eventId = ResidentConstants.NOT_AVAILABLE; ResidentTransactionEntity residentTransactionEntity = null; if(Utilitiy.isSecureSession()) { residentTransactionEntity = createResidentTransEntity(vid, indivudalId); + if (residentTransactionEntity != null) { + eventId = residentTransactionEntity.getEventId(); + } } IdentityDTO identityDTO = identityServiceImpl.getIdentity(indivudalId); String uin = identityDTO.getUIN(); @@ -472,7 +493,7 @@ public ResponseWrapper revokeVid(BaseVidRevokeRequestDTO r NotificationRequestDtoV2 notificationRequestDtoV2=(NotificationRequestDtoV2) notificationRequestDto; notificationRequestDtoV2.setTemplateType(TemplateType.SUCCESS); notificationRequestDtoV2.setRequestType(RequestType.REVOKE_VID); - notificationRequestDtoV2.setEventId(residentTransactionEntity.getEventId()); + notificationRequestDtoV2.setEventId(eventId); notificationResponseDTO=notificationService.sendNotification(notificationRequestDto); } else { @@ -486,7 +507,6 @@ public ResponseWrapper revokeVid(BaseVidRevokeRequestDTO r if(isV2Request) { RevokeVidResponseDto revokeVidResponseDto = new RevokeVidResponseDto(); vidRevokeResponseDto = revokeVidResponseDto; - revokeVidResponseDto.setEventId(residentTransactionEntity.getEventId()); revokeVidResponseDto.setStatus(ResidentConstants.SUCCESS); } else { vidRevokeResponseDto = new VidRevokeResponseDTO(); @@ -506,7 +526,7 @@ public ResponseWrapper revokeVid(BaseVidRevokeRequestDTO r NotificationRequestDtoV2 notificationRequestDtoV2=(NotificationRequestDtoV2) notificationRequestDto; notificationRequestDtoV2.setTemplateType(TemplateType.FAILURE); notificationRequestDtoV2.setRequestType(RequestType.REVOKE_VID); - notificationRequestDtoV2.setEventId(residentTransactionEntity.getEventId()); + notificationRequestDtoV2.setEventId(eventId); notificationService.sendNotification(notificationRequestDto); } else { @@ -526,7 +546,7 @@ public ResponseWrapper revokeVid(BaseVidRevokeRequestDTO r NotificationRequestDtoV2 notificationRequestDtoV2=(NotificationRequestDtoV2) notificationRequestDto; notificationRequestDtoV2.setTemplateType(TemplateType.FAILURE); notificationRequestDtoV2.setRequestType(RequestType.REVOKE_VID); - notificationRequestDtoV2.setEventId(residentTransactionEntity.getEventId()); + notificationRequestDtoV2.setEventId(eventId); notificationService.sendNotification(notificationRequestDto); } else { @@ -546,7 +566,7 @@ public ResponseWrapper revokeVid(BaseVidRevokeRequestDTO r NotificationRequestDtoV2 notificationRequestDtoV2=(NotificationRequestDtoV2) notificationRequestDto; notificationRequestDtoV2.setTemplateType(TemplateType.FAILURE); notificationRequestDtoV2.setRequestType(RequestType.REVOKE_VID); - notificationRequestDtoV2.setEventId(residentTransactionEntity.getEventId()); + notificationRequestDtoV2.setEventId(eventId); notificationService.sendNotification(notificationRequestDto); } else { @@ -578,7 +598,7 @@ public ResponseWrapper revokeVid(BaseVidRevokeRequestDTO r } responseDto.setResponsetime(DateUtils.formatToISOString(DateUtils.getUTCCurrentDateTime())); - return responseDto; + return Tuples.of(responseDto, eventId); } private ResidentTransactionEntity createResidentTransEntity(String vid, String indivudalId) throws ApisResourceAccessException, ResidentServiceCheckedException { From 0f6ea2eeecc56ac0de3cb9c41a621bdb9c926183 Mon Sep 17 00:00:00 2001 From: Neha2365 <110969715+Neha2365@users.noreply.github.com> Date: Mon, 19 Dec 2022 14:55:08 +0530 Subject: [PATCH 09/11] Mosip 25307 api create the following proxy ap is from masterdata (#621) * MOSIP-25307 Created API to get DocumentType from masterdata * JUNIT added for document API * MOSIP-25307 done * Changes done Co-authored-by: Neha Farheen --- .../controller/ProxyMasterdataController.java | 30 ++++++++++++++++++- .../resident/dto/GenderCodeResponseDTO.java | 19 ++++++++++++ .../io/mosip/resident/dto/GenderTypeDTO.java | 22 ++++++++++++++ .../mosip/resident/dto/GenderTypeListDTO.java | 21 +++++++++++++ .../service/ProxyMasterdataService.java | 4 +++ .../impl/ProxyMasterdataServiceImpl.java | 29 ++++++++++++++++-- .../io/mosip/resident/util/EventEnum.java | 7 +++++ .../ProxyMasterdataControllerTest.java | 7 +++++ .../service/ProxyMasterdataServiceTest.java | 30 +++++++++++++++++++ 9 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 resident/resident-service/src/main/java/io/mosip/resident/dto/GenderCodeResponseDTO.java create mode 100644 resident/resident-service/src/main/java/io/mosip/resident/dto/GenderTypeDTO.java create mode 100644 resident/resident-service/src/main/java/io/mosip/resident/dto/GenderTypeListDTO.java diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyMasterdataController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyMasterdataController.java index 5761343c7dd..eb61d67242d 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyMasterdataController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ProxyMasterdataController.java @@ -1,9 +1,9 @@ package io.mosip.resident.controller; +import java.io.IOException; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; @@ -420,4 +420,32 @@ public ResponseWrapper getDocumentTypesByDocumentCategoryAndLangCode(@PathVar logger.debug("ProxyMasterdataController::getDocumentTypesByDocumentCategoryLangCode::exit"); return responseWrapper; } + + /** + * Get gender code by gender type & language code. + * + * @param langCode + * @param gendertype + * @return ResponseWrapper object + * @throws IOException + */ + @ResponseFilter + @GetMapping("/proxy/masterdata/gendercode/{gendertype}/{langcode}") + @Operation(summary = "getGenderCodeByGenderTypeAndLangCode", description = "getGenderCodeByGenderTypeAndLangCode", tags = { + "proxy-masterdata-controller" }) + @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(hidden = true))), + @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 ResponseWrapper getGenderCodeByGenderTypeAndLangCode(@PathVariable("gendertype") String gendertype,@PathVariable("langcode") String langCode) + throws ResidentServiceCheckedException, IOException { + logger.debug("ProxyMasterdataController::getGenderCodeByGenderTypeAndLangCode::entry"); + auditUtil.setAuditRequestDto(EventEnum.GET_GENDER_CODE); + ResponseWrapper responseWrapper = proxyMasterdataService.getGenderCodeByGenderTypeAndLangCode(gendertype,langCode); + auditUtil.setAuditRequestDto(EventEnum.GET_GENDER_CODE_SUCCESS); + logger.debug("ProxyMasterdataController::getGenderCodeByGenderTypeAndLangCode::exit"); + return responseWrapper; + } + } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/GenderCodeResponseDTO.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/GenderCodeResponseDTO.java new file mode 100644 index 00000000000..56b9489b5a5 --- /dev/null +++ b/resident/resident-service/src/main/java/io/mosip/resident/dto/GenderCodeResponseDTO.java @@ -0,0 +1,19 @@ +package io.mosip.resident.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Resident proxy masterdata Gender API DTO. + * + * @author Neha Farheen + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class GenderCodeResponseDTO { + + private String genderCode; + +} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/GenderTypeDTO.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/GenderTypeDTO.java new file mode 100644 index 00000000000..430dffe9506 --- /dev/null +++ b/resident/resident-service/src/main/java/io/mosip/resident/dto/GenderTypeDTO.java @@ -0,0 +1,22 @@ +package io.mosip.resident.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Resident proxy masterdata Gender API DTO. + * + * @author Neha Farheen + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class GenderTypeDTO { + + private String code; + private String genderName; + private String langCode; + private String isActive; + +} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/GenderTypeListDTO.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/GenderTypeListDTO.java new file mode 100644 index 00000000000..84ceda097ee --- /dev/null +++ b/resident/resident-service/src/main/java/io/mosip/resident/dto/GenderTypeListDTO.java @@ -0,0 +1,21 @@ +package io.mosip.resident.dto; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Resident proxy masterdata Gender API DTO. + * + * @author Neha Farheen + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class GenderTypeListDTO { + + private List genderType; + +} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/ProxyMasterdataService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/ProxyMasterdataService.java index cb328981e71..975fb44fd04 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/ProxyMasterdataService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/ProxyMasterdataService.java @@ -7,6 +7,7 @@ import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.resident.constant.OrderEnum; +import io.mosip.resident.dto.GenderCodeResponseDTO; import io.mosip.resident.exception.ResidentServiceCheckedException; /** @@ -155,5 +156,8 @@ public ResponseWrapper getAllTemplateBylangCodeAndTemplateTypeCode(String lan public ResponseWrapper getGenderTypesByLangCode(String langCode) throws ResidentServiceCheckedException; public ResponseWrapper getDocumentTypesByDocumentCategoryAndLangCode(String documentcategorycode, String langCode) throws ResidentServiceCheckedException; + + public ResponseWrapper getGenderCodeByGenderTypeAndLangCode(String gendertype, String langCode) throws ResidentServiceCheckedException, IOException; + } \ No newline at end of file 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 7cdddf58bf0..b9ebdb36790 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 @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; @@ -17,6 +18,8 @@ import io.mosip.resident.constant.ApiName; import io.mosip.resident.constant.OrderEnum; import io.mosip.resident.constant.ResidentErrorCode; +import io.mosip.resident.dto.GenderCodeResponseDTO; +import io.mosip.resident.dto.GenderTypeListDTO; import io.mosip.resident.dto.TemplateResponseDto; import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.ResidentServiceCheckedException; @@ -353,7 +356,7 @@ public ResponseWrapper getLatestIdSchema(double schemaVersion, String domain, logger.debug("ProxyMasterdataServiceImpl::getLatestIdSchema()::exit"); return responseWrapper; } - + @Override public ResponseWrapper getAllTemplateBylangCodeAndTemplateTypeCode(String langCode, String templateTypeCode) throws ResidentServiceCheckedException { @@ -398,7 +401,8 @@ public ResponseWrapper getGenderTypesByLangCode(String langCode) throws Resid Map pathsegments = new HashMap(); pathsegments.put("langcode", langCode); try { - responseWrapper=residentServiceRestClient.getApi(ApiName.GENDER_TYPE_BY_LANGCODE, pathsegments, ResponseWrapper.class); + responseWrapper = residentServiceRestClient.getApi(ApiName.GENDER_TYPE_BY_LANGCODE, pathsegments, + ResponseWrapper.class); if (responseWrapper.getErrors() != null && !responseWrapper.getErrors().isEmpty()) { logger.debug(responseWrapper.getErrors().get(0).toString()); throw new ResidentServiceCheckedException(ResidentErrorCode.BAD_REQUEST.getErrorCode(), @@ -438,4 +442,25 @@ public ResponseWrapper getDocumentTypesByDocumentCategoryAndLangCode(String d return responseWrapper; } + @Override + public ResponseWrapper getGenderCodeByGenderTypeAndLangCode(String genderName, + String langCode) throws ResidentServiceCheckedException, IOException { + logger.debug("ProxyMasterdataServiceImpl::getGenderCodeByGenderTypeAndLangCode()::entry"); + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + GenderCodeResponseDTO genderCodeResponseDTO = new GenderCodeResponseDTO(); + ResponseWrapper res = getGenderTypesByLangCode(langCode); + GenderTypeListDTO response = JsonUtil.readValue(JsonUtil.writeValueAsString(res.getResponse()), + GenderTypeListDTO.class); + Optional genderCode = response.getGenderType().stream() + .filter(map -> map.getGenderName().equalsIgnoreCase(genderName)) + .map(map -> map.getCode()) + .findAny(); + if (genderCode.isPresent()) { + genderCodeResponseDTO.setGenderCode(genderCode.get()); + } + responseWrapper.setResponse(genderCodeResponseDTO); + logger.debug("ProxyMasterdataServiceImpl::getGenderCodeByGenderTypeAndLangCode()::exit"); + return responseWrapper; + } + } \ No newline at end of file diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java b/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java index 413c4012dd7..6ab80ff2c91 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/EventEnum.java @@ -709,9 +709,16 @@ public enum EventEnum { "NO_ID_TYPE", RegistrationConstants.APPLICATIONID, RegistrationConstants.APPLICATIONNAME), GET_DOCUMENT_TYPES_EXCEPTION("RES-SER-276", RegistrationConstants.SYSTEM, "get document types failure", "get document types by documentCode and langCode is failed", "RES-SER", "Residence service", "NO_ID", + "NO_ID_TYPE", RegistrationConstants.APPLICATIONID, RegistrationConstants.APPLICATIONNAME), + GET_GENDER_CODE("RES-SER-277", RegistrationConstants.SYSTEM, "get gender code", + "get gender code by genderName and langCode", "RES-SER", "Residence service", "NO_ID", "NO_ID_TYPE", + RegistrationConstants.APPLICATIONID, RegistrationConstants.APPLICATIONNAME), + GET_GENDER_CODE_SUCCESS("RES-SER-278", RegistrationConstants.SYSTEM, "get gender code success", + "get gender code by genderName and langCode is succeeded", "RES-SER", "Residence service", "NO_ID", "NO_ID_TYPE", RegistrationConstants.APPLICATIONID, RegistrationConstants.APPLICATIONNAME) ; + private final String eventId; private final String type; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyMasterdataControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyMasterdataControllerTest.java index a755d02ab23..ed2543a60f0 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyMasterdataControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ProxyMasterdataControllerTest.java @@ -205,5 +205,12 @@ public void testGetDocumentTypesByDocumentCategoryCodeAndLangCode() throws Excep mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/documenttypes/documentcategorycode/langcode")) .andExpect(status().isOk()); } + + @Test + public void testGetGenderCodeByGenderTypeAndLangCode() throws Exception { + Mockito.when(proxyMasterdataService.getGenderCodeByGenderTypeAndLangCode(Mockito.anyString(),Mockito.anyString())).thenReturn(responseWrapper); + mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/gendercode/gendertype/langcode")) + .andExpect(status().isOk()); + } } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyMasterdataServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyMasterdataServiceTest.java index 7e1b987758c..631379269d3 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyMasterdataServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ProxyMasterdataServiceTest.java @@ -1,9 +1,12 @@ package io.mosip.resident.test.service; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -22,6 +25,9 @@ import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.resident.constant.ApiName; import io.mosip.resident.constant.OrderEnum; +import io.mosip.resident.dto.GenderCodeResponseDTO; +import io.mosip.resident.dto.GenderTypeDTO; +import io.mosip.resident.dto.GenderTypeListDTO; import io.mosip.resident.dto.TemplateDto; import io.mosip.resident.dto.TemplateResponseDto; import io.mosip.resident.exception.ApisResourceAccessException; @@ -611,4 +617,28 @@ public void testGetDocumentTypesByDocumentCategoryAndLangCodeWithApisResourceAcc proxyMasterdataService.getDocumentTypesByDocumentCategoryAndLangCode("DOC","eng"); } + @Test + public void testGetGenderCodeByGenderTypeAndLangCode() + throws ApisResourceAccessException, ResidentServiceCheckedException, IOException { + GenderTypeListDTO response = new GenderTypeListDTO(); + GenderTypeDTO genderTypeDTO = new GenderTypeDTO("MLE","Male","eng","true"); + response.setGenderType(List.of(genderTypeDTO)); + ResponseWrapper res = new ResponseWrapper(); + res.setResponse(response); + when(residentServiceRestClient.getApi((ApiName) any(), any(), any())).thenReturn(res); + ResponseWrapper responseWrapper = proxyMasterdataService.getGenderCodeByGenderTypeAndLangCode("Male", "eng"); + assertEquals(genderTypeDTO.getCode(),responseWrapper.getResponse().getGenderCode()); + } + + @Test + public void testGetGenderCodeByGenderTypeAndLangCodeNoValue() + throws ApisResourceAccessException, ResidentServiceCheckedException, IOException { + GenderTypeListDTO response = new GenderTypeListDTO(); + response.setGenderType(List.of()); + ResponseWrapper res = new ResponseWrapper(); + res.setResponse(response); + when(residentServiceRestClient.getApi((ApiName) any(), any(), any())).thenReturn(res); + ResponseWrapper responseWrapper = proxyMasterdataService.getGenderCodeByGenderTypeAndLangCode("Male", "eng"); + } + } From a96ac623c8e47696d256c5f096c2abafdf9acc59 Mon Sep 17 00:00:00 2001 From: kameshsr <47484458+kameshsr@users.noreply.github.com> Date: Mon, 19 Dec 2022 15:55:03 +0530 Subject: [PATCH 10/11] MOSIP-22046 change input LocalDateTime to LocalDate. (#622) * Fixed service history issue. * MOSIP-22046 change input LocalDateTime to LocalDate. * MOSIP-22046 Refactor code. * MOSIP-22046 Fixed test case failure. * MOSIP-22046 Covered edge case of fromDate. --- .../controller/ResidentController.java | 12 +- .../resident/service/ResidentService.java | 10 +- .../service/impl/ResidentServiceImpl.java | 108 +++++++++--------- .../resident/validator/RequestValidator.java | 15 +-- .../controller/ResidentControllerTest.java | 5 +- .../ResidentServiceDownloadCardTest.java | 3 +- .../ResidentServiceGetServiceHistoryTest.java | 55 +++++---- .../test/validator/RequestValidatorTest.java | 89 ++++++++------- 8 files changed, 151 insertions(+), 146 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java index 4a2aaf2cc9a..dd54411b400 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java @@ -51,8 +51,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; -import reactor.util.function.Tuple2; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; @@ -70,10 +68,12 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import reactor.util.function.Tuple2; import javax.validation.Valid; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; import java.util.Objects; @@ -301,8 +301,8 @@ public ResponseWrapper checkAidStatus(@PathVariable(name public ResponseWrapper> getServiceHistory(@PathVariable("langcode") String langCode, @RequestParam(name = "pageStart", required = false) Integer pageStart, @RequestParam(name = "pageFetch", required = false) Integer pageFetch, - @RequestParam(name = "fromDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime fromDateTime, - @RequestParam(name = "toDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime toDateTime, + @RequestParam(name = "fromDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDateTime, + @RequestParam(name = "toDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate toDateTime, @RequestParam(name = "sortType", required = false) String sortType, @RequestParam(name = "serviceType", required = false) String serviceType, @RequestParam(name = "statusFilter", required = false) String statusFilter, @@ -538,8 +538,8 @@ public ResponseEntity downLoadServiceHistory( @RequestParam(name = "pageStart", required = false) Integer pageStart, @RequestParam(name = "pageFetch", required = false) Integer pageFetch, @RequestParam(name = "eventReqDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime eventReqDateTime, - @RequestParam(name = "fromDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime fromDateTime, - @RequestParam(name = "toDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime toDateTime, + @RequestParam(name = "fromDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDateTime, + @RequestParam(name = "toDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate toDateTime, @RequestParam(name = "sortType", required = false) String sortType, @RequestParam(name = "serviceType", required = false) String serviceType, @RequestParam(name = "statusFilter", required = false) String statusFilter, diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java index caf1dbc5603..65f532e4daf 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java @@ -1,6 +1,7 @@ package io.mosip.resident.service; import java.io.IOException; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; @@ -22,7 +23,6 @@ import io.mosip.resident.dto.RequestDTO; import io.mosip.resident.dto.ResidentReprintRequestDto; import io.mosip.resident.dto.ResidentReprintResponseDto; -import io.mosip.resident.dto.ResidentServiceHistoryResponseDto; import io.mosip.resident.dto.ResidentUpdateRequestDto; import io.mosip.resident.dto.ResponseDTO; import io.mosip.resident.dto.ServiceHistoryResponseDto; @@ -62,8 +62,8 @@ AidStatusResponseDTO getAidStatus(AidStatusRequestDTO reqDto) throws ResidentServiceCheckedException, ApisResourceAccessException, OtpValidationFailedException; ResponseWrapper> getServiceHistory(Integer pageStart, Integer pageFetch, - LocalDateTime fromDateTime, LocalDateTime toDateTime, String serviceType, String sortType, - String searchColumn, String searchText, String langCode) throws ResidentServiceCheckedException, ApisResourceAccessException; + LocalDate fromDateTime, LocalDate toDateTime, String serviceType, String sortType, + String searchColumn, String searchText, String langCode) throws ResidentServiceCheckedException, ApisResourceAccessException; byte[] downloadCard(String individualId, String idType) throws ResidentServiceCheckedException; @@ -85,8 +85,8 @@ ResponseWrapper getEventStatus(String id, String eventId ResponseWrapper> getUnreadnotifylist(String Id); byte[] downLoadServiceHistory(ResponseWrapper> responseWrapper, - String languageCode, LocalDateTime eventReqDateTime, LocalDateTime fromDateTime, LocalDateTime toDateTime, - String serviceType, String statusFilter) throws ResidentServiceCheckedException, IOException; + String languageCode, LocalDateTime eventReqDateTime, LocalDate fromDateTime, LocalDate toDateTime, + String serviceType, String statusFilter) throws ResidentServiceCheckedException, IOException; public ResponseWrapper getUserinfo(String Id) throws ApisResourceAccessException; 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 c4c7b11a5da..20dfb5faa25 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 @@ -1,48 +1,7 @@ package io.mosip.resident.service.impl; -import static io.mosip.resident.constant.ResidentErrorCode.MACHINE_MASTER_CREATE_EXCEPTION; -import static io.mosip.resident.constant.ResidentErrorCode.PACKET_SIGNKEY_EXCEPTION; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.math.BigInteger; -import java.net.URI; -import java.nio.charset.StandardCharsets; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -import javax.annotation.PostConstruct; -import javax.persistence.EntityManager; -import javax.persistence.Query; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.json.simple.JSONObject; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpEntity; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Service; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.HttpServerErrorException; - import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; - import io.mosip.commons.khazana.exception.ObjectStoreAdapterException; import io.mosip.kernel.core.exception.BaseCheckedException; import io.mosip.kernel.core.http.ResponseWrapper; @@ -151,9 +110,49 @@ import io.mosip.resident.util.UINCardDownloadService; import io.mosip.resident.util.Utilities; import io.mosip.resident.util.Utilitiy; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.json.simple.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpEntity; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Service; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; import reactor.util.function.Tuple2; import reactor.util.function.Tuples; +import javax.annotation.PostConstruct; +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.math.BigInteger; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +import static io.mosip.resident.constant.ResidentErrorCode.MACHINE_MASTER_CREATE_EXCEPTION; +import static io.mosip.resident.constant.ResidentErrorCode.PACKET_SIGNKEY_EXCEPTION; + @Service public class ResidentServiceImpl implements ResidentService { @@ -1475,8 +1474,8 @@ public ResponseWrapper getAuthLockStatus(String in @Override public ResponseWrapper> getServiceHistory(Integer pageStart, Integer pageFetch, - LocalDateTime fromDateTime, LocalDateTime toDateTime, String serviceType, String sortType, - String statusFilter, String searchText, String langCode) + LocalDate fromDateTime, LocalDate toDateTime, String serviceType, String sortType, + String statusFilter, String searchText, String langCode) throws ResidentServiceCheckedException, ApisResourceAccessException { if (pageStart == null) { @@ -1603,8 +1602,8 @@ private DigitalCardStatusResponseDto getDigitalCardStatus(String individualId) } private ResponseWrapper> getServiceHistoryDetails(String sortType, - Integer pageStart, Integer pageFetch, LocalDateTime fromDateTime, LocalDateTime toDateTime, - String serviceType, String statusFilter, String searchText, String langCode) + Integer pageStart, Integer pageFetch, LocalDate fromDateTime, LocalDate toDateTime, + String serviceType, String statusFilter, String searchText, String langCode) throws ResidentServiceCheckedException, ApisResourceAccessException { ResponseWrapper> responseWrapper = new ResponseWrapper<>(); String idaToken = identityServiceImpl.getResidentIdaToken(); @@ -1618,8 +1617,8 @@ private ResponseWrapper> getServiceHistoryDet } public PageDto getServiceHistoryResponse(String sortType, Integer pageStart, - Integer pageFetch, String idaToken, String statusFilter, String searchText, LocalDateTime fromDateTime, - LocalDateTime toDateTime, String serviceType, String langCode) + Integer pageFetch, String idaToken, String statusFilter, String searchText, LocalDate fromDateTime, + LocalDate toDateTime, String serviceType, String langCode) throws ResidentServiceCheckedException { PositionalParams positionalParams = new PositionalParams(); String nativeQueryString = getDynamicNativeQueryString(sortType, idaToken, pageStart, pageFetch, statusFilter, @@ -1640,8 +1639,8 @@ public PageDto getServiceHistoryResponse(String sortT } public String getDynamicNativeQueryString(String sortType, String idaToken, Integer pageStart, Integer pageFetch, - String statusFilter, String searchText, LocalDateTime fromDateTime, LocalDateTime toDateTime, - String serviceType, PositionalParams positionalParams) { + String statusFilter, String searchText, LocalDate fromDateTime, LocalDate toDateTime, + String serviceType, PositionalParams positionalParams) { String query = "SELECT * FROM resident_transaction where token_id = " + positionalParams.add(idaToken); @@ -1701,8 +1700,11 @@ private String getServiceQuery(String serviceType, PositionalParams params ) { return " and request_type_code in (" + params.add(serviceTypeListString) + ")"; } - private String getDateQuery(LocalDateTime fromDateTime, LocalDateTime toDateTime, PositionalParams parameters ) { - return " and cr_dtimes between " + parameters.add(fromDateTime) + " and " + parameters.add(toDateTime); + private String getDateQuery(LocalDate fromDate, LocalDate toDate, PositionalParams parameters ) { + LocalDateTime fromDateTime = fromDate.atStartOfDay(); + LocalDateTime toDateTime = toDate.plusDays(1).atStartOfDay(); + return " and cr_dtimes between " + parameters.add(fromDateTime) + " and " + + parameters.add(toDateTime); } private String getSearchQuery(String searchText, PositionalParams params) { @@ -2053,8 +2055,8 @@ public ResponseWrapper> getUnreadnotifylist(S * create the template for service history PDF and converted template into PDF */ public byte[] downLoadServiceHistory(ResponseWrapper> responseWrapper, - String languageCode, LocalDateTime eventReqDateTime, LocalDateTime fromDateTime, LocalDateTime toDateTime, - String serviceType, String statusFilter) throws ResidentServiceCheckedException, IOException { + String languageCode, LocalDateTime eventReqDateTime, LocalDate fromDateTime, LocalDate toDateTime, + String serviceType, String statusFilter) throws ResidentServiceCheckedException, IOException { logger.debug("ResidentServiceImpl::getResidentServicePDF()::entry"); String requestProperty = this.env.getProperty(ResidentConstants.SERVICE_HISTORY_PROPERTY_TEMPLATE_TYPE_CODE); 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 89a1cb75080..d42788dd731 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 @@ -55,7 +55,7 @@ import javax.annotation.PostConstruct; import javax.validation.Valid; -import java.time.LocalDateTime; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -867,7 +867,7 @@ public void validateChannelVerificationStatus(String channel, String individualI } } - public void validateServiceHistoryRequest(LocalDateTime fromDateTime, LocalDateTime toDateTime, String sortType, String serviceType, String statusFilter) { + public void validateServiceHistoryRequest(LocalDate fromDateTime, LocalDate toDateTime, String sortType, String serviceType, String statusFilter) { validateServiceType(serviceType, "Request service history API"); validateSortType(sortType, "Request service history API"); validateStatusFilter(statusFilter, "Request service history API"); @@ -878,14 +878,7 @@ public void validateServiceHistoryRequest(LocalDateTime fromDateTime, LocalDateT } } - public void validateFromDateTimeToDateTime(LocalDateTime fromDateTime, LocalDateTime toDateTime, String request_service_history_api) { - if(fromDateTime != null && toDateTime != null) { - if(fromDateTime.isAfter(toDateTime)) { - audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, ResidentConstants.FROM_DATE_TIME, - request_service_history_api)); - throw new InvalidInputException(ResidentConstants.FROM_DATE_TIME); - } - } + public void validateFromDateTimeToDateTime(LocalDate fromDateTime, LocalDate toDateTime, String request_service_history_api) { if(fromDateTime == null && toDateTime != null) { audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, ResidentConstants.FROM_DATE_TIME, request_service_history_api)); @@ -910,7 +903,7 @@ private void validateStatusFilter(String statusFilter, String request_service_hi } } - private boolean isValidDate(LocalDateTime localDateTime) { + private boolean isValidDate(LocalDate localDateTime) { if(localDateTime!=null) { if (localDateTime.getYear() < 0 || localDateTime.getMonthValue() < 0 || localDateTime.getDayOfMonth() < 0) { return false; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java index 33e019b9c3d..1b12ba6dde5 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java @@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets; import java.security.PrivateKey; import java.security.PublicKey; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -353,8 +354,8 @@ public void testGetServiceHistorySuccess() throws Exception { ResponseWrapper> response = new ResponseWrapper<>(); Mockito.when(residentService.getServiceHistory(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(response); - residentController.getServiceHistory("eng", 1, 12, LocalDateTime.parse("2022-06-10T20:04:22.956607"), - LocalDateTime.parse("2022-06-10T20:04:22.956607"), SortType.ASC.toString(), + residentController.getServiceHistory("eng", 1, 12, LocalDate.parse("2022-06-10"), + LocalDate.parse("2022-06-10"), SortType.ASC.toString(), ServiceType.AUTHENTICATION_REQUEST.name(), null, null); mockMvc.perform(MockMvcRequestBuilders.get("/service-history/eng").contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().isOk()); 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 0301d52673e..abf76b28580 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 @@ -43,6 +43,7 @@ import java.io.IOException; import java.net.URI; import java.nio.charset.StandardCharsets; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.LinkedHashMap; import java.util.List; @@ -224,7 +225,7 @@ public void testDownloadServiceHistory() throws ResidentServiceCheckedException, Mockito.when(templateManager.merge(any(), any())).thenReturn(new ByteArrayInputStream("pdf".getBytes())); Mockito.when(utility.signPdf(any(), any())).thenReturn("pdf".getBytes(StandardCharsets.UTF_8)); byte[] pdfDocument = residentServiceImpl.downLoadServiceHistory(responseWrapper, "eng", - LocalDateTime.now(), LocalDateTime.now(), LocalDateTime.now(), + LocalDateTime.now(), LocalDate.now(), LocalDate.now(), String.valueOf(RequestType.DOWNLOAD_PERSONALIZED_CARD), "SUCCESS"); assertNotNull(pdfDocument); } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceGetServiceHistoryTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceGetServiceHistoryTest.java index f535a0b67f8..6252fae0007 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceGetServiceHistoryTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceGetServiceHistoryTest.java @@ -1,25 +1,5 @@ package io.mosip.resident.test.service; -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.math.BigInteger; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.Query; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit4.SpringRunner; - import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.resident.constant.EventStatus; import io.mosip.resident.constant.EventStatusSuccess; @@ -38,6 +18,25 @@ import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.Utilities; import io.mosip.resident.validator.RequestValidator; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.io.IOException; +import java.math.BigInteger; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; /** * This class is used to test the get service history service @@ -77,8 +76,8 @@ public class ResidentServiceGetServiceHistoryTest { private int pageStart; private int pageSize; - private LocalDateTime fromDate; - private LocalDateTime toDate; + private LocalDate fromDate; + private LocalDate toDate; private String serviceType; private String sortType; List serviceHistoryResponseDto; @@ -138,10 +137,10 @@ public void setup() throws ResidentServiceCheckedException, ApisResourceAccessEx public void testGetServiceHistorySuccess() throws ResidentServiceCheckedException, ApisResourceAccessException { pageStart = 2; pageSize = 3; - fromDate = LocalDateTime.now(); - toDate = LocalDateTime.now(); - assertEquals(3, residentServiceImpl.getServiceHistory(pageStart, pageSize, LocalDateTime.now(), LocalDateTime.now(), serviceType, sortType, statusFilter, searchText, "eng").getResponse().getPageSize()); - assertEquals(3, residentServiceImpl.getServiceHistory(pageStart, pageSize, LocalDateTime.now(), LocalDateTime.now(), serviceType, "DESC", statusFilter, searchText, "eng").getResponse().getPageSize()); + fromDate = LocalDate.now(); + toDate = LocalDate.now(); + assertEquals(3, residentServiceImpl.getServiceHistory(pageStart, pageSize, LocalDate.now(), LocalDate.now(), serviceType, sortType, statusFilter, searchText, "eng").getResponse().getPageSize()); + assertEquals(3, residentServiceImpl.getServiceHistory(pageStart, pageSize, LocalDate.now(), LocalDate.now(), serviceType, "DESC", statusFilter, searchText, "eng").getResponse().getPageSize()); } @Test @@ -199,8 +198,8 @@ public void testSortTypeNullCheck() throws ResidentServiceCheckedException, Apis public void testServiceHistoryWithDifferentParameters() throws ResidentServiceCheckedException, ApisResourceAccessException { pageStart = 1; pageSize = 10; - fromDate = LocalDateTime.MAX; - toDate = LocalDateTime.MIN; + fromDate = LocalDate.MAX; + toDate = LocalDate.MIN; serviceType = ServiceType.AUTHENTICATION_REQUEST.toString(); sortType = "ASC"; statusFilter = "SUCCESS"; diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestValidatorTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestValidatorTest.java index 6de6768beec..55f6999004c 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestValidatorTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/validator/RequestValidatorTest.java @@ -12,7 +12,26 @@ import io.mosip.resident.constant.IdType; import io.mosip.resident.constant.RequestIdType; import io.mosip.resident.constant.ResidentErrorCode; -import io.mosip.resident.dto.*; +import io.mosip.resident.dto.AidStatusRequestDTO; +import io.mosip.resident.dto.AuthHistoryRequestDTO; +import io.mosip.resident.dto.AuthLockOrUnLockRequestDto; +import io.mosip.resident.dto.AuthLockOrUnLockRequestDtoV2; +import io.mosip.resident.dto.AuthTypeStatusDtoV2; +import io.mosip.resident.dto.AuthUnLockRequestDTO; +import io.mosip.resident.dto.BaseVidRevokeRequestDTO; +import io.mosip.resident.dto.DownloadCardRequestDTO; +import io.mosip.resident.dto.DownloadPersonalizedCardDto; +import io.mosip.resident.dto.EuinRequestDTO; +import io.mosip.resident.dto.OtpRequestDTOV3; +import io.mosip.resident.dto.RequestDTO; +import io.mosip.resident.dto.RequestWrapper; +import io.mosip.resident.dto.ResidentReprintRequestDto; +import io.mosip.resident.dto.ResidentUpdateRequestDto; +import io.mosip.resident.dto.ResidentVidRequestDto; +import io.mosip.resident.dto.ResidentVidRequestDtoV2; +import io.mosip.resident.dto.VidRequestDto; +import io.mosip.resident.dto.VidRequestDtoV2; +import io.mosip.resident.dto.VidRevokeRequestDTOV2; import io.mosip.resident.exception.InvalidInputException; import io.mosip.resident.exception.ResidentServiceException; import io.mosip.resident.service.ResidentService; @@ -29,6 +48,7 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Date; @@ -1414,8 +1434,8 @@ public void testValidateChannelVerificationStatusSuccess() throws Exception{ @Test(expected = InvalidInputException.class) public void testValidateServiceHistoryRequest() throws Exception{ - LocalDateTime fromDate = LocalDateTime.now(); - LocalDateTime toDate = LocalDateTime.now(); + LocalDate fromDate = LocalDate.now(); + LocalDate toDate = LocalDate.now(); String sortType = ""; String serviceType = ""; requestValidator.validateServiceHistoryRequest(fromDate, toDate, sortType, sortType, sortType); @@ -1423,8 +1443,8 @@ public void testValidateServiceHistoryRequest() throws Exception{ @Test(expected = InvalidInputException.class) public void testValidateServiceHistoryRequestBadServiceType() throws Exception{ - LocalDateTime fromDate = LocalDateTime.now(); - LocalDateTime toDate = LocalDateTime.now(); + LocalDate fromDate = LocalDate.now(); + LocalDate toDate = LocalDate.now(); String sortType = ""; String serviceType = "BadServiceType"; requestValidator.validateServiceHistoryRequest(fromDate, toDate, sortType, sortType, sortType); @@ -1432,8 +1452,8 @@ public void testValidateServiceHistoryRequestBadServiceType() throws Exception{ @Test(expected = InvalidInputException.class) public void testValidateServiceHistoryRequestBadSortType() throws Exception{ - LocalDateTime fromDate = LocalDateTime.now(); - LocalDateTime toDate = LocalDateTime.now(); + LocalDate fromDate = LocalDate.now(); + LocalDate toDate = LocalDate.now(); String sortType = "BadSortType"; String serviceType = "DATA_SHARE_REQUEST"; requestValidator.validateServiceHistoryRequest(fromDate, toDate, sortType, sortType, sortType); @@ -1441,16 +1461,16 @@ public void testValidateServiceHistoryRequestBadSortType() throws Exception{ @Test(expected = InvalidInputException.class) public void testValidateServiceHistoryRequestNullSortType() throws Exception{ - LocalDateTime fromDate = LocalDateTime.now(); - LocalDateTime toDate = LocalDateTime.now(); + LocalDate fromDate = LocalDate.now(); + LocalDate toDate = LocalDate.now(); String serviceType = "DATA_SHARE_REQUEST"; requestValidator.validateServiceHistoryRequest(fromDate, toDate, null, null, serviceType); } @Test public void testValidateServiceHistoryRequestDateCheck() throws Exception{ - LocalDateTime fromDate = LocalDateTime.now(); - LocalDateTime toDate = LocalDateTime.now(); + LocalDate fromDate = LocalDate.now(); + LocalDate toDate = LocalDate.now(); String sortType = "ASC"; String serviceType = "DATA_SHARE_REQUEST"; requestValidator.validateServiceHistoryRequest(fromDate, toDate, sortType, serviceType, null); @@ -1458,8 +1478,8 @@ public void testValidateServiceHistoryRequestDateCheck() throws Exception{ @Test public void testValidateServiceHistoryRequestServiceHistoryServiceRequest() throws Exception{ - LocalDateTime fromDate = LocalDateTime.now(); - LocalDateTime toDate = LocalDateTime.now(); + LocalDate fromDate = LocalDate.now(); + LocalDate toDate = LocalDate.now(); String sortType = "ASC"; String serviceType = "SERVICE_REQUEST"; requestValidator.validateServiceHistoryRequest(fromDate, toDate, sortType, serviceType, null); @@ -1467,8 +1487,8 @@ public void testValidateServiceHistoryRequestServiceHistoryServiceRequest() thro @Test public void testValidateServiceHistoryRequestServiceHistoryID_MANAGEMENT_REQUEST() throws Exception{ - LocalDateTime fromDate = LocalDateTime.now(); - LocalDateTime toDate = LocalDateTime.now(); + LocalDate fromDate = LocalDate.now(); + LocalDate toDate = LocalDate.now(); String sortType = "ASC"; String serviceType = "ID_MANAGEMENT_REQUEST"; requestValidator.validateServiceHistoryRequest(fromDate, toDate, sortType, serviceType, null); @@ -1476,8 +1496,8 @@ public void testValidateServiceHistoryRequestServiceHistoryID_MANAGEMENT_REQUEST @Test public void testValidateServiceHistoryRequestServiceHistoryDATA_UPDATE_REQUEST() throws Exception{ - LocalDateTime fromDate = LocalDateTime.now(); - LocalDateTime toDate = LocalDateTime.now(); + LocalDate fromDate = LocalDate.now(); + LocalDate toDate = LocalDate.now(); String sortType = "ASC"; String serviceType = "DATA_UPDATE_REQUEST"; requestValidator.validateServiceHistoryRequest(fromDate, toDate, sortType, serviceType, null); @@ -1485,8 +1505,8 @@ public void testValidateServiceHistoryRequestServiceHistoryDATA_UPDATE_REQUEST() @Test public void testValidateServiceHistoryRequestServiceHistoryAUTHENTICATION_REQUEST() throws Exception{ - LocalDateTime fromDate = LocalDateTime.now(); - LocalDateTime toDate = LocalDateTime.now(); + LocalDate fromDate = LocalDate.now(); + LocalDate toDate = LocalDate.now(); String sortType = "ASC"; String serviceType = "AUTHENTICATION_REQUEST"; requestValidator.validateServiceHistoryRequest(fromDate, toDate, sortType, serviceType, null); @@ -1494,8 +1514,8 @@ public void testValidateServiceHistoryRequestServiceHistoryAUTHENTICATION_REQUES @Test public void testValidateServiceHistoryRequestServiceHistorySuccess() throws Exception{ - LocalDateTime fromDate = LocalDateTime.now(); - LocalDateTime toDate = LocalDateTime.now(); + LocalDate fromDate = LocalDate.now(); + LocalDate toDate = LocalDate.now(); String sortType = "DESC"; String serviceType = "AUTHENTICATION_REQUEST"; requestValidator.validateServiceHistoryRequest(fromDate, toDate, sortType, serviceType, null); @@ -1998,12 +2018,6 @@ public void testValidateSortType(){ ReflectionTestUtils.invokeMethod(requestValidator, "validateSortType", "D", "sortType"); } - @Test - public void testValidateLocalTime(){ - assertEquals(false,ReflectionTestUtils.invokeMethod(requestValidator, "isValidDate", LocalDateTime.of - (-1, 4, 4, 4, 4, 4))); - } - @Test(expected = InvalidInputException.class) public void testValidateStatusFilter(){ ReflectionTestUtils.invokeMethod(requestValidator, "validateStatusFilter", "", "sortType"); @@ -2011,17 +2025,12 @@ public void testValidateStatusFilter(){ @Test(expected = InvalidInputException.class) public void testValidateFromDateTimeToDateTimeFromDateTimeNull(){ - requestValidator.validateFromDateTimeToDateTime(null, LocalDateTime.MAX, "fromDate"); + requestValidator.validateFromDateTimeToDateTime(null, LocalDate.now(), "fromDate"); } @Test(expected = InvalidInputException.class) public void testValidateFromDateTimeToDateTimeToDateTimeNull(){ - requestValidator.validateFromDateTimeToDateTime(LocalDateTime.MAX, null, "fromDate"); - } - - @Test(expected = InvalidInputException.class) - public void testValidateFromDateTimeToDateTimeToDateTime(){ - requestValidator.validateFromDateTimeToDateTime(LocalDateTime.MAX, LocalDateTime.MIN, "fromDate"); + requestValidator.validateFromDateTimeToDateTime(LocalDate.MAX, null, "fromDate"); } @Test(expected = InvalidInputException.class) @@ -2207,9 +2216,9 @@ public void testValidateVidRevokeV2RequestEmptyRequestIdEmptyVidStatusSuccess() @Test(expected = InvalidInputException.class) public void testValidateServiceHistoryRequestServiceHistoryAUTHENTICATION_REQUESTInvalidDate() throws Exception{ - LocalDateTime fromDate = LocalDateTime.of - (-1, 4, 4, 4, 4, 4); - LocalDateTime toDate = LocalDateTime.now(); + LocalDate fromDate = LocalDate.of + (-1, 4, 4); + LocalDate toDate = LocalDate.now(); String sortType = "ASC"; String serviceType = "AUTHENTICATION_REQUEST"; requestValidator.validateServiceHistoryRequest(fromDate, toDate, sortType, serviceType, null); @@ -2217,9 +2226,9 @@ public void testValidateServiceHistoryRequestServiceHistoryAUTHENTICATION_REQUES @Test(expected = InvalidInputException.class) public void testValidateServiceHistoryRequestServiceHistoryAUTHENTICATION_REQUESTInvalidToDate() throws Exception{ - LocalDateTime toDate = LocalDateTime.of - (-1, 4, 4, 4, 4, 4); - LocalDateTime fromDate = LocalDateTime.now(); + LocalDate toDate = LocalDate.of + (-1, 4, 4); + LocalDate fromDate = LocalDate.now(); String sortType = "ASC"; String serviceType = "AUTHENTICATION_REQUEST"; requestValidator.validateServiceHistoryRequest(fromDate, toDate, sortType, serviceType, null); From 6243ac8d5d7f2f4e77c657fabe02a512c03808d3 Mon Sep 17 00:00:00 2001 From: kameshsr <47484458+kameshsr@users.noreply.github.com> Date: Mon, 19 Dec 2022 16:18:26 +0530 Subject: [PATCH 11/11] MOSIP-22046 corrected query param for service history api. (#623) * Fixed service history issue. * MOSIP-22046 change input LocalDateTime to LocalDate. * MOSIP-22046 Refactor code. * MOSIP-22046 Fixed test case failure. * MOSIP-22046 Covered edge case of fromDate. * MOSIP-22046 corrected query param for service history api. --- .../resident/controller/ResidentController.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java index dd54411b400..7b63fb94934 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java @@ -301,8 +301,8 @@ public ResponseWrapper checkAidStatus(@PathVariable(name public ResponseWrapper> getServiceHistory(@PathVariable("langcode") String langCode, @RequestParam(name = "pageStart", required = false) Integer pageStart, @RequestParam(name = "pageFetch", required = false) Integer pageFetch, - @RequestParam(name = "fromDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDateTime, - @RequestParam(name = "toDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate toDateTime, + @RequestParam(name = "fromDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDate, + @RequestParam(name = "toDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate toDate, @RequestParam(name = "sortType", required = false) String sortType, @RequestParam(name = "serviceType", required = false) String serviceType, @RequestParam(name = "statusFilter", required = false) String statusFilter, @@ -310,10 +310,10 @@ public ResponseWrapper> getServiceHistory(@Pa throws ResidentServiceCheckedException, ApisResourceAccessException { audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.VALIDATE_REQUEST, "getServiceHistory")); validator.validateOnlyLanguageCode(langCode); - validator.validateServiceHistoryRequest(fromDateTime, toDateTime, sortType, serviceType, statusFilter); + validator.validateServiceHistoryRequest(fromDate, toDate, sortType, serviceType, statusFilter); audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.GET_SERVICE_HISTORY, "getServiceHistory")); ResponseWrapper> responseWrapper = residentService.getServiceHistory( - pageStart, pageFetch, fromDateTime, toDateTime, serviceType, sortType, statusFilter, searchText, langCode); + pageStart, pageFetch, fromDate, toDate, serviceType, sortType, statusFilter, searchText, langCode); return responseWrapper; } @@ -538,8 +538,8 @@ public ResponseEntity downLoadServiceHistory( @RequestParam(name = "pageStart", required = false) Integer pageStart, @RequestParam(name = "pageFetch", required = false) Integer pageFetch, @RequestParam(name = "eventReqDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime eventReqDateTime, - @RequestParam(name = "fromDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDateTime, - @RequestParam(name = "toDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate toDateTime, + @RequestParam(name = "fromDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDate, + @RequestParam(name = "toDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate toDate, @RequestParam(name = "sortType", required = false) String sortType, @RequestParam(name = "serviceType", required = false) String serviceType, @RequestParam(name = "statusFilter", required = false) String statusFilter, @@ -551,10 +551,10 @@ public ResponseEntity downLoadServiceHistory( EventEnum.getEventEnumWithValue(EventEnum.DOWNLOAD_SERVICE_HISTORY, "acknowledgement")); validator.validateOnlyLanguageCode(languageCode); ResponseWrapper> responseWrapper = residentService.getServiceHistory( - pageStart, pageFetch, fromDateTime, toDateTime, serviceType, sortType, statusFilter, searchText, languageCode); + pageStart, pageFetch, fromDate, toDate, serviceType, sortType, statusFilter, searchText, languageCode); logger.debug("after response wrapper size of " + responseWrapper.getResponse().getData().size()); byte[] pdfBytes = residentService.downLoadServiceHistory(responseWrapper, languageCode, eventReqDateTime, - fromDateTime, toDateTime, serviceType, statusFilter); + fromDate, toDate, serviceType, statusFilter); InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(pdfBytes)); audit.setAuditRequestDto(EventEnum.DOWNLOAD_SERVICE_HISTORY_SUCCESS); logger.debug("AcknowledgementController::acknowledgement()::exit");