Skip to content
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

feat : add withCodes queryparameter for GET /listeCode/{id} #123

Merged
merged 8 commits into from
Jan 26, 2024
16 changes: 13 additions & 3 deletions src/main/java/fr/insee/rmes/controller/CodeListsResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,28 @@ public ResponseEntity<String> getallCodesLists() throws RmesException {
@Operation(operationId = "getCodesList", summary = "Get one codes list", security = @SecurityRequirement(name = "bearerScheme"), responses = {@ApiResponse(content = @Content(mediaType = "application/json", schema = @Schema(type = "array", implementation = ListCodeByIdModelSwagger.class)))})
public ResponseEntity<String> getCodesList(
@PathVariable(Constants.NOTATION) String notation,
@RequestParam(name = "dateMiseAJour", defaultValue = "false") Boolean boolDateMiseAJour
@RequestParam(name = "dateMiseAJour", defaultValue = "false") Boolean boolDateMiseAJour,
@RequestParam(value="withCodes", defaultValue = "true")
boolean withCodes
) throws RmesException {

if (!withCodes){
Copy link
Member

Choose a reason for hiding this comment

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

il vaut mieux créer une méthode de controller supplémentaire qui mappe les requêtes avec un paramètre withCodes plutôt que de rallonger cette méthode existante

String jsonResult = codeListsServices.getCodesListWithoutCodes(notation);
if (Objects.isNull(jsonResult) || StringUtils.isEmpty(jsonResult)) {
return ResponseEntity.status(HttpStatus.SC_NOT_FOUND).build();
} else {
return ResponseEntity.status(HttpStatus.SC_OK).body(jsonResult);
}
}
if (!boolDateMiseAJour) {
String jsonResult = codeListsServices.getCodesList(notation);
if (Objects.isNull(jsonResult) || StringUtils.isEmpty(jsonResult)) {
return ResponseEntity.status(HttpStatus.SC_NOT_FOUND).build();
} else {

return ResponseEntity.status(HttpStatus.SC_OK).body(jsonResult);
}
} else {
}
else {
String jsonResult = codeListsServices.getCodesListDateMiseAJour(notation);
if (Objects.isNull(jsonResult) || StringUtils.isEmpty(jsonResult)) {
return ResponseEntity.status(HttpStatus.SC_NOT_FOUND).build();
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/fr/insee/rmes/services/codelists/CodeListImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@ public Integer getMaxpage(String notation) throws RmesException {
}
return total;
}

public String getCodesListWithoutCodes(String notation) throws RmesException{
Copy link
Member

Choose a reason for hiding this comment

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

Nouvelle méthode non couverte par un test


Map<String, Object> params = initParamsNotation(notation);

JSONObject codesList = repoGestion.getResponseAsObject(buildRequest(Constants.CODELISTS_QUERIES_PATH,"getCodesList.ftlh", params));

codesList.put("label", this.formatLabel(codesList));
codesList.remove("prefLabelLg1");
codesList.remove("prefLabelLg2");

if(codesList.has(STATUT_VALIDATION)){
Copy link
Member

Choose a reason for hiding this comment

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

Séquence de code dupliquée :

  • dans codeLIstImpl lignes 202, 50, 227, 237, 272, 285
  • dans SutrctureImpl lignes 114, 218, 260, 414

Mieux vaut factoriser dans une méthode

String validationState = codesList.getString(STATUT_VALIDATION);
codesList.put(STATUT_VALIDATION, this.getValidationState(validationState));
}
codesList.remove(Constants.URI);
return codesList.toString();
}
public String getCodesListPagination(String notation, int pageNumber)throws RmesException{
Map<String, Object> params = initParamsNotation(notation);
JSONObject result = repoGestion.getResponseAsObject(buildRequest(Constants.CODELISTS_QUERIES_PATH,"getCodesList.ftlh",params));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public interface CodeListsServices {
Integer getMaxpage(String notation) throws RmesException;

String getCodesListPagination(String notation, int pageNumber) throws RmesException;

String getCodesListWithoutCodes(String notation) throws RmesException;
}