Skip to content
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
6 changes: 0 additions & 6 deletions biosdk-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,6 @@
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.mosip.biosdk.services.controller;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.mosip.biosdk.services.config.LoggerConfig;
import io.mosip.biosdk.services.constants.ErrorMessages;
import io.mosip.biosdk.services.dto.*;
Expand Down Expand Up @@ -51,8 +50,6 @@ public class MainController {
@Autowired
private BioSdkServiceFactory bioSdkServiceFactory;

private Gson gson = new GsonBuilder().serializeNulls().create();;

@GetMapping(path = "/")
@ApiOperation(value = "Service status")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Service is running...") })
Expand Down Expand Up @@ -82,13 +79,26 @@ public ResponseEntity<String> init(
BioSdkServiceProvider bioSdkServiceProviderImpl = null;
bioSdkServiceProviderImpl = bioSdkServiceFactory.getBioSdkServiceProvider(request.getVersion());
responseDto.setResponse(bioSdkServiceProviderImpl.init(request));
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (BioSDKException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "BioSDKException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getErrorCode(), e.getErrorText());
responseDto.getErrors().add(errorDto);
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
} catch (JsonProcessingException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "JsonProcessingException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getMessage(), e.getMessage());
responseDto.getErrors().add(errorDto);
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
}
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
}

@PostMapping(path = "/match", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -103,13 +113,26 @@ public ResponseEntity<String> match(
BioSdkServiceProvider bioSdkServiceProviderImpl = null;
bioSdkServiceProviderImpl = bioSdkServiceFactory.getBioSdkServiceProvider(request.getVersion());
responseDto.setResponse(bioSdkServiceProviderImpl.match(request));
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (BioSDKException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "BioSDKException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getErrorCode(), e.getErrorText());
responseDto.getErrors().add(errorDto);
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
} catch (JsonProcessingException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "JsonProcessingException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getMessage(), e.getMessage());
responseDto.getErrors().add(errorDto);
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
}
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
}

@PostMapping(path = "/check-quality", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -124,13 +147,26 @@ public ResponseEntity<String> checkQuality(
BioSdkServiceProvider bioSdkServiceProviderImpl = null;
bioSdkServiceProviderImpl = bioSdkServiceFactory.getBioSdkServiceProvider(request.getVersion());
responseDto.setResponse(bioSdkServiceProviderImpl.checkQuality(request));
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (BioSDKException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "BioSDKException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getErrorCode(), e.getErrorText());
responseDto.getErrors().add(errorDto);
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
} catch (JsonProcessingException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "JsonProcessingException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getMessage(), e.getMessage());
responseDto.getErrors().add(errorDto);
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
}
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
}

@PostMapping(path = "/extract-template", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -145,13 +181,27 @@ public ResponseEntity<String> extractTemplate(
BioSdkServiceProvider bioSdkServiceProviderImpl = null;
bioSdkServiceProviderImpl = bioSdkServiceFactory.getBioSdkServiceProvider(request.getVersion());
responseDto.setResponse(bioSdkServiceProviderImpl.extractTemplate(request));
String response = serviceUtil.getObjectMapper().writeValueAsString(responseDto);
return ResponseEntity.status(HttpStatus.OK).body(response);
} catch (BioSDKException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "BioSDKException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getErrorCode(), e.getErrorText());
responseDto.getErrors().add(errorDto);
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
} catch (JsonProcessingException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "JsonProcessingException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getMessage(), e.getMessage());
responseDto.getErrors().add(errorDto);
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
}
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
}

@PostMapping(path = "/convert-format", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -166,13 +216,26 @@ public ResponseEntity<String> convertFormat(
BioSdkServiceProvider bioSdkServiceProviderImpl = null;
bioSdkServiceProviderImpl = bioSdkServiceFactory.getBioSdkServiceProvider(request.getVersion());
responseDto.setResponse(bioSdkServiceProviderImpl.convertFormat(request));
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (BioSDKException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "BioSDKException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getErrorCode(), e.getErrorText());
responseDto.getErrors().add(errorDto);
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
} catch (JsonProcessingException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "JsonProcessingException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getMessage(), e.getMessage());
responseDto.getErrors().add(errorDto);
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
}
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
}

@PostMapping(path = "/segment", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -187,13 +250,26 @@ public ResponseEntity<String> segment(
BioSdkServiceProvider bioSdkServiceProviderImpl = null;
bioSdkServiceProviderImpl = bioSdkServiceFactory.getBioSdkServiceProvider(request.getVersion());
responseDto.setResponse(bioSdkServiceProviderImpl.segment(request));
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (BioSDKException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "BioSDKException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getErrorCode(), e.getErrorText());
responseDto.getErrors().add(errorDto);
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
} catch (JsonProcessingException e) {
logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE, "JsonProcessingException: ", e.getMessage());
ErrorDto errorDto = new ErrorDto(e.getMessage(), e.getMessage());
responseDto.getErrors().add(errorDto);
try {
return ResponseEntity.status(HttpStatus.OK).body(serviceUtil.getObjectMapper().writeValueAsString(responseDto));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
}
return ResponseEntity.status(HttpStatus.OK).body(gson.toJson(responseDto));
}

private ResponseDto generateResponseTemplate(String version){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import static io.mosip.biosdk.services.constants.AppConstants.LOGGER_IDTYPE;
import static io.mosip.biosdk.services.constants.AppConstants.LOGGER_SESSIONID;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import io.mosip.biosdk.services.config.LoggerConfig;
import io.mosip.biosdk.services.constants.ErrorMessages;
import io.mosip.biosdk.services.dto.RequestDto;
Expand Down Expand Up @@ -44,8 +43,6 @@ public class BioSdkServiceProviderImpl_V_1_0 implements BioSdkServiceProvider {
@Autowired
private Utils utils;

private Gson gson = new GsonBuilder().serializeNulls().create();

@Value("${mosip.biosdk.log-request-response-enabled:false}")
private boolean isLogRequestResponse;

Expand All @@ -59,9 +56,9 @@ public Object init(RequestDto request){
SDKInfo sdkInfo = null;
String decryptedRequest = decode(request.getRequest());
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"init: ", "decoding successful");
InitRequestDto initRequestDto = gson.fromJson(decryptedRequest, InitRequestDto.class);
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"init: ", "json to dto successful");
try {
InitRequestDto initRequestDto = utils.getObjectMapper().readValue(decryptedRequest, new TypeReference<InitRequestDto>() {});
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"init: ", "json to dto successful");
logRequest(initRequestDto);
sdkInfo = iBioApi.init(initRequestDto.getInitParams());
logObject(sdkInfo);
Expand All @@ -78,9 +75,10 @@ public Object checkQuality(RequestDto request) {
Response response;
String decryptedRequest = decode(request.getRequest());
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"checkQuality: ", "decoding successful");
CheckQualityRequestDto checkQualityRequestDto = gson.fromJson(decryptedRequest, CheckQualityRequestDto.class);
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"checkQuality: ", "json to dto successful");

try {
CheckQualityRequestDto checkQualityRequestDto = utils.getObjectMapper().readValue(decryptedRequest, new TypeReference<CheckQualityRequestDto>() {});
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"checkQuality: ", "json to dto successful");
logRequest(checkQualityRequestDto);
response = iBioApi.checkQuality(
checkQualityRequestDto.getSample(),
Expand All @@ -101,10 +99,10 @@ public Object match(RequestDto request) {
Response response;
String decryptedRequest = decode(request.getRequest());
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"match: ", "decoding successful");
MatchRequestDto matchRequestDto = gson.fromJson(decryptedRequest, MatchRequestDto.class);
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"match: ", "json to dto successful");
try {
logRequest(matchRequestDto);
MatchRequestDto matchRequestDto = utils.getObjectMapper().readValue(decryptedRequest, new TypeReference<MatchRequestDto>() {});
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"match: ", "json to dto successful");
logRequest(matchRequestDto);
response = iBioApi.match(
matchRequestDto.getSample(),
matchRequestDto.getGallery(),
Expand All @@ -125,10 +123,10 @@ public Object extractTemplate(RequestDto request) {
Response response;
String decryptedRequest = decode(request.getRequest());
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"extractTemplate: ", "decoding successful");
ExtractTemplateRequestDto extractTemplateRequestDto = gson.fromJson(decryptedRequest, ExtractTemplateRequestDto.class);
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"extractTemplate: ", "json to dto successful");
try {
logRequest(extractTemplateRequestDto);
ExtractTemplateRequestDto extractTemplateRequestDto = utils.getObjectMapper().readValue(decryptedRequest, new TypeReference<ExtractTemplateRequestDto>() {});
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"extractTemplate: ", "json to dto successful");
logRequest(extractTemplateRequestDto);
response = iBioApi.extractTemplate(
extractTemplateRequestDto.getSample(),
extractTemplateRequestDto.getModalitiesToExtract(),
Expand All @@ -148,9 +146,10 @@ public Object segment(RequestDto request) {
Response response;
String decryptedRequest = decode(request.getRequest());
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"segment: ", "decoding successful");
SegmentRequestDto segmentRequestDto = gson.fromJson(decryptedRequest, SegmentRequestDto.class);
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"segment: ", "json to dto successful");

try {
SegmentRequestDto segmentRequestDto = utils.getObjectMapper().readValue(decryptedRequest, new TypeReference<SegmentRequestDto>() {});
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"segment: ", "json to dto successful");
logRequest(segmentRequestDto);
response = iBioApi.segment(
segmentRequestDto.getSample(),
Expand All @@ -171,10 +170,10 @@ public Object convertFormat(RequestDto request) {
Response response;
String decryptedRequest = decode(request.getRequest());
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"convertFormat: ", "decoding successful");
ConvertFormatRequestDto convertFormatRequestDto = gson.fromJson(decryptedRequest, ConvertFormatRequestDto.class);
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"convertFormat: ", "json to dto successful");
try {
logRequest(convertFormatRequestDto);
ConvertFormatRequestDto convertFormatRequestDto = utils.getObjectMapper().readValue(decryptedRequest, new TypeReference<ConvertFormatRequestDto>() {});
logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"convertFormat: ", "json to dto successful");
logRequest(convertFormatRequestDto);
response = iBioApi.convertFormatV2(
convertFormatRequestDto.getSample(),
convertFormatRequestDto.getSourceFormat(),
Expand Down Expand Up @@ -228,20 +227,20 @@ private void logRequest(ConvertFormatRequestDto convertFormatRequestDto) {
}
}

private <T> void logObject(T response) {
private <T> void logObject(T response) throws JsonProcessingException {
if(isLogRequestResponse) {
logger.debug(response.getClass() + ": " + gson.toJson(response));
logger.debug(response.getClass() + ": " + utils.getObjectMapper().writeValueAsString(response));
}
}

private void logResponse(Response response) {
private void logResponse(Response response) throws JsonProcessingException {
if(isLogRequestResponse) {
Object resp = response.getResponse();
if(resp instanceof BiometricRecord) {
BiometricRecord biometricRecord = (BiometricRecord) resp;
logBiometricRecord("Response BiometricRecord: ", biometricRecord);
} else {
logger.debug("Response: " + gson.toJson(resp));
logger.debug("Response: " + utils.getObjectMapper().writeValueAsString(resp));
}
}
}
Expand Down
Loading