Skip to content

Commit

Permalink
fix : fix DatasetResources.java and DatasetService in it
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoBouttes committed Aug 20, 2024
1 parent 1e1c45d commit 05224a7
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -30,8 +31,9 @@
@ConditionalOnExpression("'${fr.insee.rmes.bauhaus.activeModules}'.contains('datasets')")
public class DatasetResources {

final DatasetService datasetService;
private final DatasetService datasetService;

@Autowired
public DatasetResources(DatasetService datasetService) {
this.datasetService = datasetService;
}
Expand All @@ -40,21 +42,21 @@ public DatasetResources(DatasetService datasetService) {
@Operation(operationId = "getDatasets", summary = "List of datasets",
responses = {@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Dataset.class))))})
public String getDatasets() throws RmesException {
return this.datasetService.getDatasets();
return datasetService.getDatasets();
}

@GetMapping(value = "/{id}", produces = "application/json")
@Operation(operationId = "getDataset", summary = "Get a dataset",
responses = {@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Dataset.class))))})
public Dataset getDataset(@PathVariable(Constants.ID) String id) throws RmesException {
return this.datasetService.getDatasetByID(id);
return datasetService.getDatasetByID(id);
}

@GetMapping("/{id}/distributions")
@Operation(operationId = "getDistributionsByDataset", summary = "List of distributions for a dataset",
responses = {@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Dataset.class))))})
public String getDistributionsByDataset(@PathVariable(Constants.ID) String id) throws RmesException {
return this.datasetService.getDistributions(id);
return datasetService.getDistributions(id);
}

@PreAuthorize("isAdmin() || isDatasetContributor()")
Expand All @@ -63,7 +65,7 @@ public String getDistributionsByDataset(@PathVariable(Constants.ID) String id) t
@ResponseStatus(HttpStatus.CREATED)
public String setDataset(
@Parameter(description = "Dataset", required = true) @RequestBody String body) throws RmesException {
return this.datasetService.create(body);
return datasetService.create(body);
}

@PreAuthorize("isAdmin() || isDatasetContributorWithStamp(#datasetId)")
Expand All @@ -73,21 +75,21 @@ public String setDataset(
@PathVariable("id") String datasetId,
@Parameter(description = "Dataset", required = true) @RequestBody String body) throws RmesException {

return this.datasetService.update(datasetId, body);
return datasetService.update(datasetId, body);

Check failure

Code scanning / SonarCloud

Endpoints should not be vulnerable to reflected cross-site scripting (XSS) attacks High

Change this code to not reflect user-controlled data. See more on SonarCloud
}

@PreAuthorize("isAdmin() || isDatasetContributorWithStamp(#datasetId)")
@PutMapping("/{id}/validate")
@Operation(operationId = "publishDataset", summary = "Publish a dataset",
responses = {@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Distribution.class))))})
public String publishDataset(@PathVariable(Constants.ID) String datasetId) throws RmesException {
return this.datasetService.publishDataset(datasetId);
return datasetService.publishDataset(datasetId);

Check failure

Code scanning / SonarCloud

Endpoints should not be vulnerable to reflected cross-site scripting (XSS) attacks High

Change this code to not reflect user-controlled data. See more on SonarCloud
}

@GetMapping(value = "/archivageUnits", consumes = APPLICATION_JSON_VALUE)
@Operation(operationId = "getArchivageUnits", summary = "Get all archivage units")
public String getArchivageUnits() throws RmesException {
return this.datasetService.getArchivageUnits();
return datasetService.getArchivageUnits();
}

@PreAuthorize("isAdmin() || isDatasetContributorWithStamp(#datasetId)")
Expand All @@ -97,7 +99,7 @@ public void patchDataset(
@PathVariable("id") String datasetId,
@RequestBody PatchDataset dataset
) throws RmesException {
this.datasetService.patchDataset(datasetId, dataset);
datasetService.patchDataset(datasetId, dataset);
}

@PreAuthorize("isAdmin() || isDatasetContributorWithStamp(#datasetId)")
Expand Down

0 comments on commit 05224a7

Please sign in to comment.