-
Notifications
You must be signed in to change notification settings - Fork 4
New endpoints for Json extraction #297
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
9 commits
Select commit
Hold shift + click to select a range
3d95886
feat: add endpoints to interact with new collection which stores date…
loichenninger ed19be5
feat: add new endpoint to retrieve interrogation recorded after a spe…
loichenninger 85e2537
build: fix tests context fail
loichenninger 53200d6
Merge branch 'main' into devJsonExtraction
loichenninger 686c671
refactor: remove french and use String.format
loichenninger 9962103
refactor: review remarks
loichenninger 2fd6330
Merge branch 'main' into devJsonExtraction
loichenninger 1fcfe3d
test: selection by date in SurveyUnitService
loichenninger 4203f1b
Merge branch 'main' into devJsonExtraction
loichenninger 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
15 changes: 15 additions & 0 deletions
15
src/main/java/fr/insee/genesis/controller/dto/LastExtractionResponseDto.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,15 @@ | ||
| package fr.insee.genesis.controller.dto; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| public class LastExtractionResponseDto { | ||
| private final String lastExtractionDate; | ||
| public LastExtractionResponseDto(LocalDateTime lastExtractionDate) { | ||
| this.lastExtractionDate = lastExtractionDate != null ? lastExtractionDate.toString() : null; | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/fr/insee/genesis/controller/mappers/DataProcessingContextMapperDto.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.controller.mappers; | ||
|
|
||
| import fr.insee.genesis.controller.dto.ScheduleDto; | ||
| import fr.insee.genesis.domain.model.context.DataProcessingContextModel; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class DataProcessingContextMapperDto { | ||
|
|
||
| public ScheduleDto dataProcessingContextToScheduleDto(DataProcessingContextModel dataProcessingContext){ | ||
| return ScheduleDto.builder() | ||
| .surveyName(dataProcessingContext.getPartitionId()) | ||
| .lastExecution(dataProcessingContext.getLastExecution()) | ||
| .kraftwerkExecutionScheduleList(dataProcessingContext.getKraftwerkExecutionScheduleList()) | ||
| .build(); | ||
| } | ||
|
|
||
| public List<ScheduleDto> dataProcessingContextListToScheduleDtoList(List<DataProcessingContextModel> contexts){ | ||
| List<ScheduleDto> dtos = new ArrayList<>(); | ||
| for(DataProcessingContextModel context : contexts){ | ||
| dtos.add(dataProcessingContextToScheduleDto(context)); | ||
| } | ||
| return dtos; | ||
| } | ||
| } |
60 changes: 60 additions & 0 deletions
60
src/main/java/fr/insee/genesis/controller/rest/JsonExtractionController.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,60 @@ | ||
| package fr.insee.genesis.controller.rest; | ||
|
|
||
| import fr.insee.genesis.controller.dto.LastExtractionResponseDto; | ||
| import fr.insee.genesis.domain.model.extraction.json.LastJsonExtractionModel; | ||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
| import fr.insee.genesis.domain.ports.api.LastJsonExtractionApiPort; | ||
| import fr.insee.genesis.exceptions.GenesisException; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Slf4j | ||
| @Controller | ||
| @AllArgsConstructor | ||
| @RequestMapping(path = "/extractions") | ||
| public class JsonExtractionController { | ||
|
|
||
| LastJsonExtractionApiPort lastJsonExtractionApiPort; | ||
|
|
||
| @Operation(summary = "Record the date of the latest JSON data extraction in Kraftwerk") | ||
| @PutMapping(path = "/json") | ||
| @PreAuthorize("hasAnyRole('USER_KRAFTWERK','SCHEDULER')") | ||
| public ResponseEntity<String> saveLastJsonExtractionDate( | ||
| @RequestParam("questionnaireId") String questionnaireId, | ||
| @RequestParam(value = "mode", required = false) Mode mode){ | ||
| LocalDateTime extractDate = LocalDateTime.now(); | ||
| LastJsonExtractionModel extract = LastJsonExtractionModel.builder() | ||
| .questionnaireModelId(questionnaireId) | ||
| .mode(mode) | ||
| .lastExtractionDate(extractDate) | ||
| .build(); | ||
| lastJsonExtractionApiPort.recordDate(extract); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| @Operation(summary = "Get the date of the latest JSON data extraction in Kraftwerk") | ||
| @GetMapping(path = "/json") | ||
| @PreAuthorize("hasAnyRole('USER_KRAFTWERK','SCHEDULER')") | ||
| public ResponseEntity<LastExtractionResponseDto> getLastJsonExtractionDate( | ||
| @RequestParam("questionnaireId") String questionnaireId, | ||
| @RequestParam(value = "mode", required = false) Mode mode){ | ||
| try{ | ||
| LastJsonExtractionModel lastJsonExtraction = lastJsonExtractionApiPort.getLastExtractionDate(questionnaireId,mode); | ||
| return ResponseEntity.ok(new LastExtractionResponseDto(lastJsonExtraction.getLastExtractionDate())); | ||
| } catch (GenesisException e){ | ||
| return ResponseEntity.notFound().build(); | ||
| } | ||
| } | ||
|
|
||
| } |
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
22 changes: 22 additions & 0 deletions
22
src/main/java/fr/insee/genesis/domain/model/extraction/json/LastJsonExtractionModel.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,22 @@ | ||
| package fr.insee.genesis.domain.model.extraction.json; | ||
|
|
||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
| import org.springframework.data.annotation.Id; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Data | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class LastJsonExtractionModel { | ||
| @Id | ||
| private String id; //Used to remove warning | ||
| String questionnaireModelId; | ||
| Mode mode; | ||
| LocalDateTime lastExtractionDate; | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/fr/insee/genesis/domain/ports/api/LastJsonExtractionApiPort.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,11 @@ | ||
| package fr.insee.genesis.domain.ports.api; | ||
|
|
||
| import fr.insee.genesis.domain.model.extraction.json.LastJsonExtractionModel; | ||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
| import fr.insee.genesis.exceptions.GenesisException; | ||
|
|
||
| public interface LastJsonExtractionApiPort { | ||
| void recordDate(LastJsonExtractionModel extraction); | ||
|
|
||
| LastJsonExtractionModel getLastExtractionDate(String questionnaireModelId, Mode mode) 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
10 changes: 10 additions & 0 deletions
10
src/main/java/fr/insee/genesis/domain/ports/spi/LastJsonExtractionPersistencePort.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,10 @@ | ||
| package fr.insee.genesis.domain.ports.spi; | ||
|
|
||
| import fr.insee.genesis.domain.model.extraction.json.LastJsonExtractionModel; | ||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
| import fr.insee.genesis.exceptions.GenesisException; | ||
|
|
||
| public interface LastJsonExtractionPersistencePort { | ||
| void save(LastJsonExtractionModel extraction); | ||
| LastJsonExtractionModel getLastExecutionDate(String questionnaireModelId, Mode mode) 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
40 changes: 40 additions & 0 deletions
40
src/main/java/fr/insee/genesis/domain/service/extraction/LastJsonExtractionService.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,40 @@ | ||
| package fr.insee.genesis.domain.service.extraction; | ||
|
|
||
| import fr.insee.genesis.domain.model.extraction.json.LastJsonExtractionModel; | ||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
| import fr.insee.genesis.domain.ports.api.LastJsonExtractionApiPort; | ||
| import fr.insee.genesis.domain.ports.spi.LastJsonExtractionPersistencePort; | ||
| import fr.insee.genesis.exceptions.GenesisException; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @Slf4j | ||
| public class LastJsonExtractionService implements LastJsonExtractionApiPort { | ||
|
|
||
| @Qualifier("lastJsonExtractionMongoAdapter") | ||
| LastJsonExtractionPersistencePort extractionPersistencePort; | ||
|
|
||
| @Autowired | ||
| public LastJsonExtractionService(LastJsonExtractionPersistencePort extractionPersistencePort) { | ||
| this.extractionPersistencePort = extractionPersistencePort; | ||
| } | ||
|
|
||
| @Override | ||
| public void recordDate(LastJsonExtractionModel extraction) { | ||
| // Create a unique ID based on the questionnaire and the mode. | ||
| extraction.setId(String.format("%s_%s",extraction.getQuestionnaireModelId(),extraction.getMode())); | ||
|
|
||
| // save() does an insert if the id doesn't exist, otherwise an update | ||
| extractionPersistencePort.save(extraction); | ||
| } | ||
|
|
||
| @Override | ||
| public LastJsonExtractionModel getLastExtractionDate(String questionnaireModelId, Mode mode) throws GenesisException { | ||
| return extractionPersistencePort.getLastExecutionDate(questionnaireModelId,mode); | ||
| } | ||
|
|
||
|
|
||
| } |
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
46 changes: 46 additions & 0 deletions
46
src/main/java/fr/insee/genesis/infrastructure/adapter/LastJsonExtractionMongoAdapter.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,46 @@ | ||
| package fr.insee.genesis.infrastructure.adapter; | ||
|
|
||
| import fr.insee.genesis.domain.model.extraction.json.LastJsonExtractionModel; | ||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
| import fr.insee.genesis.domain.ports.spi.LastJsonExtractionPersistencePort; | ||
| import fr.insee.genesis.exceptions.GenesisException; | ||
| import fr.insee.genesis.infrastructure.document.extraction.json.LastJsonExtractionDocument; | ||
| import fr.insee.genesis.infrastructure.mappers.LastJsonExtractionDocumentMapper; | ||
| import fr.insee.genesis.infrastructure.repository.LastJsonExtractionMongoDBRepository; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| @Service | ||
| @Qualifier("lastJsonExtractionMongoAdapter") | ||
| @Slf4j | ||
| public class LastJsonExtractionMongoAdapter implements LastJsonExtractionPersistencePort { | ||
|
|
||
| private final LastJsonExtractionMongoDBRepository extractionRepository; | ||
|
|
||
| @Autowired | ||
| public LastJsonExtractionMongoAdapter(LastJsonExtractionMongoDBRepository extractionRepository) { | ||
| this.extractionRepository = extractionRepository; | ||
| } | ||
|
|
||
| @Override | ||
| public void save(LastJsonExtractionModel extraction) { | ||
| extractionRepository.save(LastJsonExtractionDocumentMapper.INSTANCE.modelToDocument(extraction)); | ||
| } | ||
|
|
||
| @Override | ||
| public LastJsonExtractionModel getLastExecutionDate(String questionnaireModelId, Mode mode) throws GenesisException { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add some test |
||
| String id = String.format("%s_%s",questionnaireModelId, mode); | ||
| Optional<LastJsonExtractionDocument> extraction = extractionRepository.findById(id); | ||
| if (extraction.isPresent()) { | ||
| return LastJsonExtractionDocumentMapper.INSTANCE.documentToModel(extraction.get()); | ||
| } else { | ||
| String message = String.format("No extraction date found for questionnaire %s and mode %s",questionnaireModelId,mode==null?null:mode.getModeName()); | ||
| throw new GenesisException(404,message); | ||
| } | ||
| } | ||
|
|
||
| } | ||
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
21 changes: 21 additions & 0 deletions
21
.../fr/insee/genesis/infrastructure/document/extraction/json/LastJsonExtractionDocument.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,21 @@ | ||
| package fr.insee.genesis.infrastructure.document.extraction.json; | ||
|
|
||
| import fr.insee.genesis.Constants; | ||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
| import lombok.Data; | ||
| import org.springframework.data.annotation.Id; | ||
| import org.springframework.data.mongodb.core.mapping.Document; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Data | ||
| @Document(collection = Constants.MONGODB_EXTRACTION_JSON_COLLECTION_NAME) | ||
| public class LastJsonExtractionDocument { | ||
|
|
||
| @Id | ||
| private String id; | ||
| private String questionnaireModelId; | ||
| private Mode mode; | ||
| private LocalDateTime lastExtractionDate; | ||
|
|
||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/fr/insee/genesis/infrastructure/mappers/LastJsonExtractionDocumentMapper.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,22 @@ | ||
| package fr.insee.genesis.infrastructure.mappers; | ||
|
|
||
| import fr.insee.genesis.domain.model.extraction.json.LastJsonExtractionModel; | ||
| import fr.insee.genesis.infrastructure.document.extraction.json.LastJsonExtractionDocument; | ||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.factory.Mappers; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Mapper | ||
| public interface LastJsonExtractionDocumentMapper { | ||
|
|
||
| LastJsonExtractionDocumentMapper INSTANCE = Mappers.getMapper(LastJsonExtractionDocumentMapper.class); | ||
|
|
||
| LastJsonExtractionModel documentToModel(LastJsonExtractionDocument lastJsonExtractionDoc); | ||
|
|
||
| LastJsonExtractionDocument modelToDocument(LastJsonExtractionModel lastJsonExtractionModel); | ||
|
|
||
| List<LastJsonExtractionModel> listDocumentToListModel(List<LastJsonExtractionDocument> lastJsonExtractionDocumentList); | ||
|
|
||
| List<LastJsonExtractionDocument> listModelToListDocument(List<LastJsonExtractionModel> lastJsonExtractionModelList); | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add some test