Search in sources :

Example 6 with HtmlResponse

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

the class LoginAction method login.

@Execute
public HtmlResponse login(final LoginForm form) {
    validate(form, messages -> {
    }, () -> asIndexPage(form));
    verifyToken(() -> asIndexPage(form));
    final String username = form.username;
    final String password = form.password;
    form.clearSecurityInfo();
    try {
        return fessLoginAssist.loginRedirect(new UserPasswordCredential(username, password), op -> {
        }, () -> {
            activityHelper.login(getUserBean());
            userInfoHelper.deleteUserCodeFromCookie(request);
            return getHtmlResponse();
        });
    } catch (final LoginFailureException lfe) {
        throwValidationError(messages -> messages.addErrorsLoginError(GLOBAL), () -> asIndexPage(form));
    }
    return redirect(getClass());
}
Also used : FessLoginAction(org.codelibs.fess.app.web.base.FessLoginAction) UserPasswordCredential(org.lastaflute.web.login.credential.UserPasswordCredential) Execute(org.lastaflute.web.Execute) LoginFailureException(org.lastaflute.web.login.exception.LoginFailureException) HtmlResponse(org.lastaflute.web.response.HtmlResponse) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) LoginFailureException(org.lastaflute.web.login.exception.LoginFailureException) UserPasswordCredential(org.lastaflute.web.login.credential.UserPasswordCredential) Execute(org.lastaflute.web.Execute)

Example 7 with HtmlResponse

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

the class SearchAction method doSearch.

protected HtmlResponse doSearch(final SearchForm form) {
    validate(form, messages -> {
    }, () -> asHtml(virtualHost(path_SearchJsp)));
    if (isLoginRequired()) {
        return redirectToLogin();
    }
    if (viewHelper.isUseSession()) {
        final HttpSession session = request.getSession(false);
        if (session != null) {
            final Object resultsPerPage = session.getAttribute(Constants.RESULTS_PER_PAGE);
            if (resultsPerPage instanceof Integer) {
                form.num = (Integer) resultsPerPage;
            }
        }
    }
    if (StringUtil.isBlank(form.q) && form.fields.isEmpty()) {
        // redirect to index page
        form.q = null;
        return redirectToRoot();
    }
    try {
        buildFormParams(form);
        form.lang = searchService.getLanguages(request, form);
        request.setAttribute(Constants.REQUEST_LANGUAGES, form.lang);
        request.setAttribute(Constants.REQUEST_QUERIES, form.q);
        final WebRenderData renderData = new WebRenderData();
        searchService.search(form, renderData, getUserBean());
        return asHtml(virtualHost(path_SearchJsp)).renderWith(data -> {
            renderData.register(data);
            if (favoriteSupport || thumbnailSupport) {
                final String queryId = renderData.getQueryId();
                final List<Map<String, Object>> documentItems = renderData.getDocumentItems();
                userInfoHelper.storeQueryId(queryId, documentItems);
                if (thumbnailSupport) {
                    thumbnailManager.storeRequest(queryId, documentItems);
                }
            }
            RenderDataUtil.register(data, "displayQuery", getDisplayQuery(form, labelTypeHelper.getLabelTypeItemList(SearchRequestType.SEARCH)));
            createPagingQuery(form);
        });
    } catch (final InvalidQueryException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        saveError(e.getMessageCode());
        return redirectToRoot();
    } catch (final ResultOffsetExceededException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        saveError(messages -> {
            messages.addErrorsResultSizeExceeded(GLOBAL);
        });
        return redirectToRoot();
    }
}
Also used : FessSearchAction(org.codelibs.fess.app.web.base.FessSearchAction) Constants(org.codelibs.fess.Constants) LoggerFactory(org.slf4j.LoggerFactory) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) Map(java.util.Map) RenderData(org.lastaflute.web.response.render.RenderData) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LaFunctions(org.lastaflute.taglib.function.LaFunctions) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) HttpSession(javax.servlet.http.HttpSession) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Set(java.util.Set) SearchService(org.codelibs.fess.app.service.SearchService) SearchForm(org.codelibs.fess.app.web.base.SearchForm) List(java.util.List) Execute(org.lastaflute.web.Execute) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) HttpSession(javax.servlet.http.HttpSession) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) Map(java.util.Map) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException)

Example 8 with HtmlResponse

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

the class AdminElevatewordAction method details.

// -----------------------------------------------------
//                                               Details
//                                               -------
@Execute
public HtmlResponse details(final int crudMode, final String id) {
    verifyCrudMode(crudMode, CrudMode.DETAILS);
    saveToken();
    final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
    return asHtml(path_AdminElevateword_AdminElevatewordDetailsJsp).useForm(EditForm.class, op -> op.setup(form -> {
        elevateWordService.getElevateWord(id).ifPresent(entity -> {
            copyBeanToBean(entity, form, copyOp -> {
                copyOp.excludeNull();
                copyOp.exclude(Constants.PERMISSIONS);
            });
            form.permissions = stream(entity.getPermissions()).get(stream -> stream.map(permissionHelper::decode).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
            form.crudMode = crudMode;
        }).orElse(() -> throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asListHtml()));
    })).renderWith(data -> registerLabels(data));
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) FessSystemException(org.codelibs.fess.exception.FessSystemException) ElevateWordPager(org.codelibs.fess.app.pager.ElevateWordPager) OptionalThing(org.dbflute.optional.OptionalThing) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) CrudMode(org.codelibs.fess.app.web.CrudMode) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) RenderData(org.lastaflute.web.response.render.RenderData) OutputStreamWriter(java.io.OutputStreamWriter) HtmlResponse(org.lastaflute.web.response.HtmlResponse) Path(java.nio.file.Path) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) ElevateWordService(org.codelibs.fess.app.service.ElevateWordService) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) ActionResponse(org.lastaflute.web.response.ActionResponse) Stream(java.util.stream.Stream) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) Writer(java.io.Writer) Execute(org.lastaflute.web.Execute) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) BufferedReader(java.io.BufferedReader) SuggestHelper(org.codelibs.fess.helper.SuggestHelper) InputStream(java.io.InputStream) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) Execute(org.lastaflute.web.Execute)

Example 9 with HtmlResponse

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

the class AdminDesignAction method upload.

@Execute
public HtmlResponse upload(final UploadForm form) {
    validate(form, messages -> {
    }, () -> asListHtml(form));
    verifyToken(() -> asListHtml());
    final String uploadedFileName = form.designFile.getFileName();
    String fileName = form.designFileName;
    if (StringUtil.isBlank(fileName)) {
        fileName = uploadedFileName;
        try {
            int pos = fileName.indexOf('/');
            if (pos >= 0) {
                fileName = fileName.substring(pos + 1);
            }
            pos = fileName.indexOf('\\');
            if (pos >= 0) {
                fileName = fileName.substring(pos + 1);
            }
        } catch (final Exception e) {
            throwValidationError(messages -> messages.addErrorsDesignFileNameIsInvalid("designFile"), () -> asListHtml());
        }
    }
    if (StringUtil.isBlank(fileName)) {
        throwValidationError(messages -> messages.addErrorsDesignFileNameIsNotFound("designFile"), () -> asListHtml());
    }
    File uploadFile;
    // normalize filename
    if (checkFileType(fileName, fessConfig.getSupportedUploadedMediaExtentionsAsArray()) && checkFileType(uploadedFileName, fessConfig.getSupportedUploadedMediaExtentionsAsArray())) {
        uploadFile = new File(getServletContext().getRealPath("/images/" + fileName));
    } else if (checkFileType(fileName, fessConfig.getSupportedUploadedCssExtentionsAsArray()) && checkFileType(uploadedFileName, fessConfig.getSupportedUploadedCssExtentionsAsArray())) {
        uploadFile = new File(getServletContext().getRealPath("/css/" + fileName));
    } else if (checkFileType(fileName, fessConfig.getSupportedUploadedJsExtentionsAsArray()) && checkFileType(uploadedFileName, fessConfig.getSupportedUploadedJsExtentionsAsArray())) {
        uploadFile = new File(getServletContext().getRealPath("/js/" + fileName));
    } else if (fessConfig.isSupportedUploadedFile(fileName) || fessConfig.isSupportedUploadedFile(uploadedFileName)) {
        uploadFile = ResourceUtil.getResourceAsFileNoException(fileName);
        if (uploadFile == null) {
            throwValidationError(messages -> messages.addErrorsDesignFileNameIsNotFound("designFileName"), () -> asListHtml());
            return null;
        }
    } else {
        throwValidationError(messages -> messages.addErrorsDesignFileIsUnsupportedType("designFileName"), () -> asListHtml());
        return null;
    }
    final File parentFile = uploadFile.getParentFile();
    if (!parentFile.exists() && !parentFile.mkdirs()) {
        logger.warn("Could not create " + parentFile.getAbsolutePath());
    }
    try {
        write(uploadFile.getAbsolutePath(), form.designFile.getFileData());
        final String currentFileName = fileName;
        saveInfo(messages -> messages.addSuccessUploadDesignFile(GLOBAL, currentFileName));
    } catch (final Exception e) {
        logger.error("Failed to write an image file: {}", fileName, e);
        throwValidationError(messages -> messages.addErrorsFailedToWriteDesignImageFile(GLOBAL), () -> asListHtml());
    }
    return redirect(getClass());
}
Also used : Constants(org.codelibs.fess.Constants) Logger(org.slf4j.Logger) FessSystemException(org.codelibs.fess.exception.FessSystemException) ResourceUtil(org.codelibs.core.io.ResourceUtil) OptionalEntity(org.dbflute.optional.OptionalEntity) StringUtil(org.codelibs.core.lang.StringUtil) LoggerFactory(org.slf4j.LoggerFactory) 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) ActionResponse(org.lastaflute.web.response.ActionResponse) List(java.util.List) StreamResponse(org.lastaflute.web.response.StreamResponse) FileUtil(org.codelibs.core.io.FileUtil) 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) File(java.io.File) FessSystemException(org.codelibs.fess.exception.FessSystemException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Execute(org.lastaflute.web.Execute)

Example 10 with HtmlResponse

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

the class AdminLabeltypeAction method details.

// -----------------------------------------------------
//                                               Details
//                                               -------
@Execute
public HtmlResponse details(final int crudMode, final String id) {
    verifyCrudMode(crudMode, CrudMode.DETAILS);
    saveToken();
    return asHtml(path_AdminLabeltype_AdminLabeltypeDetailsJsp).useForm(EditForm.class, op -> {
        op.setup(form -> {
            labelTypeService.getLabelType(id).ifPresent(entity -> {
                copyBeanToBean(entity, form, copyOp -> {
                    copyOp.excludeNull();
                    copyOp.exclude(Constants.PERMISSIONS);
                });
                final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
                form.permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
                form.crudMode = crudMode;
            }).orElse(() -> {
                throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asListHtml());
            });
        });
    }).renderWith(data -> {
        registerRoleTypeItems(data);
    });
}
Also used : Constants(org.codelibs.fess.Constants) LabelTypePager(org.codelibs.fess.app.pager.LabelTypePager) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) OptionalEntity(org.dbflute.optional.OptionalEntity) OptionalThing(org.dbflute.optional.OptionalThing) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) Collectors(java.util.stream.Collectors) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) LabelType(org.codelibs.fess.es.config.exentity.LabelType) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) Stream(java.util.stream.Stream) CrudMode(org.codelibs.fess.app.web.CrudMode) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) SystemHelper(org.codelibs.fess.helper.SystemHelper) Execute(org.lastaflute.web.Execute) RenderData(org.lastaflute.web.response.render.RenderData) RoleTypeService(org.codelibs.fess.app.service.RoleTypeService) HtmlResponse(org.lastaflute.web.response.HtmlResponse) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) StringUtil(org.codelibs.core.lang.StringUtil) Execute(org.lastaflute.web.Execute)

Aggregations

Execute (org.lastaflute.web.Execute)11 HtmlResponse (org.lastaflute.web.response.HtmlResponse)11 StringUtil (org.codelibs.core.lang.StringUtil)9 Resource (javax.annotation.Resource)8 Constants (org.codelibs.fess.Constants)8 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)8 ActionRuntime (org.lastaflute.web.ruts.process.ActionRuntime)8 RenderDataUtil (org.codelibs.fess.util.RenderDataUtil)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 List (java.util.List)6 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)6 ComponentUtil (org.codelibs.fess.util.ComponentUtil)6 OptionalEntity (org.dbflute.optional.OptionalEntity)6 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)4 ActionResponse (org.lastaflute.web.response.ActionResponse)4 RenderData (org.lastaflute.web.response.render.RenderData)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3