-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add two reprocess endpoints #425
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
74d88a0
add two reprocess endpoints
Hajarel-moukh 3e6d737
add record dates to endpoint for rawResponses
Hajarel-moukh dde12af
add comment for sonar
Hajarel-moukh 6646697
correct app build
Hajarel-moukh c23191b
add methods for the lunaticmodel reprocess
Hajarel-moukh 544089b
add endpoint for the lunatic model
Hajarel-moukh 84b3b85
replace campaignId with questionnaireId to reprocess old model
Hajarel-moukh 5106b0b
add tests
Hajarel-moukh 4777d96
refactor: fix some sonar issues
nsenave 97bec10
refactor: duplicate methods
nsenave 53ae3a2
test: fix stup after refactor
nsenave ba0230c
refactor: reprocess service
nsenave d7ef403
test: add comment in empty stub methods for sonar
nsenave 6c64a84
fix(reprocess): role
nsenave e78e7c3
ci: temporary deactivate docker hub push
nsenave 91a990b
delete wildcard
Hajarel-moukh 8adc0fc
rename processing method and replace localDateTime with Instant
Hajarel-moukh 9a4e6ec
replace localDateTime with Instant to correct date reprocessing problems
Hajarel-moukh 874e880
modify changelog
Hajarel-moukh 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
44 changes: 44 additions & 0 deletions
44
src/main/java/fr/insee/genesis/controller/exception/ExceptionController.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,44 @@ | ||
| package fr.insee.genesis.controller.exception; | ||
|
|
||
| import fr.insee.genesis.exceptions.GenesisException; | ||
| import fr.insee.genesis.exceptions.InvalidDateIntervalException; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ProblemDetail; | ||
| import org.springframework.web.bind.annotation.ControllerAdvice; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
|
||
| /** | ||
| * This controller uses Spring's ControllerAdvice annotation to intercept exceptions. | ||
| * It implements the <a href="https://www.rfc-editor.org/rfc/rfc9457.html">RFC 9457</a> by returning | ||
| * Spring's <code>ProblemDetail</code> object. | ||
| */ | ||
| @ControllerAdvice | ||
| @Slf4j | ||
| public class ExceptionController { | ||
|
|
||
| // Note: No handler for uncaught Exception.class for now since it breaks soms tests. | ||
|
|
||
| @ExceptionHandler | ||
| public ProblemDetail handleGenericGenesisException(GenesisException genesisException) { | ||
| log.error("GenesisException: {}", genesisException.getMessage(), genesisException); | ||
| return ProblemDetail.forStatusAndDetail( | ||
| resolveHttpCode(genesisException.getStatus()), | ||
| genesisException.getMessage()); | ||
| } | ||
|
|
||
| /** Returns the corresponding http status, or 500 if the given code does not match a http status. */ | ||
| private static HttpStatus resolveHttpCode(int statusCode) { | ||
| HttpStatus httpStatus = HttpStatus.resolve(statusCode); | ||
| return httpStatus != null ? httpStatus : HttpStatus.INTERNAL_SERVER_ERROR; | ||
| } | ||
|
|
||
| @ExceptionHandler(InvalidDateIntervalException.class) | ||
| public ProblemDetail handleInvalidDateIntervalException(InvalidDateIntervalException e) { | ||
| log.error("InvalidDateIntervalException: {}", e.getMessage()); | ||
| return ProblemDetail.forStatusAndDetail( | ||
| HttpStatus.BAD_REQUEST, | ||
| e.getMessage()); | ||
| } | ||
|
|
||
| } |
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
102 changes: 102 additions & 0 deletions
102
src/main/java/fr/insee/genesis/controller/rest/responses/RawResponseReprocessController.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,102 @@ | ||
| package fr.insee.genesis.controller.rest.responses; | ||
|
|
||
| import fr.insee.genesis.domain.model.surveyunit.rawdata.DataProcessResult; | ||
| import fr.insee.genesis.domain.model.surveyunit.rawdata.RawDataModelType; | ||
| import fr.insee.genesis.domain.ports.api.ReprocessRawResponseApiPort; | ||
| import fr.insee.genesis.exceptions.GenesisException; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.format.annotation.DateTimeFormat; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
|
|
||
| import java.time.Instant; | ||
|
|
||
| @Controller | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class RawResponseReprocessController { | ||
|
|
||
| private final ReprocessRawResponseApiPort reprocessRawResponseApiPort; | ||
|
|
||
| @Operation(summary = "Reprocess raw response of a collection instrument.") | ||
| @PostMapping(path = "/raw-responses/{collectionInstrumentId}/reprocess") | ||
| @PreAuthorize("hasRole('ADMIN')") | ||
| public ResponseEntity<String> reProcessRawResponsesByCollectionInstrumentId( | ||
| @Parameter( | ||
| description = "Id of the collection instrument (old questionnaireId)", | ||
| example = "ENQTEST2025X00") | ||
| @PathVariable("collectionInstrumentId") | ||
| String collectionInstrumentId, | ||
|
|
||
| @Parameter( | ||
| description = "Extract since", | ||
| schema = @Schema(type = "string", format = "date-time", example = "2026-01-01T00:00:00Z") | ||
| ) | ||
| @RequestParam(value = "sinceDate", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | ||
| Instant sinceDate, | ||
|
|
||
| @Parameter( | ||
| description = "Extract until", | ||
| schema = @Schema(type = "string", format = "date-time", example = "2026-02-02T00:00:00Z") | ||
| ) | ||
| @RequestParam(value = "endDate", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | ||
| Instant endDate | ||
| ) throws GenesisException { | ||
|
|
||
| DataProcessResult result = reprocessRawResponseApiPort.reprocessRawResponses( | ||
| RawDataModelType.FILIERE, | ||
| collectionInstrumentId, | ||
| sinceDate, | ||
| endDate); | ||
|
|
||
| return ResponseEntity.ok(result.message(collectionInstrumentId)); | ||
| } | ||
|
|
||
| @Operation(summary = "Reprocess Lunatic raw data for a questionnaire model. " + | ||
| "**Note**: Lunatic raw data is the legacy format of raw responses.") | ||
| @PostMapping(path = "/responses/raw/lunatic-json/{questionnaireId}/reprocess") | ||
| @PreAuthorize("hasRole('ADMIN')") | ||
| public ResponseEntity<String> reProcessJsonRawDataByQuestionnaireId( | ||
| @Parameter( | ||
| description = "Questionnaire model id (old name for collection instrument id).", | ||
| example = "ENQTEST2025X00") | ||
| @PathVariable("questionnaireId") | ||
| String collectionInstrumentId, // 'questionnaireId' is the legacy name for 'collectionInstrumentId' | ||
|
|
||
| @Parameter( | ||
| description = "Extract since", | ||
| schema = @Schema(type = "string", format = "date-time", example = "2026-01-01T00:00:00Z") | ||
| ) | ||
| @RequestParam(value = "sinceDate", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | ||
| Instant sinceDate, | ||
|
|
||
| @Parameter( | ||
| description = "Extract until", | ||
| schema = @Schema(type = "string", format = "date-time", example = "2026-02-02T00:00:00Z") | ||
| ) | ||
| @RequestParam(value = "endDate", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | ||
| Instant endDate | ||
| ) throws GenesisException { | ||
|
|
||
| DataProcessResult result = reprocessRawResponseApiPort.reprocessRawResponses( | ||
| RawDataModelType.LEGACY, | ||
| collectionInstrumentId, | ||
| sinceDate, | ||
| endDate); | ||
|
|
||
| return ResponseEntity.ok(result.message(collectionInstrumentId)); | ||
| } | ||
|
|
||
| } |
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
17 changes: 16 additions & 1 deletion
17
src/main/java/fr/insee/genesis/domain/model/surveyunit/rawdata/RawDataModelType.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 |
|---|---|---|
| @@ -1,5 +1,20 @@ | ||
| package fr.insee.genesis.domain.model.surveyunit.rawdata; | ||
|
|
||
| /** Format of raw data to be imported into the data storage. */ | ||
| public enum RawDataModelType { | ||
| DEFAULT, FILIERE | ||
|
|
||
| /** Legacy format of raw data ('Lunatic'). */ | ||
| LEGACY, | ||
|
|
||
| /** 'Filière' raw response model. */ | ||
| FILIERE; | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return switch (this) { | ||
| case LEGACY -> "LEGACY (Lunatic)"; | ||
| case FILIERE -> "FILIERE raw responses"; | ||
| }; | ||
| } | ||
|
|
||
| } |
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
Oops, something went wrong.
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.