From e6de77b0e259d623328deaa67040beaeac50a446 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Thu, 7 Dec 2023 16:20:16 +0100 Subject: feat(logger): add data model of json based statistic logger --- .../core/logger/AdvancedStatisticLogger.java | 42 +++++++++++----------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'ms_specific_connector/src/main/java/at') diff --git a/ms_specific_connector/src/main/java/at/asitplus/eidas/specific/core/logger/AdvancedStatisticLogger.java b/ms_specific_connector/src/main/java/at/asitplus/eidas/specific/core/logger/AdvancedStatisticLogger.java index 06fb1aba..b18ce89e 100644 --- a/ms_specific_connector/src/main/java/at/asitplus/eidas/specific/core/logger/AdvancedStatisticLogger.java +++ b/ms_specific_connector/src/main/java/at/asitplus/eidas/specific/core/logger/AdvancedStatisticLogger.java @@ -39,6 +39,9 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class AdvancedStatisticLogger implements IStatisticLogger { + private static final String SUCCES_CODE = "success.00"; + private static final String SUCCES_MSG = "success"; + private static final String DATEFORMATER = "yyyy.MM.dd-HH:mm:ss,SSS"; private static final String DEFAULT_NO_IDP_ID = "no idpId available"; private static final String DEFAULT_NO_SP_ID = "no appId available"; @@ -62,6 +65,8 @@ public class AdvancedStatisticLogger implements IStatisticLogger { public void logSuccessOperation(IRequest protocolRequest, IAuthData authData, boolean isSsoSession) { final StatisticLogEntry entry = buildCoreEntry(protocolRequest); entry.setSuccess(SuccessEntry.builder() + .statusCode(SUCCES_CODE) + .statusMessage(SUCCES_MSG) .spSector(protocolRequest.getServiceProviderConfiguration().getAreaSpecificTargetIdentifier()) .spCountry("AT") .citizenCountryCode(authData.getCiticenCountryCode()) @@ -83,7 +88,14 @@ public class AdvancedStatisticLogger implements IStatisticLogger { @Override public void logErrorOperation(Throwable throwable, IRequest errorRequest) { final StatisticLogEntry entry = buildCoreEntry(errorRequest); - entry.setError(new ErrorEntry(messageService.getResponseErrorCode(throwable), throwable.getMessage())); + entry.setSuccess(SuccessEntry.builder() + .statusCode(messageService.getResponseErrorCode(throwable)) + .statusMessage(throwable.getMessage()) + .spSector(errorRequest.getServiceProviderConfiguration() != null + ? errorRequest.getServiceProviderConfiguration().getAreaSpecificTargetIdentifier() + : "") + .spCountry("AT") + .build()); entry.setMatching(MatchingDetails.builder() .matchingMethod(extractMatchingState(errorRequest)) .matchingDetails(extractMatchingDetails(errorRequest)) @@ -147,7 +159,7 @@ public class AdvancedStatisticLogger implements IStatisticLogger { @Getter @Setter @RequiredArgsConstructor - @JsonInclude(Include.NON_NULL) + @JsonInclude(Include.ALWAYS) private static class StatisticLogEntry { @JsonSerialize(using = LocalDateTimeSerializer.class) @@ -167,9 +179,6 @@ public class AdvancedStatisticLogger implements IStatisticLogger { @JsonProperty("result") private SuccessEntry success; - - @JsonProperty("error") - private ErrorEntry error; @JsonProperty("identityMatching") private MatchingDetails matching; @@ -179,9 +188,15 @@ public class AdvancedStatisticLogger implements IStatisticLogger { @Getter @Setter @Builder - @JsonInclude(Include.NON_NULL) + @JsonInclude(Include.ALWAYS) private static class SuccessEntry { + @JsonProperty("code") + private final String statusCode; + + @JsonProperty("msg") + private final String statusMessage; + @JsonProperty("spSector") private final String spSector; @@ -196,7 +211,7 @@ public class AdvancedStatisticLogger implements IStatisticLogger { @Getter @Setter @Builder - @JsonInclude(Include.NON_NULL) + @JsonInclude(Include.ALWAYS) private static class MatchingDetails { @JsonProperty("finalMatchingMethod") @@ -207,17 +222,4 @@ public class AdvancedStatisticLogger implements IStatisticLogger { } - @Getter - @Setter - @RequiredArgsConstructor - private static class ErrorEntry { - - @JsonProperty("code") - private final String errorCode; - - @JsonProperty("msg") - private final String errorMessage; - - } - } -- cgit v1.2.3