-
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
Open
Hajarel-moukh
wants to merge
18
commits into
main
Choose a base branch
from
devReprocessRawDatas
base: main
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
18 commits
Select commit
Hold shift + click to select a range
49a0caf
add two reprocess endpoints
Hajarel-moukh b9b9980
add record dates to endpoint for rawResponses
Hajarel-moukh 7c9949e
add comment for sonar
Hajarel-moukh 2f2b47d
correct app build
Hajarel-moukh 3897f7c
add methods for the lunaticmodel reprocess
Hajarel-moukh 8b92f81
add endpoint for the lunatic model
Hajarel-moukh 28072a9
replace campaignId with questionnaireId to reprocess old model
Hajarel-moukh 9f747cd
add tests
Hajarel-moukh a224781
refactor: fix some sonar issues
nsenave 63fb3a1
refactor: duplicate methods
nsenave f00f967
test: fix stup after refactor
nsenave 8238d56
refactor: reprocess service
nsenave f20f30f
test: add comment in empty stub methods for sonar
nsenave 3fcba11
chore: commit merge #438
nsenave bfc2106
fix(reprocess): role
nsenave fcc2cad
ci: temporary deactivate docker hub push
nsenave 9b2dc67
delete wildcard
Hajarel-moukh d689ac3
update bpm version
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
94 changes: 94 additions & 0 deletions
94
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,94 @@ | ||
| 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.LocalDateTime; | ||
|
|
||
| @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:00")) | ||
| @RequestParam(value = "sinceDate", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | ||
| LocalDateTime sinceDate, | ||
|
|
||
| @Parameter(description = "Extract until", | ||
| schema = @Schema(type = "string", format = "date-time", example = "2026-02-02T00:00:00")) | ||
| @RequestParam(value = "endDate", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | ||
| LocalDateTime 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:00")) | ||
| @RequestParam(value = "sinceDate", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | ||
| LocalDateTime sinceDate, | ||
|
|
||
| @Parameter(description = "Extract until", | ||
| schema = @Schema(type = "string", format = "date-time", example = "2026-02-02T00:00:00")) | ||
| @RequestParam(value = "endDate", required = false) | ||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | ||
| LocalDateTime 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
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
26 changes: 26 additions & 0 deletions
26
src/main/java/fr/insee/genesis/domain/ports/api/ReprocessRawResponseApiPort.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,26 @@ | ||
| package fr.insee.genesis.domain.ports.api; | ||
|
|
||
| import fr.insee.genesis.domain.model.surveyunit.rawdata.DataProcessResult; | ||
| import fr.insee.genesis.domain.model.surveyunit.rawdata.RawDataModelType; | ||
| import fr.insee.genesis.exceptions.GenesisException; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public interface ReprocessRawResponseApiPort { | ||
|
|
||
| /** | ||
| * Reprocesses raw data of the collection that correspond to the given identifier. | ||
| * An optional date interval can be given to reprocess a subset of the collection. | ||
| * @param rawDataModelType {@link RawDataModelType} | ||
| * @param collectionInstrumentId Collection instrument identifier. | ||
| * @param sinceDate Start of the date interval. | ||
| * @param endDate End of the date interval. | ||
| * @return Data processing result record. | ||
| * @see DataProcessResult | ||
| */ | ||
| DataProcessResult reprocessRawResponses( | ||
| RawDataModelType rawDataModelType, | ||
| String collectionInstrumentId, LocalDateTime sinceDate, LocalDateTime endDate) | ||
| throws GenesisException; | ||
|
|
||
| } |
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.