-
Notifications
You must be signed in to change notification settings - Fork 1
Fact 2634 csv creation for cron job #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RebeccaHayleyPickles
wants to merge
80
commits into
master
Choose a base branch
from
FACT-2634-Csv-creation-for-cron-job
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
0a2bbfe
Initial setup for csv creation and upload
RebeccaHayleyPickles 840b3b0
Update endpoint
RebeccaHayleyPickles a9cf2a2
Update
RebeccaHayleyPickles 9ee8ffe
Fix slack message alert
RebeccaHayleyPickles af9c3e9
Update court data flow
RebeccaHayleyPickles 54ab16e
Merge branch 'master' into FACT-2634-Csv-creation-for-cron-job
RebeccaHayleyPickles 388266d
update csv formatter
RebeccaHayleyPickles 75d3a61
Update CsvUtil.java
RebeccaHayleyPickles b1266a1
Add test file
RebeccaHayleyPickles 2ad3866
fix sonar cloud
RebeccaHayleyPickles 79a3533
increase test coverage
RebeccaHayleyPickles 8e43a4b
Fix build
RebeccaHayleyPickles 1498f22
Specify exceptions
RebeccaHayleyPickles 488029e
Update exception handling
RebeccaHayleyPickles de8c63f
Update CsvUtilTest.java
RebeccaHayleyPickles e430aef
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 100985a
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 6f943d0
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 68966de
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] fcfbef8
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 3d3f94a
Address comments on PR
RebeccaHayleyPickles 842fab1
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 6303edb
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 29e39fe
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] b227fcf
Merge branch 'master' into FACT-2634-Csv-creation-for-cron-job
RebeccaHayleyPickles 1c537af
fix jackson dependency after merge
RebeccaHayleyPickles ba5b9be
Update jackson
RebeccaHayleyPickles aa731a5
Update CsvUtilTest.java
RebeccaHayleyPickles 2d23137
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] cea789c
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 9b5d715
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] fd4f8a5
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 8c94044
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 79deae8
merge conflicts
amstevenson 5d7ddc3
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] e36ff10
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 45b6675
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] a7b6070
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 74b6d60
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 9c465a0
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 1d9e9f8
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 37b2a64
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] d4a5b48
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 600f6e5
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] c29d996
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] bef1d8d
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 978dfce
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 3daf1de
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] a5540eb
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 01c86d7
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] a328d0b
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] bd3ac31
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 9130f7b
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 45ed01d
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 497796a
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] fdd07e3
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] b023678
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 0ec52c7
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 03de7bf
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 8e6cbaf
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 32bdbfa
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 346b852
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 169f0f9
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 51080ef
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 5a0e7ed
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] f100d90
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 53ef19e
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 37026a9
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] d3b6c53
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] fcad64f
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 3755db1
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 0751b5f
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] d0655ab
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 42e4a3d
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 4038cfa
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] be684cd
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 9b038c1
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 92c7d41
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] bb2153e
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] 086f71b
Merge master into FACT-2634-Csv-creation-for-cron-job
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...est/java/uk/gov/hmcts/reform/fact/functional/controllers/CsvControllerFunctionalTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package uk.gov.hmcts.reform.fact.functional.controllers; | ||
|
|
||
| import io.qameta.allure.Feature; | ||
| import io.restassured.response.Response; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import uk.gov.hmcts.reform.fact.functional.http.HttpClient; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.springframework.http.HttpStatus.UNAUTHORIZED; | ||
|
|
||
| @Feature("CSV Controller") | ||
| @DisplayName("CSV Controller") | ||
| class CsvControllerFunctionalTest { | ||
|
|
||
| private static final String CSV_ENDPOINT = "/csv/"; | ||
| private static final String INVALID_TOKEN = "invalid-token"; | ||
| private static final HttpClient http = new HttpClient(); | ||
|
|
||
| @Test | ||
| @DisplayName("POST /csv/ without bearer token returns 401") | ||
| void shouldReturnUnauthorizedWithoutToken() { | ||
| final Response response = http.doPost(CSV_ENDPOINT, null, ""); | ||
|
|
||
| assertThat(response.statusCode()).isEqualTo(UNAUTHORIZED.value()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("POST /csv/ with invalid bearer token returns 401") | ||
| void shouldReturnUnauthorizedWithInvalidToken() { | ||
| final Response response = http.doPost(CSV_ENDPOINT, null, INVALID_TOKEN); | ||
|
|
||
| assertThat(response.statusCode()).isEqualTo(UNAUTHORIZED.value()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...integrationTest/java/uk/gov/hmcts/reform/fact/data/api/controllers/CsvControllerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package uk.gov.hmcts.reform.fact.data.api.controllers; | ||
|
|
||
| import io.qameta.allure.Feature; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
| import org.springframework.test.context.bean.override.mockito.MockitoBean; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
| import uk.gov.hmcts.reform.fact.data.api.clients.SlackClient; | ||
| import uk.gov.hmcts.reform.fact.data.api.services.AzureBlobService; | ||
| import uk.gov.hmcts.reform.fact.data.api.services.CourtDetailsViewService; | ||
| import uk.gov.hmcts.reform.fact.data.api.services.CourtService; | ||
|
|
||
| import java.util.Collections; | ||
|
|
||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.anyString; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| @Feature("CSV Controller") | ||
| @DisplayName("CSV Controller") | ||
| @SpringBootTest | ||
| @AutoConfigureMockMvc(addFilters = false) | ||
| @ActiveProfiles("test") | ||
| class CsvControllerTest { | ||
|
|
||
| @Autowired | ||
| private MockMvc mvc; | ||
|
|
||
| @MockitoBean(name = "csvAzureBlobService") | ||
| private AzureBlobService azureBlobService; | ||
|
|
||
| @MockitoBean | ||
| private CourtService courtService; | ||
|
|
||
| @MockitoBean | ||
| private CourtDetailsViewService courtDetailsViewService; | ||
|
|
||
| @MockitoBean | ||
| private SlackClient slackClient; | ||
|
|
||
| @Test | ||
| @DisplayName("POST /csv/ returns 200 when CSV is created and uploaded successfully") | ||
| void createAndUploadCsvReturns200() throws Exception { | ||
| when(courtService.getAllCourtDetails()).thenReturn(Collections.emptyList()); | ||
| when(azureBlobService.uploadFile(anyString(), any())).thenReturn("http://example.com/blob"); | ||
|
|
||
| mvc.perform(post("/csv/")) | ||
| .andExpect(status().isOk()); | ||
|
|
||
| verify(azureBlobService, times(1)).uploadFile(anyString(), any()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("POST /csv/ returns 502 when Azure upload fails (e.g. container missing)") | ||
| void createAndUploadCsvReturns502OnAzureUploadException() throws Exception { | ||
| when(courtService.getAllCourtDetails()).thenReturn(Collections.emptyList()); | ||
| when(azureBlobService.uploadFile(anyString(), any())).thenThrow(new RuntimeException("Container not found")); | ||
|
|
||
| mvc.perform(post("/csv/")) | ||
| .andExpect(status().isBadGateway()) | ||
| .andExpect(jsonPath("$.message").value("Failed to upload CSV file to Azure Blob Storage")); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("POST /csv/ returns 500 when CSV creation fails") | ||
| void createAndUploadCsvReturns500OnCsvCreationException() throws Exception { | ||
| when(courtService.getAllCourtDetails()).thenThrow(new RuntimeException("DB error")); | ||
|
|
||
| mvc.perform(post("/csv/")) | ||
| .andExpect(status().isInternalServerError()) | ||
| .andExpect(jsonPath("$.message").value("Failed to create CSV file")); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/uk/gov/hmcts/reform/fact/data/api/controllers/CsvController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package uk.gov.hmcts.reform.fact.data.api.controllers; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import uk.gov.hmcts.reform.fact.data.api.security.SecuredFactRestController; | ||
| import uk.gov.hmcts.reform.fact.data.api.services.CsvService; | ||
|
|
||
| @SecuredFactRestController( | ||
| name = "CSV", | ||
| description = "Operations related to CSV file handling" | ||
| ) | ||
| @RequestMapping("/csv") | ||
| public class CsvController { | ||
|
|
||
| private final CsvService csvService; | ||
|
|
||
| public CsvController(CsvService csvService) { | ||
| this.csvService = csvService; | ||
| } | ||
|
|
||
| @PostMapping("/") | ||
| @Operation( | ||
| summary = "Create and upload CSV file", | ||
| description = "Generates a CSV file with court data and uploads it to the configured storage service." | ||
| ) | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "200", description = "CSV file created and uploaded successfully"), | ||
| @ApiResponse(responseCode = "500", description = "Failed to create CSV file"), | ||
| @ApiResponse(responseCode = "502", description = "Failed to upload CSV file to storage") | ||
| }) | ||
| public void createAndUploadCsv() { | ||
| csvService.createAndUploadCsv(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...java/uk/gov/hmcts/reform/fact/data/api/errorhandling/exceptions/CsvCreationException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package uk.gov.hmcts.reform.fact.data.api.errorhandling.exceptions; | ||
|
|
||
| import lombok.experimental.StandardException; | ||
|
|
||
| @StandardException | ||
| public class CsvCreationException extends RuntimeException { | ||
| } |
7 changes: 7 additions & 0 deletions
7
...java/uk/gov/hmcts/reform/fact/data/api/errorhandling/exceptions/JsonConvertException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package uk.gov.hmcts.reform.fact.data.api.errorhandling.exceptions; | ||
|
|
||
| import lombok.experimental.StandardException; | ||
|
|
||
| @StandardException | ||
| public class JsonConvertException extends RuntimeException { | ||
| } |
57 changes: 57 additions & 0 deletions
57
src/main/java/uk/gov/hmcts/reform/fact/data/api/models/StringMultipartFile.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package uk.gov.hmcts.reform.fact.data.api.models; | ||
|
|
||
| import lombok.Getter; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
| import java.io.ByteArrayInputStream; | ||
| import java.io.InputStream; | ||
|
|
||
| /** | ||
| * An implementation of the {@link MultipartFile} interface that wraps a {@link String} content. | ||
| * | ||
| * <p>This class is used to represent a file created from a string, which can be then treated as a standard | ||
| * multipart file for operations like uploading to cloud storage.</p> | ||
| */ | ||
| @Getter | ||
| public class StringMultipartFile implements MultipartFile { | ||
|
|
||
| private final String name; | ||
| private final String originalFilename; | ||
| private final String contentType; | ||
| private final byte[] bytes; | ||
|
|
||
| /** | ||
| * Constructs a new StringMultipartFile. | ||
| * | ||
| * @param name the name of the file | ||
| * @param originalFilename the original filename | ||
| * @param contentType the content type of the file | ||
| * @param content the string content of the file | ||
| */ | ||
| public StringMultipartFile(String name, String originalFilename, String contentType, String content) { | ||
| this.name = name; | ||
| this.originalFilename = originalFilename; | ||
| this.contentType = contentType; | ||
| this.bytes = content.getBytes(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isEmpty() { | ||
| return bytes.length == 0; | ||
| } | ||
|
|
||
| @Override | ||
| public long getSize() { | ||
| return bytes.length; | ||
| } | ||
|
|
||
| @Override | ||
| public InputStream getInputStream() { | ||
| return new ByteArrayInputStream(bytes); | ||
| } | ||
|
|
||
| @Override | ||
| public void transferTo(java.io.File dest) throws IllegalStateException { | ||
| // This implementation is currently empty as it's not required for current use cases, | ||
| // but the override is necessary for the interface. | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.