Skip to content

Commit

Permalink
[MOSIP-38107]
Browse files Browse the repository at this point in the history
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
  • Loading branch information
JanardhanBS-SyncByte committed Dec 6, 2024
1 parent 2207af2 commit 173b7e4
Show file tree
Hide file tree
Showing 14 changed files with 355 additions and 43 deletions.
6 changes: 0 additions & 6 deletions MockMDS/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<jai.imageio.core.version>1.3.0</jai.imageio.core.version>
<org.apache.httpmime.version>4.5.7</org.apache.httpmime.version>
<com.squareup.okhttp.version>2.7.5</com.squareup.okhttp.version>
<org.codehaus.jackson.mapper.asl.version>1.9.13</org.codehaus.jackson.mapper.asl.version>
<javax.xml.crypto.jsr105.api.version>1.0.1</javax.xml.crypto.jsr105.api.version>
<org.bitbucket.jose4j.version>0.7.1</org.bitbucket.jose4j.version>

Expand Down Expand Up @@ -102,11 +101,6 @@
<artifactId>httpmime</artifactId>
<version>${org.apache.httpmime.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${org.codehaus.jackson.mapper.asl.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
Expand Down
1 change: 1 addition & 0 deletions MockMDS/src/main/java/io/mosip/mock/sbi/SBIConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private SBIConstant() {
public static final String ERROR_CODE_120 = "mds_ERROR_120_msg_en";
public static final String ERROR_CODE_121 = "mds_ERROR_121_msg_en";
public static final String ERROR_CODE_122 = "mds_ERROR_122_msg_en";
public static final String ERROR_CODE_123 = "mds_ERROR_123_msg_en";

public static final String ERROR_CODE_500 = "mds_ERROR_500_msg_en";
public static final String ERROR_CODE_501 = "mds_ERROR_501_msg_en";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

import org.biometric.provider.CryptoUtility;
import org.biometric.provider.JwtUtility;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;

import io.mosip.mock.sbi.SBIConstant;
import io.mosip.mock.sbi.exception.SBIException;
import io.mosip.mock.sbi.service.SBIJsonInfo;
Expand Down
10 changes: 4 additions & 6 deletions MockMDS/src/main/java/io/mosip/mock/sbi/service/SBIJsonInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.mosip.mock.sbi.util.ApplicationPropertyHelper;
import io.mosip.registration.mdm.dto.BioMetricsDto;
import io.mosip.registration.mdm.dto.ErrorInfo;
Expand Down Expand Up @@ -87,9 +87,7 @@ public static String getCaptureErrorJson(String specVersion, String lang, String
captureResponse.setBiometrics(biometrics);

ObjectMapper mapper = new ObjectMapper();
SerializationConfig config = mapper.getSerializationConfig();
config.setSerializationInclusion(Inclusion.NON_NULL);
mapper.setSerializationConfig(config);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

try {
return mapper.writeValueAsString(captureResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import org.apache.commons.codec.binary.Hex;
import org.biometric.provider.CryptoUtility;
import org.biometric.provider.JwtUtility;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
Expand Down Expand Up @@ -130,8 +130,15 @@ public String processDeviceDicoveryInfo(SBIMockService mockService) {
String lang = "en";
try {
ObjectMapper objectMapper = new ObjectMapper();
DeviceDiscoveryRequestDetail requestObject = (DeviceDiscoveryRequestDetail) getRequestJson(
SBIConstant.MOSIP_DISC_VERB);
DeviceDiscoveryRequestDetail requestObject = null;
try {
requestObject = (DeviceDiscoveryRequestDetail) getRequestJson(SBIConstant.MOSIP_DISC_VERB);
}
catch (Exception ex) {
logger.error("processDeviceDicoveryInfo :: error ::", ex);
return SBIJsonInfo.getErrorJson(lang, "123", "");
}

String type = null;
if (requestObject != null && requestObject.getType() != null && requestObject.getType().length() > 0)
type = requestObject.getType();
Expand Down Expand Up @@ -291,7 +298,14 @@ public String processSetStatus(SBIMockService mockService) {
String response = null;
String lang = "en";
try {
StatusRequest requestObject = (StatusRequest) getRequestJson(SBIConstant.MOSIP_ADMIN_API_STATUS);
StatusRequest requestObject = null;
try {
requestObject = (StatusRequest) getRequestJson(SBIConstant.MOSIP_ADMIN_API_STATUS);
}
catch (Exception ex) {
logger.error("processSetStatus :: error ::", ex);
return SBIJsonInfo.getErrorJson(lang, "123", "");
}
String type = null;
String status = null;
if (requestObject != null && requestObject.getType() != null && requestObject.getType().length() > 0)
Expand Down Expand Up @@ -365,7 +379,14 @@ public String processSetQualityScore(SBIMockService mockService) {
String response = null;
String lang = "en";
try {
ScoreRequest requestObject = (ScoreRequest) getRequestJson(SBIConstant.MOSIP_ADMIN_API_SCORE);
ScoreRequest requestObject = null;
try {
requestObject = (ScoreRequest) getRequestJson(SBIConstant.MOSIP_ADMIN_API_SCORE);
}
catch (Exception ex) {
logger.error("processSetQualityScore :: error ::", ex);
return SBIJsonInfo.getErrorJson(lang, "123", "");
}
String type = null;
String qualityScore = null;
boolean scoreFromIso = false;
Expand Down Expand Up @@ -459,7 +480,14 @@ public String processSetDelay(SBIMockService mockService) {
String response = null;
String lang = "en";
try {
DelayRequest requestObject = (DelayRequest) getRequestJson(SBIConstant.MOSIP_ADMIN_API_DELAY);
DelayRequest requestObject = null;
try {
requestObject = (DelayRequest) getRequestJson(SBIConstant.MOSIP_ADMIN_API_DELAY);
}
catch (Exception ex) {
logger.error("processSetDelay :: error ::", ex);
return SBIJsonInfo.getErrorJson(lang, "123", "");
}
String type = null;
String delay = null;
String[] method = null;
Expand Down Expand Up @@ -558,7 +586,15 @@ public String processSetProfileInfo(SBIMockService mockService) {
String response = null;
String lang = "en";
try {
ProfileRequest requestObject = (ProfileRequest) getRequestJson(SBIConstant.MOSIP_ADMIN_API_PROFILE);
ProfileRequest requestObject = null;
try {
requestObject = (ProfileRequest) getRequestJson(SBIConstant.MOSIP_ADMIN_API_PROFILE);
}
catch (Exception ex) {
logger.error("processSetProfileInfo :: error ::", ex);
return SBIJsonInfo.getErrorJson(lang, "123", "");
}

if (requestObject != null && requestObject.getProfileId() != null
&& requestObject.getProfileId().length() > 0) {
mockService.setProfileId(requestObject.getProfileId());
Expand Down Expand Up @@ -588,8 +624,14 @@ private String processLiveStreamInfo(SBIMockService mockService, Socket socket)
return SBIJsonInfo.getStreamErrorJson(lang, "601", "");
}

StreamingRequestDetail requestObject = (StreamingRequestDetail) getRequestJson(
SBIConstant.MOSIP_STREAM_VERB);
StreamingRequestDetail requestObject = null;
try {
requestObject = (StreamingRequestDetail) getRequestJson(SBIConstant.MOSIP_STREAM_VERB);
}
catch (Exception ex) {
logger.error("processLiveStreamInfo :: error ::", ex);
return SBIJsonInfo.getErrorJson(lang, "123", "");
}
String deviceId = requestObject.getDeviceId();
int deviceSubId = Integer.parseInt(requestObject.getDeviceSubId());
boolean isStreamTimeoutSet = false;
Expand Down Expand Up @@ -727,7 +769,16 @@ private String processRCaptureInfo(SBIMockService mockService) {
String env = "";
String purpose = "";
int deviceSubId = 0;
CaptureRequestDto requestObject = (CaptureRequestDto) getRequestJson(SBIConstant.MOSIP_RCAPTURE_VERB);
CaptureRequestDto requestObject = null;
try {
requestObject = (CaptureRequestDto) getRequestJson(SBIConstant.MOSIP_RCAPTURE_VERB);
requestObject.validateCaptureRequest();
}
catch (Exception ex) {
logger.error("processRCaptureInfo :: error ::", ex);
return SBIJsonInfo.getCaptureErrorJson(specVersion, lang, "123", "", false);
}

List<CaptureRequestDeviceDetailDto> mosipBioRequest = null;
// if Null Throw Errors here
if (requestObject != null) {
Expand Down Expand Up @@ -947,9 +998,7 @@ private String processRCaptureInfo(SBIMockService mockService) {
captureResponse.setBiometrics(biometrics);

ObjectMapper mapper = new ObjectMapper();
SerializationConfig config = mapper.getSerializationConfig();
config.setSerializationInclusion(Inclusion.NON_NULL);
mapper.setSerializationConfig(config);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

response = mapper.writeValueAsString(captureResponse);
} else {
Expand Down Expand Up @@ -1007,7 +1056,16 @@ private String processCaptureInfo(SBIMockService mockService) {
String env = "";
String purpose = "";
int deviceSubId = 0;
CaptureRequestDto requestObject = (CaptureRequestDto) getRequestJson(SBIConstant.MOSIP_RCAPTURE_VERB);
CaptureRequestDto requestObject = null;
try {
requestObject = (CaptureRequestDto) getRequestJson(SBIConstant.MOSIP_CAPTURE_VERB);
requestObject.validateCaptureRequest();
}
catch (Exception ex) {
logger.error("processCaptureInfo :: error ::", ex);
return SBIJsonInfo.getCaptureErrorJson(specVersion, lang, "123", "", false);
}
;
List<CaptureRequestDeviceDetailDto> mosipBioRequest = null;
// if Null Throw Errors here
if (requestObject != null) {
Expand Down Expand Up @@ -1175,9 +1233,7 @@ private String processCaptureInfo(SBIMockService mockService) {
captureResponse.setBiometrics(biometrics);

ObjectMapper mapper = new ObjectMapper();
SerializationConfig config = mapper.getSerializationConfig();
config.setSerializationInclusion(Inclusion.NON_NULL);
mapper.setSerializationConfig(config);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

response = mapper.writeValueAsString(captureResponse);
} else {
Expand Down Expand Up @@ -1228,7 +1284,7 @@ private List<BioMetricsDto> getBioMetricsDtoList(String lang, CaptureRequestDto
String specVersion = requestObject.getSpecVersion();
String transactionId = requestObject.getTransactionId();
float captureScore = deviceHelper.getQualityScore(); // SET MANUALLY
int requestScore = requestObject.getBio().get(0).getRequestedScore();
int requestScore = Integer.parseInt(requestObject.getBio().get(0).getRequestedScore());
int bioCount = Integer.parseInt(requestObject.getBio().get(0).getCount());
String bioType = requestObject.getBio().get(0).getType();
String[] bioExceptions = requestObject.getBio().get(0).getException();// Bio exceptions
Expand Down Expand Up @@ -2013,9 +2069,7 @@ private BioMetricsDto getBiometricData(String transactionId, CaptureRequestDto r
biometricData.setTransactionId(transactionId);

ObjectMapper mapper = new ObjectMapper();
SerializationConfig config = mapper.getSerializationConfig();
config.setSerializationInclusion(Inclusion.NON_NULL);
mapper.setSerializationConfig(config);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

String currentBioData = mapper.writeValueAsString(biometricData);

Expand Down Expand Up @@ -2190,13 +2244,20 @@ public Object getRequestJson(String methodVerb) {
if (getRequest() != null && getRequest().indexOf("{") >= 0) {
try {
ObjectMapper mapper = new ObjectMapper();
// Enable FAIL_ON_UNKNOWN_PROPERTIES to handle unknown properties
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// Enable FAIL_ON_MISSING_CREATOR_PROPERTIES to fail on missing required properties
mapper.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, true);
// Use FAIL_ON_NULL_CREATOR_PROPERTIES to check for missing properties on the field level
mapper.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, true);

if (methodVerb.equalsIgnoreCase(SBIConstant.MOSIP_DISC_VERB))
return mapper.readValue(getRequest().substring(getRequest().indexOf("{")),
DeviceDiscoveryRequestDetail.class);
if (methodVerb.equalsIgnoreCase(SBIConstant.MOSIP_STREAM_VERB))
return mapper.readValue(getRequest().substring(getRequest().indexOf("{")),
StreamingRequestDetail.class);
if (methodVerb.equalsIgnoreCase(SBIConstant.MOSIP_RCAPTURE_VERB))
if (methodVerb.equalsIgnoreCase(SBIConstant.MOSIP_RCAPTURE_VERB) || methodVerb.equalsIgnoreCase(SBIConstant.MOSIP_CAPTURE_VERB))
return mapper.readValue(getRequest().substring(getRequest().indexOf("{")), CaptureRequestDto.class);

if (methodVerb.equalsIgnoreCase(SBIConstant.MOSIP_ADMIN_API_STATUS))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.mosip.registration.mdm.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import lombok.Data;

/**
Expand All @@ -17,11 +20,15 @@ public class CaptureRequestDeviceDetailDto {
/**
* The type of biometric modality to be captured (e.g., "FINGERPRINT", "IRIS").
*/
@JsonProperty(value = "type", required = true)
@JsonDeserialize(using = StringDeserializer.class)
private String type;

/**
* The desired number of biometric samples to capture (e.g., "2").
*/
@JsonProperty(value = "count", required = true)
@JsonDeserialize(using = IntegerDeserializer.class)
private String count; // Consider using int instead of String for count

/**
Expand All @@ -45,14 +52,18 @@ public class CaptureRequestDeviceDetailDto {
/**
* The minimum quality score required for a captured biometric sample.
*/
private int requestedScore;
@JsonProperty(value = "requestedScore", required = true)
@JsonDeserialize(using = IntegerDeserializer.class)
private String requestedScore;

/**
* The identifier of the device to be used for capture (optional).
*
* This field can be used to specify a particular device if multiple devices are
* available.
*/
@JsonProperty(value = "deviceId", required = true)
@JsonDeserialize(using = StringDeserializer.class)
private String deviceId;

/**
Expand All @@ -61,6 +72,8 @@ public class CaptureRequestDeviceDetailDto {
* This field might be used to specify a specific sensor on a multi-sensor
* device.
*/
@JsonProperty(value = "deviceSubId", required = true)
@JsonDeserialize(using = IntegerDeserializer.class)
private String deviceSubId;

/**
Expand All @@ -69,5 +82,49 @@ public class CaptureRequestDeviceDetailDto {
* This field can be used for liveness detection or other comparison purposes.
* The format and interpretation of the hash value depend on the implementation.
*/
@JsonProperty(value = "previousHash", required = true)
private String previousHash;

// Define the validation method
public boolean validateCaptureRequestDeviceDetail() {
if (type == null || type.trim().isEmpty()) {
throw new IllegalArgumentException("type is required and must not be null or empty.");
}
if (count == null || count.trim().isEmpty()) {
throw new IllegalArgumentException("count is required and must not be null or empty.");
}
if (requestedScore == null || requestedScore.trim().isEmpty()) {
throw new IllegalArgumentException("requestedScore is required and must not be null or empty.");
}
if (deviceId == null || deviceId.trim().isEmpty()) {
throw new IllegalArgumentException("deviceId is required and must not be null or empty.");
}
if (deviceSubId == null || deviceSubId.trim().isEmpty()) {
throw new IllegalArgumentException("deviceSubId is required and must not be null or empty.");
}
if (previousHash == null) {
throw new IllegalArgumentException("previousHash is required and must not be null.");
}

return validateStringArray(exception, "exception") || validateStringArray(bioSubType, "bioSubType") ||
validateStringCanBeEmpty(previousHash, "previousHash");
}

private boolean validateStringCanBeEmpty(String value, String fieldName) {
if (value == null) {
throw new IllegalArgumentException(fieldName + " must not be null.");
}
return true;
}

private boolean validateStringArray(String[] values, String fieldName) {
if (values == null)
return true;
for (Object val : values) {
if (!(val instanceof String)) {
throw new IllegalArgumentException(fieldName + " all elements in the array must be Strings.");
}
}
return true;
}
}
Loading

0 comments on commit 173b7e4

Please sign in to comment.