Skip to content

Commit

Permalink
added get status of individual id api. (#629)
Browse files Browse the repository at this point in the history
* Fixed service history issue.

* MOSIP-24939 Improved code coverage.

* MOSIP-24939 Improved code coverage.

* added get status of individual id api.

* added get status of individual id api.

* added get status of individual id api.
  • Loading branch information
kameshsr authored Dec 22, 2022
1 parent a9d9dd2 commit 0a30054
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,7 @@ private ResidentConstants() {
public static final String CHECK_STATUS_ID = "resident.checkstatus.id";
public static final String CHECK_STATUS_VERSION = "resident.checkstatus.version";

public static final String CHECK_STATUS_INDIVIDUAL_ID = "mosip.resident.checkstatus.individualid.id";
public static final String CHECKSTATUS_INDIVIDUALID_VERSION = "mosip.resident.checkstatus.individualid.version";

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import reactor.util.function.Tuple3;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Objects;

/**
Expand Down Expand Up @@ -71,10 +72,6 @@ public ResponseEntity<Object> downloadCard(@Validated @RequestBody MainRequestDT
Tuple3<byte[], String, ResponseWrapper<CheckStatusResponseDTO>> tupleResponse =
(Tuple3<byte[], String, ResponseWrapper<CheckStatusResponseDTO>>)
downloadCardService.getDownloadCardPDF(downloadCardRequestDTOMainRequestDTO);
ResponseWrapper<CheckStatusResponseDTO> checkStatusResponse = tupleResponse.getT3();
if(checkStatusResponse.getResponse() != null){
return ResponseEntity.badRequest().body(checkStatusResponse);
}
InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(tupleResponse.getT1()));
if(tupleResponse.getT1().length==0){
throw new CardNotReadyException();
Expand Down Expand Up @@ -117,4 +114,11 @@ public ResponseEntity<Object> requestVidCard(@PathVariable("VID") String vid) th
.header(ResidentConstants.EVENT_ID, tupleResponse.getT2())
.body(tupleResponse.getT1());
}

@GetMapping("/status/individualId/{individualId}")
public ResponseEntity<Object> getStatus(@PathVariable("individualId") String individualId) throws BaseCheckedException, IOException {
ResponseWrapper<CheckStatusResponseDTO> responseWrapper = downloadCardService.getIndividualIdStatus(individualId);
return ResponseEntity.ok()
.body(responseWrapper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

@Data
public class CheckStatusResponseDTO {
private String individualId;
private String transactionID;
private String transactionStage;
private String aidStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import io.mosip.resident.dto.MainRequestDTO;
import io.mosip.resident.dto.ResponseWrapper;
import io.mosip.resident.dto.VidDownloadCardResponseDto;
import io.mosip.resident.exception.ApisResourceAccessException;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuple3;

import java.io.IOException;

/**
* This class is used to create service class to download uin card.
* @Author Kamesh Shekhar Prasad
Expand All @@ -20,4 +23,6 @@ public interface DownloadCardService {
Tuple2<byte[], String> downloadPersonalizedCard(MainRequestDTO<DownloadPersonalizedCardDto> downloadPersonalizedCardMainRequestDTO);

Tuple2<ResponseWrapper<VidDownloadCardResponseDto>, String> getVidCardEventId(String vid) throws BaseCheckedException;

ResponseWrapper<CheckStatusResponseDTO> getIndividualIdStatus(String vid) throws ApisResourceAccessException, IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.List;
import java.util.Map;

import io.mosip.resident.constant.TransactionStage;
import io.mosip.resident.dto.CheckStatusResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
Expand Down Expand Up @@ -130,17 +129,7 @@ public Tuple3<byte[], String, ResponseWrapper<CheckStatusResponseDTO>> getDownlo
String idType = identityService.getIndividualIdType(individualId);
if (idType.equalsIgnoreCase(AID)) {
rid = individualId;
HashMap<String, String> packetStatusMap = utilities.getPacketStatus(rid);
String aidStatus = packetStatusMap.get(ResidentConstants.AID_STATUS);
String transactionStage = packetStatusMap.get(ResidentConstants.TRANSACTION_TYPE_CODE);
if(aidStatus.equalsIgnoreCase(EventStatus.SUCCESS.name()) &&
transactionStage.equalsIgnoreCase(CARD_READY_TO_DOWNLOAD)){
pdfBytes = residentService.getUINCard(rid);
} else{
checkStatusResponseDTOResponseWrapper =
getCheckStatusResponse(packetStatusMap,
downloadCardRequestDTOMainRequestDTO);
}
pdfBytes = residentService.getUINCard(rid);
} else if (idType.equalsIgnoreCase(VID)) {
ResidentTransactionEntity residentTransactionEntity = residentTransactionRepository.findTopByAidOrderByCrDtimesDesc(individualId);
if(residentTransactionEntity !=null ){
Expand Down Expand Up @@ -187,20 +176,16 @@ public Tuple3<byte[], String, ResponseWrapper<CheckStatusResponseDTO>> getDownlo
return Tuples.of(pdfBytes, eventId, checkStatusResponseDTOResponseWrapper);
}

private ResponseWrapper<CheckStatusResponseDTO> getCheckStatusResponse(HashMap<String, String> packetStatusMap,
MainRequestDTO<DownloadCardRequestDTO>
downloadCardRequestDTOMainRequestDTO) {
private ResponseWrapper<CheckStatusResponseDTO> getCheckStatusResponse(HashMap<String, String> packetStatusMap) {
ResponseWrapper<CheckStatusResponseDTO> checkStatusResponseDTOResponseWrapper = new ResponseWrapper<>();
CheckStatusResponseDTO checkStatusResponseDTO = new CheckStatusResponseDTO();
String aidStatus = packetStatusMap.get(ResidentConstants.AID_STATUS);
String transactionStage = packetStatusMap.get(ResidentConstants.TRANSACTION_TYPE_CODE);
checkStatusResponseDTO.setAidStatus(aidStatus);
checkStatusResponseDTO.setTransactionID(downloadCardRequestDTOMainRequestDTO.getRequest().getTransactionId());
checkStatusResponseDTO.setTransactionStage(transactionStage);
checkStatusResponseDTO.setIndividualId(downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId());
checkStatusResponseDTOResponseWrapper.setResponse(checkStatusResponseDTO);
checkStatusResponseDTOResponseWrapper.setId(this.environment.getProperty(ResidentConstants.CHECK_STATUS_ID));
checkStatusResponseDTOResponseWrapper.setVersion(this.environment.getProperty(ResidentConstants.CHECK_STATUS_VERSION));
checkStatusResponseDTOResponseWrapper.setId(this.environment.getProperty(ResidentConstants.CHECK_STATUS_INDIVIDUAL_ID));
checkStatusResponseDTOResponseWrapper.setVersion(this.environment.getProperty(ResidentConstants.CHECKSTATUS_INDIVIDUALID_VERSION));
return checkStatusResponseDTOResponseWrapper;
}

Expand Down Expand Up @@ -397,6 +382,12 @@ public Tuple2<ResponseWrapper<VidDownloadCardResponseDto>, String> getVidCardEve
return Tuples.of(responseWrapper, eventId);
}

@Override
public ResponseWrapper<CheckStatusResponseDTO> getIndividualIdStatus(String individualId) throws ApisResourceAccessException, IOException {
HashMap<String, String> packetStatusMap = utilities.getPacketStatus(individualId);
return getCheckStatusResponse(packetStatusMap);
}

private ResidentTransactionEntity insertDataForVidCard(String vid) throws ApisResourceAccessException, IOException {
ResidentTransactionEntity residentTransactionEntity = utilitiy.createEntity();
String uin = utilities.getUinByVid(vid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public void testGetDownloadCardPdfAID() throws ApisResourceAccessException, IOEx
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put(ResidentConstants.AID_STATUS, "SUCCESS");
hashMap.put(ResidentConstants.TRANSACTION_TYPE_CODE, "SUCCESS");
Mockito.when(utilities.getPacketStatus(Mockito.anyString())).thenReturn(hashMap);
Mockito.when(identityService.getIndividualIdType(Mockito.anyString())).thenReturn("AID");
Tuple2<byte[], String> actualResult = downloadCardService.getDownloadCardPDF(downloadCardRequestDTOMainRequestDTO);
assertNotNull(actualResult.getT1());
Expand Down

0 comments on commit 0a30054

Please sign in to comment.