Search in sources :

Example 1 with HtmlResponse

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

the class AdminSearchlistAction method delete.

// -----------------------------------------------------
// Confirm
// -------
@Execute
@Secured({ ROLE })
public HtmlResponse delete(final DeleteForm form) {
    validate(form, messages -> {
    }, this::asListHtml);
    verifyToken(this::asListHtml);
    final String docId = form.docId;
    try {
        final QueryBuilder query = QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), docId);
        searchEngineClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(), query);
        saveInfo(messages -> messages.addSuccessDeleteDocFromIndex(GLOBAL));
    } catch (final Exception e) {
        throwValidationError(messages -> messages.addErrorsFailedToDeleteDocInAdmin(GLOBAL), this::asListHtml);
    }
    return asListHtml();
}
Also used : Constants(org.codelibs.fess.Constants) HashMap(java.util.HashMap) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) 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) SearchHelper(org.codelibs.fess.helper.SearchHelper) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) QueryBuilders(org.opensearch.index.query.QueryBuilders) Secured(org.codelibs.fess.annotation.Secured) FessMessages(org.codelibs.fess.mylasta.action.FessMessages) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Consumer(java.util.function.Consumer) URLUtil(org.codelibs.core.net.URLUtil) List(java.util.List) Logger(org.apache.logging.log4j.Logger) QueryBuilder(org.opensearch.index.query.QueryBuilder) 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) LogManager(org.apache.logging.log4j.LogManager) QueryBuilder(org.opensearch.index.query.QueryBuilder) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 2 with HtmlResponse

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

the class AdminPluginAction method install.

@Execute
@Secured({ ROLE })
public HtmlResponse install(final InstallForm form) {
    validate(form, messages -> {
    }, () -> asHtml(path_AdminPlugin_AdminPluginInstallpluginJsp));
    verifyToken(() -> asHtml(path_AdminPlugin_AdminPluginInstallpluginJsp));
    try {
        if (UPLOAD.equals(form.id)) {
            if (form.jarFile == null) {
                throwValidationError(messages -> messages.addErrorsPluginFileIsNotFound(GLOBAL, form.id), this::asListHtml);
            }
            if (!form.jarFile.getFileName().endsWith(".jar")) {
                throwValidationError(messages -> messages.addErrorsFileIsNotSupported(GLOBAL, form.jarFile.getFileName()), this::asListHtml);
            }
            final String filename = form.jarFile.getFileName();
            final File tempFile = ComponentUtil.getSystemHelper().createTempFile("tmp-adminplugin-", ".jar");
            try (final InputStream is = form.jarFile.getInputStream();
                final OutputStream os = new FileOutputStream(tempFile)) {
                CopyUtil.copy(is, os);
            } catch (final Exception e) {
                if (tempFile.exists() && !tempFile.delete()) {
                    logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
                }
                logger.debug("Failed to copy {}", filename, e);
                throwValidationError(messages -> messages.addErrorsFailedToInstallPlugin(GLOBAL, filename), this::asListHtml);
            }
            new Thread(() -> {
                try {
                    final PluginHelper pluginHelper = ComponentUtil.getPluginHelper();
                    final Artifact artifact = pluginHelper.getArtifactFromFileName(ArtifactType.UNKNOWN, filename, tempFile.getAbsolutePath());
                    pluginHelper.installArtifact(artifact);
                } catch (final Exception e) {
                    logger.warn("Failed to install {}", filename, e);
                } finally {
                    if (tempFile.exists() && !tempFile.delete()) {
                        logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
                    }
                }
            }).start();
            saveInfo(messages -> messages.addSuccessInstallPlugin(GLOBAL, form.jarFile.getFileName()));
        } else {
            final Artifact artifact = getArtifactFromInstallForm(form);
            if (artifact == null) {
                throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), this::asListHtml);
            }
            installArtifact(artifact);
            saveInfo(messages -> messages.addSuccessInstallPlugin(GLOBAL, artifact.getFileName()));
        }
    } catch (final ValidationErrorException e) {
        throw e;
    } catch (final Exception e) {
        throwValidationError(messages -> messages.addErrorsFailedToInstallPlugin(GLOBAL, form.id), this::asListHtml);
    }
    return redirect(getClass());
}
Also used : OutputStream(java.io.OutputStream) Arrays(java.util.Arrays) Secured(org.codelibs.fess.annotation.Secured) Artifact(org.codelibs.fess.helper.PluginHelper.Artifact) PluginHelper(org.codelibs.fess.helper.PluginHelper) FileOutputStream(java.io.FileOutputStream) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) File(java.io.File) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ArtifactType(org.codelibs.fess.helper.PluginHelper.ArtifactType) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) ValidationErrorException(org.lastaflute.web.validation.exception.ValidationErrorException) Execute(org.lastaflute.web.Execute) CopyUtil(org.codelibs.core.io.CopyUtil) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) PluginHelper(org.codelibs.fess.helper.PluginHelper) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ValidationErrorException(org.lastaflute.web.validation.exception.ValidationErrorException) File(java.io.File) ValidationErrorException(org.lastaflute.web.validation.exception.ValidationErrorException) Artifact(org.codelibs.fess.helper.PluginHelper.Artifact) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 3 with HtmlResponse

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

the class AdminGeneralAction method sendmail.

@Execute
@Secured({ ROLE })
public HtmlResponse sendmail(final MailForm form) {
    validate(form, messages -> {
    }, () -> asHtml(path_AdminGeneral_AdminGeneralJsp));
    final String[] toAddresses = form.notificationTo.split(",");
    final Map<String, Object> dataMap = new HashMap<>();
    dataMap.put("hostname", systemHelper.getHostname());
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
    try {
        TestmailPostcard.droppedInto(postbox, postcard -> {
            postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
            postcard.addReplyTo(fessConfig.getMailReturnPath());
            stream(toAddresses).of(stream -> stream.forEach(address -> {
                postcard.addTo(address);
            }));
            BeanUtil.copyMapToBean(dataMap, postcard);
        });
        saveInfo(messages -> messages.addSuccessSendTestmail(GLOBAL));
        updateProperty(Constants.NOTIFICATION_TO_PROPERTY, form.notificationTo);
        systemProperties.store();
    } catch (final Exception e) {
        logger.warn("Failed to send a test mail.", e);
        saveError(messages -> messages.addErrorsFailedToSendTestmail(GLOBAL));
    }
    return redirectByParam(AdminGeneralAction.class, "notificationTo", form.notificationTo);
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) Secured(org.codelibs.fess.annotation.Secured) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) DynamicProperties(org.codelibs.core.misc.DynamicProperties) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) HashMap(java.util.HashMap) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) ArrayList(java.util.ArrayList) Postbox(org.lastaflute.core.mail.Postbox) List(java.util.List) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) TestmailPostcard(org.codelibs.fess.mylasta.mail.TestmailPostcard) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) SystemHelper(org.codelibs.fess.helper.SystemHelper) Map(java.util.Map) Execute(org.lastaflute.web.Execute) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LogManager(org.apache.logging.log4j.LogManager) HashMap(java.util.HashMap) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 4 with HtmlResponse

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

the class AdminBackupAction method upload.

@Execute
@Secured({ ROLE })
public HtmlResponse upload(final UploadForm form) {
    validate(form, messages -> {
    }, this::asListHtml);
    verifyToken(this::asListHtml);
    final String fileName = form.bulkFile.getFileName();
    final File tempFile = ComponentUtil.getSystemHelper().createTempFile("fess_restore_", ".tmp");
    try (final InputStream in = form.bulkFile.getInputStream();
        final OutputStream out = new FileOutputStream(tempFile)) {
        CopyUtil.copy(in, out);
        asyncImport(fileName, tempFile);
    } catch (final IOException e) {
        logger.warn("Failed to create a temp file.", e);
        if (tempFile.exists() && !tempFile.delete()) {
            logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
        }
        throwValidationError(messages -> messages.addErrorsFileIsNotSupported(GLOBAL, fileName), this::asListHtml);
    }
    saveInfo(messages -> messages.addSuccessBulkProcessStarted(GLOBAL));
    // no-op
    return redirect(getClass());
}
Also used : Arrays(java.util.Arrays) Constants(org.codelibs.fess.Constants) IORuntimeException(org.codelibs.core.exception.IORuntimeException) AsyncManager(org.lastaflute.core.magic.async.AsyncManager) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) FileConfigBhv(org.codelibs.fess.es.config.exbhv.FileConfigBhv) 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) LabelTypeBhv(org.codelibs.fess.es.config.exbhv.LabelTypeBhv) FavoriteLogBhv(org.codelibs.fess.es.log.exbhv.FavoriteLogBhv) GsaConfigParser(org.codelibs.fess.util.GsaConfigParser) CopyUtil(org.codelibs.core.io.CopyUtil) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) Secured(org.codelibs.fess.annotation.Secured) UserInfoBhv(org.codelibs.fess.es.log.exbhv.UserInfoBhv) Resource(javax.annotation.Resource) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ActionResponse(org.lastaflute.web.response.ActionResponse) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Writer(java.io.Writer) CurlResponse(org.codelibs.curl.CurlResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LocalDateTime(java.time.LocalDateTime) Pair(org.codelibs.core.misc.Pair) HashMap(java.util.HashMap) ResourceUtil(org.codelibs.fess.util.ResourceUtil) OutputStreamWriter(java.io.OutputStreamWriter) SearchEngineUtil(org.codelibs.fess.util.SearchEngineUtil) HtmlResponse(org.lastaflute.web.response.HtmlResponse) OutputStream(java.io.OutputStream) InputSource(org.xml.sax.InputSource) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) ClickLogBhv(org.codelibs.fess.es.log.exbhv.ClickLogBhv) StringUtil(org.codelibs.core.lang.StringUtil) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Consumer(java.util.function.Consumer) SearchLogBhv(org.codelibs.fess.es.log.exbhv.SearchLogBhv) WebConfigBhv(org.codelibs.fess.es.config.exbhv.WebConfigBhv) DateTimeFormatter(java.time.format.DateTimeFormatter) Execute(org.lastaflute.web.Execute) BufferedReader(java.io.BufferedReader) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 5 with HtmlResponse

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

the class AdminDesignAction method update.

@Execute
@Secured({ ROLE })
public HtmlResponse update(final EditForm form) {
    final String jspType = "view";
    final File jspFile = getJspFile(form.fileName, jspType);
    if (form.content == null) {
        form.content = StringUtil.EMPTY;
    }
    validate(form, messages -> {
    }, () -> asEditHtml(form));
    verifyToken(() -> asEditHtml(form));
    try {
        write(jspFile.getAbsolutePath(), form.content.getBytes(Constants.UTF_8));
        saveInfo(messages -> messages.addSuccessUpdateDesignJspFile(GLOBAL, jspFile.getAbsolutePath()));
    } catch (final Exception e) {
        logger.error("Failed to update {}", form.fileName, e);
        throwValidationError(messages -> messages.addErrorsFailedToUpdateJspFile(GLOBAL), this::asListHtml);
    }
    return redirect(getClass());
}
Also used : Constants(org.codelibs.fess.Constants) Secured(org.codelibs.fess.annotation.Secured) URLDecoder(java.net.URLDecoder) FessSystemException(org.codelibs.fess.exception.FessSystemException) ResourceUtil(org.codelibs.core.io.ResourceUtil) OptionalEntity(org.dbflute.optional.OptionalEntity) StringUtil(org.codelibs.core.lang.StringUtil) Pair(org.codelibs.core.misc.Pair) FileUtils(org.apache.commons.io.FileUtils) FileInputStream(java.io.FileInputStream) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) StreamResponse(org.lastaflute.web.response.StreamResponse) Logger(org.apache.logging.log4j.Logger) FileUtil(org.codelibs.core.io.FileUtil) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Locale(java.util.Locale) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Execute(org.lastaflute.web.Execute) HtmlResponse(org.lastaflute.web.response.HtmlResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LogManager(org.apache.logging.log4j.LogManager) File(java.io.File) FessSystemException(org.codelibs.fess.exception.FessSystemException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Aggregations

Execute (org.lastaflute.web.Execute)15 HtmlResponse (org.lastaflute.web.response.HtmlResponse)15 StringUtil (org.codelibs.core.lang.StringUtil)13 ComponentUtil (org.codelibs.fess.util.ComponentUtil)13 Resource (javax.annotation.Resource)12 Constants (org.codelibs.fess.Constants)11 Secured (org.codelibs.fess.annotation.Secured)11 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)11 RenderDataUtil (org.codelibs.fess.util.RenderDataUtil)11 ActionRuntime (org.lastaflute.web.ruts.process.ActionRuntime)11 LogManager (org.apache.logging.log4j.LogManager)10 Logger (org.apache.logging.log4j.Logger)10 OptionalEntity (org.dbflute.optional.OptionalEntity)10 List (java.util.List)8 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)8 Collectors (java.util.stream.Collectors)7 SystemHelper (org.codelibs.fess.helper.SystemHelper)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 OptionalThing (org.dbflute.optional.OptionalThing)6