Skip to content

Commit

Permalink
fix (print debug message with miniofiles)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrice B committed Dec 13, 2024
1 parent cd19871 commit 5a99c51
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package fr.insee.rmes.bauhaus_services;

import fr.insee.rmes.bauhaus_services.operations.documentations.documents.DocumentsUtils;
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;
Expand All @@ -14,11 +17,15 @@

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

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

@Override
public InputStream read(String pathFile){
String fileName= extractFileName(pathFile);
String objectName = directoryGestion + "/" + fileName;

logger.debug("Reading file with name {} from path {} as object {} in bucket {}", fileName, pathFile, objectName, bucketName);

try {
return minioClient.getObject(GetObjectArgs.builder()
.bucket(bucketName)
Expand All @@ -38,6 +45,7 @@ private static String extractFileName(String filePath) {
@Override
public boolean existsInStorage(String filename) {
var objectName = extractFileName(requireNonNull(filename));
logger.debug("Check existence of file with name {} as object {} in bucket {}", filename, objectName, bucketName);
try {
return minioClient.statObject(StatObjectArgs.builder()
.bucket(bucketName)
Expand All @@ -52,6 +60,7 @@ public boolean existsInStorage(String filename) {
public void write(InputStream content, Path filePath) {
String filename = filePath.getFileName().toString();
String objectName = directoryGestion + "/" + filename;
logger.debug("Writing to file with name {} from path {} as object {} in bucket {}", filename, filePath, objectName, bucketName);
try {
minioClient.putObject(PutObjectArgs.builder()
.bucket(bucketName)
Expand All @@ -71,6 +80,8 @@ public void copy(String srcObjectName, String destObjectName) {
String srcObject = directoryGestion + "/" + extractFileName(srcObjectName);
String destObject = directoryPublication + "/" + extractFileName(srcObjectName);

logger.debug("Copy from source {} as object {} to destination {} as object {} in bucket {}", srcObjectName, srcObject, destObjectName, destObject, bucketName);

try {
CopySource source = CopySource.builder()
.bucket(bucketName)
Expand All @@ -96,6 +107,9 @@ public boolean dirExists(Path gestionStorageFolder) {
@Override
public void delete(Path absolutePath) {
String objectName = absolutePath.getFileName().toString();

logger.debug("Delete file with path {} as object {} in bucket {}", absolutePath, objectName, bucketName);

try {
minioClient.removeObject(RemoveObjectArgs.builder()
.bucket(bucketName)
Expand Down

0 comments on commit 5a99c51

Please sign in to comment.