Skip to content

Commit

Permalink
Merge pull request #88 from LoganathanSekar7627/MOSIP-29287-correctio…
Browse files Browse the repository at this point in the history
…n-to-logging-the-response

MOSIP-29287 - More fixes to logger
  • Loading branch information
vishwa-vyom authored Oct 30, 2023
2 parents d6438c5 + 57eaa4f commit 6b16082
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 <T> void logObject(T response) {
if(isLogRequestResponse) {
logger.debug(gson.toJson(response));
logger.debug(response.getClass() + ": " + gson.toJson(response));
}
}

Expand All @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -80,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);
}
Expand All @@ -109,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\": ");
Expand Down Expand Up @@ -221,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\": ");
Expand All @@ -247,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\": ");
Expand Down Expand Up @@ -290,23 +287,27 @@ 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(DateUtils.formatToISOString(birInfo.getCreationDate())));
stringBuilder.append(stringOf(dateAsString(birInfo.getCreationDate())));
stringBuilder.append(", \"notValidBefore\": ");
stringBuilder.append(surroundWithQuote(DateUtils.formatToISOString(birInfo.getNotValidBefore())));
stringBuilder.append(stringOf(dateAsString(birInfo.getNotValidBefore())));
stringBuilder.append(", \"notValidAfter\": ");
stringBuilder.append(surroundWithQuote(DateUtils.formatToISOString(birInfo.getNotValidAfter())));
stringBuilder.append(stringOf(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);
}
Expand Down

0 comments on commit 6b16082

Please sign in to comment.