Skip to content

Commit

Permalink
Mosip 24879 add event id in the response of the below stories (#614)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
RitikJain4108 and Ritik Jain authored Dec 15, 2022
1 parent e4e12d3 commit 19aab32
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -228,7 +230,7 @@ public ResponseWrapper<ResponseDTO> 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<ResponseDTO> reqAauthTypeStatusUpdateV2(
public ResponseEntity<Object> reqAauthTypeStatusUpdateV2(
@Valid @RequestBody RequestWrapper<AuthLockOrUnLockRequestDtoV2> requestDTO)
throws ResidentServiceCheckedException, ApisResourceAccessException {
audit.setAuditRequestDto(
Expand All @@ -237,11 +239,14 @@ public ResponseWrapper<ResponseDTO> reqAauthTypeStatusUpdateV2(
validator.validateAuthLockOrUnlockRequestV2(requestDTO);
audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.REQ_AUTH_LOCK, individualId));
ResponseWrapper<ResponseDTO> response = new ResponseWrapper<>();
response.setResponse(residentService.reqAauthTypeStatusUpdateV2(requestDTO.getRequest()));
Tuple2<ResponseDTO, String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand Down Expand Up @@ -116,15 +118,19 @@ public ResponseEntity<Object> requestShareCredWithPartner(
request.setRequest(credentialRequestDto);
buildAdditionalMetadata(requestDTO, request);
ResponseWrapper<ResidentCredentialResponseDtoV2> response = new ResponseWrapper<>();
Tuple2<ResidentCredentialResponseDtoV2, String> 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}")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@Data
public class ResidentCredentialResponseDtoV2 {

private String eventId;
private String status;

}
Original file line number Diff line number Diff line change
@@ -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<String,Object> metadata;

/**
* Constructor the initialize Handler exception
Expand All @@ -29,4 +35,17 @@ public ResidentCredentialServiceException(String errorCode, String errorMessage)
public ResidentCredentialServiceException(String errorCode, String errorMessage, Throwable rootCause) {
super(errorCode, errorMessage, rootCause);
}

public Map<String, Object> getMetadata() {
return metadata;
}

public void setMetadata(Map<String, Object> metadata) {
this.metadata = metadata;
}

public ResidentCredentialServiceException(ResidentErrorCode err, Throwable rootCause, Map<String, Object> metadata) {
this(err.getErrorCode(), err.getErrorMessage(), rootCause);
this.metadata = metadata;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ public void setMetadata(Map<String, Object> metadata) {

public ResidentServiceException(ResidentErrorCode err, Throwable rootCause, Map<String,Object> metadata) {
this(err, rootCause);
this.metadata=metadata;
this.metadata = metadata;
}

public ResidentServiceException(ResidentErrorCode err, Map<String, Object> metadata) {
this(err);
this.metadata = metadata;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
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 {

public ResidentCredentialResponseDto reqCredential(ResidentCredentialRequestDto request) throws ResidentServiceCheckedException;

public ResidentCredentialResponseDto reqCredential(ResidentCredentialRequestDto request, String id) throws ResidentServiceCheckedException;

public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequestDto request, String requestType) throws ResidentServiceCheckedException, ApisResourceAccessException;
public Tuple2<ResidentCredentialResponseDtoV2, String> shareCredential(ResidentCredentialRequestDto request, String requestType) throws ResidentServiceCheckedException, ApisResourceAccessException;

public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequestDto request, String requestType, String purpose) throws ResidentServiceCheckedException, ApisResourceAccessException;
public Tuple2<ResidentCredentialResponseDtoV2, String> shareCredential(ResidentCredentialRequestDto request, String requestType, String purpose) throws ResidentServiceCheckedException, ApisResourceAccessException;

public CredentialRequestStatusResponseDto getStatus(String requestId) throws ResidentServiceCheckedException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<ResponseDTO, String> reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 request)
throws ResidentServiceCheckedException, ApisResourceAccessException;

public ResponseWrapper<AuthLockOrUnLockRequestDtoV2> getAuthLockStatus(String individualId) throws ResidentServiceCheckedException;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,23 @@ public Tuple2<byte[], String> downloadPersonalizedCard(MainRequestDTO<DownloadPe
residentTransactionEntity.setStatusCode(EventStatusInProgress.NEW.name());
}
catch (Exception e) {
residentTransactionEntity.setRequestSummary(ResidentConstants.FAILED);
residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name());
if (residentTransactionEntity != null) {
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, Map.of(ResidentConstants.EVENT_ID, eventId));
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);
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);
}
}
return Tuples.of(utilitiy.signPdf(new ByteArrayInputStream(decodedData), password), eventId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
import io.mosip.resident.util.JsonUtil;
import io.mosip.resident.util.ResidentServiceRestClient;
import io.mosip.resident.util.Utilitiy;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

@Service
public class ResidentCredentialServiceImpl implements ResidentCredentialService {
Expand Down Expand Up @@ -221,13 +223,13 @@ public ResidentCredentialResponseDto reqCredential(ResidentCredentialRequestDto
}

@Override
public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequestDto dto, String requestType)
public Tuple2<ResidentCredentialResponseDtoV2, String> shareCredential(ResidentCredentialRequestDto dto, String requestType)
throws ResidentServiceCheckedException, ApisResourceAccessException {
return shareCredential(dto, requestType, null);
}

@Override
public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequestDto dto, String requestType,
public Tuple2<ResidentCredentialResponseDtoV2, String> shareCredential(ResidentCredentialRequestDto dto, String requestType,
String purpose) throws ResidentServiceCheckedException, ApisResourceAccessException {
ResidentCredentialResponseDto residentCredentialResponseDto = new ResidentCredentialResponseDto();
ResidentCredentialResponseDtoV2 residentCredentialResponseDtoV2=new ResidentCredentialResponseDtoV2();
Expand All @@ -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());
Expand Down Expand Up @@ -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.
Expand All @@ -304,7 +309,7 @@ public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequest
residentTransactionRepository.save(residentTransactionEntity);
}
}
return residentCredentialResponseDtoV2;
return Tuples.of(residentCredentialResponseDtoV2, eventId);
}

private ResidentTransactionEntity createResidentTransactionEntity(ResidentCredentialRequestDto dto,
Expand Down
Loading

0 comments on commit 19aab32

Please sign in to comment.