Skip to content

Commit

Permalink
feat: remove sonar issues (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey authored Jan 23, 2025
1 parent 7aa2832 commit 122880d
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import static java.util.Objects.requireNonNull;

public record MinioFilesOperation(MinioClient minioClient, String bucketName, String directoryGestion, String directoryPublication) implements FilesOperations {

static final Logger logger = LoggerFactory.getLogger(MinioFilesOperation.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class ClassificationPublication extends RdfService{
public void publishClassification(Resource graphIri) throws RmesException {
Model model = new LinkedHashModel();

// TODO notify...
RepositoryConnection con = repoGestion.getConnection();
RepositoryResult<Statement> classifStatements = repoGestion.getCompleteGraph(con, graphIri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ public void publishCollection(JSONArray collectionsToValidate) throws RmesExcept
String collectionId = collectionsToValidate.getString(i);
Model model = new LinkedHashModel();
Resource collection = RdfUtils.collectionIRI(collectionId);
//TODO uncomment when we can notify...
//Boolean creation = !repositoryPublication.getResponseAsBoolean(CollectionsQueries.isCollectionExist(collectionId));
RepositoryConnection con = repoGestion.getConnection();
RepositoryResult<Statement> statements = repoGestion.getStatements(con, collection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void publishSims(String simsId) throws RmesException {
Model model = new LinkedHashModel();
Resource graph = RdfUtils.simsGraph(simsId);

// TODO notify...
RepositoryConnection con = repoGestion.getConnection();
RepositoryResult<Statement> metadataReportStatements = repoGestion.getCompleteGraph(con, graph);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public void publishFamily(String familyId) throws RmesException {

Model model = new LinkedHashModel();
Resource family = RdfUtils.familyIRI(familyId);
//TODO notify...
RepositoryConnection con = repoGestion.getConnection();
RepositoryResult<Statement> statements = repoGestion.getStatements(con, family);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public void publishIndicator(String indicatorId) throws RmesException {
Model model = new LinkedHashModel();
Resource indicator = RdfUtils.objectIRI(ObjectType.INDICATOR, indicatorId);

// TODO notify...
RepositoryConnection con = repoGestion.getConnection();
RepositoryResult<Statement> statements = repoGestion.getStatements(con, indicator);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ private static void logTrace(String message, Repository repository, String query

/**
* Method which aims to load a file in database
* @param graph
* @param secondRepo TODO
* @param updateQuery
* @return String
* @throws RmesException
*/
public static HttpStatus persistFile(InputStream input,RDFFormat format, String graph, Repository repository, Repository secondRepo) throws RmesException {
if (repository == null) {return HttpStatus.EXPECTATION_FAILED;}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/fr/insee/rmes/config/LogRequestFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import static java.util.Optional.empty;

//TODO Test
@Component
public class LogRequestFilter extends AbstractRequestLoggingFilter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.eclipse.rdf4j.model.impl.SimpleNamespace;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;

// TODO Add @see tags
/**
* Vocabulary constants for XKOS.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ public DocumentsResources(DocumentsService documentsService) {
@Operation(operationId = "getDocuments", summary = "List of documents and links",
responses = {@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Document.class))))})
public ResponseEntity<String> getDocuments() throws RmesException {
String jsonResultat;
jsonResultat = documentsService.getDocuments();

return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(jsonResultat);
String documents = documentsService.getDocuments();
return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(documents);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ public class IndicatorsResources extends OperationsCommonResources {
@io.swagger.v3.oas.annotations.Operation(operationId = "getIndicators", summary = "List of indicators",
responses = {@ApiResponse(content=@Content(schema=@Schema(type="array",implementation=IdLabelAltLabel.class)))})
public ResponseEntity<Object> getIndicators() throws RmesException {
String jsonResultat = operationsService.getIndicators();
return ResponseEntity.status(HttpStatus.OK).body(jsonResultat);
String indicators = operationsService.getIndicators();
return ResponseEntity.status(HttpStatus.OK).body(indicators);

}

@GetMapping(value="/indicators/withSims",produces= MediaType.APPLICATION_JSON_VALUE)
@io.swagger.v3.oas.annotations.Operation(operationId = "annotations", summary = "List of series with related sims", responses = {@ApiResponse(content=@Content(schema=@Schema(type="array",implementation= IdLabelAltLabelSims.class)))})
public ResponseEntity<Object> getIndicatorsWIthSims() throws RmesException {
String jsonResultat = operationsService.getIndicatorsWithSims();
return ResponseEntity.status(HttpStatus.OK).body(jsonResultat);
String indicators = operationsService.getIndicatorsWithSims();
return ResponseEntity.status(HttpStatus.OK).body(indicators);
}

@GetMapping(value="/indicators/advanced-search", produces=MediaType.APPLICATION_JSON_VALUE)
@io.swagger.v3.oas.annotations.Operation(operationId = "getIndicatorsForSearch", summary = "List of indicators for search",
responses = {@ApiResponse(content=@Content(schema=@Schema(type="array",implementation=Indicator.class)))})
public ResponseEntity<Object> getIndicatorsForSearch() throws RmesException {
String jsonResultat = operationsService.getIndicatorsForSearch();
return ResponseEntity.status(HttpStatus.OK).body(jsonResultat);
String indicators = operationsService.getIndicatorsForSearch();
return ResponseEntity.status(HttpStatus.OK).body(indicators);

}

Expand All @@ -62,29 +62,23 @@ public ResponseEntity<Object> getIndicatorsForSearch() throws RmesException {
responses = { @ApiResponse(content = @Content(schema = @Schema(implementation = Indicator.class)))})
public ResponseEntity<Object> getIndicatorByID(@PathVariable(Constants.ID) String id,
@Parameter(hidden = true)@RequestHeader(required=false) String accept) {
String resultat;
String indicator;
if (accept != null && accept.equals(MediaType.APPLICATION_XML_VALUE)) {
try {
resultat=XMLUtils.produceXMLResponse(operationsService.getIndicatorById(id));
indicator=XMLUtils.produceXMLResponse(operationsService.getIndicatorById(id));
} catch (RmesException e) {
return returnRmesException(e);
}
} else {
try {
resultat = operationsService.getIndicatorJsonByID(id);
indicator = operationsService.getIndicatorJsonByID(id);
} catch (RmesException e) {
return returnRmesException(e);
}
}
return ResponseEntity.status(HttpStatus.OK).body(resultat);
return ResponseEntity.status(HttpStatus.OK).body(indicator);
}

/**
* UPDATE
* @param id
* @param body
* @return
*/
//TODO Test : admin then INDICATOR_CONTRIBUTOR with stamp fit then not
@PreAuthorize("hasAnyRole(T(fr.insee.rmes.config.auth.roles.Roles).ADMIN , T(fr.insee.rmes.config.auth.roles.Roles).INDICATOR_CONTRIBUTOR)")
@PutMapping(value="/indicator/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -101,16 +95,11 @@ public ResponseEntity<Object> setIndicatorById(
return ResponseEntity.noContent().build();
}

/**
* PUBLISH
* @param id
* @return response
*/
@PreAuthorize("hasAnyRole(T(fr.insee.rmes.config.auth.roles.Roles).ADMIN , T(fr.insee.rmes.config.auth.roles.Roles).INDICATOR_CONTRIBUTOR)")
@PutMapping(value="/indicator/validate/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
@io.swagger.v3.oas.annotations.Operation(operationId = "setIndicatorValidation", summary = "Indicator validation")
public ResponseEntity<Object> setIndicatorValidation(
@PathVariable(Constants.ID) String id) throws RmesException {
@PathVariable(Constants.ID) String id) {
try {
operationsService.setIndicatorValidation(id);
} catch (RmesException e) {
Expand All @@ -127,7 +116,7 @@ public ResponseEntity<Object> setIndicator(
@Parameter(description = "Indicator to create", required = true,
content = @Content(schema = @Schema(implementation = Indicator.class))) @RequestBody String body) {
logger.info("POST indicator");
String id = null;
String id;
try {
id = operationsService.setIndicator(body);
} catch (RmesException e) {
Expand All @@ -136,6 +125,4 @@ public ResponseEntity<Object> setIndicator(
if (id == null) {return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(id);}
return ResponseEntity.status(HttpStatus.OK).body(id);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public ResponseEntity<Object> getSeriesForSearch() {
/**
* Get series where stamp is the creator
* If only id, label, altlabel are needed, prefere /series/seriesWithStamp/{stamp}
* @param stamp
* @return
* @throws RmesException
*/
@GetMapping(value = "/series/advanced-search/{stamp}", produces = MediaType.APPLICATION_JSON_VALUE)
@io.swagger.v3.oas.annotations.Operation(operationId = "getSeriesForSearchWithStamps", summary = "Series", responses = { @ApiResponse(content = @Content(mediaType = "application/json", schema = @Schema(implementation = Series.class)))})
Expand Down Expand Up @@ -153,7 +150,7 @@ public ResponseEntity<Object> getOperationsWithReport(@PathVariable(Constants.ID
public ResponseEntity<Object> createSeries(
@Parameter(description = "Series to create", required = true,
content = @Content(schema = @Schema(implementation = Series.class))) @RequestBody String body) {
String id = null;
String id;
try {
id = operationsService.createSeries(body);
} catch (RmesException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -87,7 +86,7 @@ void testExportAsZip_success() throws Exception {


InputStream inputStreamMock = mock(InputStream.class);
when(exportUtils.exportAsInputStream(eq("simslabel"), eq(xmlContent), eq(xslFile), eq(xmlPattern), eq(zip), eq(objectType), eq(FilesUtils.ODT_EXTENSION)))
when(exportUtils.exportAsInputStream("simslabel", xmlContent, xslFile, xmlPattern, zip, objectType, FilesUtils.ODT_EXTENSION))
.thenReturn(inputStreamMock);
when(inputStreamMock.readAllBytes()).thenReturn(new byte[0]);

Expand Down Expand Up @@ -136,9 +135,9 @@ void testExportMetadataReport_Failure_UnknownGoal() throws RmesException {
when(parentUtils.getDocumentationTargetTypeAndId(id)).thenReturn(new String[]{"someTargetType", "someId"});
when(documentationsUtils.getFullSimsForXml(id)).thenReturn(new Documentation());

RmesBadRequestException exception = assertThrows(RmesBadRequestException.class, () -> {
documentationExport.exportMetadataReport(id, includeEmptyMas, lg1, lg2, document, goal, 100);
});
RmesBadRequestException exception = assertThrows(RmesBadRequestException.class,
() -> documentationExport.exportMetadataReport(id, includeEmptyMas, lg1, lg2, document, goal, 100)
);

assertEquals("{\"message\":\"The goal is unknown\"}", exception.getDetails());
}
Expand Down
1 change: 0 additions & 1 deletion src/test/java/fr/insee/rmes/config/ConfigStub.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public String getOrgInseeGraph() {
return "http://rdf.insee.fr/graphes/organisations/insee";
}

//TODO
@Override
public String getStructuresComponentsGraph() {
return "http://rdf.insee.fr/graphes/composants";
Expand Down

0 comments on commit 122880d

Please sign in to comment.