Search in sources :

Example 1 with StreamResponse

use of org.lastaflute.web.response.StreamResponse in project fess by codelibs.

the class ApiAdminDictKuromojiAction method get$download.

// GET /api/admin/dict/kuromoji/download/{dictId}
@Execute
public StreamResponse get$download(final String dictId, final DownloadBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    return kuromojiService.getKuromojiFile(body.dictId).map(file -> {
        return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
            try (InputStream inputStream = file.getInputStream()) {
                out.write(inputStream);
            }
        });
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsFailedToDownloadProtwordsFile(GLOBAL));
        return null;
    });
}
Also used : FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) File(java.io.File) KuromojiItem(org.codelibs.fess.dict.kuromoji.KuromojiItem) StreamResponse(org.lastaflute.web.response.StreamResponse) KuromojiPager(org.codelibs.fess.app.pager.KuromojiPager) CrudMode(org.codelibs.fess.app.web.CrudMode) KuromojiFile(org.codelibs.fess.dict.kuromoji.KuromojiFile) Execute(org.lastaflute.web.Execute) AdminDictKuromojiAction.createKuromojiItem(org.codelibs.fess.app.web.admin.dict.kuromoji.AdminDictKuromojiAction.createKuromojiItem) KuromojiService(org.codelibs.fess.app.service.KuromojiService) InputStream(java.io.InputStream) UploadForm(org.codelibs.fess.app.web.admin.dict.kuromoji.UploadForm) InputStream(java.io.InputStream) File(java.io.File) KuromojiFile(org.codelibs.fess.dict.kuromoji.KuromojiFile) Execute(org.lastaflute.web.Execute)

Example 2 with StreamResponse

use of org.lastaflute.web.response.StreamResponse in project fess by codelibs.

the class ApiAdminDictMappingAction method get$download.

// GET /api/admin/dict/mapping/download/{dictId}
@Execute
public StreamResponse get$download(final String dictId, final DownloadBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    return charMappingService.getCharMappingFile(body.dictId).map(file -> {
        return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
            try (InputStream inputStream = file.getInputStream()) {
                out.write(inputStream);
            }
        });
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsFailedToDownloadProtwordsFile(GLOBAL));
        return null;
    });
}
Also used : UploadForm(org.codelibs.fess.app.web.admin.dict.mapping.UploadForm) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) CharMappingPager(org.codelibs.fess.app.pager.CharMappingPager) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) CharMappingItem(org.codelibs.fess.dict.mapping.CharMappingItem) File(java.io.File) CharMappingFile(org.codelibs.fess.dict.mapping.CharMappingFile) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) CharMappingService(org.codelibs.fess.app.service.CharMappingService) AdminDictMappingAction(org.codelibs.fess.app.web.admin.dict.mapping.AdminDictMappingAction) Execute(org.lastaflute.web.Execute) InputStream(java.io.InputStream) InputStream(java.io.InputStream) File(java.io.File) CharMappingFile(org.codelibs.fess.dict.mapping.CharMappingFile) Execute(org.lastaflute.web.Execute)

Example 3 with StreamResponse

use of org.lastaflute.web.response.StreamResponse in project fess by codelibs.

the class ApiAdminDictProtwordsAction method get$download.

// GET /api/admin/dict/protwords/download/{dictId}
@Execute
public StreamResponse get$download(final String dictId, final DownloadBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    return protwordsService.getProtwordsFile(body.dictId).map(file -> {
        return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
            try (InputStream inputStream = file.getInputStream()) {
                out.write(inputStream);
            }
        });
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsFailedToDownloadProtwordsFile(GLOBAL));
        return null;
    });
}
Also used : AdminDictProtwordsAction.createProtwordsItem(org.codelibs.fess.app.web.admin.dict.protwords.AdminDictProtwordsAction.createProtwordsItem) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) ProtwordsPager(org.codelibs.fess.app.pager.ProtwordsPager) Resource(javax.annotation.Resource) UploadForm(org.codelibs.fess.app.web.admin.dict.protwords.UploadForm) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) File(java.io.File) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) ProtwordsItem(org.codelibs.fess.dict.protwords.ProtwordsItem) ProtwordsService(org.codelibs.fess.app.service.ProtwordsService) Execute(org.lastaflute.web.Execute) ProtwordsFile(org.codelibs.fess.dict.protwords.ProtwordsFile) InputStream(java.io.InputStream) InputStream(java.io.InputStream) File(java.io.File) ProtwordsFile(org.codelibs.fess.dict.protwords.ProtwordsFile) Execute(org.lastaflute.web.Execute)

Example 4 with StreamResponse

use of org.lastaflute.web.response.StreamResponse in project fess by codelibs.

the class ApiAdminDictSynonymAction method get$download.

// GET /api/admin/dict/synonym/download/{dictId}
@Execute
public StreamResponse get$download(final String dictId, final DownloadBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    return synonymService.getSynonymFile(body.dictId).map(file -> {
        return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
            try (InputStream inputStream = file.getInputStream()) {
                out.write(inputStream);
            }
        });
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsFailedToDownloadProtwordsFile(GLOBAL));
        return null;
    });
}
Also used : FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) SynonymItem(org.codelibs.fess.dict.synonym.SynonymItem) JsonResponse(org.lastaflute.web.response.JsonResponse) SynonymFile(org.codelibs.fess.dict.synonym.SynonymFile) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) File(java.io.File) UploadForm(org.codelibs.fess.app.web.admin.dict.synonym.UploadForm) SynonymPager(org.codelibs.fess.app.pager.SynonymPager) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) Execute(org.lastaflute.web.Execute) SynonymService(org.codelibs.fess.app.service.SynonymService) InputStream(java.io.InputStream) AdminDictSynonymAction(org.codelibs.fess.app.web.admin.dict.synonym.AdminDictSynonymAction) InputStream(java.io.InputStream) SynonymFile(org.codelibs.fess.dict.synonym.SynonymFile) File(java.io.File) Execute(org.lastaflute.web.Execute)

Example 5 with StreamResponse

use of org.lastaflute.web.response.StreamResponse 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)

Aggregations

StreamResponse (org.lastaflute.web.response.StreamResponse)10 Execute (org.lastaflute.web.Execute)9 InputStream (java.io.InputStream)8 Resource (javax.annotation.Resource)6 ApiResult (org.codelibs.fess.app.web.api.ApiResult)6 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)6 JsonResponse (org.lastaflute.web.response.JsonResponse)6 File (java.io.File)5 Collectors (java.util.stream.Collectors)5 CrudMode (org.codelibs.fess.app.web.CrudMode)5 IOException (java.io.IOException)3 Map (java.util.Map)3 ComponentUtil (org.codelibs.fess.util.ComponentUtil)3 URLEncoder (java.net.URLEncoder)2 List (java.util.List)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 StringUtil (org.codelibs.core.lang.StringUtil)2 Constants (org.codelibs.fess.Constants)2 ActionResponse (org.lastaflute.web.response.ActionResponse)2