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

fix: remove sonar issues #843

Merged
merged 8 commits into from
Jan 23, 2025
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.insee.rmes.bauhaus_services;

import fr.insee.rmes.exceptions.RmesException;
import org.springframework.web.multipart.MultipartFile;

public interface ClassificationsService {

Expand Down Expand Up @@ -38,7 +37,4 @@ public interface ClassificationsService {
public String getCorrespondenceAssociation(String correspondenceId, String associationId) throws RmesException;

public String setClassificationValidation(String id) throws RmesException;

public void uploadClassification(MultipartFile file, String database) throws RmesException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import static java.util.Objects.requireNonNull;
Expand All @@ -28,12 +27,10 @@ public class StampAuthorizationChecker extends StampsRestrictionServiceImpl {
private static final Logger logger = LoggerFactory.getLogger(StampAuthorizationChecker.class);
public static final String CHECKING_AUTHORIZATION_ERROR_MESSAGE = "Error while checking authorization for user with stamp {} to modify or delete {}";
public static final String ERROR_AUTHORIZATION = "Error while checking authorization for user with stamp {} to modify {}";
private final String baseInternalUri;

@Autowired
public StampAuthorizationChecker(RepositoryGestion repoGestion, AuthorizeMethodDecider authorizeMethodDecider, UserProvider userProvider, @Value("${fr.insee.rmes.bauhaus.sesame.gestion.baseInternalURI}") String baseInternalUri) {
public StampAuthorizationChecker(RepositoryGestion repoGestion, AuthorizeMethodDecider authorizeMethodDecider, UserProvider userProvider) {
super(repoGestion, authorizeMethodDecider, userProvider);
this.baseInternalUri = baseInternalUri;
}

public boolean isSeriesManagerWithStamp(String seriesId, Stamp stamp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.insee.rmes.bauhaus_services.ClassificationsService;
import fr.insee.rmes.bauhaus_services.Constants;
import fr.insee.rmes.bauhaus_services.rdf_utils.RdfService;
import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils;
import fr.insee.rmes.bauhaus_services.rdf_utils.RepositoryGestion;
import fr.insee.rmes.config.auth.security.restrictions.StampsRestrictionsService;
import fr.insee.rmes.exceptions.ErrorCodes;
import fr.insee.rmes.exceptions.RmesException;
import fr.insee.rmes.exceptions.RmesNotFoundException;
Expand All @@ -23,24 +24,28 @@
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Service
public class ClassificationsImpl extends RdfService implements ClassificationsService {
public class ClassificationsImpl implements ClassificationsService {
private static final String CAN_T_READ_REQUEST_BODY = "Can't read request body";

@Autowired
ClassificationUtils classificationUtils;

@Autowired
private ClassificationPublication classificationPublication;
private final StampsRestrictionsService stampsRestrictionsService;
private final RepositoryGestion repoGestion;
private final ClassificationUtils classificationUtils;
private final ClassificationPublication classificationPublication;

static final Logger logger = LoggerFactory.getLogger(ClassificationsImpl.class);


public ClassificationsImpl(StampsRestrictionsService stampsRestrictionsService, RepositoryGestion repoGestion, ClassificationUtils classificationUtils, ClassificationPublication classificationPublication) {
this.stampsRestrictionsService = stampsRestrictionsService;
this.repoGestion = repoGestion;
this.classificationUtils = classificationUtils;
this.classificationPublication = classificationPublication;
}

@Override
public String getFamilies() throws RmesException {
logger.info("Starting to get classification families");
Expand Down Expand Up @@ -180,13 +185,4 @@ public String setClassificationValidation(String classificationId) throws RmesEx

return classificationId;
}

@Override
public void uploadClassification(MultipartFile file, String database) throws RmesException {
// TODO
// 1 . XSLT ods to XML
// 2 . XSLT XML to trig.
// 3 . Call load trig service

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public class CollectionExportBuilder extends RdfService {
@Autowired
ExportUtils exportUtils;

private static final String xslFile = "/xslTransformerFiles/rmes2odt.xsl";
private static final String xmlPattern = "/xslTransformerFiles/collection/collectionPatternContent.xml";
private static final String zip = "/xslTransformerFiles/collection/toZipForCollection.zip";
private static final String zipold = "/xslTransformerFiles/collection/toZipForCollectionOld.zip";
private static final String xmlPatternFR = "/xslTransformerFiles/collection/collectionFrPatternContent.xml";
private static final String xmlPatternEN = "/xslTransformerFiles/collection/collectionEnPatternContent.xml";
private static final String xmlPatternODS = "/xslTransformerFiles/collection/collectionOdsPatternContent.xml";
private static final String zipODS = "/xslTransformerFiles/collection/toZipForCollectionOds.zip";
private static final String XSL_FILE = "/xslTransformerFiles/rmes2odt.xsl";
private static final String XML_PATERN = "/xslTransformerFiles/collection/collectionPatternContent.xml";
private static final String ZIP = "/xslTransformerFiles/collection/toZipForCollection.zip";
private static final String ZIP_OLD = "/xslTransformerFiles/collection/toZipForCollectionOld.zip";
private static final String XML_PATTERN_FR = "/xslTransformerFiles/collection/collectionFrPatternContent.xml";
private static final String XML_PATTERN_EN = "/xslTransformerFiles/collection/collectionEnPatternContent.xml";
private static final String XML_PATTERN_ODS = "/xslTransformerFiles/collection/collectionOdsPatternContent.xml";
private static final String ZIP_ODS = "/xslTransformerFiles/collection/toZipForCollectionOds.zip";

final Collator instance = Collator.getInstance();

Expand All @@ -64,17 +64,17 @@ public CollectionForExport getCollectionData(String id) throws RmesException {

instance.setStrength(Collator.NO_DECOMPOSITION);

Collections.sort( orderMembers, new Comparator<JSONObject>() {
private static final String KEY_NAME = "prefLabelLg1";
Collections.sort( orderMembers, new Comparator<>() {
private static final String KEY_NAME = "prefLabelLg1";

@Override
public int compare(JSONObject a, JSONObject b) {
String valA = (String) a.get(KEY_NAME);
String valB = (String) b.get(KEY_NAME);
@Override
public int compare(JSONObject a, JSONObject b) {
String valA = (String) a.get(KEY_NAME);
String valB = (String) b.get(KEY_NAME);

return instance.compare(valA.toLowerCase(), valB.toLowerCase());
}
});
return instance.compare(valA.toLowerCase(), valB.toLowerCase());
}
});


JSONArray orderMembersJSONArray = new JSONArray(orderMembers);
Expand Down Expand Up @@ -105,34 +105,34 @@ public int compare(JSONObject a, JSONObject b) {
public ResponseEntity<Resource> exportAsResponse(String fileName, Map<String, String> xmlContent, boolean lg1, boolean lg2, boolean includeEmptyFields) throws RmesException {
String parametersXML = XsltUtils.buildParams(lg1, lg2, includeEmptyFields, Constants.COLLECTION);
xmlContent.put(Constants.PARAMETERS_FILE, parametersXML);
return exportUtils.exportAsODT(fileName, xmlContent,xslFile,xmlPattern,zipold, Constants.COLLECTION);
return exportUtils.exportAsODT(fileName, xmlContent,XSL_FILE,XML_PATERN,ZIP_OLD, Constants.COLLECTION);
}


public ResponseEntity<Resource> exportAsResponseODT(String fileName, Map<String, String> xmlContent, boolean lg1, boolean lg2, boolean includeEmptyFields, ConceptsCollectionsResources.Language lg) throws RmesException {
String parametersXML = XsltUtils.buildParams(true, true, includeEmptyFields, Constants.COLLECTION);
xmlContent.put(Constants.PARAMETERS_FILE, parametersXML);
String xmlPattern = lg == ConceptsCollectionsResources.Language.lg1 ? xmlPatternFR : xmlPatternEN;
return exportUtils.exportAsODT(fileName, xmlContent, xslFile, xmlPattern, zip, Constants.COLLECTION);
String xmlPattern = lg == ConceptsCollectionsResources.Language.lg1 ? XML_PATTERN_FR : XML_PATTERN_EN;
return exportUtils.exportAsODT(fileName, xmlContent, XSL_FILE, xmlPattern, ZIP, Constants.COLLECTION);
}

public ResponseEntity<Resource> exportAsResponseODS(String fileName, Map<String, String> xmlContent, boolean lg1, boolean lg2, boolean includeEmptyFields) throws RmesException {
String parametersXML = XsltUtils.buildParams(lg1, lg2, includeEmptyFields, Constants.COLLECTION);
xmlContent.put(Constants.PARAMETERS_FILE, parametersXML);
return exportUtils.exportAsODS(fileName, xmlContent,xslFile,xmlPatternODS,zipODS, Constants.COLLECTION);
return exportUtils.exportAsODS(fileName, xmlContent,XSL_FILE,XML_PATTERN_ODS,ZIP_ODS, Constants.COLLECTION);
}

public void exportMultipleCollectionsAsZipOdt(Map<String, Map<String, String>> collections, boolean lg1, boolean lg2, boolean includeEmptyFields, HttpServletResponse response, ConceptsCollectionsResources.Language lg, Map<String, Map<String, InputStream>> concepts, boolean withConcepts) throws RmesException {
String parametersXML = XsltUtils.buildParams(lg1, lg2, includeEmptyFields, Constants.COLLECTION);
collections.values().stream().forEach(collection -> collection.put(Constants.PARAMETERS_FILE, parametersXML));
String xmlPattern = lg == ConceptsCollectionsResources.Language.lg1 ? xmlPatternFR : xmlPatternEN;
exportMultipleResourceAsZip(collections,xslFile,xmlPattern,zip, response, FilesUtils.ODT_EXTENSION, concepts, withConcepts);
String xmlPattern = lg == ConceptsCollectionsResources.Language.lg1 ? XML_PATTERN_FR : XML_PATTERN_EN;
exportMultipleResourceAsZip(collections,XSL_FILE,xmlPattern,ZIP, response, FilesUtils.ODT_EXTENSION, concepts, withConcepts);
}

public void exportMultipleCollectionsAsZipOds(Map<String, Map<String, String>> collections, boolean lg1, boolean lg2, boolean includeEmptyFields, HttpServletResponse response, Map<String, Map<String, InputStream>> concepts, boolean withConcepts) throws RmesException {
String parametersXML = XsltUtils.buildParams(lg1, lg2, includeEmptyFields, Constants.COLLECTION);
collections.values().stream().forEach(collection -> collection.put(Constants.PARAMETERS_FILE, parametersXML));
exportMultipleResourceAsZip(collections,xslFile,xmlPatternODS, zipODS, response, FilesUtils.ODS_EXTENSION, concepts, withConcepts);
exportMultipleResourceAsZip(collections,XSL_FILE,XML_PATTERN_ODS, ZIP_ODS, response, FilesUtils.ODS_EXTENSION, concepts, withConcepts);
}

private void exportMultipleResourceAsZip(Map<String, Map<String, String>> resources, String xslFile, String xmlPattern, String zip, HttpServletResponse response, String extension, Map<String, Map<String, InputStream>> concepts, boolean withConcepts) throws RmesException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.List;

@Component
public class CollectionsUtils extends RdfService{
public class CollectionsUtils extends RdfService {

static final Logger logger = LoggerFactory.getLogger(CollectionsUtils.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private void addKeywordsToDataset(String id, JSONObject dataset) throws RmesExce
List<String> lg2 = new ArrayList<>();

if(keywords != null){
keywords.forEach((k) -> {
keywords.forEach(k -> {
JSONObject keyword = (JSONObject) k;
if(keyword.getString("lang").equalsIgnoreCase(config.getLg1())){
lg1.add(keyword.getString("keyword"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,8 @@ public String createRdfGeoFeature(GeoFeature geoFeature) throws RmesException {
RdfUtils.addTripleStringMdToXhtml(geoIRI, DCTERMS.ABSTRACT, geoFeature.getDescriptionLg2(), config.getLg2(), model, RdfUtils.simsGeographyGraph());


geoFeature.getUnions().forEach(feature -> {
RdfUtils.addTripleUri(geoIRI, GEO.UNION, feature.getUri(), model, RdfUtils.simsGeographyGraph());

});
geoFeature.getDifference().forEach(feature -> {
RdfUtils.addTripleUri(geoIRI, GEO.DIFFERENCE, feature.getUri(), model, RdfUtils.simsGeographyGraph());
});
geoFeature.getUnions().forEach(feature -> RdfUtils.addTripleUri(geoIRI, GEO.UNION, feature.getUri(), model, RdfUtils.simsGeographyGraph()));
geoFeature.getDifference().forEach(feature -> RdfUtils.addTripleUri(geoIRI, GEO.DIFFERENCE, feature.getUri(), model, RdfUtils.simsGeographyGraph()));
repoGestion.loadSimpleObject(geoIRI, model);

return RdfUtils.toString(geoIRI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,4 @@ public void getMultipleTripletsForObject(JSONObject object, String objectKey, St
array.iterator().forEachRemaining(r -> results.add(((JSONObject) r).getString(queryKey)));
object.put(objectKey, results);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private RdfUtils(){}

static ValueFactory factory = SimpleValueFactory.getInstance();

public static BNode createBlankNode(){ return factory.createBNode(); };
public static BNode createBlankNode(){ return factory.createBNode(); }
public static String getBaseGraph(){
return config.getBaseGraph();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/insee/rmes/config/keycloak/ServerZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void setZone(String zone) {
.filter(z->zone.toUpperCase().equals(z.name()))
.findFirst()
.orElseGet(()->{
logger.warn("No zone found for value "+zone+" : this is serverZone set to default zone");
logger.warn(String.format("No zone found for value {0} : this is serverZone set to default zone"), zone);
return Zone.defaultZone();
});
}
Expand All @@ -28,7 +28,7 @@ public ServerZone(String zone) {
.filter(z->zone.toUpperCase().equals(z.name()))
.findFirst()
.orElseGet(()->{
logger.warn("No zone found for value "+zone+" : this is serverZone set to default zone");
logger.warn(String.format("No zone found for value {0} : this is serverZone set to default zone", zone));
return Zone.defaultZone();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ private GEO() {

static {
final ValueFactory f = SimpleValueFactory.getInstance();

FEATURE = f.createIRI(NAMESPACE, "Feature");
DIFFERENCE = f.createIRI(NAMESPACE, "difference");
UNION = f.createIRI(NAMESPACE, "union");
Expand Down
1 change: 0 additions & 1 deletion src/main/java/fr/insee/rmes/utils/JSONUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/fr/insee/rmes/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class StringUtils {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Encoding;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
Expand All @@ -29,7 +27,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/classifications")
Expand Down Expand Up @@ -311,6 +308,7 @@ public ResponseEntity<Object> getCorrespondenceItem(@PathVariable("correspondenc
}



@PreAuthorize("isAdmin()")
@Operation(operationId = "uploadClassification", summary = "Upload a new classification in database" )
@PostMapping(value = "/upload/classification", consumes = MediaType.MULTIPART_FORM_DATA_VALUE )
Copy link
Contributor

Choose a reason for hiding this comment

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

end-point à supprimer ?
Il a fait l'objet de tests introduits dans cette PR : https://github.com/InseeFr/Bauhaus-Back-Office/pull/848/files

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,14 @@ void shouldReturnDataset() throws RmesException, JSONException, JsonProcessingEx
JSONObject object1 = new JSONObject().put("id", "1").put("theme", "theme1");
JSONObject object2 = new JSONObject().put("id", "1").put("theme", "theme2");
JSONArray array = new JSONArray().put(object).put(object1).put(object2);
JSONArray keywords = new JSONArray().put(
new JSONObject().put("lang","fr").put("keyword", "keyword 1")
).put(
new JSONObject().put("lang","en").put("keyword", "keyword 2")
);

when(repositoryGestion.getResponseAsArray("query")).thenReturn(array);
when(repositoryGestion.getResponseAsArray("query-keywords")).thenReturn(keywords);
when(repositoryGestion.getResponseAsArray("query-creators")).thenReturn(new JSONArray().put(new JSONObject().put("creator", "creator-1")));
when(repositoryGestion.getResponseAsArray("query-spacialResolutions")).thenReturn(new JSONArray().put(new JSONObject().put("spacialResolution", "spacialResolutions-1")));
when(repositoryGestion.getResponseAsArray("query-statisticalUnits")).thenReturn(new JSONArray().put(new JSONObject().put("statisticalUnit", "statisticalUnit-1")));
Expand All @@ -134,9 +140,10 @@ void shouldReturnDataset() throws RmesException, JSONException, JsonProcessingEx
mockedFactory.when(() -> DatasetQueries.getDatasetCreators(eq("1"), any())).thenReturn("query-creators");
mockedFactory.when(() -> DatasetQueries.getDatasetSpacialResolutions(eq("1"), any())).thenReturn("query-spacialResolutions");
mockedFactory.when(() -> DatasetQueries.getDatasetStatisticalUnits(eq("1"), any())).thenReturn("query-statisticalUnits");
mockedFactory.when(() -> DatasetQueries.getKeywords(eq("1"), any())).thenReturn("query-keywords");
Dataset response = datasetService.getDatasetByID("1");
String responseJson = objectMapper.writeValueAsString(response);
Assertions.assertEquals("{\"creators\":[\"creator-1\"],\"keywords\":{\"lg1\":[],\"lg2\":[]},\"statisticalUnit\":[\"statisticalUnit-1\"],\"spacialResolutions\":[\"spacialResolutions-1\"],\"id\":\"1\",\"themes\":[\"theme2\",\"theme1\"],\"catalogRecord\":{\"creator\":null,\"contributor\":null,\"created\":null,\"updated\":null}}", responseJson);
Assertions.assertEquals("{\"creators\":[\"creator-1\"],\"keywords\":{\"lg1\":[\"keyword 1\"],\"lg2\":[\"keyword 2\"]},\"statisticalUnit\":[\"statisticalUnit-1\"],\"spacialResolutions\":[\"spacialResolutions-1\"],\"id\":\"1\",\"themes\":[\"theme2\",\"theme1\"],\"catalogRecord\":{\"creator\":null,\"contributor\":null,\"created\":null,\"updated\":null}}", responseJson);
}
}

Expand Down
Loading
Loading