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

Introducing Tracking Mechanism to track RID Stage Process and restric… #1986

Open
wants to merge 6 commits into
base: release-1.2.0.x
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import javax.jms.Message;
Expand Down Expand Up @@ -491,7 +492,7 @@ public void consumerListener(Message message, String abisInBoundAddress, MosipQu
"AbisMiddlewareStage::consumerListener()::All identify are requests processed sending to Abis handler");

sendToAbisHandler(eventBus, bioRefId, registrationId, internalRegStatusDto.getRegistrationType(),
internalRegStatusDto.getIteration(), internalRegStatusDto.getWorkflowInstanceId());
internalRegStatusDto.getIteration(), internalRegStatusDto.getWorkflowInstanceId(), internalRegStatusDto.getLatestTransactionFlowId());

}
} else {
Expand Down Expand Up @@ -770,7 +771,7 @@ private boolean checkAllIdentifyRequestsProcessed(String batchId) {
}

private void sendToAbisHandler(MosipEventBus eventBus, List<String> bioRefId,
String regId, String regType, int iteration, String workflowInstanceId) {
String regId, String regType, int iteration, String workflowInstanceId, String transactionFlowId) {
if (bioRefId != null) {
MessageDTO messageDto = new MessageDTO();
messageDto.setRid(regId);
Expand All @@ -779,6 +780,8 @@ private void sendToAbisHandler(MosipEventBus eventBus, List<String> bioRefId,
messageDto.setInternalError(Boolean.FALSE);
messageDto.setIteration(iteration);
messageDto.setWorkflowInstanceId(workflowInstanceId);
messageDto.setTransactionFlowId(transactionFlowId);
messageDto.setTransactionId(UUID.randomUUID().toString());
regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), "",
"AbisMiddlewareStage::consumerListener()::sending to Abis handler");
this.send(eventBus, MessageBusAddress.ABIS_MIDDLEWARE_BUS_OUT, messageDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ && isValidCbeff(object)) {
} else {
regProcLogger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
registrationId, "Duplicate request received for same latest transaction id. This will be ignored.");
object.setIsValid(false);
object.setInternalError(true);
object=null;
}
}
return object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class BiometricExtractionStage extends MosipVerticleAPIManager{
private Long messageExpiryTimeLimit;

/** worker pool size. */
@Value("${worker.pool.size}")
@Value("${biometric.extraction.worker.pool.size:20}")
private Integer workerPoolSize;

/**partner policy ids */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public boolean updatePacketStatus(ManualAdjudicationResponseDTO manualVerificati
messageDTO.setIsValid(false);
messageDTO.setRid(regId);
messageDTO.setReg_type(registrationStatusDto.getRegistrationType());
messageDTO.setTransactionFlowId(registrationStatusDto.getLatestTransactionFlowId());
messageDTO.setTransactionId(UUID.randomUUID().toString());

List<ManualVerificationEntity> entities = retrieveInqueuedRecordsByRid(regId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ public boolean updatePacketStatus(VerificationResponseDTO manualVerificationDTO,
messageDTO.setIsValid(false);
messageDTO.setRid(regId);
messageDTO.setReg_type(registrationStatusDto.getRegistrationType());
messageDTO.setTransactionFlowId(registrationStatusDto.getLatestTransactionFlowId());
messageDTO.setTransactionId(UUID.randomUUID().toString());

List<VerificationEntity> entities = retrieveInqueuedRecordsByRid(regId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public MessageDTO process(MessageDTO object) {
registrationStatusDto.getLatestRegistrationTransactionId(),
registrationStatusDto.getLatestTransactionTypeCode(), "updated registration status record",
registrationStatusDto.getLatestTransactionStatusCode(), registrationStatusDto.getStatusComment(),
registrationStatusDto.getSubStatusCode());
registrationStatusDto.getSubStatusCode(), registrationStatusDto.getLatestTransactionFlowId());
transactionDto.setReferenceId(registrationStatusDto.getRegistrationId());
transactionDto.setReferenceIdType(MessageSenderConstant.REFERENCE_TYPE_ID);
transactionStatusService.addRegistrationTransaction(transactionDto);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package io.mosip.registration.processor.transaction.api.controller;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

import javax.servlet.http.HttpServletRequest;

import com.google.gson.Gson;
import io.mosip.kernel.core.exception.ExceptionUtils;
import io.mosip.registration.processor.core.code.RegistrationTransactionStatusCode;
import io.mosip.registration.processor.core.http.RequestWrapper;
import io.mosip.registration.processor.core.http.ResponseWrapper;
import io.mosip.registration.processor.core.tracker.dto.TrackRequestDto;
import io.mosip.registration.processor.core.tracker.dto.TrackResponseDto;
import io.mosip.registration.processor.status.entity.TrackerEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
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;
import org.springframework.web.bind.annotation.*;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -77,38 +85,44 @@ public class RegistrationTransactionController {

/**
* get transaction details for the given registration id
*
* @param rid registration id
* @param request servlet request
*
* @return list of RegTransactionResponseDTOs
* @throws Exception
*/
@PreAuthorize("hasAnyRole(@authorizedTransactionRoles.getGetsearchrid())")
@PreAuthorize("hasAnyRole(@authorizedTransactionRoles.getGettransactionallowed())")
//@PreAuthorize("hasAnyRole('REGISTRATION_PROCESSOR','REGISTRATION_ADMIN')")
@GetMapping(path = "/search/{rid}")
@Operation(summary = "Get the transaction entity/entities", description = "Get the transaction entity/entities", tags = { "Registration Status" })
@PostMapping(path = "/track/transaction", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Track Transaction Id from entity", description = "Track Transaction Id from entity", tags = { "Registration Track" })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Transaction Entity/Entities successfully fetched"),
@ApiResponse(responseCode = "200", description = "Track Transaction successful"),
@ApiResponse(responseCode = "400", description = "Unable to fetch Transaction Entity/Entities" ,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 ResponseEntity<RegTransactionResponseDTO> getTransactionsbyRid(@PathVariable("rid") String rid,
HttpServletRequest request) throws Exception {
List<RegistrationTransactionDto> dtoList;
HttpHeaders headers = new HttpHeaders();
public ResponseEntity<ResponseWrapper> getTrackInfo(@RequestBody RequestWrapper<TrackRequestDto> request) throws Exception {
try {
dtoList = transactionService.getTransactionByRegId(rid);
RegTransactionResponseDTO responseDTO=buildRegistrationTransactionResponse(dtoList);
if (isEnabled) {
headers.add(RESPONSE_SIGNATURE,
digitalSignatureUtility.getDigitalSignature(buildSignatureRegistrationTransactionResponse(responseDTO)));
return ResponseEntity.status(HttpStatus.OK).headers(headers).body(responseDTO);
ResponseWrapper<TrackResponseDto> responseWrapper = new ResponseWrapper<>();
responseWrapper.setResponsetime(LocalDateTime.now());
responseWrapper.setVersion("1.0");

TrackRequestDto trackRequestDto = request.getRequest();
TrackResponseDto responseDto = new TrackResponseDto();
responseDto.setRegid(trackRequestDto.getRegid());
responseDto.setTransactionId(trackRequestDto.getTransactionId());
responseDto.setTransactionFlowId(trackRequestDto.getTransactionFlowId());
TrackerEntity entity = transactionService.isTransactionExist(trackRequestDto.getRegid(), trackRequestDto.getTransactionId(), trackRequestDto.getTransactionFlowId());

if(entity.getStatusCode().equals(RegistrationTransactionStatusCode.IN_PROGRESS.toString()) || entity.getStatusCode().equals(RegistrationTransactionStatusCode.PROCESSED.toString())) {
responseDto.setTransactionAllowed(false);
} else {
responseDto.setTransactionAllowed(true);
}
return ResponseEntity.status(HttpStatus.OK).body(responseDTO);
responseWrapper.setResponse(responseDto);
return new ResponseEntity<ResponseWrapper>(responseWrapper, HttpStatus.OK);
}catch (Exception e) {
if( e instanceof InvalidTokenException |e instanceof AccessDeniedException | e instanceof RegTransactionAppException
| e instanceof TransactionsUnavailableException | e instanceof TransactionTableNotAccessibleException | e instanceof JsonProcessingException ) {
regProcLogger.error("Error While Processing Tracker" + ExceptionUtils.getStackTrace(e));
throw e;
}
else {
Expand Down Expand Up @@ -152,4 +166,90 @@ private String buildSignatureRegistrationTransactionResponse(RegTransactionRespo


}

@PreAuthorize("hasAnyRole(@authorizedTransactionRoles.getGetsearchrid())")
//@PreAuthorize("hasAnyRole('REGISTRATION_PROCESSOR','REGISTRATION_ADMIN')")
@GetMapping(path = "/search/{rid}")
@Operation(summary = "Get the transaction entity/entities", description = "Get the transaction entity/entities", tags = { "Registration Status" })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Transaction Entity/Entities successfully fetched"),
@ApiResponse(responseCode = "400", description = "Unable to track Transaction" ,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 ResponseEntity<RegTransactionResponseDTO> getTransactionsbyRid(@PathVariable("rid") String rid,
HttpServletRequest request) throws Exception {
List<RegistrationTransactionDto> dtoList;
HttpHeaders headers = new HttpHeaders();
try {
dtoList = transactionService.getTransactionByRegId(rid);
RegTransactionResponseDTO responseDTO=buildRegistrationTransactionResponse(dtoList);
if (isEnabled) {
headers.add(RESPONSE_SIGNATURE,
digitalSignatureUtility.getDigitalSignature(buildSignatureRegistrationTransactionResponse(responseDTO)));
return ResponseEntity.status(HttpStatus.OK).headers(headers).body(responseDTO);
}
return ResponseEntity.status(HttpStatus.OK).body(responseDTO);
}catch (Exception e) {
if( e instanceof InvalidTokenException |e instanceof AccessDeniedException | e instanceof RegTransactionAppException
| e instanceof TransactionsUnavailableException | e instanceof TransactionTableNotAccessibleException | e instanceof JsonProcessingException ) {
throw e;
}
else {
throw new RegTransactionAppException(PlatformErrorMessages.RPR_RTS_UNKNOWN_EXCEPTION.getCode(),
PlatformErrorMessages.RPR_RTS_UNKNOWN_EXCEPTION.getMessage()+" -->"+e.getMessage());
}
}
}

/**
* get transaction details for the given registration id
*
* @return list of RegTransactionResponseDTOs
* @throws Exception
*/
@PreAuthorize("hasAnyRole(@authorizedTransactionRoles.getGettransactionallowed())")
//@PreAuthorize("hasAnyRole('REGISTRATION_PROCESSOR','REGISTRATION_ADMIN')")
@PostMapping(path = "/update/transaction", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Track Transaction Id from entity", description = "Track Transaction Id from entity", tags = { "Registration Track" })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Track Transaction successful"),
@ApiResponse(responseCode = "400", description = "Unable to fetch Transaction Entity/Entities" ,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 ResponseEntity<ResponseWrapper> updateTransactionStatus(@RequestBody RequestWrapper<TrackRequestDto> request) throws Exception {
try {
ResponseWrapper<TrackResponseDto> responseWrapper = new ResponseWrapper<>();
responseWrapper.setResponsetime(LocalDateTime.now());
responseWrapper.setVersion("1.0");

TrackRequestDto trackRequestDto = request.getRequest();
TrackResponseDto responseDto = new TrackResponseDto();
responseDto.setTransactionId(trackRequestDto.getTransactionId());
regProcLogger.info("Request for Track Update" + (new Gson()).toJson(trackRequestDto));

TrackerEntity entity = transactionService.updateTransactionComplete(trackRequestDto.getTransactionId(), trackRequestDto.getStatusCode());

if(entity.getStatusCode().equals(trackRequestDto.getStatusCode())) {
responseDto.setTransactionAllowed(true);
} else {
responseDto.setTransactionAllowed(false);
}
regProcLogger.info("Response for Track Update" + (new Gson()).toJson(responseDto));

responseWrapper.setResponse(responseDto);
return new ResponseEntity<ResponseWrapper>(responseWrapper, HttpStatus.OK);
}catch (Exception e) {
if( e instanceof InvalidTokenException |e instanceof AccessDeniedException | e instanceof RegTransactionAppException
| e instanceof TransactionsUnavailableException | e instanceof TransactionTableNotAccessibleException | e instanceof JsonProcessingException ) {
regProcLogger.error("Error While Processing Tracker" + ExceptionUtils.getStackTrace(e));
throw e;
}
else {
throw new RegTransactionAppException(PlatformErrorMessages.RPR_RTS_UNKNOWN_EXCEPTION.getCode(),
PlatformErrorMessages.RPR_RTS_UNKNOWN_EXCEPTION.getMessage()+" -->"+e.getMessage());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class AuthorizedRolesDto {

private List<String> getsearchrid;

private List<String> gettransactionallowed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void setUp() {
public void testSyncController() throws Exception {
List<RegistrationTransactionDto> dtoList = new ArrayList<>();
dtoList.add(new RegistrationTransactionDto("id", "registrationId", "transactionTypeCode", "parentTransactionId",
"statusCode", "subStatusCode", "statusComment", null));
"statusCode", "subStatusCode", "statusComment", null, null));
Mockito.when(transactionService.getTransactionByRegId(ArgumentMatchers.any()))
.thenReturn(dtoList);
this.mockMvc.perform(get("/search/27847657360002520190320095010").accept(MediaType.APPLICATION_JSON_VALUE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ public MessageDTO process(MessageDTO object, String stageName) {
// save audit details
InternalRegistrationStatusDto finalRegistrationStatusDto = registrationStatusDto;
String finalRegistrationId = registrationId;
Runnable r = () -> {
try {
auditUtility.saveAuditDetails(finalRegistrationId,
finalRegistrationStatusDto.getRegistrationType());
Expand All @@ -217,10 +216,7 @@ public MessageDTO process(MessageDTO object, String stageName) {
description.getCode() + " Inside Runnable ", "");

}
};
ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
es.submit(r);
es.shutdown();

registrationStatusDto
.setLatestTransactionStatusCode(RegistrationTransactionStatusCode.SUCCESS.toString());
object.setIsValid(Boolean.TRUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class AuditUtility {
*
*
*/
@Async
//@Async
public void saveAuditDetails(String registrationId, String process) {
try {
regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
package io.mosip.registration.processor.stages.utils;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import io.mosip.kernel.biometrics.commons.CbeffValidator;
import io.mosip.kernel.biometrics.constant.BiometricType;
import io.mosip.kernel.biometrics.constant.ProcessedLevelType;
import io.mosip.kernel.biometrics.constant.PurposeType;
import io.mosip.kernel.biometrics.constant.QualityType;
import io.mosip.kernel.biometrics.entities.BDBInfo;
import io.mosip.kernel.biometrics.entities.BIR;
import io.mosip.kernel.biometrics.entities.BIRInfo;
import io.mosip.kernel.biometrics.entities.BiometricRecord;
import io.mosip.kernel.biometrics.entities.RegistryIDType;
import io.mosip.kernel.biometrics.entities.VersionType;
import io.mosip.kernel.cbeffutil.container.impl.CbeffContainerImpl;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.InputStream;
import java.net.URL;

@Component
public class BiometricsXSDValidator {

Expand All @@ -30,12 +20,17 @@ public class BiometricsXSDValidator {
@Value("${mosip.kernel.xsdfile}")
private String schemaFileName;

private byte[] xsd = null;

public void validateXSD(BiometricRecord biometricRecord ) throws Exception {
try (InputStream xsd = new URL(configServerFileStorageURL + schemaFileName).openStream()) {
CbeffContainerImpl cbeffContainer = new CbeffContainerImpl();
BIR bir = cbeffContainer.createBIRType(biometricRecord.getSegments());
CbeffValidator.createXMLBytes(bir, IOUtils.toByteArray(xsd));//validates XSD
if(xsd==null) {
try (InputStream inputStream = new URL(configServerFileStorageURL + schemaFileName).openStream()) {
xsd = IOUtils.toByteArray(inputStream);
}
}
CbeffContainerImpl cbeffContainer = new CbeffContainerImpl();
BIR bir = cbeffContainer.createBIRType(biometricRecord.getSegments());
CbeffValidator.createXMLBytes(bir, xsd);//validates XSD
}


Expand Down
Loading