Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Changelog
## 1.12.0 [TODO]
- Get review indicator endpoint

## 1.11.0 [2025-10-20]
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public class DataProcessingContextController {

@Operation(summary = "Create or update a data processing context")
@PutMapping(path = "/review")
@PreAuthorize("hasAnyRole('USER_BACK_OFFICE','SCHEDULER')")
@PreAuthorize("hasAnyRole('USER_PLATINE', 'USER_BACK_OFFICE', 'SCHEDULER')")
public ResponseEntity<Object> saveContext(
@Parameter(description = "Identifier of the partition", required = true) @RequestParam("partitionId") String partitionId,
@Parameter(description = "Allow reviewing") @RequestParam(value = "withReview", defaultValue = "false") Boolean withReview
) {
){
try {
withReview = withReview != null && withReview; //False if null
dataProcessingContextApiPort.saveContext(partitionId, withReview);
Expand All @@ -60,6 +60,20 @@ public ResponseEntity<Object> saveContext(
return ResponseEntity.ok().build();
}

@Operation(summary = "Returns partition review indicator")
@GetMapping(path = "/review")
@PreAuthorize("hasAnyRole('USER_BACK_OFFICE','SCHEDULER','USER_PLATINE')")
public ResponseEntity<Object> getReviewIndicator(
@Parameter(description = "Identifier of the partition", required = true) @RequestParam("partitionId") String partitionId
){
try {
boolean withReview = dataProcessingContextApiPort.getReviewByPartitionId(partitionId);
return ResponseEntity.ok(withReview);
}catch (GenesisException e){
return new ResponseEntity<>(e.getMessage(), HttpStatusCode.valueOf(e.getStatus()));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plutôt à faire via les @CotnrollerAdvice / @ExceptionHandler (définir & throw un type d'exception dédié si besoin)

}
}

@Operation(summary = "Schedule a Kraftwerk execution")
@PutMapping(path = "/schedules")
@PreAuthorize("hasRole('USER_KRAFTWERK')")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ void saveKraftwerkExecutionSchedule(String partitionId,
DataProcessingContextModel getContext(String interrogationId) throws GenesisException;
DataProcessingContextModel getContextByPartitionId(String partitionId) throws GenesisException;
List<String> getPartitionIds(boolean withReview);

/**
* Gets the review indicator for a partition
* @param partitionId id of the partition
* @return the review indicator stored in genesis
*/
boolean getReviewByPartitionId(String partitionId) throws GenesisException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import fr.insee.genesis.domain.ports.spi.DataProcessingContextPersistancePort;
import fr.insee.genesis.domain.ports.spi.SurveyUnitPersistencePort;
import fr.insee.genesis.exceptions.GenesisException;
import fr.insee.genesis.infrastructure.document.context.DataProcessingContextDocument;
import fr.insee.genesis.infrastructure.mappers.DataProcessingContextMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -168,7 +169,7 @@ public DataProcessingContextModel getContext(String interrogationId) throws Gene

@Override
public DataProcessingContextModel getContextByPartitionId(String partitionId){
return DataProcessingContextMapper.INSTANCE.documentToModel(
return DataProcessingContextMapper.INSTANCE.documentToModel(
dataProcessingContextPersistancePort.findByPartitionId(partitionId)
);
}
Expand All @@ -184,4 +185,16 @@ public List<String> getPartitionIds(boolean withReview){
}
return partitionIds;
}

@Override
public boolean getReviewByPartitionId(String partitionId) throws GenesisException {
DataProcessingContextDocument dataProcessingContextDocument =
dataProcessingContextPersistancePort.findByPartitionId(partitionId);
if(dataProcessingContextDocument == null){
throw new GenesisException(404, "Data processing context not found");
}
return DataProcessingContextMapper.INSTANCE.documentToModel(
dataProcessingContextPersistancePort.findByPartitionId(partitionId)
).isWithReview();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.http.ResponseEntity;

import java.io.IOException;
Expand Down Expand Up @@ -442,6 +444,41 @@ void deleteExpiredScheduleTest_appendLog() throws IOException, GenesisException
.toFile()).exists().content().isNotEmpty().contains("2000","2001");
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
void getReview_test(boolean withReview){
//GIVEN
String partitionId = "TESTPARTITION";
dataProcessingContextPersistancePortStub.getMongoStub().add(
new DataProcessingContextDocument(
"TESTPARTITION",
new ArrayList<>(),
withReview
)
);

//WHEN
ResponseEntity<Object> response = dataProcessingContextController.getReviewIndicator(partitionId);

//THEN
Assertions.assertThat(response.getStatusCode().value()).isEqualTo(200);
Assertions.assertThat(response.getBody().getClass()).isEqualTo(Boolean.class);
Assertions.assertThat((Boolean) response.getBody()).isEqualTo(withReview);
}

@Test
void getReview_no_context_test(){
//WHEN
ResponseEntity<Object> response = dataProcessingContextController.getReviewIndicator(
"TESTPARTITIONIDNOCONTEXT"
);

//THEN
Assertions.assertThat(response.getStatusCode().value()).isEqualTo(404);
}


//UTILITY
private void addNewDocumentToStub() {
DataProcessingContextDocument dataProcessingContextDocumentTest = new DataProcessingContextDocument(
"TESTSURVEY",
Expand Down
Loading