Search in sources :

Example 1 with ActionResponse

use of org.lastaflute.web.response.ActionResponse 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 2 with ActionResponse

use of org.lastaflute.web.response.ActionResponse 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 3 with ActionResponse

use of org.lastaflute.web.response.ActionResponse 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 4 with ActionResponse

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

the class GoAction method index.

// ===================================================================================
//                                                                           Attribute
//
// ===================================================================================
//                                                                               Hook
//                                                                              ======
// ===================================================================================
//                                                                      Search Execute
//                                                                      ==============
@Execute
public ActionResponse index(final GoForm form) throws IOException {
    validate(form, messages -> {
    }, () -> asHtml(virtualHost(path_Error_ErrorJsp)));
    if (isLoginRequired()) {
        return redirectToLogin();
    }
    Map<String, Object> doc = null;
    try {
        doc = searchService.getDocumentByDocId(form.docId, new String[] { fessConfig.getIndexFieldUrl(), fessConfig.getIndexFieldConfigId() }, getUserBean()).orElse(null);
    } catch (final Exception e) {
        logger.warn("Failed to request: " + form.docId, e);
    }
    if (doc == null) {
        saveError(messages -> messages.addErrorsDocidNotFound(GLOBAL, form.docId));
        return redirect(ErrorAction.class);
    }
    final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
    if (url == null) {
        saveError(messages -> messages.addErrorsDocumentNotFound(GLOBAL, form.docId));
        return redirect(ErrorAction.class);
    }
    if (fessConfig.isSearchLog()) {
        final String userSessionId = userInfoHelper.getUserCode();
        if (userSessionId != null) {
            final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper();
            final ClickLog clickLog = new ClickLog();
            clickLog.setUrl(url);
            clickLog.setRequestedAt(systemHelper.getCurrentTimeAsLocalDateTime());
            clickLog.setQueryRequestedAt(DfTypeUtil.toLocalDateTime(Long.parseLong(form.rt)));
            clickLog.setUserSessionId(userSessionId);
            clickLog.setDocId(form.docId);
            clickLog.setQueryId(form.queryId);
            if (form.order != null) {
                clickLog.setOrder(form.order);
            }
            searchLogHelper.addClickLog(clickLog);
        }
    }
    String hash;
    if (StringUtil.isNotBlank(form.hash)) {
        final String value = URLUtil.decode(form.hash, Constants.UTF_8);
        final StringBuilder buf = new StringBuilder(value.length() + 100);
        for (final char c : value.toCharArray()) {
            if (CharUtil.isUrlChar(c) || c == ' ') {
                buf.append(c);
            } else {
                try {
                    buf.append(URLEncoder.encode(String.valueOf(c), Constants.UTF_8));
                } catch (final UnsupportedEncodingException e) {
                // NOP
                }
            }
        }
        hash = buf.toString();
    } else {
        hash = StringUtil.EMPTY;
    }
    final String targetUrl = pathMappingHelper.replaceUrl(url);
    if (isFileSystemPath(targetUrl)) {
        if (fessConfig.isSearchFileProxyEnabled()) {
            final ViewHelper viewHelper = ComponentUtil.getViewHelper();
            try {
                final StreamResponse response = viewHelper.asContentResponse(doc);
                if (response.getHttpStatus().orElse(200) == 404) {
                    logger.debug("Not found: " + targetUrl);
                    saveError(messages -> messages.addErrorsNotFoundOnFileSystem(GLOBAL, targetUrl));
                    return redirect(ErrorAction.class);
                }
                return response;
            } catch (final Exception e) {
                logger.warn("Failed to load: " + doc, e);
                saveError(messages -> messages.addErrorsNotLoadFromServer(GLOBAL, targetUrl));
                return redirect(ErrorAction.class);
            }
        } else {
            return redirect(targetUrl + hash);
        }
    } else {
        return redirect(targetUrl + hash);
    }
}
Also used : FessSearchAction(org.codelibs.fess.app.web.base.FessSearchAction) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) LoggerFactory(org.slf4j.LoggerFactory) ClickLog(org.codelibs.fess.es.log.exentity.ClickLog) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) HttpServletRequest(javax.servlet.http.HttpServletRequest) ErrorAction(org.codelibs.fess.app.web.error.ErrorAction) StreamResponse(org.lastaflute.web.response.StreamResponse) Map(java.util.Map) CharUtil(org.codelibs.fess.crawler.util.CharUtil) HtmlResponse(org.lastaflute.web.response.HtmlResponse) Logger(org.slf4j.Logger) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) URLUtil(org.codelibs.core.net.URLUtil) ActionResponse(org.lastaflute.web.response.ActionResponse) URLEncoder(java.net.URLEncoder) SearchLogHelper(org.codelibs.fess.helper.SearchLogHelper) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DfTypeUtil(org.dbflute.util.DfTypeUtil) PathMappingHelper(org.codelibs.fess.helper.PathMappingHelper) Execute(org.lastaflute.web.Execute) ViewHelper(org.codelibs.fess.helper.ViewHelper) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StreamResponse(org.lastaflute.web.response.StreamResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SearchLogHelper(org.codelibs.fess.helper.SearchLogHelper) ViewHelper(org.codelibs.fess.helper.ViewHelper) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ErrorAction(org.codelibs.fess.app.web.error.ErrorAction) ClickLog(org.codelibs.fess.es.log.exentity.ClickLog) Execute(org.lastaflute.web.Execute)

Example 5 with ActionResponse

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

the class SsoAction method index.

// ===================================================================================
//                                                                       Login Execute
//                                                                      ==============
@Execute
public ActionResponse index() {
    final SsoManager ssoManager = ComponentUtil.getSsoManager();
    final LoginCredential loginCredential = ssoManager.getLoginCredential();
    if (loginCredential == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("No user in SSO request.");
        }
        if (ssoManager.available()) {
            saveError(messages -> messages.addErrorsSsoLoginError(GLOBAL));
        }
        return redirect(LoginAction.class);
    } else if (loginCredential instanceof ActionResponseCredential) {
        return ((ActionResponseCredential) loginCredential).execute();
    }
    try {
        return fessLoginAssist.loginRedirect(loginCredential, op -> {
        }, () -> {
            activityHelper.login(getUserBean());
            userInfoHelper.deleteUserCodeFromCookie(request);
            return getHtmlResponse();
        });
    } catch (final LoginFailureException lfe) {
        if (logger.isDebugEnabled()) {
            logger.debug("SSO login failure.", lfe);
        }
        if (ssoManager.available()) {
            saveError(messages -> messages.addErrorsSsoLoginError(GLOBAL));
        }
        return redirect(LoginAction.class);
    }
}
Also used : FessLoginAction(org.codelibs.fess.app.web.base.FessLoginAction) ActionResponse(org.lastaflute.web.response.ActionResponse) Logger(org.slf4j.Logger) ActionResponseCredential(org.codelibs.fess.app.web.base.login.ActionResponseCredential) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SsoManager(org.codelibs.fess.sso.SsoManager) Execute(org.lastaflute.web.Execute) LoggerFactory(org.slf4j.LoggerFactory) LoginCredential(org.lastaflute.web.login.credential.LoginCredential) LoginFailureException(org.lastaflute.web.login.exception.LoginFailureException) LoginAction(org.codelibs.fess.app.web.login.LoginAction) LoginFailureException(org.lastaflute.web.login.exception.LoginFailureException) LoginCredential(org.lastaflute.web.login.credential.LoginCredential) FessLoginAction(org.codelibs.fess.app.web.base.FessLoginAction) LoginAction(org.codelibs.fess.app.web.login.LoginAction) ActionResponseCredential(org.codelibs.fess.app.web.base.login.ActionResponseCredential) SsoManager(org.codelibs.fess.sso.SsoManager) Execute(org.lastaflute.web.Execute)

Aggregations

Execute (org.lastaflute.web.Execute)8 ActionResponse (org.lastaflute.web.response.ActionResponse)8 StringUtil (org.codelibs.core.lang.StringUtil)7 Constants (org.codelibs.fess.Constants)7 ComponentUtil (org.codelibs.fess.util.ComponentUtil)7 HtmlResponse (org.lastaflute.web.response.HtmlResponse)7 File (java.io.File)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 Resource (javax.annotation.Resource)6 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)6 ActionRuntime (org.lastaflute.web.ruts.process.ActionRuntime)6 BeanUtil (org.codelibs.core.beans.util.BeanUtil)5 CrudMode (org.codelibs.fess.app.web.CrudMode)5 AdminDictAction (org.codelibs.fess.app.web.admin.dict.AdminDictAction)5 RenderDataUtil (org.codelibs.fess.util.RenderDataUtil)5 OptionalEntity (org.dbflute.optional.OptionalEntity)5 OptionalThing (org.dbflute.optional.OptionalThing)5 RenderData (org.lastaflute.web.response.render.RenderData)5 VaErrorHook (org.lastaflute.web.validation.VaErrorHook)3