diff --git a/MockMDS/pom.xml b/MockMDS/pom.xml index 2ffced8f..27c0901a 100644 --- a/MockMDS/pom.xml +++ b/MockMDS/pom.xml @@ -45,7 +45,6 @@ 1.3.0 4.5.7 2.7.5 - 1.9.13 1.0.1 0.7.1 @@ -102,11 +101,6 @@ httpmime ${org.apache.httpmime.version} - - org.codehaus.jackson - jackson-mapper-asl - ${org.codehaus.jackson.mapper.asl.version} - javax.xml.bind jaxb-api diff --git a/MockMDS/src/main/java/io/mosip/mock/sbi/SBIConstant.java b/MockMDS/src/main/java/io/mosip/mock/sbi/SBIConstant.java index c53e4661..bf9b495d 100644 --- a/MockMDS/src/main/java/io/mosip/mock/sbi/SBIConstant.java +++ b/MockMDS/src/main/java/io/mosip/mock/sbi/SBIConstant.java @@ -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"; diff --git a/MockMDS/src/main/java/io/mosip/mock/sbi/devicehelper/SBIDeviceHelper.java b/MockMDS/src/main/java/io/mosip/mock/sbi/devicehelper/SBIDeviceHelper.java index 348fc941..2dc2201c 100644 --- a/MockMDS/src/main/java/io/mosip/mock/sbi/devicehelper/SBIDeviceHelper.java +++ b/MockMDS/src/main/java/io/mosip/mock/sbi/devicehelper/SBIDeviceHelper.java @@ -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; diff --git a/MockMDS/src/main/java/io/mosip/mock/sbi/service/SBIJsonInfo.java b/MockMDS/src/main/java/io/mosip/mock/sbi/service/SBIJsonInfo.java index bdb49af8..6e7aba24 100644 --- a/MockMDS/src/main/java/io/mosip/mock/sbi/service/SBIJsonInfo.java +++ b/MockMDS/src/main/java/io/mosip/mock/sbi/service/SBIJsonInfo.java @@ -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; @@ -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); diff --git a/MockMDS/src/main/java/io/mosip/mock/sbi/service/SBIServiceResponse.java b/MockMDS/src/main/java/io/mosip/mock/sbi/service/SBIServiceResponse.java index 22d6a6cd..42d60b94 100644 --- a/MockMDS/src/main/java/io/mosip/mock/sbi/service/SBIServiceResponse.java +++ b/MockMDS/src/main/java/io/mosip/mock/sbi/service/SBIServiceResponse.java @@ -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; @@ -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(); @@ -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) @@ -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; @@ -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; @@ -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()); @@ -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; @@ -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 mosipBioRequest = null; // if Null Throw Errors here if (requestObject != null) { @@ -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 { @@ -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 mosipBioRequest = null; // if Null Throw Errors here if (requestObject != null) { @@ -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 { @@ -1228,7 +1284,7 @@ private List 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 @@ -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); @@ -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)) diff --git a/MockMDS/src/main/java/io/mosip/registration/mdm/dto/CaptureRequestDeviceDetailDto.java b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/CaptureRequestDeviceDetailDto.java index ad15bb6a..bfdb8d93 100644 --- a/MockMDS/src/main/java/io/mosip/registration/mdm/dto/CaptureRequestDeviceDetailDto.java +++ b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/CaptureRequestDeviceDetailDto.java @@ -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; /** @@ -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 /** @@ -45,7 +52,9 @@ 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). @@ -53,6 +62,8 @@ public class CaptureRequestDeviceDetailDto { * 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; /** @@ -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; /** @@ -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; + } } \ No newline at end of file diff --git a/MockMDS/src/main/java/io/mosip/registration/mdm/dto/CaptureRequestDto.java b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/CaptureRequestDto.java index 736841a5..4ae2cf12 100644 --- a/MockMDS/src/main/java/io/mosip/registration/mdm/dto/CaptureRequestDto.java +++ b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/CaptureRequestDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import lombok.Data; @@ -24,22 +25,30 @@ public class CaptureRequestDto { * The environment in which the capture is taking place (e.g., "PRODUCTION", * "TEST"). */ + @JsonProperty(value = "env", required = true) + @JsonDeserialize(using = StringDeserializer.class) private String env; /** * The purpose for which the biometric data is being captured. */ + @JsonProperty(value = "purpose", required = true) + @JsonDeserialize(using = StringDeserializer.class) private String purpose; /** * The device specification version used by the capturing device (optional). */ + @JsonProperty(value = "specVersion", required = true) + @JsonDeserialize(using = StringDeserializer.class) private String specVersion; /** * The maximum allowed time in milliseconds for the capture operation. */ - private int timeout; + @JsonProperty(value = "timeout", required = true) + @JsonDeserialize(using = IntegerDeserializer.class) + private String timeout; /** * The URI of the domain or application where the capture is taking place @@ -51,19 +60,22 @@ public class CaptureRequestDto { /** * The timestamp of the capture operation (private field). */ - @JsonIgnore + @JsonProperty(value = "captureTime", required = true) + @JsonDeserialize(using = StringDeserializer.class) private String captureTime; /** * A unique identifier for the capture transaction. */ + @JsonProperty(value = "transactionId", required = true) + @JsonDeserialize(using = StringDeserializer.class) private String transactionId; /** * A list of capture details for each biometric modality to be captured * (serialized as "bio"). */ - @JsonProperty("bio") + @JsonProperty(value = "bio", required = true) private List bio; /** @@ -75,5 +87,39 @@ public class CaptureRequestDto { */ @JsonIgnore private List> customOpts; + + // Define the validation method + public boolean validateCaptureRequest() { + if (env == null || env.trim().isEmpty()) { + throw new IllegalArgumentException("env is required and must not be null or empty."); + } + if (purpose == null || purpose.trim().isEmpty()) { + throw new IllegalArgumentException("purpose is required and must not be null or empty."); + } + if (timeout == null || timeout.trim().isEmpty()) { + throw new IllegalArgumentException("timeout is required and must not be null or empty."); + } + if (captureTime == null || captureTime.trim().isEmpty()) { + throw new IllegalArgumentException("captureTime is required and must not be null or empty."); + } + if (transactionId == null || transactionId.trim().isEmpty()) { + throw new IllegalArgumentException("transactionId is required and must not be null or empty."); + } + if (bio == null) { + throw new IllegalArgumentException("bio is required and must not be null."); + } + + return validateDeviceDetailList(bio); + } + private boolean validateDeviceDetailList(List bioList) { + if (bioList == null) return false; + for (Object val : bioList) { + if (!(val instanceof CaptureRequestDeviceDetailDto)) + throw new IllegalArgumentException("Object must be of type CaptureRequestDeviceDetailDto."); + if (!((CaptureRequestDeviceDetailDto)val).validateCaptureRequestDeviceDetail()) + throw new IllegalArgumentException("CaptureRequestDeviceDetailDto validation failed."); + } + return true; + } } \ No newline at end of file diff --git a/MockMDS/src/main/java/io/mosip/registration/mdm/dto/IntegerCanBeNullDeserializer.java b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/IntegerCanBeNullDeserializer.java new file mode 100644 index 00000000..8a89fa46 --- /dev/null +++ b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/IntegerCanBeNullDeserializer.java @@ -0,0 +1,38 @@ +package io.mosip.registration.mdm.dto; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +public class IntegerCanBeNullDeserializer extends JsonDeserializer { + + @Override + public String deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + // Get the JSON node for the timeout field + JsonNode node = jp.getCodec().readTree(jp); + + String fieldName = jp.getCurrentName(); + + if (node == null || node.isNull()) { + return null; + } + + // Check if the node is a number (not a string) + if (node.isNumber()) { + throw new IOException(fieldName + " must be a string, not a number."); + } + + String value = node.asText(); + if (value.trim().isEmpty()) { + throw new IOException(fieldName + " must not be empty."); + } + + return value; + } +} \ No newline at end of file diff --git a/MockMDS/src/main/java/io/mosip/registration/mdm/dto/IntegerDeserializer.java b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/IntegerDeserializer.java new file mode 100644 index 00000000..3154ad8f --- /dev/null +++ b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/IntegerDeserializer.java @@ -0,0 +1,38 @@ +package io.mosip.registration.mdm.dto; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +public class IntegerDeserializer extends JsonDeserializer { + + @Override + public String deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + // Get the JSON node for the timeout field + JsonNode node = jp.getCodec().readTree(jp); + + String fieldName = jp.getCurrentName(); + + if (node == null || node.isNull()) { + throw new IOException(fieldName + " must not be null."); + } + + // Check if the node is a number (not a string) + if (node.isNumber()) { + throw new IOException(fieldName + " must be a string, not a number."); + } + + String value = node.asText(); + if (value.trim().isEmpty()) { + throw new IOException(fieldName + " must not be empty."); + } + + return value; + } +} \ No newline at end of file diff --git a/MockMDS/src/main/java/io/mosip/registration/mdm/dto/ScoreRequest.java b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/ScoreRequest.java index 43f00a08..fa838034 100644 --- a/MockMDS/src/main/java/io/mosip/registration/mdm/dto/ScoreRequest.java +++ b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/ScoreRequest.java @@ -1,5 +1,7 @@ package io.mosip.registration.mdm.dto; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + import lombok.Data; /** @@ -26,6 +28,7 @@ public class ScoreRequest { * This field can be populated by the device itself if the request includes * retrieving the quality score along with the requested score type. */ + @JsonDeserialize(using = IntegerDeserializer.class) private String qualityScore; /** diff --git a/MockMDS/src/main/java/io/mosip/registration/mdm/dto/StreamingRequestDetail.java b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/StreamingRequestDetail.java index 71cb6a7c..a73575df 100644 --- a/MockMDS/src/main/java/io/mosip/registration/mdm/dto/StreamingRequestDetail.java +++ b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/StreamingRequestDetail.java @@ -1,5 +1,7 @@ package io.mosip.registration.mdm.dto; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + import lombok.Data; /** @@ -16,16 +18,19 @@ public class StreamingRequestDetail { /** * The unique identifier of the device initiating the streaming request. */ + @JsonDeserialize(using = StringDeserializer.class) private String deviceId; /** * The sub-identifier of the device, specific to the modality or sensor used for * streaming (e.g., fingerprint sensor number). */ + @JsonDeserialize(using = IntegerDeserializer.class) private String deviceSubId; /** * The timeout value for the streaming request, specified in milliseconds. */ + @JsonDeserialize(using = IntegerCanBeNullDeserializer.class) private String timeout; } \ No newline at end of file diff --git a/MockMDS/src/main/java/io/mosip/registration/mdm/dto/StringDeserializer.java b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/StringDeserializer.java new file mode 100644 index 00000000..7eefb9ae --- /dev/null +++ b/MockMDS/src/main/java/io/mosip/registration/mdm/dto/StringDeserializer.java @@ -0,0 +1,42 @@ +package io.mosip.registration.mdm.dto; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +public class StringDeserializer extends JsonDeserializer { + + @Override + public String deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + // Get the JSON node for the timeout field + JsonNode node = jp.getCodec().readTree(jp); + + // Retrieve the field name for better error context + String fieldName = jp.getCurrentName(); + + // Check if the node is null + if (node == null || node.isNull()) { + throw new IOException(fieldName + " must not be null."); + } + + // Check if the node is a number (not a string) + if (node.isNumber()) { + throw new IOException(fieldName + " must be a string, not a number."); + } + + // Check if the node is an empty string + String value = node.asText(); + if (value == null || value.trim().isEmpty()) { + throw new IOException(fieldName + " must not be null or empty."); + } + + // Return the validated string value + return value; + } +} \ No newline at end of file diff --git a/MockMDS/src/main/java/org/biometric/provider/CaptureRequest.java b/MockMDS/src/main/java/org/biometric/provider/CaptureRequest.java index 5030a404..62c30c36 100644 --- a/MockMDS/src/main/java/org/biometric/provider/CaptureRequest.java +++ b/MockMDS/src/main/java/org/biometric/provider/CaptureRequest.java @@ -483,7 +483,7 @@ private void captureFingersModality(CaptureRequestDeviceDetailDto bio, List getSegmentsToCapture(List defaultSubTypes, List cryptoResult) { NewBioAuthDto bioResponse = new NewBioAuthDto(); bioResponse.setBioSubType(bioMetricsData.getBioSubType()); diff --git a/MockMDS/src/main/java/org/biometric/provider/IntegerDeserializer.java b/MockMDS/src/main/java/org/biometric/provider/IntegerDeserializer.java new file mode 100644 index 00000000..d3079023 --- /dev/null +++ b/MockMDS/src/main/java/org/biometric/provider/IntegerDeserializer.java @@ -0,0 +1,28 @@ +package org.biometric.provider; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +public class IntegerDeserializer extends JsonDeserializer { + + @Override + public String deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + // Get the JSON node for the timeout field + JsonNode node = jp.getCodec().readTree(jp); + + // Check if the node is a number (not a string) + if (node.isNumber()) { + throw new IOException(jp.getCurrentName() + " must be a string, not a number."); + } + + // Return the string value if it is already a string + return node.asText(); + } +} \ No newline at end of file