From c2771bbb92ff62360c651bc9ed06acf3d5b11e8e Mon Sep 17 00:00:00 2001
From: JanardhanBS-SyncByte
Date: Wed, 24 Apr 2024 12:27:38 +0530
Subject: [PATCH 1/8] [MOSIP-32456]
Signed-off-by: JanardhanBS-SyncByte
---
image-compressor/pom.xml | 127 ++++++++++--------
.../sdk/service/ImageCompressionService.java | 6 +-
2 files changed, 76 insertions(+), 57 deletions(-)
diff --git a/image-compressor/pom.xml b/image-compressor/pom.xml
index f9ffc4a..e1101ff 100644
--- a/image-compressor/pom.xml
+++ b/image-compressor/pom.xml
@@ -1,8 +1,10 @@
-
+
4.0.0
image-compressor
io.mosip.image.compressor
- 0.0.1-SNAPSHOT
+ 0.0.1-java21-SNAPSHOT
image-compressor
Image Compressorimplementation of biometrics SDK
jar
@@ -31,18 +33,6 @@
-
-
- ossrh
- Central Repository
- https://oss.sonatype.org/content/repositories/snapshots
- default
-
- true
-
-
-
-
ossrh
@@ -55,44 +45,64 @@
-
UTF-8
+ 21
- 11
- 11
- 3.8.0
- UTF-8
- 2.9
- 0.8.5
- 3.7.0.1746
- 3.0.1
- 2.3
+ ${java.version}
+ ${java.version}
+ 3.11.0
+ 3.0.2
+ 3.1.0
+ 3.2.0
+ 2.3
+ 0.8.11
+ 3.1.1
+ 3.3.1
+ 3.2.0
+ 3.2.3
+ 3.0.2
+ 3.1.0
+ 2.22.0
+ 3.1.1
+ 1.6.7
+ 3.2.5
+
+
+ 3.0.1
- 1.2.0.1-B1
- 1.2.0.1-B2
- 1.2.0.1-B2-SNAPSHOT
+ 1.2.1-java21-SNAPSHOT
+ 1.2.1-java21-SNAPSHOT
+ 1.2.1-java21-SNAPSHOT
+ 1.2.1-java21-SNAPSHOT
-
- 1.7.25
-
- 1.3.0
+
+ 1.3.0
1.15
3.11
- 2.10.1
5.2.17.Final
6.0.12.Final
- 2.0.2.RELEASE
+
+
+
+ io.mosip.kernel
+ kernel-bom
+ ${kernel.bom.version}
+ pom
+ import
+
+
+
+
org.springframework.boot
spring-boot-starter-validation
- ${spring.boot.version}
io.mosip.kernel
@@ -108,48 +118,41 @@
org.apache.commons
commons-lang3
- ${apache.commons.version}
commons-codec
commons-codec
- ${commons-codec.version}
org.slf4j
jul-to-slf4j
- ${slf4j.version}
org.slf4j
jcl-over-slf4j
- ${slf4j.version}
-
+
com.github.jai-imageio
jai-imageio-jpeg2000
- ${jai-imageio.version}
+ ${jai.imageio.jpeg2000.version}
com.fasterxml.jackson.core
jackson-databind
- ${fasterxml.jackson.version}
com.fasterxml.jackson.dataformat
jackson-dataformat-xml
- ${fasterxml.jackson.version}
com.fasterxml.jackson.module
jackson-module-jaxb-annotations
- ${fasterxml.jackson.version}
org.hibernate.validator
hibernate-validator
- ${hibernate.validator.version}
org.hibernate
@@ -159,16 +162,31 @@
io.mosip.kernel
kernel-core
- ${kernel.version}
+ ${kernel.core.version}
+
+
+ org.junit.vintage
+ junit-vintage-engine
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven.compiler.version}
+
+ ${java.version}
+
+ --enable-preview
+
+
+
org.apache.maven.plugins
maven-assembly-plugin
- 3.1.1
+ ${maven.assembly.plugin.version}
jar-with-dependencies
@@ -194,7 +212,7 @@
org.jacoco
jacoco-maven-plugin
- ${maven.jacoco.plugin.version}
+ ${jacoco.maven.plugin.version}
true
@@ -223,7 +241,7 @@
org.apache.maven.plugins
maven-source-plugin
- 2.2.1
+ ${maven.source.plugin.version}
attach-sources
@@ -236,7 +254,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.2.0
+ ${maven.javadoc.plugin.version}
attach-javadocs
@@ -252,7 +270,7 @@
org.apache.maven.plugins
maven-gpg-plugin
- 1.5
+ ${maven.gpg.plugin.version}
@@ -273,7 +291,7 @@
maven-deploy-plugin
- 2.8.1
+ ${maven.deploy.plugin.version}
default-deploy
@@ -287,7 +305,7 @@
org.sonatype.plugins
nexus-staging-maven-plugin
- 1.6.7
+ ${nexus.staging.maven.plugin.version}
true
@@ -308,7 +326,7 @@
pl.project13.maven
git-commit-id-plugin
- 3.0.1
+ ${git.commit.id.plugin.version}
get-the-git-infos
@@ -320,7 +338,8 @@
true
- ${project.build.outputDirectory}/git.properties
+
+ ${project.build.outputDirectory}/git.properties
^git.build.(time|version)$
^git.commit.id.(abbrev|full)$
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
index f6b54f0..4e66091 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
@@ -35,14 +35,14 @@ public class ImageCompressionService extends SDKService {
static {
// load OpenCV library
- nu.pattern.OpenCV.loadShared();
+ //nu.pattern.OpenCV.loadShared();
+ //System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
/**
* In Java >= 12 it is no longer possible to use addLibraryPath, which modifies
* the ClassLoader's static usr_paths field. There does not seem to be any way
* around this so we fall back to loadLocally() and return.
*/
- // nu.pattern.OpenCV.loadLocally();
- System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
+ nu.pattern.OpenCV.loadLocally();
}
private BiometricRecord sample;
From 6e5ddc65f3d185c27a9ec11c39e15bfd81513ada Mon Sep 17 00:00:00 2001
From: JanardhanBS-SyncByte
Date: Wed, 24 Apr 2024 12:52:55 +0530
Subject: [PATCH 2/8] [MOSIP-32456]
Signed-off-by: JanardhanBS-SyncByte
---
.github/workflows/push-trigger.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml
index 5cc54ec..9aed4de 100644
--- a/.github/workflows/push-trigger.yml
+++ b/.github/workflows/push-trigger.yml
@@ -22,7 +22,7 @@ on:
jobs:
build-maven-image-compressor:
- uses: mosip/kattu/.github/workflows/maven-build.yml@master
+ uses: mosip/kattu/.github/workflows/maven-build.yml@master-java21
with:
SERVICE_LOCATION: image-compressor
BUILD_ARTIFACT: image-compressor
From 29c52445e831d7405cf8f4c65c63fdd811414ea9 Mon Sep 17 00:00:00 2001
From: JanardhanBS-SyncByte
Date: Mon, 6 May 2024 18:47:27 +0530
Subject: [PATCH 3/8] MOSIP-32456
Signed-off-by: JanardhanBS-SyncByte
---
.github/workflows/push-trigger.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml
index 9aed4de..e60152a 100644
--- a/.github/workflows/push-trigger.yml
+++ b/.github/workflows/push-trigger.yml
@@ -16,7 +16,7 @@ on:
branches:
- '!release-branch'
- 'MOSIP*'
- - 'develop'
+ - 'develop*'
- 'master'
- '1.*'
@@ -37,7 +37,7 @@ jobs:
publish_to_nexus:
if: "${{ !contains(github.ref, 'master') && github.event_name != 'pull_request' }}"
needs: build-maven-image-compressor
- uses: mosip/kattu/.github/workflows/maven-publish-to-nexus.yml@master
+ uses: mosip/kattu/.github/workflows/maven-publish-to-nexus.yml@master-java21
with:
SERVICE_LOCATION: image-compressor
secrets:
From 14ecbfdd928f466591b8cbccd4149827bf4f50f6 Mon Sep 17 00:00:00 2001
From: JanardhanBS-SyncByte
Date: Sat, 25 May 2024 01:12:32 +0530
Subject: [PATCH 4/8] [MOSIP-33318]
Signed-off-by: JanardhanBS-SyncByte
---
.github/workflows/push-trigger.yml | 16 ++++
image-compressor/pom.xml | 41 +++++++--
.../sdk/constant/ResponseStatus.java | 11 +--
.../compressor/sdk/constant/SdkConstant.java | 10 ++-
.../sdk/impl/ImageCompressorSDK.java | 34 +++----
.../sdk/impl/ImageCompressorSDKV2.java | 38 ++++----
.../sdk/service/ImageCompressionService.java | 88 +++++++++----------
.../sdk/service/SDKInfoService.java | 11 +--
.../compressor/sdk/service/SDKService.java | 55 +++++-------
.../image/compressor/sdk/utils/Util.java | 20 +++--
.../compressor/sdk/test/SampleSDKTest.java | 86 ++++++++++--------
.../compressor/sdk/test/SampleSDKTest1.java | 20 ++---
12 files changed, 229 insertions(+), 201 deletions(-)
diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml
index e60152a..7a73b34 100644
--- a/.github/workflows/push-trigger.yml
+++ b/.github/workflows/push-trigger.yml
@@ -48,3 +48,19 @@ jobs:
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
+ sonar_analysis:
+ needs: build-maven-image-compressor
+ if: "${{ github.event_name != 'pull_request' }}"
+ uses: mosip/kattu/.github/workflows/maven-sonar-analysis.yml@master-java21
+ with:
+ SERVICE_LOCATION: image-compressor
+ secrets:
+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
+ ORG_KEY: ${{ secrets.ORG_KEY }}
+ OSSRH_USER: ${{ secrets.OSSRH_USER }}
+ OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
+ OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
+ GPG_SECRET: ${{ secrets.GPG_SECRET }}
+ SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
+
+
diff --git a/image-compressor/pom.xml b/image-compressor/pom.xml
index e1101ff..65dee1f 100644
--- a/image-compressor/pom.xml
+++ b/image-compressor/pom.xml
@@ -67,6 +67,7 @@
3.1.1
1.6.7
3.2.5
+ 3.7.0.1746
3.0.1
@@ -191,13 +192,6 @@
jar-with-dependencies
-
-
-
@@ -271,7 +265,6 @@
org.apache.maven.plugins
maven-gpg-plugin
${maven.gpg.plugin.version}
-
sign-artifacts
@@ -346,10 +339,40 @@
full
${project.basedir}/.git
-
+
+
+ sonar
+
+ .
+ src/main/java/**,src/main/resources/**
+ ${sonar.coverage.exclusions}
+ https://sonarcloud.io
+
+
+ false
+
+
+
+
+ org.sonarsource.scanner.maven
+ sonar-maven-plugin
+ ${maven.sonar.plugin.version}
+
+
+ verify
+
+ sonar
+
+
+
+
+
+
+
+
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/ResponseStatus.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/ResponseStatus.java
index cb0aca6..61d3c23 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/ResponseStatus.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/ResponseStatus.java
@@ -11,8 +11,8 @@ public enum ResponseStatus {
UNKNOWN_ERROR(500, "UNKNOWN_ERROR");
ResponseStatus(int statusCode, String statusMessage) {
- this.setStatusCode(statusCode);
- this.setStatusMessage(statusMessage);
+ this.statusCode = statusCode;
+ this.statusMessage = statusMessage;
}
private int statusCode;
@@ -21,18 +21,11 @@ public enum ResponseStatus {
public int getStatusCode() {
return statusCode;
}
- public void setStatusCode(int statusCode) {
- this.statusCode = statusCode;
- }
public String getStatusMessage() {
return statusMessage;
}
- public void setStatusMessage(String statusMessage) {
- this.statusMessage = statusMessage;
- }
-
public static ResponseStatus fromStatusCode(int code) {
for (ResponseStatus paramCode : ResponseStatus.values()) {
if (paramCode.getStatusCode() == code) {
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/SdkConstant.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/SdkConstant.java
index 741690f..e1c6db9 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/SdkConstant.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/SdkConstant.java
@@ -7,16 +7,20 @@
*
*/
public class SdkConstant {
+ private SdkConstant() {
+ throw new IllegalStateException("SdkConstant class");
+ }
+
/**
* 0 to Double.Max_value
*/
- public static String IMAGE_COMPRESSOR_RESIZE_FACTOR_FX = "mosip.bio.image.compressor.resize.factor.fx";
+ public static final String IMAGE_COMPRESSOR_RESIZE_FACTOR_FX = "mosip.bio.image.compressor.resize.factor.fx";
/**
* 0 to Double.Max_value
*/
- public static String IMAGE_COMPRESSOR_RESIZE_FACTOR_FY = "mosip.bio.image.compressor.resize.factor.fy";
+ public static final String IMAGE_COMPRESSOR_RESIZE_FACTOR_FY = "mosip.bio.image.compressor.resize.factor.fy";
/**
* 1 to 1000
*/
- public static String IMAGE_COMPRESSOR_COMPRESSION_RATIO = "mosip.bio.image.compressor.compression.ratio";
+ public static final String IMAGE_COMPRESSOR_COMPRESSION_RATIO = "mosip.bio.image.compressor.compression.ratio";
}
\ No newline at end of file
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
index ee7fd3b..4119d9e 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
@@ -3,14 +3,14 @@
import java.util.List;
import java.util.Map;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
+import io.mosip.image.compressor.sdk.constant.ResponseStatus;
+import io.mosip.image.compressor.sdk.service.ImageCompressionService;
+import io.mosip.image.compressor.sdk.service.SDKInfoService;
import io.mosip.kernel.biometrics.constant.BiometricType;
import io.mosip.kernel.biometrics.entities.BiometricRecord;
import io.mosip.kernel.biometrics.model.MatchDecision;
@@ -18,9 +18,6 @@
import io.mosip.kernel.biometrics.model.Response;
import io.mosip.kernel.biometrics.model.SDKInfo;
import io.mosip.kernel.biometrics.spi.IBioApi;
-import io.mosip.image.compressor.sdk.constant.ResponseStatus;
-import io.mosip.image.compressor.sdk.service.ImageCompressionService;
-import io.mosip.image.compressor.sdk.service.SDKInfoService;
/**
* The Class ImageCompressorSDK.
@@ -30,20 +27,20 @@
*/
@Component
@EnableAutoConfiguration
-@Deprecated
-public class ImageCompressorSDK implements IBioApi {
- private Logger LOGGER = LoggerFactory.getLogger(ImageCompressorSDK.class);
-
+@Deprecated(since="1.2.0.1", forRemoval=true)
+public class ImageCompressorSDK implements IBioApi // NOSONAR
+{
/** The environment. */
- @Autowired
- private Environment env;
+ @Autowired // NOSONAR
+ private Environment env;
private static final String API_VERSION = "0.9";
+ private static final String ERROR_NOT_IMPLEMENTED = "Sorry! Method functionality not implemented...";
+
@Override
public SDKInfo init(Map initParams) {
- // TODO validate for mandatory initParams
- SDKInfoService service = new SDKInfoService(env, API_VERSION, "sample", "sample", "sample");
+ SDKInfoService service = new SDKInfoService(env, API_VERSION, "sample", "sample", "sample");// NOSONAR
return service.getSDKInfo();
}
@@ -52,7 +49,8 @@ public Response checkQuality(BiometricRecord sample, List flags) {
Response response = new Response<>();
response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage() + " Sorry! Method functionality not implemented..."));
+ response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage(),
+ ERROR_NOT_IMPLEMENTED));// NOSONAR
response.setResponse(null);
return response;
}
@@ -62,7 +60,8 @@ public Response match(BiometricRecord sample, BiometricRecord[]
List modalitiesToMatch, Map flags) {
Response response = new Response<>();
response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage() + " Sorry! Method functionality not implemented..."));
+ response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage(),
+ ERROR_NOT_IMPLEMENTED));
response.setResponse(null);
return response;
}
@@ -79,7 +78,8 @@ public Response segment(BiometricRecord sample, List flags) {
Response response = new Response<>();
response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage() + " Sorry! Method functionality not implemented..."));
+ response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage(),
+ ERROR_NOT_IMPLEMENTED));
response.setResponse(null);
return response;
}
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java
index 8d15a9d..2fb1c12 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java
@@ -3,14 +3,14 @@
import java.util.List;
import java.util.Map;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
+import io.mosip.image.compressor.sdk.constant.ResponseStatus;
+import io.mosip.image.compressor.sdk.service.ImageCompressionService;
+import io.mosip.image.compressor.sdk.service.SDKInfoService;
import io.mosip.kernel.biometrics.constant.BiometricType;
import io.mosip.kernel.biometrics.entities.BiometricRecord;
import io.mosip.kernel.biometrics.model.MatchDecision;
@@ -18,9 +18,6 @@
import io.mosip.kernel.biometrics.model.Response;
import io.mosip.kernel.biometrics.model.SDKInfo;
import io.mosip.kernel.biometrics.spi.IBioApiV2;
-import io.mosip.image.compressor.sdk.constant.ResponseStatus;
-import io.mosip.image.compressor.sdk.service.ImageCompressionService;
-import io.mosip.image.compressor.sdk.service.SDKInfoService;
/**
* The Class ImageCompressorSDKV2.
@@ -31,18 +28,16 @@
@Component
@EnableAutoConfiguration
public class ImageCompressorSDKV2 implements IBioApiV2 {
- private Logger LOGGER = LoggerFactory.getLogger(ImageCompressorSDKV2.class);
-
/** The environment. */
- @Autowired
+ @Autowired // NOSONAR
private Environment env;
private static final String API_VERSION = "0.9";
+ private static final String ERROR_NOT_IMPLEMENTED = "Sorry! Method functionality not implemented...";
@Override
public SDKInfo init(Map initParams) {
- // TODO validate for mandatory initParams
- SDKInfoService service = new SDKInfoService(env, API_VERSION, "sample", "sample", "sample");
+ SDKInfoService service = new SDKInfoService(env, API_VERSION, "sample", "sample1", "sample2");
return service.getSDKInfo();
}
@@ -51,7 +46,8 @@ public Response checkQuality(BiometricRecord sample, List flags) {
Response response = new Response<>();
response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage() + " Sorry! Method functionality not implemented..."));
+ response.setStatusMessage(
+ String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage(), ERROR_NOT_IMPLEMENTED));
response.setResponse(null);
return response;
}
@@ -61,7 +57,8 @@ public Response match(BiometricRecord sample, BiometricRecord[]
List modalitiesToMatch, Map flags) {
Response response = new Response<>();
response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage() + " Sorry! Method functionality not implemented..."));
+ response.setStatusMessage(
+ String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage(), ERROR_NOT_IMPLEMENTED));
response.setResponse(null);
return response;
}
@@ -78,13 +75,17 @@ public Response segment(BiometricRecord sample, List flags) {
Response response = new Response<>();
response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage() + " Sorry! Method functionality not implemented..."));
+ response.setStatusMessage(
+ String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage(), ERROR_NOT_IMPLEMENTED));
response.setResponse(null);
return response;
}
+ /**
+ * @deprecated (use convertFormatV2)
+ */
@Override
- @Deprecated
+ @Deprecated(since = "1.2.0.1", forRemoval = true)
public BiometricRecord convertFormat(BiometricRecord sample, String sourceFormat, String targetFormat,
Map sourceParams, Map targetParams,
List modalitiesToConvert) {
@@ -92,12 +93,13 @@ public BiometricRecord convertFormat(BiometricRecord sample, String sourceFormat
}
@Override
- public Response convertFormatV2(BiometricRecord record, String sourceFormat, String targetFormat,
- Map sourceParams, Map targetParams,
+ public Response convertFormatV2(BiometricRecord bioRecord, String sourceFormat,
+ String targetFormat, Map sourceParams, Map targetParams,
List modalitiesToConvert) {
Response response = new Response<>();
response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage() + " Sorry! Method functionality not implemented..."));
+ response.setStatusMessage(
+ String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage(), ERROR_NOT_IMPLEMENTED));
response.setResponse(null);
return response;
}
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
index 4e66091..80aabb9 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
@@ -1,6 +1,5 @@
package io.mosip.image.compressor.sdk.service;
-import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@@ -11,32 +10,30 @@
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.springframework.core.env.Environment;
+import io.mosip.biometrics.util.ConvertRequestDto;
+import io.mosip.biometrics.util.face.FaceEncoder;
+import io.mosip.image.compressor.sdk.constant.ResponseStatus;
+import io.mosip.image.compressor.sdk.constant.SdkConstant;
+import io.mosip.image.compressor.sdk.exceptions.SDKException;
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.entities.BDBInfo;
import io.mosip.kernel.biometrics.entities.BIR;
import io.mosip.kernel.biometrics.entities.BiometricRecord;
import io.mosip.kernel.biometrics.model.Response;
-import io.mosip.biometrics.util.ConvertRequestDto;
-import io.mosip.biometrics.util.face.FaceEncoder;
-import io.mosip.image.compressor.sdk.constant.ResponseStatus;
-import io.mosip.image.compressor.sdk.constant.SdkConstant;
-import io.mosip.image.compressor.sdk.exceptions.SDKException;
public class ImageCompressionService extends SDKService {
- private Logger LOGGER = LoggerFactory.getLogger(ImageCompressionService.class);
+ private Logger logger = LoggerFactory.getLogger(ImageCompressionService.class); // NOSONAR
static {
- // load OpenCV library
- //nu.pattern.OpenCV.loadShared();
- //System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
+ /**
+ * load OpenCV library nu.pattern.OpenCV.loadShared();
+ * System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
+ */
/**
* In Java >= 12 it is no longer possible to use addLibraryPath, which modifies
* the ClassLoader's static usr_paths field. There does not seem to be any way
@@ -46,10 +43,7 @@ public class ImageCompressionService extends SDKService {
}
private BiometricRecord sample;
- private List modalitiesToExtract;
-
- private ProcessedLevelType[] types = new ProcessedLevelType[] { ProcessedLevelType.INTERMEDIATE,
- ProcessedLevelType.PROCESSED };
+ private List modalitiesToExtract;// NOSONAR
public static final long FORMAT_TYPE_FACE = 8;
@@ -60,8 +54,9 @@ public ImageCompressionService(Environment env, BiometricRecord sample, List getExtractTemplateInfo() {
- LOGGER.info("ExtractTemplateInfo :: Started Request :: {}", sample != null ? sample.toString() : null);
+ public Response getExtractTemplateInfo() // NOSONAR
+ {
+ logger.info("ExtractTemplateInfo :: Started Request :: {}", sample != null ? sample.toString() : null);
ResponseStatus responseStatus = null;
Response response = new Response<>();
@@ -71,17 +66,12 @@ public Response getExtractTemplateInfo() {
throw new SDKException(responseStatus.getStatusCode() + "", responseStatus.getStatusMessage());
}
- for (int index = 0 ; index < sample.getSegments().size(); index++) {
+ for (int index = 0; index < sample.getSegments().size(); index++) {
BIR segment = sample.getSegments().get(index);
/*
* Below Code can be removed if we require PayLoad information
*/
- /*
- * if (segment.getBirInfo() == null) segment.setBirInfo(new BIRInfo(new
- * BIRInfoBuilder().withPayload(segment.getBdb()))); else
- * segment.getBirInfo().setPayload(segment.getBdb());
- */
if (segment.getBdbInfo() != null && segment.getBdbInfo().getFormat() != null) {
String type = segment.getBdbInfo().getFormat().getType();
@@ -99,44 +89,43 @@ public Response getExtractTemplateInfo() {
byte[] faceBdb = getBirData(segment);
/*
- * do actual resize and compression .. create the face ISO ISO19794_5_2011
+ * do actual resize and compression .. create the face ISO ISO19794_5_2011
*/
byte[] data = doFaceConversion("REGISTRATION", resizeAndCompress(faceBdb));
extractBir.setBdb(data);
/*
- * Update the Created Date
+ * Update the Created Date
*/
extractBir.getBdbInfo().setCreationDate(LocalDateTime.now());
-
+
/*
- * Update the Processed Level Type
+ * Update the Processed Level Type
*/
extractBir.getBdbInfo().setLevel(getProcessedLevelType());
/*
- * Update the Purpose Type
+ * Update the Purpose Type
*/
extractBir.getBdbInfo().setPurpose(getPurposeType());
-
+
/*
- * Update the Quality to null as we do not have quality tool to set the value
+ * Update the Quality to null as we do not have quality tool to set the value
*/
extractBir.getBdbInfo().setQuality(null);
sample.getSegments().set(index, extractBir);
} else {
- throw new SDKException(ResponseStatus.INVALID_INPUT.ordinal() + "",
- String.format(" FORMAT_TYPE_FACE is wrong ! Excepected Value is 8, Received is %s", type));
+ throw new SDKException(ResponseStatus.INVALID_INPUT.ordinal() + "", String
+ .format(" FORMAT_TYPE_FACE is wrong ! Excepected Value is 8, Received is %s", type));
}
- }
- else {
+ } else {
throw new SDKException(ResponseStatus.INVALID_INPUT.ordinal() + "",
- String.format(" BDBInfo is null or Format Value is null"));
+ "BDBInfo is null or Format Value is null");
}
}
} catch (SDKException ex) {
- LOGGER.error("extractTemplate -- error", ex);
+ logger.error("extractTemplate -- error", ex);
switch (ResponseStatus.fromStatusCode(Integer.parseInt(ex.getErrorCode()))) {
case INVALID_INPUT:
response.setStatusCode(ResponseStatus.INVALID_INPUT.getStatusCode());
@@ -177,7 +166,7 @@ public Response getExtractTemplateInfo() {
return response;
}
} catch (Exception ex) {
- LOGGER.error("extractTemplate -- error", ex);
+ logger.error("extractTemplate -- error", ex);
response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage(), ""));
response.setResponse(null);
@@ -186,15 +175,15 @@ public Response getExtractTemplateInfo() {
response.setStatusCode(ResponseStatus.SUCCESS.getStatusCode());
response.setResponse(sample);
- LOGGER.info("ExtractTemplateInfo :: End Response :: {}", response != null ? response.toString() : null);
+ logger.info("ExtractTemplateInfo :: End Response :: {}", response != null ? response.toString() : null);
return response;
}
- public byte[] resizeAndCompress(byte[] jp2000Bytes) throws IOException {
+ public byte[] resizeAndCompress(byte[] jp2000Bytes) {
// Storing the image in a Matrix object
// of Mat type
Mat src = Imgcodecs.imdecode(new MatOfByte(jp2000Bytes), Imgcodecs.IMREAD_UNCHANGED);
- LOGGER.info("Orginal Image Details :: Width {} Height {} Total Size {}", src.width(), src.height(),
+ logger.info("Orginal Image Details :: Width {} Height {} Total Size {}", src.width(), src.height(),
(src.width() * src.height()));
// New matrix to store the final image
// where the input image is supposed to be written
@@ -211,11 +200,11 @@ public byte[] resizeAndCompress(byte[] jp2000Bytes) throws IOException {
compression = this.getEnv().getProperty(SdkConstant.IMAGE_COMPRESSOR_COMPRESSION_RATIO, Integer.class, 50);
}
- LOGGER.info("Factor ratio Details :: {} ", String
- .format("orginal fx=%.2f, orginal fy=%.2f, Compression Ratio==%d ", fxOrginal, fyOrginal, compression));
+ logger.info("Factor ratio Details :: {} ", String
+ .format("orginal fx=%.2f, orginal fy=%.2f, Compression Ratio==%d ", fxOrginal, fyOrginal, compression));// NOSONAR
Imgproc.resize(src, dst, new Size(0, 0), fxOrginal, fyOrginal, Imgproc.INTER_AREA);
- LOGGER.info("Resized Image Details :: Width {} Height {} Total Size {}", dst.width(), dst.height(),
+ logger.info("Resized Image Details :: Width {} Height {} Total Size {}", dst.width(), dst.height(),
(dst.width() * dst.height()));
MatOfInt map = new MatOfInt(Imgcodecs.IMWRITE_JPEG2000_COMPRESSION_X1000, compression);
@@ -223,7 +212,7 @@ public byte[] resizeAndCompress(byte[] jp2000Bytes) throws IOException {
Imgcodecs.imencode(".jp2", dst, mem, map);
byte[] data = mem.toArray();
- LOGGER.info("Compressed Image Details :: Image length {}", data.length);
+ logger.info("Compressed Image Details :: Image length {}", data.length);
return data;
}
@@ -249,11 +238,14 @@ public byte[] doFaceConversion(String purpose, byte[] imageData) {
responseStatus = ResponseStatus.UNKNOWN_ERROR;
throw new SDKException(responseStatus.getStatusCode() + "", responseStatus.getStatusMessage());
}
- return null;
+ throw new SDKException(ResponseStatus.UNKNOWN_ERROR + "", "null");
}
public ProcessedLevelType getProcessedLevelType() {
- return ProcessedLevelType.RAW;
+ ProcessedLevelType[] types = new ProcessedLevelType[] { ProcessedLevelType.RAW, ProcessedLevelType.INTERMEDIATE,
+ ProcessedLevelType.PROCESSED };// NOSONAR
+
+ return types[0];
}
public PurposeType getPurposeType() {
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java
index c37356c..86bb5d1 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java
@@ -5,9 +5,6 @@
import java.util.List;
import java.util.Map;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.springframework.core.env.Environment;
import io.mosip.kernel.biometrics.constant.BiometricFunction;
@@ -15,10 +12,10 @@
import io.mosip.kernel.biometrics.model.SDKInfo;
public class SDKInfoService extends SDKService {
- private Logger LOGGER = LoggerFactory.getLogger(SDKInfoService.class);
-
private String apiVersion;
- private String sample1, sample2, sample3;
+ private String sample1;
+ private String sample2;
+ private String sample3;
public SDKInfoService(Environment env, String apiVersion, String sample1, String sample2, String sample3) {
super(env, null);
@@ -33,7 +30,7 @@ public SDKInfo getSDKInfo() {
List supportedModalities = new ArrayList<>();
supportedModalities.add(BiometricType.FACE);
sdkInfo.setSupportedModalities(supportedModalities);
- Map> supportedMethods = new HashMap<>();
+ Map> supportedMethods = new HashMap<>(); // NOSONAR
supportedMethods.put(BiometricFunction.EXTRACT, supportedModalities);
sdkInfo.setSupportedMethods(supportedMethods);
return sdkInfo;
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java
index 7107747..9e7c6db 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java
@@ -22,7 +22,7 @@
import io.mosip.kernel.biometrics.entities.BiometricRecord;
public abstract class SDKService {
- protected Logger LOGGER = LoggerFactory.getLogger(SDKService.class);
+ protected Logger logger = LoggerFactory.getLogger(SDKService.class);
private Map flags;
private Environment env;
@@ -47,7 +47,7 @@ protected void setEnv(Environment env) {
this.env = env;
}
- protected Map> getBioSegmentMap(BiometricRecord record,
+ protected Map> getBioSegmentMap(BiometricRecord bioRecord,
List modalitiesToMatch) {
Boolean noFilter = false;
@@ -58,19 +58,17 @@ protected Map> getBioSegmentMap(BiometricRecord record,
if (modalitiesToMatch == null || modalitiesToMatch.isEmpty())
noFilter = true;
- Map> bioSegmentMap = new HashMap<>();
- for (BIR segment : record.getSegments()) {
+ Map> bioSegmentMap = new HashMap<>(); // NOSONAR
+ for (BIR segment : bioRecord.getSegments()) {
BiometricType bioType = segment.getBdbInfo().getType().get(0);
/**
* ignore modalities that are not to be matched
*/
- if (noFilter == false && !modalitiesToMatch.contains(bioType))
+ if (Boolean.FALSE.equals(noFilter) && !modalitiesToMatch.contains(bioType))
continue;
- if (!bioSegmentMap.containsKey(bioType)) {
- bioSegmentMap.put(bioType, new ArrayList());
- }
+ bioSegmentMap.computeIfAbsent(bioType, k -> new ArrayList<>());
bioSegmentMap.get(bioType).add(segment);
}
@@ -89,28 +87,25 @@ protected byte[] getBirData(BIR bir) {
bioSubType += " " + bioSubTypeList.get(1).trim();
}
- if (isValidBIRParams(bir, biometricType, bioSubType))
- {
+ if (isValidBIRParams(bir, biometricType, bioSubType)) {
return getBDBData(purposeType, biometricType, bioSubType, bir.getBdb());
}
- return null;
+ throw new SDKException(ResponseStatus.UNKNOWN_ERROR + "", "null");
}
- protected boolean isValidBIRParams(BIR segment, BiometricType bioType, String bioSubType) {
+ protected boolean isValidBIRParams(BIR segment, BiometricType bioType, String bioSubType) // NOSONAR
+ {
ResponseStatus responseStatus = null;
- switch (bioType) {
- case FACE:
- break;
- default:
- LOGGER.error("isValidBIRParams>>BiometricType#" + bioType + ">>BioSubType#" + bioSubType);
+ if (bioType == BiometricType.FACE)
+ return true;
+ else {
+ logger.error("isValidBIRParams::BiometricType{} BioSubType{}", bioType, bioSubType);
responseStatus = ResponseStatus.MISSING_INPUT;
throw new SDKException(responseStatus.getStatusCode() + "", responseStatus.getStatusMessage());
}
- return true;
}
- protected byte[] getBDBData(PurposeType purposeType, BiometricType bioType, String bioSubType,
- byte[] bdbData) {
+ protected byte[] getBDBData(PurposeType purposeType, BiometricType bioType, String bioSubType, byte[] bdbData) {
ResponseStatus responseStatus = null;
if (bdbData != null && bdbData.length != 0) {
@@ -124,30 +119,22 @@ protected byte[] getBDBData(PurposeType purposeType, BiometricType bioType, Stri
protected byte[] getBiometericData(PurposeType purposeType, BiometricType bioType, String bioSubType,
String bdbData) {
ResponseStatus responseStatus = null;
- switch (bioType) {
- case FACE:
+ if (bioType == BiometricType.FACE)
return getFaceBdb(purposeType, bioSubType, bdbData);
- default:
- break;
- }
responseStatus = ResponseStatus.INVALID_INPUT;
throw new SDKException(responseStatus.getStatusCode() + "", responseStatus.getStatusMessage());
}
- protected byte[] getFaceBdb(PurposeType purposeType, String biometricSubType, String bdbData) {
+ protected byte[] getFaceBdb(PurposeType purposeType, String biometricSubType, String bdbData) // NOSONAR
+ {
ResponseStatus responseStatus = null;
try {
ConvertRequestDto requestDto = new ConvertRequestDto();
requestDto.setModality("Face");
requestDto.setVersion("ISO19794_5_2011");
- byte[] bioData = null;
- try {
- bioData = Util.decodeURLSafeBase64(bdbData);
- requestDto.setInputBytes(bioData);
- } catch (Exception e) {
- responseStatus = ResponseStatus.INVALID_INPUT;
- throw new SDKException(responseStatus.getStatusCode() + "", responseStatus.getStatusMessage());
- }
+ byte[] bioData = Util.decodeURLSafeBase64(bdbData);
+ requestDto.setInputBytes(bioData);
+
FaceBDIR bdir = FaceDecoder.getFaceBDIR(requestDto);
return bdir.getImage();
} catch (Exception ex) {
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/utils/Util.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/utils/Util.java
index 5a2f485..32e72b2 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/utils/Util.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/utils/Util.java
@@ -1,21 +1,27 @@
package io.mosip.image.compressor.sdk.utils;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang3.ArrayUtils;
-
import java.nio.charset.StandardCharsets;
-import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Base64.Encoder;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang3.ArrayUtils;
+
+import io.mosip.image.compressor.sdk.constant.ResponseStatus;
+import io.mosip.image.compressor.sdk.exceptions.SDKException;
+
public class Util {
- public static boolean compareHash(byte[] s1, byte[] s2) throws NoSuchAlgorithmException {
+ private Util() {
+ throw new IllegalStateException("Util class");
+ }
+
+ public static boolean compareHash(byte[] s1, byte[] s2) {
String checksum1 = computeFingerPrint(s1, null).toLowerCase();
String checksum2 = computeFingerPrint(s2, null).toLowerCase();
return checksum1.equals(checksum2);
}
- public static String computeFingerPrint(byte[] data, String metaData) throws NoSuchAlgorithmException {
+ public static String computeFingerPrint(byte[] data, String metaData) {
byte[] combinedPlainTextBytes = null;
if (metaData == null) {
combinedPlainTextBytes = ArrayUtils.addAll(data);
@@ -46,7 +52,7 @@ public static String encodeToURLSafeBase64(String data) {
public static byte[] decodeURLSafeBase64(String data) {
if (isNullEmpty(data)) {
- return null;
+ throw new SDKException(ResponseStatus.UNKNOWN_ERROR.toString(), "decodeURLSafeBase64::data{null}");
}
return Base64.getUrlDecoder().decode(data);
}
diff --git a/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest.java b/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest.java
index b669f46..148c43d 100644
--- a/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest.java
+++ b/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest.java
@@ -1,10 +1,19 @@
package io.mosip.image.compressor.sdk.test;
-import io.mosip.image.compressor.sdk.impl.ImageCompressorSDK;
-import io.mosip.kernel.biometrics.constant.BiometricType;
-import io.mosip.kernel.biometrics.constant.ProcessedLevelType;
-import io.mosip.kernel.biometrics.entities.*;
-import io.mosip.kernel.biometrics.model.Response;
+import static java.lang.Integer.parseInt;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -16,15 +25,17 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.File;
-import java.io.IOException;
-import java.util.*;
-
-import static java.lang.Integer.parseInt;
+import io.mosip.image.compressor.sdk.impl.ImageCompressorSDK;
+import io.mosip.kernel.biometrics.constant.BiometricType;
+import io.mosip.kernel.biometrics.constant.ProcessedLevelType;
+import io.mosip.kernel.biometrics.entities.BDBInfo;
+import io.mosip.kernel.biometrics.entities.BIR;
+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.biometrics.model.Response;
+@SuppressWarnings("removal")
public class SampleSDKTest {
Logger LOGGER = LoggerFactory.getLogger(SampleSDKTest.class);
@@ -37,25 +48,26 @@ public void Setup() {
}
@Test
+ @SuppressWarnings("deprecation")
public void test_face() {
try {
- List modalitiesToMatch = new ArrayList(){{
+ List modalitiesToMatch = new ArrayList<>(){{
add(BiometricType.FACE);
add(BiometricType.FINGER);
add(BiometricType.IRIS);
}};
- BiometricRecord sample_record = xmlFileToBiometricRecord(sampleFace);
+ BiometricRecord sampleRecord = xmlFileToBiometricRecord(sampleFace);
- ImageCompressorSDK sampleSDK = new ImageCompressorSDK();
- Response response = sampleSDK.extractTemplate(sample_record, modalitiesToMatch, new HashMap<>());
+ ImageCompressorSDK sampleSDK = new ImageCompressorSDK(); // NOSONAR
+ Response response = sampleSDK.extractTemplate(sampleRecord, modalitiesToMatch, new HashMap<>());// NOSONAR
if (response != null && response.getResponse() != null)
{
- BiometricRecord compressed_record = response.getResponse();
- LOGGER.info("Response {}", compressed_record.toString());
+ BiometricRecord compressedRecord = response.getResponse();
+ LOGGER.info("Response {}", compressedRecord);
- Assert.assertEquals("Should be Raw", compressed_record.getSegments().get(0).getBdbInfo().getLevel().toString(), ProcessedLevelType.RAW.toString());
+ Assert.assertEquals("Should be Raw", compressedRecord.getSegments().get(0).getBdbInfo().getLevel().toString(), ProcessedLevelType.RAW.toString());
- LOGGER.info("BDB base64 encoded {}", Base64.getEncoder().encodeToString(compressed_record.getSegments().get(0).getBdb()));
+ LOGGER.info("BDB base64 encoded {}", Base64.getEncoder().encodeToString(compressedRecord.getSegments().get(0).getBdb()));
}
} catch (ParserConfigurationException e) {
e.printStackTrace();
@@ -68,13 +80,13 @@ public void test_face() {
private BiometricRecord xmlFileToBiometricRecord(String path) throws ParserConfigurationException, IOException, SAXException {
BiometricRecord biometricRecord = new BiometricRecord();
- List bir_segments = new ArrayList();
+ List birSegments = new ArrayList();
File fXmlFile = new File(path);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
- LOGGER.debug("Root element :" + doc.getDocumentElement().getNodeName());
+ LOGGER.debug("Root element :{}", doc.getDocumentElement().getNodeName());
Node rootBIRElement = doc.getDocumentElement();
NodeList childNodes = rootBIRElement.getChildNodes();
for (int temp = 0; temp < childNodes.getLength(); temp++) {
@@ -98,35 +110,35 @@ private BiometricRecord xmlFileToBiometricRecord(String path) throws ParserConfi
/* BDB Info */
Node nBDBInfo = ((Element) childNode).getElementsByTagName("BDBInfo").item(0);
- String bdb_info_type = "";
- String bdb_info_subtype = "";
- String bdb_info_format = "";
- String bdb_info_creation_date = "";
+ String bdbInfoType = "";
+ String bdbInfoSubtype = "";
+ String bdbInfoFormat = "";
+ String bdbInfoCreationDate = ""; // NOSONAR
NodeList nBDBInfoChilds = nBDBInfo.getChildNodes();
for (int z=0; z < nBDBInfoChilds.getLength(); z++){
Node nBDBInfoChild = nBDBInfoChilds.item(z);
if(nBDBInfoChild.getNodeName().equalsIgnoreCase("Type")){
- bdb_info_type = nBDBInfoChild.getTextContent();
+ bdbInfoType = nBDBInfoChild.getTextContent();
}
if(nBDBInfoChild.getNodeName().equalsIgnoreCase("Subtype")){
- bdb_info_subtype = nBDBInfoChild.getTextContent();
+ bdbInfoSubtype = nBDBInfoChild.getTextContent();
}
if(nBDBInfoChild.getNodeName().equalsIgnoreCase("Format")){
- bdb_info_format = nBDBInfoChild.getTextContent();
+ bdbInfoFormat = nBDBInfoChild.getTextContent();
}
if(nBDBInfoChild.getNodeName().equalsIgnoreCase("CreationDate")){
- bdb_info_creation_date = nBDBInfoChild.getTextContent();
+ bdbInfoCreationDate = nBDBInfoChild.getTextContent();// NOSONAR
}
}
BDBInfo.BDBInfoBuilder bdbInfoBuilder = new BDBInfo.BDBInfoBuilder();
- if (!bdb_info_format.isEmpty())
+ if (!bdbInfoFormat.isEmpty())
{
- String[] info = bdb_info_format.split("\n");
+ String[] info = bdbInfoFormat.split("\n");
bdbInfoBuilder.withFormat(new RegistryIDType(info[1].trim(), info[2].trim()));
}
- bdbInfoBuilder.withType(Arrays.asList(BiometricType.fromValue(bdb_info_type)));
- bdbInfoBuilder.withSubtype(Arrays.asList(bdb_info_subtype));
+ bdbInfoBuilder.withType(Arrays.asList(BiometricType.fromValue(bdbInfoType)));
+ bdbInfoBuilder.withSubtype(Arrays.asList(bdbInfoSubtype));
BDBInfo bdbInfo = new BDBInfo(bdbInfoBuilder);
bd.withBdbInfo(bdbInfo);
@@ -138,10 +150,10 @@ private BiometricRecord xmlFileToBiometricRecord(String path) throws ParserConfi
BIR bir = new BIR(bd);
/* Add BIR to list of segments */
- bir_segments.add(bir);
+ birSegments.add(bir);
}
}
- biometricRecord.setSegments(bir_segments);
+ biometricRecord.setSegments(birSegments);
return biometricRecord;
}
}
\ No newline at end of file
diff --git a/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest1.java b/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest1.java
index 97de763..dfa3c9d 100644
--- a/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest1.java
+++ b/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest1.java
@@ -33,23 +33,22 @@
import io.mosip.kernel.biometrics.model.Response;
public class SampleSDKTest1 {
- Logger LOGGER = LoggerFactory.getLogger(SampleSDKTest1.class);
+ private Logger LOGGER = LoggerFactory.getLogger(SampleSDKTest1.class);
private static String sampleFace = "";
public static void main(String[] args) {
- // TODO Auto-generated method stub
SampleSDKTest1 test = new SampleSDKTest1();
- test.test_face();
+ test.testFace();
}
public void Setup() {
sampleFace = SampleSDKTest1.class.getResource("/sample_files/sample_face.xml").getPath();
}
- public void test_face() {
+ public void testFace() {
try {
- List modalitiesToMatch = new ArrayList(){{
+ List modalitiesToMatch = new ArrayList<>(){{
add(BiometricType.FACE);
add(BiometricType.FINGER);
add(BiometricType.IRIS);
@@ -74,13 +73,13 @@ public void test_face() {
private BiometricRecord xmlFileToBiometricRecord(String path) throws ParserConfigurationException, IOException, SAXException {
BiometricRecord biometricRecord = new BiometricRecord();
- List bir_segments = new ArrayList();
+ List birSegments = new ArrayList<>();
File fXmlFile = new File(path);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
- LOGGER.debug("Root element :" + doc.getDocumentElement().getNodeName());
+ LOGGER.debug("Root element :{}", doc.getDocumentElement().getNodeName());
Node rootBIRElement = doc.getDocumentElement();
NodeList childNodes = rootBIRElement.getChildNodes();
for (int temp = 0; temp < childNodes.getLength(); temp++) {
@@ -124,9 +123,6 @@ private BiometricRecord xmlFileToBiometricRecord(String path) throws ParserConfi
bd.withBdbInfo(bdbInfo);
/* BDB */
- //String nBDB = ((Element) childNode).getElementsByTagName("BDB").item(0).getTextContent();
- //bd.withBdb(nBDB.getBytes("UTF-8"));
-
byte[] nBDB = Base64.getDecoder().decode(((Element) childNode).getElementsByTagName("BDB").item(0).getTextContent());
bd.withBdb(nBDB);
@@ -134,10 +130,10 @@ private BiometricRecord xmlFileToBiometricRecord(String path) throws ParserConfi
BIR bir = new BIR(bd);
/* Add BIR to list of segments */
- bir_segments.add(bir);
+ birSegments.add(bir);
}
}
- biometricRecord.setSegments(bir_segments);
+ biometricRecord.setSegments(birSegments);
return biometricRecord;
}
From 8dd2ecd70419aa394fb44ee44ddb86a3c6e8d93c Mon Sep 17 00:00:00 2001
From: JanardhanBS-SyncByte
Date: Sat, 25 May 2024 11:34:48 +0530
Subject: [PATCH 5/8] [MOSIP-33318]
Signed-off-by: JanardhanBS-SyncByte
---
.github/workflows/push-trigger.yml | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml
index 7a73b34..bfe7f8a 100644
--- a/.github/workflows/push-trigger.yml
+++ b/.github/workflows/push-trigger.yml
@@ -50,10 +50,11 @@ jobs:
sonar_analysis:
needs: build-maven-image-compressor
- if: "${{ github.event_name != 'pull_request' }}"
+ if: "${{ github.event_name != 'pull_request' }}"
uses: mosip/kattu/.github/workflows/maven-sonar-analysis.yml@master-java21
with:
SERVICE_LOCATION: image-compressor
+ PROJECT_KEY: 'mosip_image-compressor'
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
ORG_KEY: ${{ secrets.ORG_KEY }}
@@ -61,6 +62,4 @@ jobs:
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
- SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
-
-
+ SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
\ No newline at end of file
From 30971768de2305aa46cb6da8d745181746ba9026 Mon Sep 17 00:00:00 2001
From: JanardhanBS-SyncByte
Date: Mon, 27 May 2024 10:58:54 +0530
Subject: [PATCH 6/8] [MOSIP-33318]
Signed-off-by: JanardhanBS-SyncByte
---
.../mosip/image/compressor/sdk/impl/ImageCompressorSDK.java | 4 ++++
.../image/compressor/sdk/service/ImageCompressionService.java | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
index 4119d9e..12684c9 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
@@ -24,6 +24,10 @@
*
* @author Janardhan B S
*
+ * This class is deprecated and will be removed in future versions.
+ *
+ * @since 1.2.0.1
+ * @deprecated since 1.2.0.1, for removal in a future release
*/
@Component
@EnableAutoConfiguration
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
index 80aabb9..03e135c 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
@@ -234,7 +234,7 @@ public byte[] doFaceConversion(String purpose, byte[] imageData) {
return FaceEncoder.convertFaceImageToISO(requestDto);
}
} catch (Exception ex) {
- ex.printStackTrace();
+ logger.error("doFaceConversion::error", ex);
responseStatus = ResponseStatus.UNKNOWN_ERROR;
throw new SDKException(responseStatus.getStatusCode() + "", responseStatus.getStatusMessage());
}
From 1703291852348b3049adca91b51812b116c7ae04 Mon Sep 17 00:00:00 2001
From: JanardhanBS-SyncByte
Date: Wed, 29 May 2024 14:00:45 +0530
Subject: [PATCH 7/8] [MOSIP-33318]
Signed-off-by: JanardhanBS-SyncByte
---
.../sdk/impl/ImageCompressorSDK.java | 9 +-
.../sdk/impl/ImageCompressorSDKV2.java | 3 +-
.../sdk/service/ImageCompressionService.java | 15 +-
.../sdk/service/SDKInfoService.java | 2 +-
.../compressor/sdk/service/SDKService.java | 10 +-
.../compressor/sdk/test/SampleSDKTest.java | 245 +++++++++---------
.../compressor/sdk/test/SampleSDKTest1.java | 6 +-
7 files changed, 152 insertions(+), 138 deletions(-)
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
index 12684c9..091a037 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
@@ -32,10 +32,11 @@
@Component
@EnableAutoConfiguration
@Deprecated(since="1.2.0.1", forRemoval=true)
-public class ImageCompressorSDK implements IBioApi // NOSONAR
+public class ImageCompressorSDK implements IBioApi
{
/** The environment. */
- @Autowired // NOSONAR
+ @SuppressWarnings({ "java:S6813" })
+ @Autowired
private Environment env;
private static final String API_VERSION = "0.9";
@@ -44,7 +45,7 @@ public class ImageCompressorSDK implements IBioApi // NOSONAR
@Override
public SDKInfo init(Map initParams) {
- SDKInfoService service = new SDKInfoService(env, API_VERSION, "sample", "sample", "sample");// NOSONAR
+ SDKInfoService service = new SDKInfoService(env, API_VERSION, "sample1", "sample2", "sample3");
return service.getSDKInfo();
}
@@ -54,7 +55,7 @@ public Response checkQuality(BiometricRecord sample, List response = new Response<>();
response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage(),
- ERROR_NOT_IMPLEMENTED));// NOSONAR
+ ERROR_NOT_IMPLEMENTED));
response.setResponse(null);
return response;
}
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java
index 2fb1c12..5eacd42 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java
@@ -29,7 +29,8 @@
@EnableAutoConfiguration
public class ImageCompressorSDKV2 implements IBioApiV2 {
/** The environment. */
- @Autowired // NOSONAR
+ @SuppressWarnings({ "java:S6813" })
+ @Autowired
private Environment env;
private static final String API_VERSION = "0.9";
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
index 03e135c..d23b4be 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
@@ -27,7 +27,7 @@
import io.mosip.kernel.biometrics.model.Response;
public class ImageCompressionService extends SDKService {
- private Logger logger = LoggerFactory.getLogger(ImageCompressionService.class); // NOSONAR
+ private Logger logger = LoggerFactory.getLogger(ImageCompressionService.class);
static {
/**
@@ -43,7 +43,8 @@ public class ImageCompressionService extends SDKService {
}
private BiometricRecord sample;
- private List modalitiesToExtract;// NOSONAR
+ @SuppressWarnings("unused")
+ private List modalitiesToExtract;
public static final long FORMAT_TYPE_FACE = 8;
@@ -54,8 +55,8 @@ public ImageCompressionService(Environment env, BiometricRecord sample, List getExtractTemplateInfo() // NOSONAR
- {
+ @SuppressWarnings({ "java:S3776", "java:S6541" })
+ public Response getExtractTemplateInfo() {
logger.info("ExtractTemplateInfo :: Started Request :: {}", sample != null ? sample.toString() : null);
ResponseStatus responseStatus = null;
@@ -200,8 +201,8 @@ public byte[] resizeAndCompress(byte[] jp2000Bytes) {
compression = this.getEnv().getProperty(SdkConstant.IMAGE_COMPRESSOR_COMPRESSION_RATIO, Integer.class, 50);
}
- logger.info("Factor ratio Details :: {} ", String
- .format("orginal fx=%.2f, orginal fy=%.2f, Compression Ratio==%d ", fxOrginal, fyOrginal, compression));// NOSONAR
+ logger.info("Factor ratio Details :: orginal fx={}, orginal fy={}, Compression Ratio=={} ", fxOrginal,
+ fyOrginal, compression);
Imgproc.resize(src, dst, new Size(0, 0), fxOrginal, fyOrginal, Imgproc.INTER_AREA);
logger.info("Resized Image Details :: Width {} Height {} Total Size {}", dst.width(), dst.height(),
@@ -243,7 +244,7 @@ public byte[] doFaceConversion(String purpose, byte[] imageData) {
public ProcessedLevelType getProcessedLevelType() {
ProcessedLevelType[] types = new ProcessedLevelType[] { ProcessedLevelType.RAW, ProcessedLevelType.INTERMEDIATE,
- ProcessedLevelType.PROCESSED };// NOSONAR
+ ProcessedLevelType.PROCESSED };
return types[0];
}
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java
index 86bb5d1..7005248 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java
@@ -30,7 +30,7 @@ public SDKInfo getSDKInfo() {
List supportedModalities = new ArrayList<>();
supportedModalities.add(BiometricType.FACE);
sdkInfo.setSupportedModalities(supportedModalities);
- Map> supportedMethods = new HashMap<>(); // NOSONAR
+ Map> supportedMethods = new HashMap<>();
supportedMethods.put(BiometricFunction.EXTRACT, supportedModalities);
sdkInfo.setSupportedMethods(supportedMethods);
return sdkInfo;
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java
index 9e7c6db..9f1a792 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java
@@ -22,7 +22,7 @@
import io.mosip.kernel.biometrics.entities.BiometricRecord;
public abstract class SDKService {
- protected Logger logger = LoggerFactory.getLogger(SDKService.class);
+ private Logger logger = LoggerFactory.getLogger(SDKService.class);
private Map flags;
private Environment env;
@@ -58,7 +58,7 @@ protected Map> getBioSegmentMap(BiometricRecord bioReco
if (modalitiesToMatch == null || modalitiesToMatch.isEmpty())
noFilter = true;
- Map> bioSegmentMap = new HashMap<>(); // NOSONAR
+ Map> bioSegmentMap = new HashMap<>();
for (BIR segment : bioRecord.getSegments()) {
BiometricType bioType = segment.getBdbInfo().getType().get(0);
@@ -93,7 +93,8 @@ protected byte[] getBirData(BIR bir) {
throw new SDKException(ResponseStatus.UNKNOWN_ERROR + "", "null");
}
- protected boolean isValidBIRParams(BIR segment, BiometricType bioType, String bioSubType) // NOSONAR
+ @SuppressWarnings({ "unused" })
+ protected boolean isValidBIRParams(BIR segment, BiometricType bioType, String bioSubType)
{
ResponseStatus responseStatus = null;
if (bioType == BiometricType.FACE)
@@ -125,7 +126,8 @@ protected byte[] getBiometericData(PurposeType purposeType, BiometricType bioTyp
throw new SDKException(responseStatus.getStatusCode() + "", responseStatus.getStatusMessage());
}
- protected byte[] getFaceBdb(PurposeType purposeType, String biometricSubType, String bdbData) // NOSONAR
+ @SuppressWarnings({ "unused" })
+ protected byte[] getFaceBdb(PurposeType purposeType, String biometricSubType, String bdbData)
{
ResponseStatus responseStatus = null;
try {
diff --git a/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest.java b/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest.java
index 148c43d..9545313 100644
--- a/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest.java
+++ b/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest.java
@@ -38,122 +38,131 @@
@SuppressWarnings("removal")
public class SampleSDKTest {
- Logger LOGGER = LoggerFactory.getLogger(SampleSDKTest.class);
-
- private String sampleFace = "";
-
- @Before
- public void Setup() {
- sampleFace = SampleSDKTest.class.getResource("/sample_files/sample_face.xml").getPath();
- }
-
- @Test
- @SuppressWarnings("deprecation")
- public void test_face() {
- try {
- List modalitiesToMatch = new ArrayList<>(){{
- add(BiometricType.FACE);
- add(BiometricType.FINGER);
- add(BiometricType.IRIS);
- }};
- BiometricRecord sampleRecord = xmlFileToBiometricRecord(sampleFace);
-
- ImageCompressorSDK sampleSDK = new ImageCompressorSDK(); // NOSONAR
- Response response = sampleSDK.extractTemplate(sampleRecord, modalitiesToMatch, new HashMap<>());// NOSONAR
- if (response != null && response.getResponse() != null)
- {
- BiometricRecord compressedRecord = response.getResponse();
- LOGGER.info("Response {}", compressedRecord);
-
- Assert.assertEquals("Should be Raw", compressedRecord.getSegments().get(0).getBdbInfo().getLevel().toString(), ProcessedLevelType.RAW.toString());
-
- LOGGER.info("BDB base64 encoded {}", Base64.getEncoder().encodeToString(compressedRecord.getSegments().get(0).getBdb()));
- }
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (SAXException e) {
- e.printStackTrace();
- }
- }
-
- private BiometricRecord xmlFileToBiometricRecord(String path) throws ParserConfigurationException, IOException, SAXException {
- BiometricRecord biometricRecord = new BiometricRecord();
- List birSegments = new ArrayList();
- File fXmlFile = new File(path);
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- Document doc = dBuilder.parse(fXmlFile);
- doc.getDocumentElement().normalize();
- LOGGER.debug("Root element :{}", doc.getDocumentElement().getNodeName());
- Node rootBIRElement = doc.getDocumentElement();
- NodeList childNodes = rootBIRElement.getChildNodes();
- for (int temp = 0; temp < childNodes.getLength(); temp++) {
- Node childNode = childNodes.item(temp);
- if(childNode.getNodeName().equalsIgnoreCase("bir")){
- BIR.BIRBuilder bd = new BIR.BIRBuilder();
-
- /* Version */
- Node nVersion = ((Element) childNode).getElementsByTagName("Version").item(0);
- String major_version = ((Element) nVersion).getElementsByTagName("Major").item(0).getTextContent();
- String minor_version = ((Element) nVersion).getElementsByTagName("Minor").item(0).getTextContent();
- VersionType bir_version = new VersionType(parseInt(major_version), parseInt(minor_version));
- bd.withVersion(bir_version);
-
- /* CBEFF Version */
- Node nCBEFFVersion = ((Element) childNode).getElementsByTagName("Version").item(0);
- String cbeff_major_version = ((Element) nCBEFFVersion).getElementsByTagName("Major").item(0).getTextContent();
- String cbeff_minor_version = ((Element) nCBEFFVersion).getElementsByTagName("Minor").item(0).getTextContent();
- VersionType cbeff_bir_version = new VersionType(parseInt(cbeff_major_version), parseInt(cbeff_minor_version));
- bd.withCbeffversion(cbeff_bir_version);
-
- /* BDB Info */
- Node nBDBInfo = ((Element) childNode).getElementsByTagName("BDBInfo").item(0);
- String bdbInfoType = "";
- String bdbInfoSubtype = "";
- String bdbInfoFormat = "";
- String bdbInfoCreationDate = ""; // NOSONAR
- NodeList nBDBInfoChilds = nBDBInfo.getChildNodes();
- for (int z=0; z < nBDBInfoChilds.getLength(); z++){
- Node nBDBInfoChild = nBDBInfoChilds.item(z);
- if(nBDBInfoChild.getNodeName().equalsIgnoreCase("Type")){
- bdbInfoType = nBDBInfoChild.getTextContent();
- }
- if(nBDBInfoChild.getNodeName().equalsIgnoreCase("Subtype")){
- bdbInfoSubtype = nBDBInfoChild.getTextContent();
- }
- if(nBDBInfoChild.getNodeName().equalsIgnoreCase("Format")){
- bdbInfoFormat = nBDBInfoChild.getTextContent();
- }
- if(nBDBInfoChild.getNodeName().equalsIgnoreCase("CreationDate")){
- bdbInfoCreationDate = nBDBInfoChild.getTextContent();// NOSONAR
- }
- }
-
- BDBInfo.BDBInfoBuilder bdbInfoBuilder = new BDBInfo.BDBInfoBuilder();
- if (!bdbInfoFormat.isEmpty())
- {
- String[] info = bdbInfoFormat.split("\n");
- bdbInfoBuilder.withFormat(new RegistryIDType(info[1].trim(), info[2].trim()));
- }
- bdbInfoBuilder.withType(Arrays.asList(BiometricType.fromValue(bdbInfoType)));
- bdbInfoBuilder.withSubtype(Arrays.asList(bdbInfoSubtype));
- BDBInfo bdbInfo = new BDBInfo(bdbInfoBuilder);
- bd.withBdbInfo(bdbInfo);
-
- /* BDB */
- String strBDB = ((Element) childNode).getElementsByTagName("BDB").item(0).getTextContent();
- bd.withBdb(Base64.getDecoder().decode (strBDB));
-
- /* Prepare BIR */
- BIR bir = new BIR(bd);
-
- /* Add BIR to list of segments */
- birSegments.add(bir);
- }
- }
- biometricRecord.setSegments(birSegments);
- return biometricRecord;
- }
+ Logger LOGGER = LoggerFactory.getLogger(SampleSDKTest.class);
+
+ private String sampleFace = "";
+
+ @Before
+ public void Setup() {
+ sampleFace = SampleSDKTest.class.getResource("/sample_files/sample_face.xml").getPath();
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ public void test_face() {
+ try {
+ List modalitiesToMatch = new ArrayList<>() {
+ {
+ add(BiometricType.FACE);
+ add(BiometricType.FINGER);
+ add(BiometricType.IRIS);
+ }
+ };
+ BiometricRecord sampleRecord = xmlFileToBiometricRecord(sampleFace);
+
+ ImageCompressorSDK sampleSDK = new ImageCompressorSDK();
+ Response response = sampleSDK.extractTemplate(sampleRecord, modalitiesToMatch,
+ new HashMap<>());
+ if (response != null && response.getResponse() != null) {
+ BiometricRecord compressedRecord = response.getResponse();
+ LOGGER.info("Response {}", compressedRecord);
+
+ Assert.assertEquals("Should be Raw",
+ compressedRecord.getSegments().get(0).getBdbInfo().getLevel().toString(),
+ ProcessedLevelType.RAW.toString());
+
+ LOGGER.info("BDB base64 encoded {}",
+ Base64.getEncoder().encodeToString(compressedRecord.getSegments().get(0).getBdb()));
+ }
+ } catch (ParserConfigurationException e) {
+ LOGGER.error("test_face", e);
+ } catch (IOException e) {
+ LOGGER.error("test_face", e);
+ } catch (SAXException e) {
+ LOGGER.error("test_face", e);
+ }
+ }
+
+ @SuppressWarnings({ "java:S1854", "unused" })
+ private BiometricRecord xmlFileToBiometricRecord(String path)
+ throws ParserConfigurationException, IOException, SAXException {
+ BiometricRecord biometricRecord = new BiometricRecord();
+ List birSegments = new ArrayList();
+ File fXmlFile = new File(path);
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+ Document doc = dBuilder.parse(fXmlFile);
+ doc.getDocumentElement().normalize();
+ LOGGER.debug("Root element :{}", doc.getDocumentElement().getNodeName());
+ Node rootBIRElement = doc.getDocumentElement();
+ NodeList childNodes = rootBIRElement.getChildNodes();
+ for (int temp = 0; temp < childNodes.getLength(); temp++) {
+ Node childNode = childNodes.item(temp);
+ if (childNode.getNodeName().equalsIgnoreCase("bir")) {
+ BIR.BIRBuilder bd = new BIR.BIRBuilder();
+
+ /* Version */
+ Node nVersion = ((Element) childNode).getElementsByTagName("Version").item(0);
+ String major_version = ((Element) nVersion).getElementsByTagName("Major").item(0).getTextContent();
+ String minor_version = ((Element) nVersion).getElementsByTagName("Minor").item(0).getTextContent();
+ VersionType bir_version = new VersionType(parseInt(major_version), parseInt(minor_version));
+ bd.withVersion(bir_version);
+
+ /* CBEFF Version */
+ Node nCBEFFVersion = ((Element) childNode).getElementsByTagName("Version").item(0);
+ String cbeff_major_version = ((Element) nCBEFFVersion).getElementsByTagName("Major").item(0)
+ .getTextContent();
+ String cbeff_minor_version = ((Element) nCBEFFVersion).getElementsByTagName("Minor").item(0)
+ .getTextContent();
+ VersionType cbeff_bir_version = new VersionType(parseInt(cbeff_major_version),
+ parseInt(cbeff_minor_version));
+ bd.withCbeffversion(cbeff_bir_version);
+
+ /* BDB Info */
+ Node nBDBInfo = ((Element) childNode).getElementsByTagName("BDBInfo").item(0);
+ String bdbInfoType = "";
+ String bdbInfoSubtype = "";
+ String bdbInfoFormat = "";
+ String bdbInfoCreationDate = "";
+ NodeList nBDBInfoChilds = nBDBInfo.getChildNodes();
+ for (int z = 0; z < nBDBInfoChilds.getLength(); z++) {
+ Node nBDBInfoChild = nBDBInfoChilds.item(z);
+ if (nBDBInfoChild.getNodeName().equalsIgnoreCase("Type")) {
+ bdbInfoType = nBDBInfoChild.getTextContent();
+ }
+ if (nBDBInfoChild.getNodeName().equalsIgnoreCase("Subtype")) {
+ bdbInfoSubtype = nBDBInfoChild.getTextContent();
+ }
+ if (nBDBInfoChild.getNodeName().equalsIgnoreCase("Format")) {
+ bdbInfoFormat = nBDBInfoChild.getTextContent();
+ }
+ if (nBDBInfoChild.getNodeName().equalsIgnoreCase("CreationDate")) {
+ bdbInfoCreationDate = nBDBInfoChild.getTextContent();
+ }
+ }
+
+ BDBInfo.BDBInfoBuilder bdbInfoBuilder = new BDBInfo.BDBInfoBuilder();
+ if (!bdbInfoFormat.isEmpty()) {
+ String[] info = bdbInfoFormat.split("\n");
+ bdbInfoBuilder.withFormat(new RegistryIDType(info[1].trim(), info[2].trim()));
+ }
+ bdbInfoBuilder.withType(Arrays.asList(BiometricType.fromValue(bdbInfoType)));
+ bdbInfoBuilder.withSubtype(Arrays.asList(bdbInfoSubtype));
+ BDBInfo bdbInfo = new BDBInfo(bdbInfoBuilder);
+ bd.withBdbInfo(bdbInfo);
+
+ /* BDB */
+ String strBDB = ((Element) childNode).getElementsByTagName("BDB").item(0).getTextContent();
+ bd.withBdb(Base64.getDecoder().decode(strBDB));
+
+ /* Prepare BIR */
+ BIR bir = new BIR(bd);
+
+ /* Add BIR to list of segments */
+ birSegments.add(bir);
+ }
+ }
+ biometricRecord.setSegments(birSegments);
+ return biometricRecord;
+ }
}
\ No newline at end of file
diff --git a/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest1.java b/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest1.java
index dfa3c9d..cdd462e 100644
--- a/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest1.java
+++ b/image-compressor/src/test/java/io/mosip/image/compressor/sdk/test/SampleSDKTest1.java
@@ -63,11 +63,11 @@ public void testFace() {
Assert.assertEquals("Should be Raw", compressed_record.getSegments().get(0).getBdbInfo().getLevel().toString(), ProcessedLevelType.RAW.toString());
}
} catch (ParserConfigurationException e) {
- e.printStackTrace();
+ LOGGER.error("testFace", e);
} catch (IOException e) {
- e.printStackTrace();
+ LOGGER.error("testFace", e);
} catch (SAXException e) {
- e.printStackTrace();
+ LOGGER.error("testFace", e);
}
}
From 2e5c264e245ef1dd5c220a0a12517f9b16bbc83e Mon Sep 17 00:00:00 2001
From: JanardhanBS-SyncByte
Date: Tue, 18 Jun 2024 12:34:08 +0530
Subject: [PATCH 8/8] [MOSIP-33318] Merge develop from develop-java21
Signed-off-by: JanardhanBS-SyncByte
---
.gitignore | 1 +
image-compressor/pom.xml | 10 +-
.../sdk/constant/ResponseStatus.java | 98 +++++++--
.../compressor/sdk/constant/SdkConstant.java | 47 +++-
.../sdk/impl/ImageCompressorSDK.java | 81 ++++++-
.../sdk/impl/ImageCompressorSDKV2.java | 99 ++++++++-
.../sdk/service/ImageCompressionService.java | 201 +++++++++++++-----
.../sdk/service/SDKInfoService.java | 33 ++-
.../compressor/sdk/service/SDKService.java | 129 ++++++++++-
9 files changed, 602 insertions(+), 97 deletions(-)
diff --git a/.gitignore b/.gitignore
index 524f096..9b13ee0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,3 +22,4 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
+/.metadata/
diff --git a/image-compressor/pom.xml b/image-compressor/pom.xml
index 65dee1f..f2614f5 100644
--- a/image-compressor/pom.xml
+++ b/image-compressor/pom.xml
@@ -4,7 +4,7 @@
4.0.0
image-compressor
io.mosip.image.compressor
- 0.0.1-java21-SNAPSHOT
+ 0.0.1-SNAPSHOT
image-compressor
Image Compressorimplementation of biometrics SDK
jar
@@ -73,10 +73,10 @@
3.0.1
- 1.2.1-java21-SNAPSHOT
- 1.2.1-java21-SNAPSHOT
- 1.2.1-java21-SNAPSHOT
- 1.2.1-java21-SNAPSHOT
+ 1.2.1-SNAPSHOT
+ 1.2.1-SNAPSHOT
+ 1.2.1-SNAPSHOT
+ 1.2.1-SNAPSHOT
1.3.0
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/ResponseStatus.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/ResponseStatus.java
index 61d3c23..4c3b683 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/ResponseStatus.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/ResponseStatus.java
@@ -1,23 +1,95 @@
package io.mosip.image.compressor.sdk.constant;
+/**
+ * Enumeration representing various HTTP response statuses used by the BioSDK
+ * client.
+ *
+ * This enum defines commonly used HTTP response statuses and their
+ * corresponding messages for responses generated by the BioSDK client
+ * application. It provides a standardized way to communicate success or error
+ * conditions to external clients.
+ *
+ * @author Janardhan B S
+ * @since 1.0.0
+ */
public enum ResponseStatus {
+ /**
+ * Indicates a successful operation.
+ *
+ * This status code (200) and message ("OK") are used when the BioSDK client
+ * processes a request successfully and has a valid response to return.
+ */
SUCCESS(200, "OK"),
- INVALID_INPUT(401, "Invalid Input Parameter"),
- MISSING_INPUT(402, "Missing Input Parameter"),
+
+ /**
+ * Indicates an invalid input parameter in the request.
+ *
+ * This status code (400) and message format ("Invalid Input Parameter - %s")
+ * are used when a required input parameter is missing, has an invalid format,
+ * or violates any defined validation rules. The specific parameter name or
+ * details can be included in the formatted message using String.format().
+ */
+ INVALID_INPUT(401, "Invalid Input Parameter - %s"),
+
+ /**
+ * Indicates a missing input parameter in the request.
+ *
+ * This status code (402) and message format ("Missing Input Parameter - %s")
+ * are used when a required input parameter is completely absent from the
+ * request. The specific parameter name can be included in the formatted message
+ * using String.format().
+ */
+ MISSING_INPUT(402, "Missing Input Parameter - %s"),
+
+ /**
+ * Indicates a failure during quality check of biometric data.
+ *
+ * This status code (403) and message ("Quality check of Biometric data failed")
+ * are used when the BioSDK client performs quality checks on biometric data and
+ * the data fails to meet the minimum quality requirements.
+ */
QUALITY_CHECK_FAILED(403, "Quality check of Biometric data failed"),
+
+ /**
+ * Indicates a failure during biometric data not found.
+ *
+ * This status code (404) and message ("Biometric data not found").
+ */
BIOMETRIC_NOT_FOUND_IN_CBEFF(404, "Biometrics not found in CBEFF"),
+
+ /**
+ * Indicates a failure during biometric data Mathcing data failed.
+ *
+ * This status code (405) and message ("Matching of Biometric data failed").
+ */
MATCHING_OF_BIOMETRIC_DATA_FAILED(405, "Matching of Biometric data failed"),
+
+ /**
+ * Indicates poor quality of provided data.
+ *
+ * This status code (406) and message ("Data provided is of poor quality") , although
+ * technically valid, might be of insufficient quality for further processing.
+ */
POOR_DATA_QUALITY(406, "Data provided is of poor quality"),
+
+ /**
+ * Indicates an unexpected error occurred on the server.
+ *
+ * This status code (500) and message ("UNKNOWN_ERROR") are used as a catch-all
+ * for any internal server errors that may occur during processing. It's
+ * important to investigate and resolve the root cause of such errors for proper
+ * handling in future versions.
+ */
UNKNOWN_ERROR(500, "UNKNOWN_ERROR");
-
+
ResponseStatus(int statusCode, String statusMessage) {
this.statusCode = statusCode;
this.statusMessage = statusMessage;
}
-
+
private int statusCode;
private String statusMessage;
-
+
public int getStatusCode() {
return statusCode;
}
@@ -26,12 +98,12 @@ public String getStatusMessage() {
return statusMessage;
}
- public static ResponseStatus fromStatusCode(int code) {
- for (ResponseStatus paramCode : ResponseStatus.values()) {
- if (paramCode.getStatusCode() == code) {
- return paramCode;
- }
- }
- return UNKNOWN_ERROR;
- }
+ public static ResponseStatus fromStatusCode(int code) {
+ for (ResponseStatus paramCode : ResponseStatus.values()) {
+ if (paramCode.getStatusCode() == code) {
+ return paramCode;
+ }
+ }
+ return UNKNOWN_ERROR;
+ }
}
\ No newline at end of file
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/SdkConstant.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/SdkConstant.java
index e1c6db9..86d9a0c 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/SdkConstant.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/constant/SdkConstant.java
@@ -1,10 +1,30 @@
package io.mosip.image.compressor.sdk.constant;
/**
- * The class contains variable names used from configuration
+ * Constants used in the Image Compressor SDK configuration.
+ *
+ * This class provides constant variable names used in the configuration
+ * related to image compression and resizing factors.
+ *
+ *
+ * Example usage:
+ *
{@code
+ * double resizeFactorFx = env.getProperty(SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FX, Double.class, 0.25);
+ * double resizeFactorFy = env.getProperty(SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FY, Double.class, 0.25);
+ * int compressionRatio = env.getProperty(SdkConstant.IMAGE_COMPRESSOR_COMPRESSION_RATIO, Integer.class, 50);
+ * }
+ *
+ *
+ * Note: The constants {@code IMAGE_COMPRESSOR_RESIZE_FACTOR_FX} and {@code IMAGE_COMPRESSOR_RESIZE_FACTOR_FY}
+ * represent the resize factors for image compression, and {@code IMAGE_COMPRESSOR_COMPRESSION_RATIO} represents
+ * the compression ratio.
+ *
+ *
+ * All constants are defined as {@code public static final} and are not meant to be instantiated.
+ *
*
* @author Janardhan B S
- *
+ * @since 1.0
*/
public class SdkConstant {
private SdkConstant() {
@@ -12,15 +32,24 @@ private SdkConstant() {
}
/**
- * 0 to Double.Max_value
- */
+ * Configuration key for the resize factor FX used in image compression.
+ *
+ * The value range is from 0 to {@code Double.MAX_VALUE}.
+ *
+ */
public static final String IMAGE_COMPRESSOR_RESIZE_FACTOR_FX = "mosip.bio.image.compressor.resize.factor.fx";
- /**
- * 0 to Double.Max_value
- */
+ /**
+ * Configuration key for the resize factor FY used in image compression.
+ *
+ * The value range is from 0 to {@code Double.MAX_VALUE}.
+ *
+ */
public static final String IMAGE_COMPRESSOR_RESIZE_FACTOR_FY = "mosip.bio.image.compressor.resize.factor.fy";
/**
- * 1 to 1000
- */
+ * Configuration key for the compression ratio used in image compression.
+ *
+ * The value range is from 1 to 1000.
+ *
+ */
public static final String IMAGE_COMPRESSOR_COMPRESSION_RATIO = "mosip.bio.image.compressor.compression.ratio";
}
\ No newline at end of file
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
index 091a037..dba69af 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDK.java
@@ -20,14 +20,38 @@
import io.mosip.kernel.biometrics.spi.IBioApi;
/**
- * The Class ImageCompressorSDK.
- *
- * @author Janardhan B S
- *
- * This class is deprecated and will be removed in future versions.
+ * Deprecated implementation class for the Image Compressor SDK.
+ *
+ * This class provides biometric operations that include initializing the SDK,
+ * quality checks, matching biometric samples, extracting templates, and segmenting samples.
+ *
+ *
+ * This class is deprecated and will be removed in a future release.
+ * Please migrate to {@link ImageCompressorSDKV2} for updated functionality.
+ *
+ *
+ * It uses Spring's {@code @Component} for automatic component scanning and {@code @EnableAutoConfiguration}
+ * for enabling Spring Boot auto-configuration.
+ *
+ *
+ * The methods in this class handle various response scenarios and use {@code Response} objects
+ * to encapsulate the response status, message, and data.
+ *
+ *
+ * Example usage:
+ *
{@code
+ * ImageCompressorSDK sdk = new ImageCompressorSDK();
+ * SDKInfo sdkInfo = sdk.init(initParams);
+ * Response response = sdk.extractTemplate(sample, modalitiesToExtract, flags);
+ * }
+ *
*
+ * @author Janardhan B S
* @since 1.2.0.1
- * @deprecated since 1.2.0.1, for removal in a future release
+ * @deprecated Since 1.2.0.1, for removal in a future release. Use {@link ImageCompressorSDKV2} instead.
+ * @see IBioApi
+ * @see ImageCompressionService
+ * @see SDKInfoService
*/
@Component
@EnableAutoConfiguration
@@ -43,12 +67,26 @@ public class ImageCompressorSDK implements IBioApi
private static final String ERROR_NOT_IMPLEMENTED = "Sorry! Method functionality not implemented...";
+ /**
+ * Initializes the SDK with the provided initialization parameters.
+ *
+ * @param initParams The initialization parameters for the SDK.
+ * @return Information about the initialized SDK.
+ */
@Override
public SDKInfo init(Map initParams) {
SDKInfoService service = new SDKInfoService(env, API_VERSION, "sample1", "sample2", "sample3");
return service.getSDKInfo();
}
+ /**
+ * Performs quality check on the provided biometric sample.
+ *
+ * @param sample The biometric record sample to check.
+ * @param modalitiesToCheck The list of biometric types to check.
+ * @param flags Additional configuration flags.
+ * @return Response containing the quality check result.
+ */
@Override
public Response checkQuality(BiometricRecord sample, List modalitiesToCheck,
Map flags) {
@@ -60,6 +98,15 @@ public Response checkQuality(BiometricRecord sample, List match(BiometricRecord sample, BiometricRecord[] gallery,
List modalitiesToMatch, Map flags) {
@@ -71,6 +118,14 @@ public Response match(BiometricRecord sample, BiometricRecord[]
return response;
}
+ /**
+ * Extracts biometric template from the provided biometric sample.
+ *
+ * @param sample The biometric record sample to extract template from.
+ * @param modalitiesToExtract The list of biometric types to extract.
+ * @param flags Additional configuration flags.
+ * @return Response containing the extracted biometric record.
+ */
@Override
public Response extractTemplate(BiometricRecord sample, List modalitiesToExtract,
Map flags) {
@@ -78,6 +133,14 @@ public Response extractTemplate(BiometricRecord sample, List segment(BiometricRecord sample, List modalitiesToSegment,
Map flags) {
@@ -89,10 +152,14 @@ public Response segment(BiometricRecord sample, List sourceParams, Map targetParams,
List modalitiesToConvert) {
return null;
}
-}
+}
\ No newline at end of file
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java
index 5eacd42..39fbc95 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/impl/ImageCompressorSDKV2.java
@@ -20,10 +20,49 @@
import io.mosip.kernel.biometrics.spi.IBioApiV2;
/**
- * The Class ImageCompressorSDKV2.
+ * Implementation class for the Image Compressor SDK version 2.
+ * This class provides methods for biometric operations like template extraction,
+ * quality checks, matching, and format conversion.
+ *
+ * This class is annotated with Spring's {@code @Component} for automatic component scanning
+ * and {@code @EnableAutoConfiguration} for enabling Spring Boot auto-configuration.
+ *
+ *
+ * This class implements {@code IBioApiV2} interface to provide biometric API operations.
+ *
+ *
+ * It initializes the SDK with environment settings and provides methods to perform biometric
+ * operations such as template extraction, quality checks, matching, and format conversion.
+ *
+ *
+ * The methods in this class handle various response scenarios and use {@code Response} objects
+ * to encapsulate the response status, message, and data.
+ *
+ *
+ * This SDK implementation is versioned with API_VERSION and supports basic biometric operations.
+ *
+ *
+ * This class includes a deprecated method for biometric format conversion, advising to use
+ * {@code convertFormatV2} for updated functionality.
+ *
+ *
+ * The environment is injected using Spring's {@code @Autowired} annotation, facilitating
+ * configuration and initialization within the SDK.
+ *
+ *
+ * Example usage:
+ *
{@code
+ * ImageCompressorSDKV2 sdk = new ImageCompressorSDKV2();
+ * SDKInfo sdkInfo = sdk.init(initParams);
+ * Response response = sdk.extractTemplate(sample, modalitiesToExtract, flags);
+ * }
+ *
*
* @author Janardhan B S
- *
+ * @since 0.9
+ * @see IBioApiV2
+ * @see ImageCompressionService
+ * @see SDKInfoService
*/
@Component
@EnableAutoConfiguration
@@ -36,12 +75,26 @@ public class ImageCompressorSDKV2 implements IBioApiV2 {
private static final String API_VERSION = "0.9";
private static final String ERROR_NOT_IMPLEMENTED = "Sorry! Method functionality not implemented...";
+ /**
+ * Initializes the SDK with the provided initialization parameters.
+ *
+ * @param initParams The initialization parameters for the SDK.
+ * @return Information about the initialized SDK.
+ */
@Override
public SDKInfo init(Map initParams) {
SDKInfoService service = new SDKInfoService(env, API_VERSION, "sample", "sample1", "sample2");
return service.getSDKInfo();
}
+ /**
+ * Performs quality check on the provided biometric sample.
+ *
+ * @param sample The biometric record sample to check.
+ * @param modalitiesToCheck The list of biometric types to check.
+ * @param flags Additional configuration flags.
+ * @return Response containing the quality check result.
+ */
@Override
public Response checkQuality(BiometricRecord sample, List modalitiesToCheck,
Map flags) {
@@ -53,6 +106,15 @@ public Response checkQuality(BiometricRecord sample, List match(BiometricRecord sample, BiometricRecord[] gallery,
List modalitiesToMatch, Map flags) {
@@ -64,6 +126,14 @@ public Response match(BiometricRecord sample, BiometricRecord[]
return response;
}
+ /**
+ * Extracts biometric template from the provided biometric sample.
+ *
+ * @param sample The biometric record sample to extract template from.
+ * @param modalitiesToExtract The list of biometric types to extract.
+ * @param flags Additional configuration flags.
+ * @return Response containing the extracted biometric record.
+ */
@Override
public Response extractTemplate(BiometricRecord sample, List modalitiesToExtract,
Map flags) {
@@ -71,6 +141,14 @@ public Response extractTemplate(BiometricRecord sample, List segment(BiometricRecord sample, List modalitiesToSegment,
Map flags) {
@@ -82,9 +160,9 @@ public Response segment(BiometricRecord sample, List convertFormatV2(BiometricRecord bioRecord, String sourceFormat,
String targetFormat, Map sourceParams, Map targetParams,
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
index d23b4be..70c7310 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/ImageCompressionService.java
@@ -3,6 +3,7 @@
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
@@ -26,6 +27,10 @@
import io.mosip.kernel.biometrics.entities.BiometricRecord;
import io.mosip.kernel.biometrics.model.Response;
+/**
+ * Service class for image compression operations on biometric data. Handles
+ * resizing, compression, and conversion of biometric images.
+ */
public class ImageCompressionService extends SDKService {
private Logger logger = LoggerFactory.getLogger(ImageCompressionService.class);
@@ -48,6 +53,15 @@ public class ImageCompressionService extends SDKService {
public static final long FORMAT_TYPE_FACE = 8;
+ /**
+ * Compression service constructor initializing with environment settings,
+ * biometric sample, modalities to extract, and additional flags.
+ *
+ * @param env The environment configuration for the SDK.
+ * @param sample The biometric record sample to process.
+ * @param modalitiesToExtract The list of biometric types to extract.
+ * @param flags Additional configuration flags.
+ */
public ImageCompressionService(Environment env, BiometricRecord sample, List modalitiesToExtract,
Map flags) {
super(env, flags);
@@ -55,6 +69,11 @@ public ImageCompressionService(Environment env, BiometricRecord sample, List getExtractTemplateInfo() {
logger.info("ExtractTemplateInfo :: Started Request :: {}", sample != null ? sample.toString() : null);
@@ -127,45 +146,8 @@ public Response getExtractTemplateInfo() {
}
} catch (SDKException ex) {
logger.error("extractTemplate -- error", ex);
- switch (ResponseStatus.fromStatusCode(Integer.parseInt(ex.getErrorCode()))) {
- case INVALID_INPUT:
- response.setStatusCode(ResponseStatus.INVALID_INPUT.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.INVALID_INPUT.getStatusMessage(), "sample"));
- response.setResponse(null);
- return response;
- case MISSING_INPUT:
- response.setStatusCode(ResponseStatus.MISSING_INPUT.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.MISSING_INPUT.getStatusMessage(), "sample"));
- response.setResponse(null);
- return response;
- case QUALITY_CHECK_FAILED:
- response.setStatusCode(ResponseStatus.QUALITY_CHECK_FAILED.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.QUALITY_CHECK_FAILED.getStatusMessage(), ""));
- response.setResponse(null);
- return response;
- case BIOMETRIC_NOT_FOUND_IN_CBEFF:
- response.setStatusCode(ResponseStatus.BIOMETRIC_NOT_FOUND_IN_CBEFF.getStatusCode());
- response.setStatusMessage(
- String.format(ResponseStatus.BIOMETRIC_NOT_FOUND_IN_CBEFF.getStatusMessage(), ""));
- response.setResponse(null);
- return response;
- case MATCHING_OF_BIOMETRIC_DATA_FAILED:
- response.setStatusCode(ResponseStatus.MATCHING_OF_BIOMETRIC_DATA_FAILED.getStatusCode());
- response.setStatusMessage(
- String.format(ResponseStatus.MATCHING_OF_BIOMETRIC_DATA_FAILED.getStatusMessage(), ""));
- response.setResponse(null);
- return response;
- case POOR_DATA_QUALITY:
- response.setStatusCode(ResponseStatus.POOR_DATA_QUALITY.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.POOR_DATA_QUALITY.getStatusMessage(), ""));
- response.setResponse(null);
- return response;
- default:
- response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
- response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage(), ""));
- response.setResponse(null);
- return response;
- }
+ handleUnknownException(ex, response);
+ return response;
} catch (Exception ex) {
logger.error("extractTemplate -- error", ex);
response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
@@ -180,6 +162,55 @@ public Response getExtractTemplateInfo() {
return response;
}
+ private void handleUnknownException(SDKException ex, Response response) {
+ ResponseStatus status = ResponseStatus.fromStatusCode(Integer.parseInt(ex.getErrorCode()));
+ switch (status) {
+ case INVALID_INPUT:
+ response.setStatusCode(ResponseStatus.INVALID_INPUT.getStatusCode());
+ response.setStatusMessage(String.format(ResponseStatus.INVALID_INPUT.getStatusMessage(), "sample"));
+ response.setResponse(null);
+ break;
+ case MISSING_INPUT:
+ response.setStatusCode(ResponseStatus.MISSING_INPUT.getStatusCode());
+ response.setStatusMessage(String.format(ResponseStatus.MISSING_INPUT.getStatusMessage(), "sample"));
+ response.setResponse(null);
+ break;
+ case QUALITY_CHECK_FAILED:
+ response.setStatusCode(ResponseStatus.QUALITY_CHECK_FAILED.getStatusCode());
+ response.setStatusMessage(String.format(ResponseStatus.QUALITY_CHECK_FAILED.getStatusMessage(), ""));
+ response.setResponse(null);
+ break;
+ case BIOMETRIC_NOT_FOUND_IN_CBEFF:
+ response.setStatusCode(ResponseStatus.BIOMETRIC_NOT_FOUND_IN_CBEFF.getStatusCode());
+ response.setStatusMessage(
+ String.format(ResponseStatus.BIOMETRIC_NOT_FOUND_IN_CBEFF.getStatusMessage(), ""));
+ response.setResponse(null);
+ break;
+ case MATCHING_OF_BIOMETRIC_DATA_FAILED:
+ response.setStatusCode(ResponseStatus.MATCHING_OF_BIOMETRIC_DATA_FAILED.getStatusCode());
+ response.setStatusMessage(
+ String.format(ResponseStatus.MATCHING_OF_BIOMETRIC_DATA_FAILED.getStatusMessage(), ""));
+ response.setResponse(null);
+ break;
+ case POOR_DATA_QUALITY:
+ response.setStatusCode(ResponseStatus.POOR_DATA_QUALITY.getStatusCode());
+ response.setStatusMessage(String.format(ResponseStatus.POOR_DATA_QUALITY.getStatusMessage(), ""));
+ response.setResponse(null);
+ break;
+ default:
+ response.setStatusCode(ResponseStatus.UNKNOWN_ERROR.getStatusCode());
+ response.setStatusMessage(String.format(ResponseStatus.UNKNOWN_ERROR.getStatusMessage(), ""));
+ response.setResponse(null);
+ break;
+ }
+ }
+
+ /**
+ * Resizes and compresses the provided JPEG2000 image data.
+ *
+ * @param jp2000Bytes The input JPEG2000 image data.
+ * @return Compressed image data as byte array.
+ */
public byte[] resizeAndCompress(byte[] jp2000Bytes) {
// Storing the image in a Matrix object
// of Mat type
@@ -192,23 +223,19 @@ public byte[] resizeAndCompress(byte[] jp2000Bytes) {
// standard calculation for image size width = 498 and height = 640 is 0.25f
// Scaling the Image using Resize function
- float fxOrginal = 0.25f;
- float fyOrginal = 0.25f;
- int compression = 50;
- if (this.getEnv() != null) {
- fxOrginal = this.getEnv().getProperty(SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FX, Float.class, 0.25f);
- fyOrginal = this.getEnv().getProperty(SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FY, Float.class, 0.25f);
- compression = this.getEnv().getProperty(SdkConstant.IMAGE_COMPRESSOR_COMPRESSION_RATIO, Integer.class, 50);
- }
+ float[] fxOrginal = new float[] { 0.25f };
+ float[] fyOrginal = new float[] { 0.25f };
+ int[] compression = new int[] { 50 };
+ setImageCompressorSettings(fxOrginal, fyOrginal, compression);
- logger.info("Factor ratio Details :: orginal fx={}, orginal fy={}, Compression Ratio=={} ", fxOrginal,
- fyOrginal, compression);
+ logger.info("Factor ratio Details :: orginal fx={}, orginal fy={}, Compression Ratio=={} ", fxOrginal[0],
+ fyOrginal[0], compression[0]);
- Imgproc.resize(src, dst, new Size(0, 0), fxOrginal, fyOrginal, Imgproc.INTER_AREA);
+ Imgproc.resize(src, dst, new Size(0, 0), fxOrginal[0], fyOrginal[0], Imgproc.INTER_AREA);
logger.info("Resized Image Details :: Width {} Height {} Total Size {}", dst.width(), dst.height(),
(dst.width() * dst.height()));
- MatOfInt map = new MatOfInt(Imgcodecs.IMWRITE_JPEG2000_COMPRESSION_X1000, compression);
+ MatOfInt map = new MatOfInt(Imgcodecs.IMWRITE_JPEG2000_COMPRESSION_X1000, compression[0]);
MatOfByte mem = new MatOfByte();
Imgcodecs.imencode(".jp2", dst, mem, map);
byte[] data = mem.toArray();
@@ -218,6 +245,13 @@ public byte[] resizeAndCompress(byte[] jp2000Bytes) {
return data;
}
+ /**
+ * Converts the given image data to Face ISO/IEC 19794-5:2011 format.
+ *
+ * @param purpose The purpose for the conversion.
+ * @param imageData The image data to convert.
+ * @return Converted image data as byte array.
+ */
public byte[] doFaceConversion(String purpose, byte[] imageData) {
ResponseStatus responseStatus = null;
try {
@@ -242,6 +276,11 @@ public byte[] doFaceConversion(String purpose, byte[] imageData) {
throw new SDKException(ResponseStatus.UNKNOWN_ERROR + "", "null");
}
+ /**
+ * Retrieves the processed level type for the biometric data.
+ *
+ * @return ProcessedLevelType object representing the processed level.
+ */
public ProcessedLevelType getProcessedLevelType() {
ProcessedLevelType[] types = new ProcessedLevelType[] { ProcessedLevelType.RAW, ProcessedLevelType.INTERMEDIATE,
ProcessedLevelType.PROCESSED };
@@ -249,7 +288,67 @@ public ProcessedLevelType getProcessedLevelType() {
return types[0];
}
+ /**
+ * Retrieves the purpose type for the biometric data.
+ *
+ * @return PurposeType object representing the purpose.
+ */
public PurposeType getPurposeType() {
return PurposeType.VERIFY;
}
+
+ /**
+ * Sets image compressor settings based on environment variables and
+ * configuration flags.
+ *
+ * This method prioritizes settings obtained from environment variables over
+ * configuration flags. It attempts to retrieve the following properties from
+ * the environment: - `SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FX`: Resize
+ * factor for the X-axis (default: 0.25). -
+ * `SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FY`: Resize factor for the Y-axis
+ * (default: 0.25). - `SdkConstant.IMAGE_COMPRESSOR_COMPRESSION_RATIO`:
+ * Compression ratio for the image (default: 50). - standard calculation for
+ * image size width = 498 and height = 640 is 0.25f If environment variables are
+ * not available, the method checks the configuration flags (`this.getFlags()`)
+ * for the same keys. It attempts to parse the flag values as floats and integer
+ * for resize factors and compression ratio, respectively.
+ *
+ * In case of any exceptions during retrieval or parsing, the method logs an
+ * error message but continues execution with the default values.
+ *
+ * @param fxOrginal An array to hold the resize factor for the X-axis
+ * (modified in-place).
+ * @param fyOrginal An array to hold the resize factor for the Y-axis
+ * (modified in-place).
+ * @param compressionRatio An array to hold the compression ratio (modified
+ * in-place).
+ */
+ protected void setImageCompressorSettings(float[] fxOrginal, float[] fyOrginal, int[] compressionRatio) {
+ fxOrginal[0] = 0.25f;
+ fyOrginal[0] = 0.25f;
+ compressionRatio[0] = 50;
+ if (this.getEnv() != null) {
+ try {
+ fxOrginal[0] = this.getEnv().getProperty(SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FX, Float.class,
+ 0.25f);
+ fyOrginal[0] = this.getEnv().getProperty(SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FY, Float.class,
+ 0.25f);
+ compressionRatio[0] = this.getEnv().getProperty(SdkConstant.IMAGE_COMPRESSOR_COMPRESSION_RATIO,
+ Integer.class, 50);
+ } catch (Exception ex) {
+ logger.error("setImageCompressorSettings::error for env values", ex);
+ }
+ }
+ if (!Objects.isNull(getFlags()) && (getFlags().containsKey(SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FX)
+ && getFlags().containsKey(SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FY)
+ && getFlags().containsKey(SdkConstant.IMAGE_COMPRESSOR_COMPRESSION_RATIO))) {
+ try {
+ fxOrginal[0] = Float.parseFloat(getFlags().get(SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FX));
+ fyOrginal[0] = Float.parseFloat(getFlags().get(SdkConstant.IMAGE_COMPRESSOR_RESIZE_FACTOR_FY));
+ compressionRatio[0] = Integer.parseInt(getFlags().get(SdkConstant.IMAGE_COMPRESSOR_COMPRESSION_RATIO));
+ } catch (Exception ex) {
+ logger.error("setImageCompressorSettings::error for flag values", ex);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java
index 7005248..568c63a 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKInfoService.java
@@ -1,7 +1,7 @@
package io.mosip.image.compressor.sdk.service;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.EnumMap;
import java.util.List;
import java.util.Map;
@@ -11,12 +11,31 @@
import io.mosip.kernel.biometrics.constant.BiometricType;
import io.mosip.kernel.biometrics.model.SDKInfo;
+/**
+ * Provides information about the Biometric Software Development Kit (SDK).
+ *
+ * This class extends `SDKService` and offers methods to retrieve details about
+ * the SDK's capabilities and functionalities.
+ */
public class SDKInfoService extends SDKService {
private String apiVersion;
private String sample1;
private String sample2;
private String sample3;
+ /**
+ * Constructs a new `SDKInfoService` instance.
+ *
+ * @param env An environment object likely used to access configuration
+ * properties.
+ * @param apiVersion The API version of the Biometric SDK.
+ * @param sample1 A string value of unclear purpose (might be sample data
+ * reference).
+ * @param sample2 A string value of unclear purpose (might be sample data
+ * reference).
+ * @param sample3 A string value of unclear purpose (might be sample data
+ * reference).
+ */
public SDKInfoService(Environment env, String apiVersion, String sample1, String sample2, String sample3) {
super(env, null);
this.apiVersion = apiVersion;
@@ -25,12 +44,22 @@ public SDKInfoService(Environment env, String apiVersion, String sample1, String
this.sample3 = sample3;
}
+ /**
+ * Creates and returns an `SDKInfo` object containing details about the
+ * Biometric SDK.
+ *
+ * This method constructs an `SDKInfo` object with the provided API version and
+ * sets pre-defined supported modalities (facial recognition) and supported
+ * methods (extraction).
+ *
+ * @return An `SDKInfo` object containing information about the Biometric SDK.
+ */
public SDKInfo getSDKInfo() {
SDKInfo sdkInfo = new SDKInfo(this.apiVersion, this.sample1, this.sample2, this.sample3);
List supportedModalities = new ArrayList<>();
supportedModalities.add(BiometricType.FACE);
sdkInfo.setSupportedModalities(supportedModalities);
- Map> supportedMethods = new HashMap<>();
+ Map> supportedMethods = new EnumMap<>(BiometricFunction.class);
supportedMethods.put(BiometricFunction.EXTRACT, supportedModalities);
sdkInfo.setSupportedMethods(supportedMethods);
return sdkInfo;
diff --git a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java
index 9f1a792..6c2241c 100644
--- a/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java
+++ b/image-compressor/src/main/java/io/mosip/image/compressor/sdk/service/SDKService.java
@@ -21,32 +21,89 @@
import io.mosip.kernel.biometrics.entities.BIR;
import io.mosip.kernel.biometrics.entities.BiometricRecord;
+/**
+ * Abstract base class for Biometric SDK services.
+ *
+ * This class defines common methods and functionalities for processing
+ * biometric data used by its concrete implementations. It provides methods for:
+ * - Accessing environment variables and configuration flags. - Extracting
+ * biometric segments from a BiometricRecord object based on specified
+ * modalities. - Retrieving biometric data from a Biometric Identification
+ * Record (BIR) object. - Processing and extracting relevant information from
+ * different biometric modalities (currently only Face is supported).
+ *
+ * Subclasses can extend this class to implement specific functionalities
+ * related to the Biometric SDK.
+ */
public abstract class SDKService {
private Logger logger = LoggerFactory.getLogger(SDKService.class);
private Map flags;
private Environment env;
+ /**
+ * Constructs an instance of SDKService with the specified environment and
+ * flags.
+ *
+ * @param env The environment configuration for SDK operations.
+ * @param flags The flags configuration for SDK operations.
+ */
protected SDKService(Environment env, Map flags) {
setEnv(env);
setFlags(flags);
}
+ /**
+ * Retrieves the flags configuration currently set in this SDKService instance.
+ *
+ * @return The map of flags configured for SDK operations.
+ */
protected Map getFlags() {
return flags;
}
+ /**
+ * Sets the flags configuration for this SDKService instance.
+ *
+ * @param flags The map of flags to be set for SDK operations.
+ */
protected void setFlags(Map flags) {
this.flags = flags;
}
+ /**
+ * Retrieves the environment configuration currently set in this SDKService
+ * instance.
+ *
+ * @return The environment configuration for SDK operations.
+ */
protected Environment getEnv() {
return env;
}
+ /**
+ * Sets the environment configuration for this SDKService instance.
+ *
+ * @param env The environment configuration to be set for SDK operations.
+ */
protected void setEnv(Environment env) {
this.env = env;
}
+ /**
+ * Extracts a map of BiometricType to corresponding BIR (Biometric
+ * Identification Record) segments from a BiometricRecord object.
+ *
+ * This method iterates through the segments in the BiometricRecord and filters
+ * them based on the provided modalitiesToMatch list. If no modalities are
+ * specified, all segments are included.
+ *
+ * @param bioRecord The BiometricRecord object containing biometric data
+ * segments.
+ * @param modalitiesToMatch A list of BiometricType values specifying the
+ * modalities to extract (optional).
+ * @return A map where keys are BiometricType and values are lists of
+ * corresponding BIR segments.
+ */
protected Map> getBioSegmentMap(BiometricRecord bioRecord,
List modalitiesToMatch) {
Boolean noFilter = false;
@@ -58,7 +115,7 @@ protected Map> getBioSegmentMap(BiometricRecord bioReco
if (modalitiesToMatch == null || modalitiesToMatch.isEmpty())
noFilter = true;
- Map> bioSegmentMap = new HashMap<>();
+ Map> bioSegmentMap = new HashMap<>();
for (BIR segment : bioRecord.getSegments()) {
BiometricType bioType = segment.getBdbInfo().getType().get(0);
@@ -75,6 +132,19 @@ protected Map> getBioSegmentMap(BiometricRecord bioReco
return bioSegmentMap;
}
+ /**
+ * Extracts the raw biometric data from a BIR (Biometric Identification Record)
+ * object.
+ *
+ * This method validates the provided BIR object and its parameters before
+ * attempting to extract the data. If validation fails, an SDKException is
+ * thrown. Otherwise, the appropriate processing method is called based on the
+ * BiometricType.
+ *
+ * @param bir The BIR object containing biometric data.
+ * @return A byte array containing the raw biometric data.
+ * @throws SDKException If the BIR object is invalid or data extraction fails.
+ */
protected byte[] getBirData(BIR bir) {
BiometricType biometricType = bir.getBdbInfo().getType().get(0);
PurposeType purposeType = bir.getBdbInfo().getPurpose();
@@ -93,9 +163,22 @@ protected byte[] getBirData(BIR bir) {
throw new SDKException(ResponseStatus.UNKNOWN_ERROR + "", "null");
}
+ /**
+ * Validates the parameters of a BIR object (BiometricType and BioSubType).
+ *
+ * This method currently only supports facial recognition (BiometricType.FACE).
+ * If a different BiometricType is encountered, it logs an error message and
+ * throws an SDKException. Subclasses can potentially override this method to
+ * support additional modalities.
+ *
+ * @param segment The BIR object to be validated.
+ * @param bioType The BiometricType of the BIR object.
+ * @param bioSubType The BioSubType of the BIR object (optional).
+ * @return boolean (always true for Face modality currently).
+ * @throws SDKException If the BiometricType is not supported.
+ */
@SuppressWarnings({ "unused" })
- protected boolean isValidBIRParams(BIR segment, BiometricType bioType, String bioSubType)
- {
+ protected boolean isValidBIRParams(BIR segment, BiometricType bioType, String bioSubType) {
ResponseStatus responseStatus = null;
if (bioType == BiometricType.FACE)
return true;
@@ -106,6 +189,20 @@ protected boolean isValidBIRParams(BIR segment, BiometricType bioType, String bi
}
}
+ /**
+ * Retrieves the biometric data from the given BDB data based on the specified
+ * parameters. If the BDB data is null or empty, throws an SDKException
+ * indicating biometric not found.
+ *
+ * @param purposeType The purpose type for biometric data retrieval.
+ * @param bioType The type of biometric data (e.g., fingerprint, iris,
+ * face).
+ * @param bioSubType The subtype of biometric data, specific to the bioType.
+ * @param bdbData The BDB data in URL safe Base64 encoded format.
+ * @return The retrieved biometric data as a byte array.
+ * @throws SDKException If the BDB data is null or empty, indicating biometric
+ * not found in CBEFF.
+ */
protected byte[] getBDBData(PurposeType purposeType, BiometricType bioType, String bioSubType, byte[] bdbData) {
ResponseStatus responseStatus = null;
@@ -117,6 +214,19 @@ protected byte[] getBDBData(PurposeType purposeType, BiometricType bioType, Stri
throw new SDKException(responseStatus.getStatusCode() + "", responseStatus.getStatusMessage());
}
+ /**
+ * Retrieves the biometric data based on the specified parameters and BDB data.
+ * Currently supports FACE biometric type.
+ *
+ * @param purposeType The purpose type for biometric data retrieval.
+ * @param bioType The type of biometric data (currently only supports
+ * BiometricType.FACE).
+ * @param bioSubType The subtype of biometric data, specific to the bioType.
+ * @param bdbData The BDB data in URL safe Base64 encoded format.
+ * @return The retrieved biometric data as a byte array.
+ * @throws SDKException If the biometric type is not supported or if there is an
+ * error retrieving the biometric data.
+ */
protected byte[] getBiometericData(PurposeType purposeType, BiometricType bioType, String bioSubType,
String bdbData) {
ResponseStatus responseStatus = null;
@@ -126,9 +236,18 @@ protected byte[] getBiometericData(PurposeType purposeType, BiometricType bioTyp
throw new SDKException(responseStatus.getStatusCode() + "", responseStatus.getStatusMessage());
}
+ /**
+ * Retrieves the FACE biometric data based on the specified parameters and BDB
+ * data.
+ *
+ * @param purposeType The purpose type for biometric data retrieval.
+ * @param biometricSubType The subtype of the FACE biometric data.
+ * @param bdbData The BDB data in URL safe Base64 encoded format.
+ * @return The retrieved FACE biometric data as a byte array.
+ * @throws SDKException If there is an error retrieving the FACE biometric data.
+ */
@SuppressWarnings({ "unused" })
- protected byte[] getFaceBdb(PurposeType purposeType, String biometricSubType, String bdbData)
- {
+ protected byte[] getFaceBdb(PurposeType purposeType, String biometricSubType, String bdbData) {
ResponseStatus responseStatus = null;
try {
ConvertRequestDto requestDto = new ConvertRequestDto();