Skip to content

Commit

Permalink
DIAC-555 add logs (#934)
Browse files Browse the repository at this point in the history
* Added logs

* Added logs
  • Loading branch information
apereverzin1 authored Aug 6, 2024
1 parent 4352de7 commit 99fd5c9
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<Resource> resourceResponseEntity = caseDocumentClient.getDocumentBinary(
accessTokenProvider.getAccessToken(),
serviceAuthTokenGenerator.generate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,7 @@
*/
@Component
@ComponentScan("uk.gov.hmcts.reform.ccd.document.am.feign")
@Slf4j
public class CdamDocumentManagementUploader {

private final CaseDocumentClient caseDocumentClient;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +21,7 @@
*/
@Component
@Deprecated
@Slf4j
public class DmDocumentDownloadClient {

private final DocumentDownloadClientApi documentDownloadClientApi;
Expand Down Expand Up @@ -50,6 +53,7 @@ public Resource download(String documentBinaryUrl) {

UserDetails userDetails = userDetailsProvider.getUserDetails();

log.info("Downloading {} using DocumentDownloadClientApi (no CDAM)", documentBinaryUrl);
ResponseEntity<Resource> resourceResponseEntity = documentDownloadClientApi.downloadBinary(
accessTokenProvider.getAccessToken(),
serviceAuthTokenGenerator.generate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +24,7 @@

@Component
@Deprecated
@Slf4j
public class DmDocumentManagementUploader {

private final DocumentUploadClientApi documentUploadClientApi;
Expand Down Expand Up @@ -56,6 +59,7 @@ public Document upload(
ByteStreams.toByteArray(resource.getInputStream())
);

log.info("Uploading {} using DocumentUploadClientApi (CDAM)", resource.getFilename());
UploadResponse uploadResponse =
documentUploadClientApi
.upload(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
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;


@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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,6 +10,7 @@

@Service
@RequiredArgsConstructor
@Slf4j
public class DocumentManagementUploader implements DocumentUploader {

private final FeatureToggler featureToggler;
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

}

0 comments on commit 99fd5c9

Please sign in to comment.