Search in sources :

Example 1 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class AdminBackupAction method upload.

@Execute
public HtmlResponse upload(final UploadForm form) {
    validate(form, messages -> {
    }, () -> asListHtml());
    verifyToken(() -> asListHtml());
    asyncManager.async(() -> {
        final String fileName = form.bulkFile.getFileName();
        if (fileName.startsWith("system") && fileName.endsWith(".properties")) {
            try (final InputStream in = form.bulkFile.getInputStream()) {
                ComponentUtil.getSystemProperties().load(in);
            } catch (final IOException e) {
                logger.warn("Failed to process system.properties file: " + form.bulkFile.getFileName(), e);
            }
        } else {
            try (CurlResponse response = Curl.post(ResourceUtil.getElasticsearchHttpUrl() + "/_bulk").header("Content-Type", "application/json").onConnect((req, con) -> {
                con.setDoOutput(true);
                try (InputStream in = form.bulkFile.getInputStream();
                    OutputStream out = con.getOutputStream()) {
                    CopyUtil.copy(in, out);
                } catch (IOException e) {
                    throw new IORuntimeException(e);
                }
            }).execute()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Bulk Response:\n" + response.getContentAsString());
                }
                systemHelper.reloadConfiguration();
            } catch (final Exception e) {
                logger.warn("Failed to process bulk file: " + form.bulkFile.getFileName(), e);
            }
        }
    });
    saveInfo(messages -> messages.addSuccessBulkProcessStarted(GLOBAL));
    // no-op
    return redirect(getClass());
}
Also used : IORuntimeException(org.codelibs.core.exception.IORuntimeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AsyncManager(org.lastaflute.core.magic.async.AsyncManager) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) Curl(org.codelibs.elasticsearch.runner.net.Curl) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) ResourceUtil(org.codelibs.fess.util.ResourceUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamResponse(org.lastaflute.web.response.StreamResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) OutputStreamWriter(java.io.OutputStreamWriter) FavoriteLogBhv(org.codelibs.fess.es.log.exbhv.FavoriteLogBhv) CurlResponse(org.codelibs.elasticsearch.runner.net.CurlResponse) CopyUtil(org.codelibs.core.io.CopyUtil) HtmlResponse(org.lastaflute.web.response.HtmlResponse) OutputStream(java.io.OutputStream) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) UserInfoBhv(org.codelibs.fess.es.log.exbhv.UserInfoBhv) BufferedWriter(java.io.BufferedWriter) ClickLogBhv(org.codelibs.fess.es.log.exbhv.ClickLogBhv) SearchFieldLogBhv(org.codelibs.fess.es.log.exbhv.SearchFieldLogBhv) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) CsvWriter(com.orangesignal.csv.CsvWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) RuntimeIOException(com.healthmarketscience.jackcess.RuntimeIOException) CsvConfig(com.orangesignal.csv.CsvConfig) ActionResponse(org.lastaflute.web.response.ActionResponse) List(java.util.List) SearchLogBhv(org.codelibs.fess.es.log.exbhv.SearchLogBhv) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DateTimeFormatter(java.time.format.DateTimeFormatter) Execute(org.lastaflute.web.Execute) InputStream(java.io.InputStream) IORuntimeException(org.codelibs.core.exception.IORuntimeException) CurlResponse(org.codelibs.elasticsearch.runner.net.CurlResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) RuntimeIOException(com.healthmarketscience.jackcess.RuntimeIOException) IORuntimeException(org.codelibs.core.exception.IORuntimeException) IOException(java.io.IOException) RuntimeIOException(com.healthmarketscience.jackcess.RuntimeIOException) Execute(org.lastaflute.web.Execute)

Example 2 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class AdminDictProtwordsAction method download.

@Execute
public ActionResponse download(final DownloadForm form) {
    validate(form, messages -> {
    }, () -> downloadpage(form.dictId));
    verifyTokenKeep(() -> downloadpage(form.dictId));
    return protwordsService.getProtwordsFile(form.dictId).map(file -> {
        return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
            try (InputStream inputStream = file.getInputStream()) {
                out.write(inputStream);
            }
        });
    }).orElseGet(() -> {
        throwValidationError(messages -> messages.addErrorsFailedToDownloadProtwordsFile(GLOBAL), () -> downloadpage(form.dictId));
        return null;
    });
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) OptionalEntity(org.dbflute.optional.OptionalEntity) ProtwordsPager(org.codelibs.fess.app.pager.ProtwordsPager) OptionalThing(org.dbflute.optional.OptionalThing) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) VaErrorHook(org.lastaflute.web.validation.VaErrorHook) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) File(java.io.File) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ActionResponse(org.lastaflute.web.response.ActionResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) ProtwordsItem(org.codelibs.fess.dict.protwords.ProtwordsItem) ProtwordsService(org.codelibs.fess.app.service.ProtwordsService) Execute(org.lastaflute.web.Execute) RenderData(org.lastaflute.web.response.render.RenderData) AdminDictAction(org.codelibs.fess.app.web.admin.dict.AdminDictAction) HtmlResponse(org.lastaflute.web.response.HtmlResponse) InputStream(java.io.InputStream) InputStream(java.io.InputStream) File(java.io.File) Execute(org.lastaflute.web.Execute)

Example 3 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class AdminDictSeunjeonAction method download.

@Execute
public ActionResponse download(final DownloadForm form) {
    validate(form, messages -> {
    }, () -> downloadpage(form.dictId));
    verifyTokenKeep(() -> downloadpage(form.dictId));
    return seunjeonService.getSeunjeonFile(form.dictId).map(file -> {
        return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
            try (InputStream inputStream = file.getInputStream()) {
                out.write(inputStream);
            }
        });
    }).orElseGet(() -> {
        throwValidationError(messages -> messages.addErrorsFailedToDownloadSynonymFile(GLOBAL), () -> downloadpage(form.dictId));
        return null;
    });
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) SeunjeonItem(org.codelibs.fess.dict.seunjeon.SeunjeonItem) SeunjeonService(org.codelibs.fess.app.service.SeunjeonService) OptionalEntity(org.dbflute.optional.OptionalEntity) OptionalThing(org.dbflute.optional.OptionalThing) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) VaErrorHook(org.lastaflute.web.validation.VaErrorHook) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) File(java.io.File) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ActionResponse(org.lastaflute.web.response.ActionResponse) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) CrudMode(org.codelibs.fess.app.web.CrudMode) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Execute(org.lastaflute.web.Execute) RenderData(org.lastaflute.web.response.render.RenderData) AdminDictAction(org.codelibs.fess.app.web.admin.dict.AdminDictAction) HtmlResponse(org.lastaflute.web.response.HtmlResponse) InputStream(java.io.InputStream) SeunjeonPager(org.codelibs.fess.app.pager.SeunjeonPager) InputStream(java.io.InputStream) File(java.io.File) Execute(org.lastaflute.web.Execute)

Example 4 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class AdminDictSynonymAction method download.

@Execute
public ActionResponse download(final DownloadForm form) {
    validate(form, messages -> {
    }, () -> downloadpage(form.dictId));
    verifyTokenKeep(() -> downloadpage(form.dictId));
    return synonymService.getSynonymFile(form.dictId).map(file -> {
        return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
            try (InputStream inputStream = file.getInputStream()) {
                out.write(inputStream);
            }
        });
    }).orElseGet(() -> {
        throwValidationError(messages -> messages.addErrorsFailedToDownloadSynonymFile(GLOBAL), () -> downloadpage(form.dictId));
        return null;
    });
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) OptionalThing(org.dbflute.optional.OptionalThing) SynonymItem(org.codelibs.fess.dict.synonym.SynonymItem) VaErrorHook(org.lastaflute.web.validation.VaErrorHook) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) CrudMode(org.codelibs.fess.app.web.CrudMode) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) RenderData(org.lastaflute.web.response.render.RenderData) HtmlResponse(org.lastaflute.web.response.HtmlResponse) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) File(java.io.File) ActionResponse(org.lastaflute.web.response.ActionResponse) List(java.util.List) SynonymPager(org.codelibs.fess.app.pager.SynonymPager) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Execute(org.lastaflute.web.Execute) SynonymService(org.codelibs.fess.app.service.SynonymService) AdminDictAction(org.codelibs.fess.app.web.admin.dict.AdminDictAction) InputStream(java.io.InputStream) InputStream(java.io.InputStream) File(java.io.File) Execute(org.lastaflute.web.Execute)

Example 5 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class AdminSearchlistAction method delete.

// -----------------------------------------------------
// Confirm
// -------
@Execute
public HtmlResponse delete(final DeleteForm form) {
    validate(form, messages -> {
    }, () -> asListHtml());
    verifyToken(() -> asListHtml());
    final String docId = form.docId;
    try {
        final QueryBuilder query = QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), docId);
        fessEsClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(), fessConfig.getIndexDocumentType(), query);
        saveInfo(messages -> messages.addSuccessDeleteDocFromIndex(GLOBAL));
    } catch (final Exception e) {
        throwValidationError(messages -> messages.addErrorsFailedToDeleteDocInAdmin(GLOBAL), () -> asListHtml());
    }
    return asListHtml();
}
Also used : Constants(org.codelibs.fess.Constants) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) HttpServletRequest(javax.servlet.http.HttpServletRequest) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) CrudMode(org.codelibs.fess.app.web.CrudMode) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) QueryHelper(org.codelibs.fess.helper.QueryHelper) RenderData(org.lastaflute.web.response.render.RenderData) HtmlResponse(org.lastaflute.web.response.HtmlResponse) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) FessMessages(org.codelibs.fess.mylasta.action.FessMessages) Logger(org.slf4j.Logger) FessEsClient(org.codelibs.fess.es.client.FessEsClient) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Consumer(java.util.function.Consumer) SearchService(org.codelibs.fess.app.service.SearchService) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) Execute(org.lastaflute.web.Execute) VaMessenger(org.lastaflute.web.validation.VaMessenger) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) Execute(org.lastaflute.web.Execute)

Aggregations

Execute (org.lastaflute.web.Execute)125 ApiResult (org.codelibs.fess.app.web.api.ApiResult)94 Resource (javax.annotation.Resource)83 CrudMode (org.codelibs.fess.app.web.CrudMode)77 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)71 JsonResponse (org.lastaflute.web.response.JsonResponse)71 Collectors (java.util.stream.Collectors)70 List (java.util.List)51 InputStream (java.io.InputStream)39 File (java.io.File)35 StreamResponse (org.lastaflute.web.response.StreamResponse)34 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)32 Status (org.codelibs.fess.app.web.api.ApiResult.Status)31 Constants (org.codelibs.fess.Constants)26 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)26 StringUtil (org.codelibs.core.lang.StringUtil)24 ComponentUtil (org.codelibs.fess.util.ComponentUtil)23 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)22 HtmlResponse (org.lastaflute.web.response.HtmlResponse)20 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)14