Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Mosip-39000 corrected print uin #1389

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public enum ApiName {
PACKETSIGNPUBLICKEY,
MACHINESEARCH,
MACHINECREATE,
MACHINEUPDATE,

PARTNER_API_URL, DECRYPT_API_URL, OTP_GEN_URL, POLICY_REQ_URL,

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.mosip.resident.dto;

/*
* @author Kamesh Shekhar Prasad
*/

import lombok.Data;

@Data
public class StatusResponseDto {

private String status;
}

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;

import io.mosip.resident.dto.*;
import io.mosip.resident.util.*;
import io.mosip.resident.validator.ValidateNewUpdateRequest;
import io.mosip.resident.validator.ValidateSameData;
Expand Down Expand Up @@ -86,53 +87,6 @@
import io.mosip.resident.constant.ServiceType;
import io.mosip.resident.constant.TemplateType;
import io.mosip.resident.constant.TemplateVariablesConstants;
import io.mosip.resident.dto.AidStatusRequestDTO;
import io.mosip.resident.dto.AidStatusResponseDTO;
import io.mosip.resident.dto.AuthHistoryRequestDTO;
import io.mosip.resident.dto.AuthHistoryResponseDTO;
import io.mosip.resident.dto.AuthLockOrUnLockRequestDto;
import io.mosip.resident.dto.AuthLockOrUnLockRequestDtoV2;
import io.mosip.resident.dto.AuthLockStatusResponseDtoV2;
import io.mosip.resident.dto.AuthTxnDetailsDTO;
import io.mosip.resident.dto.AuthTypeStatusDtoV2;
import io.mosip.resident.dto.AuthUnLockRequestDTO;
import io.mosip.resident.dto.BellNotificationDto;
import io.mosip.resident.dto.DocumentResponseDTO;
import io.mosip.resident.dto.EuinRequestDTO;
import io.mosip.resident.dto.EventStatusResponseDTO;
import io.mosip.resident.dto.IdResponseDTO1;
import io.mosip.resident.dto.IdentityDTO;
import io.mosip.resident.dto.MachineCreateRequestDTO;
import io.mosip.resident.dto.MachineCreateResponseDTO;
import io.mosip.resident.dto.MachineDto;
import io.mosip.resident.dto.MachineSearchRequestDTO;
import io.mosip.resident.dto.MachineSearchResponseDTO;
import io.mosip.resident.dto.NotificationRequestDto;
import io.mosip.resident.dto.NotificationRequestDtoV2;
import io.mosip.resident.dto.NotificationResponseDTO;
import io.mosip.resident.dto.PacketGeneratorResDto;
import io.mosip.resident.dto.PacketSignPublicKeyRequestDTO;
import io.mosip.resident.dto.PacketSignPublicKeyResponseDTO;
import io.mosip.resident.dto.PageDto;
import io.mosip.resident.dto.RegProcRePrintRequestDto;
import io.mosip.resident.dto.RegStatusCheckResponseDTO;
import io.mosip.resident.dto.RegistrationStatusRequestDTO;
import io.mosip.resident.dto.RegistrationStatusResponseDTO;
import io.mosip.resident.dto.RegistrationStatusSubRequestDto;
import io.mosip.resident.dto.RegistrationType;
import io.mosip.resident.dto.RequestDTO;
import io.mosip.resident.dto.ResidentDocuments;
import io.mosip.resident.dto.ResidentIndividialIDType;
import io.mosip.resident.dto.ResidentReprintRequestDto;
import io.mosip.resident.dto.ResidentReprintResponseDto;
import io.mosip.resident.dto.ResidentUpdateDto;
import io.mosip.resident.dto.ResidentUpdateRequestDto;
import io.mosip.resident.dto.ResidentUpdateResponseDTO;
import io.mosip.resident.dto.ResidentUpdateResponseDTOV2;
import io.mosip.resident.dto.ResponseDTO;
import io.mosip.resident.dto.ServiceHistoryResponseDto;
import io.mosip.resident.dto.UnreadNotificationDto;
import io.mosip.resident.dto.UserInfoDto;
import io.mosip.resident.entity.ResidentSessionEntity;
import io.mosip.resident.entity.ResidentTransactionEntity;
import io.mosip.resident.entity.ResidentUserEntity;
Expand All @@ -157,6 +111,7 @@
import io.mosip.resident.service.NotificationService;
import io.mosip.resident.service.PartnerService;
import io.mosip.resident.service.ResidentService;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

Expand Down Expand Up @@ -545,7 +500,7 @@ public ResidentReprintResponseDto reqPrintUin(ResidentReprintRequestDto dto)
RegProcRePrintRequestDto rePrintReq = new RegProcRePrintRequestDto();
rePrintReq.setCardType(dto.getCardType());
rePrintReq.setCenterId(centerId);
rePrintReq.setMachineId(machineId);
rePrintReq.setMachineId(getMachineId());
rePrintReq.setId(dto.getIndividualId());
rePrintReq.setIdType(dto.getIndividualIdType());
rePrintReq.setReason("resident");
Expand Down Expand Up @@ -862,20 +817,11 @@ public Tuple2<Object, String> reqUinUpdate(ResidentUpdateRequestDto dto, JSONObj
logger.debug(AuditEnum.VALIDATE_OTP_SUCCESS.getDescription(), dto.getTransactionID());
}

final String publicKey = getPublicKeyFromKeyManager();
MachineSearchResponseDTO machineSearchResponseDTO = searchMachineInMasterService(residentMachinePrefix,
publicKey);
String machineId = getMachineId(machineSearchResponseDTO, publicKey);
if (machineId == null) {
machineId = createNewMachineInMasterService(residentMachinePrefix, machineSpecId, zoneCode, centerId,
publicKey);
}

ResidentUpdateDto regProcReqUpdateDto = new ResidentUpdateDto();
regProcReqUpdateDto.setIdValue(dto.getIndividualId());
regProcReqUpdateDto.setIdType(ResidentIndividialIDType.valueOf(dto.getIndividualIdType().toUpperCase()));
regProcReqUpdateDto.setCenterId(centerId);
regProcReqUpdateDto.setMachineId(machineId);
regProcReqUpdateDto.setMachineId(getMachineId());
JSONObject jsonObject = new JSONObject();
jsonObject.put(IDENTITY, demographicIdentity);
String encodedIdentityJson = CryptoUtil.encodeToURLSafeBase64(jsonObject.toJSONString().getBytes());
Expand Down Expand Up @@ -1079,6 +1025,45 @@ public Tuple2<Object, String> reqUinUpdate(ResidentUpdateRequestDto dto, JSONObj
return Tuples.of(responseDto, eventId);
}

private String getMachineId() throws ApisResourceAccessException {
final String publicKey = getPublicKeyFromKeyManager();
MachineSearchResponseDTO machineSearchResponseDTO = searchMachineInMasterService(residentMachinePrefix,
publicKey);
String machineId = getMachineIdIfExists(machineSearchResponseDTO, publicKey);
if (machineId == null) {
machineId = createNewMachineInMasterService(residentMachinePrefix, machineSpecId, zoneCode, centerId,
publicKey);
}
activateMachineId(machineId);
return machineId;
}

private void activateMachineId(String machineId) throws ApisResourceAccessException {
try {
String baseUrl = env.getProperty(ApiName.MACHINEUPDATE.name());

String apiUrl = UriComponentsBuilder.fromHttpUrl(baseUrl)
.queryParam("id", machineId)
.queryParam("isActive", true)
.toUriString();

ResponseWrapper<StatusResponseDto> response =
residentServiceRestClient.patchApi(apiUrl, MediaType.APPLICATION_JSON, null,
ResponseWrapper.class);

if (response.getErrors() != null && !response.getErrors().isEmpty()) {
throw new ResidentMachineServiceException(response.getErrors().get(0).getErrorCode(),
response.getErrors().get(0).getMessage());
}
} catch (Exception e) {
logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(),
residentMachinePrefix, "ResidentServiceImpl::reqUinUpdate():: activateMachineId Patch service call"
+ ExceptionUtils.getStackTrace(e));
throw new ApisResourceAccessException("Could not activate machines in master data", e);
}
}


private void sendFailureNotification(ResidentTransactionEntity residentTransactionEntity, ResidentUpdateRequestDto dto, JSONObject idRepoJson) throws ResidentServiceCheckedException {
if (Utility.isSecureSession()) {
residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name());
Expand Down Expand Up @@ -1369,7 +1354,7 @@ private MachineSearchResponseDTO searchMachineInMasterService(String residentMac
return machineSearchResponseDTO;
}

private String getMachineId(MachineSearchResponseDTO machineSearchResponseDTO, final String publicKey) {
private String getMachineIdIfExists(MachineSearchResponseDTO machineSearchResponseDTO, final String publicKey) {
if (machineSearchResponseDTO.getResponse() != null) {
List<MachineDto> fetchedMachines = machineSearchResponseDTO.getResponse().getData();
if (fetchedMachines != null && !fetchedMachines.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import io.mosip.resident.constant.ApiName;
import io.mosip.resident.util.Utilities;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -16,7 +20,9 @@
import org.mockito.Mockito;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
Expand All @@ -31,6 +37,9 @@
import io.mosip.resident.dto.ResidentReprintRequestDto;
import io.mosip.resident.dto.ResidentReprintResponseDto;
import io.mosip.resident.dto.ResponseWrapper;
import io.mosip.resident.dto.MachineDto;
import io.mosip.resident.dto.MachineSearchResponseDTO;
import io.mosip.resident.dto.PacketSignPublicKeyResponseDTO;
import io.mosip.resident.exception.ApisResourceAccessException;
import io.mosip.resident.exception.OtpValidationFailedException;
import io.mosip.resident.exception.ResidentServiceCheckedException;
Expand Down Expand Up @@ -67,6 +76,9 @@ public class ResidentServiceReqReprintTest {

@Mock
NotificationService notificationService;

@Mock
private Utilities utilities;

private ResidentReprintRequestDto residentReqDto;

Expand All @@ -87,7 +99,7 @@ public void setUp() throws IOException, BaseCheckedException {
}

@Test
public void reqPrintUinTest() throws ResidentServiceCheckedException {
public void reqPrintUinTest() throws ResidentServiceCheckedException, ApisResourceAccessException {

RegProcCommonResponseDto reprintResp = new RegProcCommonResponseDto();
reprintResp.setMessage("sent to packet receiver");
Expand All @@ -96,6 +108,47 @@ public void reqPrintUinTest() throws ResidentServiceCheckedException {
NotificationResponseDTO notificationResponse = new NotificationResponseDTO();
notificationResponse.setMessage("Notification sent to registered contact details");
notificationResponse.setStatus("success");

String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGXPqbFOIZhB_N_fbTXOMIsRgq_LMdL9DJ5kWYAneCj_LPw3OEm2ncLVIRyJsF2DcSQwvzt_Njdvg1Cr54nD1uHBu3Vt9G1sy3p6uwbeK1l5mJSMNe5oGe11fmehtsR2QcB_45_us_IiiiUzzHJrySexmDfdOiPdy-dID4DYRDAf-HXlMIEf4Di_8NV3wVrA3jq1tuNkXX3qKtM4NhZOihp0HmB9E7RHttSV9VJNh00BrC57qdMfa5xqsHok3qftU5SAan4BGuPklN2fzOVcsa-V-B8JbwxRfPdwMkq-jW7Eu1LcNhNVQYJGEWDLAQDGKY_fOB_YwBzn8xvYRjqSfQIDAQAB";
List<MachineDto> machineDtos = new ArrayList<>();
MachineDto machineDto = new MachineDto();
machineDto.setMachineSpecId("1001");
machineDto.setIsActive(false);
machineDto.setId("10147");
machineDto.setName("resident_machine_1640777004542");
machineDto.setValidityDateTime("2024-12-29T11:23:24.541Z");
machineDto.setPublicKey(publicKey);
machineDto.setSignPublicKey(publicKey);
machineDtos.add(machineDto);
MachineSearchResponseDTO.MachineSearchDto response = MachineSearchResponseDTO.MachineSearchDto.builder()
.fromRecord(0).toRecord(0).toRecord(0).data(machineDtos).build();
MachineSearchResponseDTO machineSearchResponseDTO = new MachineSearchResponseDTO();
machineSearchResponseDTO.setId("null");
machineSearchResponseDTO.setVersion("1.0");
machineSearchResponseDTO.setResponsetime("2022-01-28T06:25:23.958Z");
machineSearchResponseDTO.setResponse(response);

PacketSignPublicKeyResponseDTO responseDto = new PacketSignPublicKeyResponseDTO();
PacketSignPublicKeyResponseDTO.PacketSignPublicKeyResponse publicKeyResponse = new PacketSignPublicKeyResponseDTO.PacketSignPublicKeyResponse();
publicKeyResponse.setPublicKey(publicKey);
responseDto.setId(null);
responseDto.setVersion(null);
responseDto.setResponsetime("2022-01-28T06:51:30.286Z");
responseDto.setResponse(publicKeyResponse);
responseDto.setErrors(new ArrayList<>());

Mockito.when(env.getProperty(ApiName.PACKETSIGNPUBLICKEY.name())).thenReturn("PACKETSIGNPUBLICKEY");
Mockito.when(env.getProperty(ApiName.MACHINESEARCH.name())).thenReturn("MACHINESEARCH");
Mockito.when(env.getProperty(ApiName.MACHINEUPDATE.name())).thenReturn("http://localhost");

Mockito.when(residentServiceRestClient.postApi(eq("PACKETSIGNPUBLICKEY"), any(MediaType.class),
any(HttpEntity.class), eq(PacketSignPublicKeyResponseDTO.class))).thenReturn(responseDto);
Mockito.when(residentServiceRestClient.postApi(eq("MACHINESEARCH"), any(MediaType.class), any(HttpEntity.class),
eq(MachineSearchResponseDTO.class))).thenReturn(machineSearchResponseDTO);
when(residentServiceRestClient.patchApi(any(), any(), any(), any())).thenReturn(new io.mosip.kernel.core.http.ResponseWrapper<>());

when(utilities.getLanguageCode()).thenReturn("eng");

Mockito.when(notificationService.sendNotification(any(), Mockito.nullable(Map.class))).thenReturn(notificationResponse);
ResidentReprintResponseDto residentResponse = residentServiceImpl.reqPrintUin(residentReqDto);
assertEquals("10008200070004620191203115734", residentResponse.getRegistrationId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ public void setUp() throws BaseCheckedException, IOException {
notificationResponse.setStatus("success");
Mockito.when(notificationService.sendNotification(any(), Mockito.nullable(Map.class))).thenReturn(notificationResponse);

Mockito.when(env.getProperty(ApiName.MACHINEUPDATE.name())).thenReturn("http://localhost");
when(residentServiceRestClient.patchApi(any(), any(), any(), any())).thenReturn(new io.mosip.kernel.core.http.ResponseWrapper<>());

String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGXPqbFOIZhB_N_fbTXOMIsRgq_LMdL9DJ5kWYAneCj_LPw3OEm2ncLVIRyJsF2DcSQwvzt_Njdvg1Cr54nD1uHBu3Vt9G1sy3p6uwbeK1l5mJSMNe5oGe11fmehtsR2QcB_45_us_IiiiUzzHJrySexmDfdOiPdy-dID4DYRDAf-HXlMIEf4Di_8NV3wVrA3jq1tuNkXX3qKtM4NhZOihp0HmB9E7RHttSV9VJNh00BrC57qdMfa5xqsHok3qftU5SAan4BGuPklN2fzOVcsa-V-B8JbwxRfPdwMkq-jW7Eu1LcNhNVQYJGEWDLAQDGKY_fOB_YwBzn8xvYRjqSfQIDAQAB";
List<MachineDto> machineDtos = new ArrayList<>();
MachineDto machineDto = new MachineDto();
Expand Down