Search in sources :

Example 1 with StorageException

use of org.codelibs.fess.exception.StorageException in project fess by codelibs.

the class AdminStorageAction method downloadObject.

public static void downloadObject(final String objectName, final WrittenStreamOut out) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final GetObjectArgs args = GetObjectArgs.builder().bucket(fessConfig.getStorageBucket()).object(objectName).build();
    try (InputStream in = createClient(fessConfig).getObject(args)) {
        out.write(in);
    } catch (final Exception e) {
        throw new StorageException("Failed to download " + objectName, e);
    }
}
Also used : InputStream(java.io.InputStream) GetObjectArgs(io.minio.GetObjectArgs) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StorageException(org.codelibs.fess.exception.StorageException) StorageException(org.codelibs.fess.exception.StorageException) ErrorResponseException(io.minio.errors.ErrorResponseException)

Example 2 with StorageException

use of org.codelibs.fess.exception.StorageException in project fess by codelibs.

the class AdminStorageAction method download.

@Execute
@Secured({ ROLE, ROLE + VIEW })
public ActionResponse download(final String id) {
    final String[] values = decodeId(id);
    if (StringUtil.isEmpty(values[1])) {
        throwValidationError(messages -> messages.addErrorsStorageFileNotFound(GLOBAL), () -> asListHtml(encodeId(values[0])));
    }
    final StreamResponse response = new StreamResponse(StringUtil.EMPTY);
    final String name = values[1];
    final String encodedName = URLEncoder.encode(name, Constants.UTF_8_CHARSET).replace("+", "%20");
    response.header("Content-Disposition", "attachment; filename=\"" + name + "\"; filename*=utf-8''" + encodedName);
    response.header("Pragma", "no-cache");
    response.header("Cache-Control", "no-cache");
    response.header("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
    response.contentTypeOctetStream();
    return response.stream(out -> {
        try {
            downloadObject(getObjectName(values[0], values[1]), out);
        } catch (final StorageException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to download {}", values[1], e);
            }
            throwValidationError(messages -> messages.addErrorsStorageFileDownloadFailure(GLOBAL, values[1]), () -> asListHtml(encodeId(values[0])));
        }
    });
}
Also used : Result(io.minio.Result) URLDecoder(java.net.URLDecoder) MakeBucketArgs(io.minio.MakeBucketArgs) OptionalThing(org.dbflute.optional.OptionalThing) HashMap(java.util.HashMap) GetObjectArgs(io.minio.GetObjectArgs) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamResponse(org.lastaflute.web.response.StreamResponse) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) MinioClient(io.minio.MinioClient) Item(io.minio.messages.Item) PutObjectArgs(io.minio.PutObjectArgs) HtmlResponse(org.lastaflute.web.response.HtmlResponse) Secured(org.codelibs.fess.annotation.Secured) StringUtil(org.codelibs.core.lang.StringUtil) ListObjectsArgs(io.minio.ListObjectsArgs) StorageException(org.codelibs.fess.exception.StorageException) Constants(org.codelibs.fess.crawler.Constants) ActionResponse(org.lastaflute.web.response.ActionResponse) URLEncoder(java.net.URLEncoder) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) RemoveObjectArgs(io.minio.RemoveObjectArgs) MultipartFormFile(org.lastaflute.web.ruts.multipart.MultipartFormFile) Execute(org.lastaflute.web.Execute) WrittenStreamOut(org.lastaflute.web.servlet.request.stream.WrittenStreamOut) ErrorResponseException(io.minio.errors.ErrorResponseException) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) StreamResponse(org.lastaflute.web.response.StreamResponse) StorageException(org.codelibs.fess.exception.StorageException) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 3 with StorageException

use of org.codelibs.fess.exception.StorageException in project fess by codelibs.

the class AdminStorageAction method deleteObject.

public static void deleteObject(final String objectName) {
    try {
        final FessConfig fessConfig = ComponentUtil.getFessConfig();
        final MinioClient minioClient = createClient(fessConfig);
        final RemoveObjectArgs args = RemoveObjectArgs.builder().bucket(fessConfig.getStorageBucket()).object(objectName).build();
        minioClient.removeObject(args);
    } catch (final Exception e) {
        throw new StorageException("Failed to delete " + objectName, e);
    }
}
Also used : MinioClient(io.minio.MinioClient) RemoveObjectArgs(io.minio.RemoveObjectArgs) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StorageException(org.codelibs.fess.exception.StorageException) StorageException(org.codelibs.fess.exception.StorageException) ErrorResponseException(io.minio.errors.ErrorResponseException)

Example 4 with StorageException

use of org.codelibs.fess.exception.StorageException in project fess by codelibs.

the class AdminStorageAction method uploadObject.

public static void uploadObject(final String objectName, final MultipartFormFile uploadFile) {
    try (final InputStream in = uploadFile.getInputStream()) {
        final FessConfig fessConfig = ComponentUtil.getFessConfig();
        final MinioClient minioClient = createClient(fessConfig);
        final PutObjectArgs args = PutObjectArgs.builder().bucket(fessConfig.getStorageBucket()).object(objectName).stream(in, uploadFile.getFileSize(), -1).contentType("application/octet-stream").build();
        minioClient.putObject(args);
    } catch (final Exception e) {
        throw new StorageException("Failed to upload " + objectName, e);
    }
}
Also used : MinioClient(io.minio.MinioClient) InputStream(java.io.InputStream) PutObjectArgs(io.minio.PutObjectArgs) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StorageException(org.codelibs.fess.exception.StorageException) StorageException(org.codelibs.fess.exception.StorageException) ErrorResponseException(io.minio.errors.ErrorResponseException)

Aggregations

ErrorResponseException (io.minio.errors.ErrorResponseException)4 StorageException (org.codelibs.fess.exception.StorageException)4 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)4 MinioClient (io.minio.MinioClient)3 InputStream (java.io.InputStream)3 GetObjectArgs (io.minio.GetObjectArgs)2 PutObjectArgs (io.minio.PutObjectArgs)2 RemoveObjectArgs (io.minio.RemoveObjectArgs)2 ListObjectsArgs (io.minio.ListObjectsArgs)1 MakeBucketArgs (io.minio.MakeBucketArgs)1 Result (io.minio.Result)1 Item (io.minio.messages.Item)1 URLDecoder (java.net.URLDecoder)1 URLEncoder (java.net.URLEncoder)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1