Skip to content

Commit

Permalink
Revert "Fix minio bogues (#834)" (#840)
Browse files Browse the repository at this point in the history
This reverts commit 3eefa1d.
  • Loading branch information
FBibonne authored Dec 13, 2024
1 parent 3eefa1d commit 646a0cd
Show file tree
Hide file tree
Showing 55 changed files with 840 additions and 907 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<groupId>fr.insee.rmes</groupId>
<artifactId>Bauhaus-BO</artifactId>
<packaging>jar</packaging>
<version>4.1.7-beta</version>
<version>4.1.6</version>
<name>Bauhaus-Back-Office</name>
<description>Back-office services for Bauhaus</description>
<url>https://github.com/InseeFr/Bauhaus-Back-Office</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public void delete(String path) {
try {
Files.delete(Paths.get(path));
} catch (IOException e) {
throw new RmesFileException(path, "Failed to delete file: " + path, e);
throw new RmesFileException("Failed to delete file: " + path, e);
}
}

@Override
public byte[] read(String fileName) {
public InputStream read(String fileName) {
try {
return Files.readAllBytes(Paths.get(config.getDocumentsStorageGestion()).resolve(fileName));
return Files.newInputStream(Paths.get(config.getDocumentsStorageGestion()).resolve(fileName));
} catch (IOException e) {
throw new RmesFileException(fileName, "Failed to read file: " + fileName, e);
throw new RmesFileException("Failed to read file: " + fileName, e);
}
}

Expand All @@ -40,7 +40,7 @@ public void write(InputStream content, Path destPath) {
try {
Files.copy(content, destPath, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new RmesFileException(destPath.toString(),"Failed to write file: " + destPath, e);
throw new RmesFileException("Failed to write file: " + destPath, e);
}
}

Expand All @@ -51,17 +51,12 @@ public void copy(String srcPath, String destPath) {
try {
Files.copy(file, targetPath.resolve(file.getFileName()), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new RmesFileException(srcPath, "Failed to copy file : " + srcPath + " to " + destPath, e);
throw new RmesFileException("Failed to copy file : " + srcPath + " to " + destPath, e);
}
}

@Override
public boolean dirExists(Path gestionStorageFolder) {
return Files.isDirectory(requireNonNull(gestionStorageFolder));
}

@Override
public boolean exists(Path path) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

public interface FilesOperations {
void delete(String path);
byte[] read(String path);
InputStream read(String path);
void write(InputStream content, Path destPath);
void copy(String srcPath, String destPath);

boolean dirExists(Path gestionStorageFolder);

boolean exists(Path path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,71 @@
import fr.insee.rmes.exceptions.RmesFileException;
import io.minio.*;
import io.minio.errors.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
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 {

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

@Override
public byte[] read(String pathFile){
String objectName = getObjectName(requireNonNull(pathFile));
try(InputStream inputStream = minioClient.getObject(GetObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.build())) {
return inputStream.readAllBytes();
public InputStream read(String pathFile){
String objectName= extractFileName(pathFile);

try {
return minioClient.getObject(GetObjectArgs.builder()
.bucket(bucketName)
.object(directoryGestion +"/"+ objectName)
.build());
} catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) {
throw new RmesFileException(pathFile, "Error reading file: " + pathFile+" as object `"+objectName+"` in bucket "+bucketName, e);
throw new RmesFileException("Error reading file: " + objectName, e);
}
}

private String getObjectName(String pathFile) {
return getObjectName(Path.of(pathFile));
}

private String getObjectName(Path pathFile) {
return directoryGestion + "/" + pathFile.getFileName().toString();
private static String extractFileName(String filePath) {
if (filePath == null || filePath.isEmpty()) {
return "";
}
return Path.of(filePath).getFileName().toString();
}


@Override
public void write(InputStream content, Path filePath) {
String objectName = getObjectName(requireNonNull(filePath));
public void write(InputStream content, Path objectName) {
try {
minioClient.putObject(PutObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.object(directoryGestion +"/"+ objectName.getFileName().toString())
.stream(content, content.available(), -1)
.build());
} catch (IOException | ErrorResponseException | InsufficientDataException | InternalException |
InvalidKeyException | InvalidResponseException | NoSuchAlgorithmException | ServerException |
XmlParserException e) {
throw new RmesFileException(filePath.toString(), "Error writing file: " + filePath+ "as object `"+objectName+"` in bucket "+bucketName, e);
throw new RmesFileException("Error writing file: " + objectName, e);
}
}

@Override
public void copy(String srcObjectName, String destObjectName) {

String srcObject = getObjectName(requireNonNull(srcObjectName));
String destObject = getObjectName(requireNonNull(srcObjectName));
try {
CopySource source = CopySource.builder()
.bucket(bucketName)
.object(srcObject)
.object(directoryGestion +"/"+ extractFileName(srcObjectName))
.build();

minioClient.copyObject(CopyObjectArgs.builder()
.bucket(bucketName)
.object(destObject)
.object(directoryPublication +"/"+ extractFileName(srcObjectName))
.source(source)
.build());
} catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) {
throw new RmesFileException(srcObjectName,"Error copying file from `" + srcObject + "` to `" + destObject+"` in bucket "+bucketName, e);
throw new RmesFileException("Error copying file from " + srcObjectName + " to " + destObjectName, e);
}
}

Expand All @@ -78,28 +77,15 @@ public boolean dirExists(Path gestionStorageFolder) {
return true;
}

@Override
public boolean exists(Path path) {
var objectName = getObjectName(requireNonNull(path));
try {
return minioClient.statObject(StatObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.build()).size() > 0;
} catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) {
return false;
}
}

@Override
@Override
public void delete(String objectName) {
try {
minioClient.removeObject(RemoveObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.build());
} catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) {
throw new RmesFileException(objectName,"Error deleting file: " + objectName+" in bucket "+bucketName, e);
throw new RmesFileException("Error deleting file: " + objectName, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ private IRI findDistributionIRI(String distributionId) {
private IRI findComponentIRI(String componentId) throws RmesException {
JSONObject type = repoGestion.getResponseAsObject(StructureQueries.getComponentType(componentId));
String componentType = type.getString("type");
if (componentType.equals(QB.ATTRIBUTE_PROPERTY.toString())) {
if (componentType.equals(RdfUtils.toString(QB.ATTRIBUTE_PROPERTY))) {
return RdfUtils.structureComponentAttributeIRI(componentId);
} else if (componentType.equals(QB.DIMENSION_PROPERTY.toString())) {
} else if (componentType.equals(RdfUtils.toString(QB.DIMENSION_PROPERTY))) {
return RdfUtils.structureComponentDimensionIRI(componentId);
} else {
return RdfUtils.structureComponentMeasureIRI(componentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.insee.rmes.bauhaus_services.Constants;
import fr.insee.rmes.bauhaus_services.rdf_utils.PublicationUtils;
import fr.insee.rmes.bauhaus_services.rdf_utils.RdfService;
import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils;
import fr.insee.rmes.exceptions.ErrorCodes;
import fr.insee.rmes.exceptions.RmesException;
import fr.insee.rmes.exceptions.RmesNotFoundException;
Expand Down Expand Up @@ -52,7 +53,7 @@ public void transformStatementToPublish(Model model, RepositoryResult<Statement>
while (classifStatements.hasNext()) {
Statement st = classifStatements.next();
// Triplets that don't get published
String predicate = st.getPredicate().toString();
String predicate = RdfUtils.toString(st.getPredicate());
if (!isTripletForPublication(predicate)) {
// nothing, wouldn't copy this attr
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void checkIfResourceExists(RepositoryResult<Statement> statements, Resou
}

private boolean shouldExcludeTriplet(Statement statement){
String pred = statement.getPredicate().toString();
String pred = RdfUtils.toString(statement.getPredicate());
return pred.endsWith("validationState")
|| pred.endsWith(Constants.CREATOR)
|| pred.endsWith(Constants.CONTRIBUTOR)
Expand All @@ -54,7 +54,7 @@ private void publishCodeListAndCodesWithConnection(Resource codeListOrCode, Repo
}


String predicate = st.getPredicate().toString();
String predicate = RdfUtils.toString(st.getPredicate());
String object = st.getObject().stringValue();
if (RDFS.SEEALSO.toString().equalsIgnoreCase(predicate)) {
publishSeeAlsoTriplets(object, connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private boolean checkCodeListUnicity(boolean partial, JSONObject codeList, Strin
String id = codeList.getString(Constants.ID);
if(!partial) {
IRI seeAlso = RdfUtils.codeListIRI(CONCEPT + codeList.getString(LAST_CLASS_URI_SEGMENT));
return repoGestion.getResponseAsBoolean(CodeListQueries.checkCodeListUnicity(id, iri, seeAlso.toString(), false));
return repoGestion.getResponseAsBoolean(CodeListQueries.checkCodeListUnicity(id, iri, RdfUtils.toString(seeAlso), false));
}
return repoGestion.getResponseAsBoolean(CodeListQueries.checkCodeListUnicity(id, iri, "", true));
}
Expand All @@ -280,7 +280,7 @@ public String setCodesList(String body, boolean partial) throws RmesException {

IRI codeListIri = this.generateIri(codesList, partial);

if(this.checkCodeListUnicity(partial, codesList, codeListIri.toString())){
if(this.checkCodeListUnicity(partial, codesList, RdfUtils.toString(codeListIri))){
throw new RmesBadRequestException(CodesListErrorCodes.CODE_LIST_UNICITY,
"The identifier, IRI and OWL class should be unique", "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public String getConceptByID(String id) throws RmesException{

@Override
public String getRelatedConcepts(String id) throws RmesException{
String uriConcept = RdfUtils.objectIRI(ObjectType.CONCEPT, id).toString();
String uriConcept = RdfUtils.toString(RdfUtils.objectIRI(ObjectType.CONCEPT,id));
JSONArray resQuery = conceptsUtils.getRelatedConcepts(uriConcept);
return QueryUtils.correctEmptyGroupConcat(resQuery.toString());
}
Expand All @@ -102,7 +102,7 @@ public String getRelatedConcepts(String id) throws RmesException{
*/
@Override
public String deleteConcept(String id) throws RmesException {
String uriConcept = RdfUtils.objectIRI(ObjectType.CONCEPT, id).toString();
String uriConcept = RdfUtils.toString(RdfUtils.objectIRI(ObjectType.CONCEPT,id));
JSONArray graphArray = conceptsUtils.getGraphsWithConcept(uriConcept);

/* check concept isn't used in several graphs */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ public JSONArray getRelatedConcepts(String id) throws RmesException{
}

public HttpStatus deleteConcept(String id) throws RmesException{
HttpStatus result = repoGestion.executeUpdate(ConceptsQueries.deleteConcept(RdfUtils.objectIRI(ObjectType.CONCEPT, id).toString(),RdfUtils.conceptGraph().toString()));
HttpStatus result = repoGestion.executeUpdate(ConceptsQueries.deleteConcept(RdfUtils.toString(RdfUtils.objectIRI(ObjectType.CONCEPT,id)),RdfUtils.conceptGraph().toString()));
if (result.equals(HttpStatus.OK)) {
result = repositoryPublication.executeUpdate(ConceptsQueries.deleteConcept(RdfUtils.objectIRIPublication(ObjectType.CONCEPT, id).toString(),RdfUtils.conceptGraph().toString()));
result = repositoryPublication.executeUpdate(ConceptsQueries.deleteConcept(RdfUtils.toString(RdfUtils.objectIRIPublication(ObjectType.CONCEPT,id)),RdfUtils.conceptGraph().toString()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import fr.insee.rmes.persistance.ontologies.XKOS;
import fr.insee.rmes.persistance.sparql_queries.concepts.ConceptsQueries;
import org.apache.http.HttpStatus;
import org.eclipse.rdf4j.model.*;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.impl.LinkedHashModel;
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
import org.eclipse.rdf4j.model.vocabulary.SKOS;
Expand Down Expand Up @@ -77,7 +80,7 @@ private Boolean prepareOneTripleToPublicationAndCheckIfHasBroader(Model model, L

Resource subject = publicationUtils.tranformBaseURIToPublish(st.getSubject());
Resource graph = st.getContext();
String predicat = st.getPredicate().toString();
String predicat = RdfUtils.toString(st.getPredicate());

if (PublicationUtils.stringEndsWithItemFromList(predicat,notes)) {
model.add(subject, st.getPredicate(), publicationUtils.tranformBaseURIToPublish((Resource) st.getObject()),
Expand Down Expand Up @@ -144,7 +147,7 @@ private void publishExplanatoryNotes(RepositoryConnection con, Resource note, Mo
Resource graph = null;
while (statements.hasNext()) {
Statement st = statements.next();
String predicat = st.getPredicate().toString();
String predicat = RdfUtils.toString(st.getPredicate());
subject = publicationUtils.tranformBaseURIToPublish(st.getSubject());
graph = st.getContext();
if (predicat.endsWith("conceptVersion")) {
Expand Down Expand Up @@ -211,12 +214,12 @@ public void publishCollection(JSONArray collectionsToValidate) throws RmesExcept
while (statements.hasNext()) {
Statement st = statements.next();
// Other URI to transform
if (st.getPredicate().toString().endsWith("member")) {
if (RdfUtils.toString(st.getPredicate()).endsWith("member")) {
model.add(publicationUtils.tranformBaseURIToPublish(st.getSubject()), st.getPredicate(),
publicationUtils.tranformBaseURIToPublish((Resource) st.getObject()), st.getContext());
} else if (st.getPredicate().toString().endsWith("isValidated")
|| (st.getPredicate().toString().endsWith(Constants.CREATOR))
|| (st.getPredicate().toString().endsWith(Constants.CONTRIBUTOR))) {
} else if (RdfUtils.toString(st.getPredicate()).endsWith("isValidated")
|| (RdfUtils.toString(st.getPredicate()).endsWith(Constants.CREATOR))
|| (RdfUtils.toString(st.getPredicate()).endsWith(Constants.CONTRIBUTOR))) {
// nothing, wouldn't copy this attr
}
// Literals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public String createRdfGeoFeature(GeoFeature geoFeature) throws RmesException {
});
repoGestion.loadSimpleObject(geoIRI, model);

return geoIRI.toString();
}
return RdfUtils.toString(geoIRI);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean checkIfSeriesHasSims(String uriSeries) throws RmesException {
}

public void checkIfParentIsASeriesWithOperations(String idParent) throws RmesException {
String uriParent = RdfUtils.objectIRI(ObjectType.SERIES, idParent).toString();
String uriParent = RdfUtils.toString(RdfUtils.objectIRI(ObjectType.SERIES, idParent));
if (checkIfParentExists(uriParent) && checkIfSeriesHasOperation(uriParent)) throw new RmesNotAcceptableException(ErrorCodes.SERIES_OPERATION_OR_SIMS,
"Cannot create Sims for a series which already has operations", idParent);
}
Expand Down Expand Up @@ -117,7 +117,7 @@ public JSONArray getSeriesCreators(String id) throws RmesException {
}

public JSONArray getSeriesCreators(IRI iri) throws RmesException {
return repoGestion.getResponseAsJSONList(OpSeriesQueries.getCreatorsBySeriesUri("<" + iri.toString() + ">"));
return repoGestion.getResponseAsJSONList(OpSeriesQueries.getCreatorsBySeriesUri("<" + RdfUtils.toString(iri) + ">"));
}

public String[] getDocumentationTargetTypeAndId(String idSims) throws RmesException {
Expand Down
Loading

0 comments on commit 646a0cd

Please sign in to comment.