From 99fd5c9ad2dc5e36f9ec77a8d6fae7370ffa3031 Mon Sep 17 00:00:00 2001 From: apereverzin1 <140609226+apereverzin1@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:53:57 +0100 Subject: [PATCH] DIAC-555 add logs (#934) * Added logs * Added logs --- .../clients/CdamDocumentDownloadClient.java | 3 +++ .../clients/CdamDocumentManagementUploader.java | 3 +++ .../clients/DmDocumentDownloadClient.java | 4 ++++ .../clients/DmDocumentManagementUploader.java | 4 ++++ .../clients/DocumentDownloadClient.java | 7 ++++--- .../clients/DocumentManagementUploader.java | 4 ++++ .../clients/DocumentManagementUploaderTest.java | 14 ++++++++++---- 7 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/CdamDocumentDownloadClient.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/CdamDocumentDownloadClient.java index 2ade4f0b2..0ac6a76c3 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/CdamDocumentDownloadClient.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/CdamDocumentDownloadClient.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.clients; +import lombok.extern.slf4j.Slf4j; import org.springframework.core.io.Resource; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; @@ -8,6 +9,7 @@ import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.security.AccessTokenProvider; @Component +@Slf4j public class CdamDocumentDownloadClient { private final CaseDocumentClient caseDocumentClient; private final AuthTokenGenerator serviceAuthTokenGenerator; @@ -26,6 +28,7 @@ public CdamDocumentDownloadClient( //TODO Upgrade ccd-case-document-am-client. Need to get UUID, string cannot be converted. public Resource download(String documentBinaryUrl) { + log.info("Downloading {} using CaseDocumentClient (CDAM)", documentBinaryUrl); ResponseEntity resourceResponseEntity = caseDocumentClient.getDocumentBinary( accessTokenProvider.getAccessToken(), serviceAuthTokenGenerator.generate(), diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/CdamDocumentManagementUploader.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/CdamDocumentManagementUploader.java index 9d1569141..acebd5b5d 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/CdamDocumentManagementUploader.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/CdamDocumentManagementUploader.java @@ -3,6 +3,7 @@ import com.google.common.io.ByteStreams; import java.util.Collections; import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.ComponentScan; import org.springframework.core.io.Resource; @@ -21,6 +22,7 @@ */ @Component @ComponentScan("uk.gov.hmcts.reform.ccd.document.am.feign") +@Slf4j public class CdamDocumentManagementUploader { private final CaseDocumentClient caseDocumentClient; @@ -50,6 +52,7 @@ public Document upload(Resource resource, String contentType) { ByteStreams.toByteArray(resource.getInputStream()) ); + log.info("Uploading {} using CaseDocumentClient (no CDAM)", resource.getFilename()); UploadResponse uploadResponse = caseDocumentClient.uploadDocuments( accessToken, serviceAuthorizationToken, diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DmDocumentDownloadClient.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DmDocumentDownloadClient.java index c698a96b8..b165d6cf4 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DmDocumentDownloadClient.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DmDocumentDownloadClient.java @@ -4,6 +4,8 @@ import java.net.MalformedURLException; import java.net.URL; + +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.core.io.Resource; import org.springframework.http.ResponseEntity; @@ -19,6 +21,7 @@ */ @Component @Deprecated +@Slf4j public class DmDocumentDownloadClient { private final DocumentDownloadClientApi documentDownloadClientApi; @@ -50,6 +53,7 @@ public Resource download(String documentBinaryUrl) { UserDetails userDetails = userDetailsProvider.getUserDetails(); + log.info("Downloading {} using DocumentDownloadClientApi (no CDAM)", documentBinaryUrl); ResponseEntity resourceResponseEntity = documentDownloadClientApi.downloadBinary( accessTokenProvider.getAccessToken(), serviceAuthTokenGenerator.generate(), diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DmDocumentManagementUploader.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DmDocumentManagementUploader.java index a015755bc..3165944d4 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DmDocumentManagementUploader.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DmDocumentManagementUploader.java @@ -3,6 +3,8 @@ import com.google.common.io.ByteStreams; import java.io.IOException; import java.util.Collections; + +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.core.io.Resource; import org.springframework.stereotype.Component; @@ -22,6 +24,7 @@ @Component @Deprecated +@Slf4j public class DmDocumentManagementUploader { private final DocumentUploadClientApi documentUploadClientApi; @@ -56,6 +59,7 @@ public Document upload( ByteStreams.toByteArray(resource.getInputStream()) ); + log.info("Uploading {} using DocumentUploadClientApi (CDAM)", resource.getFilename()); UploadResponse uploadResponse = documentUploadClientApi .upload( diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentDownloadClient.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentDownloadClient.java index 3de06e285..d3df73183 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentDownloadClient.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentDownloadClient.java @@ -1,6 +1,7 @@ package uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.clients; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.FeatureToggler; @@ -8,19 +9,19 @@ @Service @RequiredArgsConstructor +@Slf4j public class DocumentDownloadClient { - - private final FeatureToggler featureToggler; private final DmDocumentDownloadClient dmDocumentDownloadClient; private final CdamDocumentDownloadClient cdamDocumentDownLoadClient; - public Resource download(String documentBinaryUrl) { if (featureToggler.getValue("use-ccd-document-am", false)) { + log.info("Downloading {} using CDAM", documentBinaryUrl); return cdamDocumentDownLoadClient.download(documentBinaryUrl); } else { + log.info("Downloading {} not using CDAM", documentBinaryUrl); return dmDocumentDownloadClient.download(documentBinaryUrl); } } diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentManagementUploader.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentManagementUploader.java index 9c0f70045..fc40383f0 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentManagementUploader.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentManagementUploader.java @@ -1,6 +1,7 @@ package uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.clients; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.Document; @@ -9,6 +10,7 @@ @Service @RequiredArgsConstructor +@Slf4j public class DocumentManagementUploader implements DocumentUploader { private final FeatureToggler featureToggler; @@ -18,8 +20,10 @@ public class DocumentManagementUploader implements DocumentUploader { @Override public Document upload(Resource resource, String contentType) { if (featureToggler.getValue("use-ccd-document-am", false)) { + log.info("Uploading {} using CDAM", resource.getFilename()); return cdamDocumentManagementUploader.upload(resource, contentType); } else { + log.info("Uploading {} not using CDAM", resource.getFilename()); return dmDocumentManagementUploader.upload(resource, contentType); } } diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentManagementUploaderTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentManagementUploaderTest.java index 256bb5c75..712da9ea5 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentManagementUploaderTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/clients/DocumentManagementUploaderTest.java @@ -8,11 +8,13 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.core.io.Resource; import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.FeatureToggler; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -38,25 +40,29 @@ public void setUp() { @Test void should_use_cdam_when_feature_flag_true() throws IOException { // Given + Resource resource = mock(Resource.class); + given(resource.getFilename()).willReturn("file.ext"); given(featureToggler.getValue(eq("use-ccd-document-am"), anyBoolean())).willReturn(true); // When - documentManagementUploader.upload(null, null); + documentManagementUploader.upload(resource, null); // Then - verify(cdamDocumentManagementUploader, times(1)).upload(null, null); + verify(cdamDocumentManagementUploader, times(1)).upload(resource, null); } @Test void should_use_dm_when_feature_flag_false() throws IOException { // Given + Resource resource = mock(Resource.class); + given(resource.getFilename()).willReturn("file.ext"); given(featureToggler.getValue(eq("use-ccd-document-am"), anyBoolean())).willReturn(false); // When - documentManagementUploader.upload(null, null); + documentManagementUploader.upload(resource, null); // Then - verify(dmDocumentManagementUploader, times(1)).upload(null, null); + verify(dmDocumentManagementUploader, times(1)).upload(resource, null); } }