From cf423759b6167f990c9e9af2bc654d3e6dba36be Mon Sep 17 00:00:00 2001 From: Loganathan Sekar Date: Tue, 17 Oct 2023 21:27:13 +0530 Subject: [PATCH 1/2] Fixed null date time Signed-off-by: Loganathan Sekar --- .../java/io/mosip/biosdk/services/utils/Utils.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java b/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java index 5f055626..8e203ca4 100644 --- a/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java +++ b/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java @@ -1,6 +1,7 @@ package io.mosip.biosdk.services.utils; import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; import java.util.Arrays; import java.util.Base64; import java.util.Date; @@ -298,15 +299,19 @@ public String toString(BIRInfo birInfo) { stringBuilder.append(", \"integrity\":"); stringBuilder.append(booleanAsString(birInfo.getIntegrity())); stringBuilder.append(", \"creationDate\": "); - stringBuilder.append(surroundWithQuote(DateUtils.formatToISOString(birInfo.getCreationDate()))); + stringBuilder.append(surroundWithQuote(dateAsString(birInfo.getCreationDate()))); stringBuilder.append(", \"notValidBefore\": "); - stringBuilder.append(surroundWithQuote(DateUtils.formatToISOString(birInfo.getNotValidBefore()))); + stringBuilder.append(surroundWithQuote(dateAsString(birInfo.getNotValidBefore()))); stringBuilder.append(", \"notValidAfter\": "); - stringBuilder.append(surroundWithQuote(DateUtils.formatToISOString(birInfo.getNotValidAfter()))); + stringBuilder.append(surroundWithQuote(dateAsString(birInfo.getNotValidAfter()))); stringBuilder.append(" }"); return stringBuilder.toString(); } + private String dateAsString(LocalDateTime localDateTime) { + return localDateTime == null ? "null" : DateUtils.formatToISOString(localDateTime); + } + private static String booleanAsString(Boolean bool) { return bool == null ? "null" : Boolean.toString(bool); } From 57eaa4fe50dd2d0ddf314c1c671c79649dce5abb Mon Sep 17 00:00:00 2001 From: Loganathan Sekar Date: Tue, 24 Oct 2023 16:27:05 +0530 Subject: [PATCH 2/2] Fix logger issues Signed-off-by: Loganathan Sekar --- .../BioSdkServiceProviderImpl_V_1_0.java | 27 ++++++++---------- .../io/mosip/biosdk/services/utils/Utils.java | 28 ++++++++----------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/biosdk-services/src/main/java/io/mosip/biosdk/services/impl/spec_1_0/BioSdkServiceProviderImpl_V_1_0.java b/biosdk-services/src/main/java/io/mosip/biosdk/services/impl/spec_1_0/BioSdkServiceProviderImpl_V_1_0.java index 03dc1d00..798920cd 100644 --- a/biosdk-services/src/main/java/io/mosip/biosdk/services/impl/spec_1_0/BioSdkServiceProviderImpl_V_1_0.java +++ b/biosdk-services/src/main/java/io/mosip/biosdk/services/impl/spec_1_0/BioSdkServiceProviderImpl_V_1_0.java @@ -27,11 +27,6 @@ import io.mosip.kernel.biometrics.model.SDKInfo; import io.mosip.kernel.biometrics.spi.IBioApiV2; import io.mosip.kernel.core.logger.spi.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import static io.mosip.biosdk.services.constants.AppConstants.LOGGER_IDTYPE; -import static io.mosip.biosdk.services.constants.AppConstants.LOGGER_SESSIONID; @Component public class BioSdkServiceProviderImpl_V_1_0 implements BioSdkServiceProvider { @@ -199,43 +194,43 @@ public Object convertFormat(RequestDto request) { private void logRequest(ExtractTemplateRequestDto extractTemplateRequestDto) { if(isLogRequestResponse) { - logger.debug(utils.toString(extractTemplateRequestDto)); + logger.debug("REQUEST: " + utils.toString(extractTemplateRequestDto)); } } private void logRequest(MatchRequestDto matchRequestDto) { if(isLogRequestResponse) { - logger.debug(utils.toString(matchRequestDto)); + logger.debug("REQUEST: " + utils.toString(matchRequestDto)); } } private void logRequest(InitRequestDto initRequestDto) { if(isLogRequestResponse) { - logger.debug(utils.toString(initRequestDto)); + logger.debug("REQUEST: " + utils.toString(initRequestDto)); } } private void logRequest(CheckQualityRequestDto checkQualityRequestDto) { if(isLogRequestResponse) { - logger.debug(utils.toString(checkQualityRequestDto)); + logger.debug("REQUEST: " + utils.toString(checkQualityRequestDto)); } } private void logRequest(SegmentRequestDto segmentRequestDto) { if(isLogRequestResponse) { - logger.debug(utils.toString(segmentRequestDto)); + logger.debug("REQUEST: " + utils.toString(segmentRequestDto)); } } private void logRequest(ConvertFormatRequestDto convertFormatRequestDto) { if(isLogRequestResponse) { - logger.debug(utils.toString(convertFormatRequestDto)); + logger.debug("REQUEST: " + utils.toString(convertFormatRequestDto)); } } private void logObject(T response) { if(isLogRequestResponse) { - logger.debug(gson.toJson(response)); + logger.debug(response.getClass() + ": " + gson.toJson(response)); } } @@ -244,16 +239,16 @@ private void logResponse(Response response) { Object resp = response.getResponse(); if(resp instanceof BiometricRecord) { BiometricRecord biometricRecord = (BiometricRecord) resp; - logBiometricRecord(biometricRecord); + logBiometricRecord("Response BiometricRecord: ", biometricRecord); } else { - logger.debug(gson.toJson(resp)); + logger.debug("Response: " + gson.toJson(resp)); } } } - private void logBiometricRecord(BiometricRecord biometricRecord) { + private void logBiometricRecord(String prefix, BiometricRecord biometricRecord) { if(isLogRequestResponse) { - logger.debug(utils.toString(biometricRecord)); + logger.debug(prefix + utils.toString(biometricRecord)); } } diff --git a/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java b/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java index 8e203ca4..9a29bb5d 100644 --- a/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java +++ b/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java @@ -81,10 +81,6 @@ private void appendString(BiometricRecord biometricRecord, StringBuilder stringB } } - private String surroundWithQuote(String str) { - return str == null ? "null" : String.format("\"%s\"", gson.toJson(str)); - } - private String stringOf(Object obj) { return obj == null ? "null" : gson.toJson(obj); } @@ -110,7 +106,7 @@ private void appendString(BIR bir, StringBuilder stringBuilder) { stringBuilder.append(", \"bdbInfo\": "); stringBuilder.append(toString(bir.getBdbInfo())); stringBuilder.append(", \"birInfo\": "); - stringBuilder.append(stringOf(bir.getBirInfo())); + stringBuilder.append(toString(bir.getBirInfo())); stringBuilder.append(", \"cbeffversion\": "); stringBuilder.append(stringOf(bir.getCbeffversion())); stringBuilder.append(", \"others\": "); @@ -222,9 +218,9 @@ public String toString(ConvertFormatRequestDto convertFormatRequestDto) { stringBuilder.append("{"); stringBuilder.append(" \"_modelClass\": \"ConvertFormatRequestDto\""); stringBuilder.append(", \"sourceFormat\":"); - stringBuilder.append(surroundWithQuote(convertFormatRequestDto.getSourceFormat())); + stringBuilder.append(stringOf(convertFormatRequestDto.getSourceFormat())); stringBuilder.append(", \"targetFormat\": "); - stringBuilder.append(surroundWithQuote(convertFormatRequestDto.getTargetFormat())); + stringBuilder.append(stringOf(convertFormatRequestDto.getTargetFormat())); stringBuilder.append(", \"modalitiesToConvert\": "); stringBuilder.append(stringOf(convertFormatRequestDto.getModalitiesToConvert())); stringBuilder.append(", \"sample\": "); @@ -248,17 +244,17 @@ public String toString(BDBInfo bdbInfo) { stringBuilder.append(", \"challengeResponseHash\":"); stringBuilder.append(getHashOfBytes(bdbInfo.getChallengeResponse())); stringBuilder.append(", \"index\": "); - stringBuilder.append(surroundWithQuote(bdbInfo.getIndex())); + stringBuilder.append(stringOf(bdbInfo.getIndex())); stringBuilder.append(", \"format\": "); stringBuilder.append(stringOf(bdbInfo.getFormat())); stringBuilder.append(", \"encryption\":"); stringBuilder.append(booleanAsString(bdbInfo.getEncryption())); stringBuilder.append(", \"creationDate\": "); - stringBuilder.append(surroundWithQuote(DateUtils.formatToISOString(bdbInfo.getCreationDate()))); + stringBuilder.append(stringOf(dateAsString(bdbInfo.getCreationDate()))); stringBuilder.append(", \"notValidBefore\": "); - stringBuilder.append(surroundWithQuote(DateUtils.formatToISOString(bdbInfo.getNotValidBefore()))); + stringBuilder.append(stringOf(dateAsString(bdbInfo.getNotValidBefore()))); stringBuilder.append(", \"notValidAfter\": "); - stringBuilder.append(surroundWithQuote(DateUtils.formatToISOString(bdbInfo.getNotValidAfter()))); + stringBuilder.append(stringOf(dateAsString(bdbInfo.getNotValidAfter()))); stringBuilder.append(", \"type\": "); stringBuilder.append(stringOf(bdbInfo.getType())); stringBuilder.append(", \"subtype\": "); @@ -291,19 +287,19 @@ public String toString(BIRInfo birInfo) { stringBuilder.append("{"); stringBuilder.append(" \"_modelClass\": \"BIRInfo\""); stringBuilder.append(", \"creator\": "); - stringBuilder.append(surroundWithQuote(birInfo.getCreator())); + stringBuilder.append(stringOf(birInfo.getCreator())); stringBuilder.append(", \"index\": "); - stringBuilder.append(surroundWithQuote(birInfo.getIndex())); + stringBuilder.append(stringOf(birInfo.getIndex())); stringBuilder.append(", \"payloadHash\":"); stringBuilder.append(getHashOfBytes(birInfo.getPayload())); stringBuilder.append(", \"integrity\":"); stringBuilder.append(booleanAsString(birInfo.getIntegrity())); stringBuilder.append(", \"creationDate\": "); - stringBuilder.append(surroundWithQuote(dateAsString(birInfo.getCreationDate()))); + stringBuilder.append(stringOf(dateAsString(birInfo.getCreationDate()))); stringBuilder.append(", \"notValidBefore\": "); - stringBuilder.append(surroundWithQuote(dateAsString(birInfo.getNotValidBefore()))); + stringBuilder.append(stringOf(dateAsString(birInfo.getNotValidBefore()))); stringBuilder.append(", \"notValidAfter\": "); - stringBuilder.append(surroundWithQuote(dateAsString(birInfo.getNotValidAfter()))); + stringBuilder.append(stringOf(dateAsString(birInfo.getNotValidAfter()))); stringBuilder.append(" }"); return stringBuilder.toString(); }