Skip to content

Commit

Permalink
refactor (Do not use raw generics types)
Browse files Browse the repository at this point in the history
- done for ConceptsService
- to do for ConceptsCollectionService (#836)
- Use of fr.insee.rmes.model.operations.Indicator.isWasGenerattedByEmpty
  • Loading branch information
Fabrice B committed Dec 12, 2024
1 parent 79220e3 commit c39af48
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public interface ConceptsCollectionService {

String getCollectionMembersByID(String id) throws RmesException;

ResponseEntity getCollectionExportODT(String id, String accept, ConceptsCollectionsResources.Language lg, boolean withConcepts, HttpServletResponse response) throws RmesException;
ResponseEntity<?> getCollectionExportODT(String id, String accept, ConceptsCollectionsResources.Language lg, boolean withConcepts, HttpServletResponse response) throws RmesException;

ResponseEntity getCollectionExportODS(String id, String accept, boolean withConcepts, HttpServletResponse response) throws RmesException;
ResponseEntity<?> getCollectionExportODS(String id, String accept, boolean withConcepts, HttpServletResponse response) throws RmesException;

void exportZipCollection(String id, String accept, HttpServletResponse response, ConceptsCollectionsResources.Language lg, String type, boolean withConcepts) throws RmesException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.insee.rmes.model.concepts.MembersLg;
import fr.insee.rmes.webservice.ConceptsCollectionsResources;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;

import java.io.InputStream;
Expand Down Expand Up @@ -39,7 +40,7 @@ public interface ConceptsService {

void setConceptsValidation(String body) throws RmesException ;

ResponseEntity exportConcept(String id, String acceptHeader) throws RmesException;
ResponseEntity<Resource> exportConcept(String id, String acceptHeader) throws RmesException;

void exportZipConcept(String id, String acceptHeader, HttpServletResponse response, ConceptsCollectionsResources.Language lg, String type, boolean withConcepts) throws RmesException;

Expand All @@ -49,11 +50,11 @@ public interface ConceptsService {

void setCollectionsValidation(String body) throws RmesException ;

ResponseEntity getCollectionExport(String id, String acceptHeader) throws RmesException ;
ResponseEntity<Resource> getCollectionExport(String id, String acceptHeader) throws RmesException ;

String getRelatedConcepts(String id) throws RmesException;

String deleteConcept(String id) throws RmesException;
void deleteConcept(String id) throws RmesException;

Map<String, InputStream> getConceptsExportIS(List<String> ids, List<MembersLg> members) throws RmesException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import fr.insee.rmes.utils.XMLUtils;
import fr.insee.rmes.webservice.ConceptsCollectionsResources;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.text.CaseUtils;
import org.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -101,7 +102,7 @@ public String getRelatedConcepts(String id) throws RmesException{
* @throws RmesException
*/
@Override
public String deleteConcept(String id) throws RmesException {
public void deleteConcept(String id) throws RmesException {
String uriConcept = RdfUtils.toString(RdfUtils.objectIRI(ObjectType.CONCEPT,id));
JSONArray graphArray = conceptsUtils.getGraphsWithConcept(uriConcept);

Expand Down Expand Up @@ -139,8 +140,6 @@ public String deleteConcept(String id) throws RmesException {
String successMessage=THE_CONCEPT+id+" has been deleted from graph "+RdfUtils.conceptGraph();
if (result!= HttpStatus.OK) {
throw new RmesException(HttpStatus.INTERNAL_SERVER_ERROR.value(),"Unexpected return message: ",result.toString());
} else {
return successMessage;
}
}

Expand Down Expand Up @@ -214,14 +213,8 @@ public void setConceptsValidation(String body) throws RmesException {
* Export concept(s)
*/
@Override
public ResponseEntity<?> exportConcept(String id, String acceptHeader) throws RmesException {
ConceptForExport concept;
try {
concept = conceptsExport.getConceptData(id);
} catch (RmesException e) {
return ResponseEntity.status(e.getStatus()).contentType(MediaType.TEXT_PLAIN).body(e.getDetails());
}

public ResponseEntity<Resource> exportConcept(String id, String acceptHeader) throws RmesException {
ConceptForExport concept = conceptsExport.getConceptData(id);
Map<String, String> xmlContent = convertConceptInXml(concept);
String fileName = getFileNameForExport(concept);
return conceptsExport.exportAsResponse(fileName,xmlContent,true,true,true);
Expand Down Expand Up @@ -339,13 +332,8 @@ public void setCollectionsValidation(String body) throws RmesException {
}

@Override
public ResponseEntity<?> getCollectionExport(String id, String acceptHeader) throws RmesException{
CollectionForExportOld collection;
try {
collection = collectionExport.getCollectionDataOld(id);
} catch (RmesException e) {
return ResponseEntity.status(e.getStatus()).contentType(MediaType.TEXT_PLAIN).body(e.getDetails());
}
public ResponseEntity<Resource> getCollectionExport(String id, String acceptHeader) throws RmesException{
CollectionForExportOld collection= collectionExport.getCollectionDataOld(id);
Map<String, String> xmlContent = convertCollectionInXml(collection);
String fileName = FilesUtils.generateFinalFileNameWithoutExtension(collection.getId() + "-" + collection.getPrefLabelLg1(), maxLength);
return collectionExport.exportAsResponse(fileName,xmlContent,true,true,true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public IndicatorsUtils(
}

private void validate(Indicator indicator) throws RmesException {
if(indicator.getWasGeneratedBy() == null || indicator.getWasGeneratedBy().isEmpty()){
if(indicator.isWasGenerattedByEmpty()){
throw new RmesBadRequestException(IndicatorErrorCodes.EMPTY_WAS_GENERATED_BY, "An indicator should be linked to a series.");
}
if(repositoryGestion.getResponseAsBoolean(IndicatorsQueries.checkPrefLabelUnicity(indicator.getId(), indicator.getPrefLabelLg1(), lg1))){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.insee.rmes.exceptions;

import fr.insee.rmes.webservice.ConceptsCollectionsResources;
import fr.insee.rmes.webservice.ConceptsResources;
import fr.insee.rmes.webservice.UserResources;
import fr.insee.rmes.webservice.codesLists.CodeListsResources;
import fr.insee.rmes.webservice.dataset.DatasetResources;
Expand All @@ -23,6 +25,8 @@
OperationsResources.class,
DocumentsResources.class,
UserResources.class,
ConceptsResources.class,
ConceptsCollectionsResources.class

})
public class RmesExceptionHandler extends ResponseEntityExceptionHandler {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fr/insee/rmes/model/operations/Indicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ public List<OperationsLink> getWasGeneratedBy() {
return wasGeneratedBy;
}

public boolean isWasGenerattedByEmpty() {
return this.wasGeneratedBy == null || this.wasGeneratedBy.isEmpty();
}

public String getIdSims() {
return idSims;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -256,7 +257,7 @@ public ResponseEntity<?> getCollectionExport(@PathVariable(Constants.ID) String

@GetMapping(value = "/concept/export/{id}", produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE, "application/zip" })
@Operation(operationId = "exportConcept", summary = "Blob of concept")
public ResponseEntity<?> exportConcept(@PathVariable(Constants.ID) String id, @RequestHeader(required=false) String accept) throws RmesException {
public ResponseEntity<Resource> exportConcept(@PathVariable(Constants.ID) String id, @RequestHeader(required=false) String accept) throws RmesException {
return conceptsService.exportConcept(id, accept);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -135,13 +136,13 @@ void exportConceptTest() throws RmesException, IOException, URISyntaxException {
.reduce((a,b)->a+"\n"+b).get();

// WHEN
ResponseEntity<ByteArrayResource> result = (ResponseEntity<ByteArrayResource>) conceptsImpl.exportConcept(idConcept, MediaType.APPLICATION_OCTET_STREAM_VALUE);
ResponseEntity<Resource> result = conceptsImpl.exportConcept(idConcept, MediaType.APPLICATION_OCTET_STREAM_VALUE);
// THEN
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getHeaders().getContentDisposition().getFilename()).isEqualTo("c1116accid.odt");

Diff inputsDiffs = DiffBuilder.compare(expectedXmlForOdtContent)
.withTest(getOdtContent(result.getBody().getByteArray()))
.withTest(getOdtContent(((ByteArrayResource)result.getBody()).getByteArray()))
.ignoreWhitespace()
.ignoreComments()
.build();
Expand Down

0 comments on commit c39af48

Please sign in to comment.