diff --git a/pom.xml b/pom.xml index ba4709af1..b481e9182 100644 --- a/pom.xml +++ b/pom.xml @@ -120,7 +120,6 @@ org/codelibs/fess/app/web/admin/DocumentForm.java org/codelibs/fess/app/web/admin/DataForm.java org/codelibs/fess/app/web/admin/SuggestBadWordAction.java - org/codelibs/fess/app/web/admin/PathMappingForm.java org/codelibs/fess/app/web/admin/IndexAction.java org/codelibs/fess/app/web/admin/RoleTypeForm.java org/codelibs/fess/app/web/admin/LogAction.java @@ -137,7 +136,6 @@ org/codelibs/fess/app/web/admin/FileConfigAction.java org/codelibs/fess/app/web/admin/SuggestBadWordForm.java org/codelibs/fess/app/web/admin/FileAuthenticationAction.java - org/codelibs/fess/app/web/admin/PathMappingAction.java org/codelibs/fess/app/web/admin/CrawlingSessionForm.java org/codelibs/fess/app/web/admin/LabelTypeForm.java org/codelibs/fess/app/web/admin/FileConfigForm.java diff --git a/src/main/java/org/codelibs/fess/app/web/admin/PathMappingAction.java b/src/main/java/org/codelibs/fess/app/web/admin/PathMappingAction.java deleted file mode 100644 index e43f49411..000000000 --- a/src/main/java/org/codelibs/fess/app/web/admin/PathMappingAction.java +++ /dev/null @@ -1,331 +0,0 @@ -/* - * Copyright 2009-2015 the CodeLibs Project and the Others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language - * governing permissions and limitations under the License. - */ - -package org.codelibs.fess.app.web.admin; - -import java.beans.Beans; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; - -import org.codelibs.core.beans.util.BeanUtil; -import org.codelibs.fess.annotation.Token; -import org.codelibs.fess.app.web.base.FessAdminAction; -import org.codelibs.fess.beans.FessBeans; -import org.codelibs.fess.crud.CommonConstants; -import org.codelibs.fess.crud.CrudMessageException; -import org.codelibs.fess.crud.util.SAStrutsUtil; -import org.codelibs.fess.es.exentity.PathMapping; -import org.codelibs.fess.exception.SSCActionMessagesException; -import org.codelibs.fess.helper.PathMappingHelper; -import org.codelibs.fess.helper.SystemHelper; -import org.codelibs.fess.app.pager.PathMappingPager; -import org.codelibs.fess.app.service.PathMappingService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PathMappingAction extends FessAdminAction { - - private static final Logger logger = LoggerFactory.getLogger(PathMappingAction.class); - - // for list - - public List pathMappingItems; - - // for edit/confirm/delete - - //@ActionForm - @Resource - protected PathMappingForm pathMappingForm; - - @Resource - protected PathMappingService pathMappingService; - - @Resource - protected PathMappingPager pathMappingPager; - - @Resource - protected PathMappingHelper pathMappingHelper; - - @Resource - protected SystemHelper systemHelper; - - public String getHelpLink() { - return systemHelper.getHelpLink("pathMapping"); - } - - protected String displayList(final boolean redirect) { - if (redirect) { - pathMappingHelper.init(); - } - - // page navi - pathMappingItems = pathMappingService.getPathMappingList(pathMappingPager); - - // restore from pager - BeanUtil.copyBeanToBean(pathMappingPager, pathMappingForm.searchParams, - option -> option.exclude(CommonConstants.PAGER_CONVERSION_RULE)); - - if (redirect) { - return "index?redirect=true"; - } else { - return "index.jsp"; - } - } - - //@Execute(validator = false, input = "error.jsp") - public String index() { - return displayList(false); - } - - //@Execute(validator = false, input = "error.jsp", urlPattern = "list/{pageNumber}") - public String list() { - // page navi - if (StringUtil.isNotBlank(pathMappingForm.pageNumber)) { - try { - pathMappingPager.setCurrentPageNumber(Integer.parseInt(pathMappingForm.pageNumber)); - } catch (final NumberFormatException e) { - if (logger.isDebugEnabled()) { - logger.debug("Invalid value: " + pathMappingForm.pageNumber, e); - } - } - } - - return displayList(false); - } - - //@Execute(validator = false, input = "error.jsp") - public String search() { - BeanUtil.copyBeanToBean(pathMappingForm.searchParams, pathMappingPager, - option -> option.exclude(CommonConstants.PAGER_CONVERSION_RULE)); - - return displayList(false); - } - - //@Execute(validator = false, input = "error.jsp") - public String reset() { - pathMappingPager.clear(); - - return displayList(false); - } - - //@Execute(validator = false, input = "error.jsp") - public String back() { - return displayList(false); - } - - @Token(save = true, validate = false) - //@Execute(validator = false, input = "error.jsp") - public String editagain() { - return "edit.jsp"; - } - - //@Execute(validator = false, input = "error.jsp", urlPattern = "confirmpage/{crudMode}/{id}") - public String confirmpage() { - if (pathMappingForm.crudMode != CommonConstants.CONFIRM_MODE) { - throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.CONFIRM_MODE, - pathMappingForm.crudMode }); - } - - loadPathMapping(); - - return "confirm.jsp"; - } - - @Token(save = true, validate = false) - //@Execute(validator = false, input = "error.jsp") - public String createpage() { - // page navi - pathMappingForm.initialize(); - pathMappingForm.crudMode = CommonConstants.CREATE_MODE; - - return "edit.jsp"; - } - - @Token(save = true, validate = false) - //@Execute(validator = false, input = "error.jsp", urlPattern = "editpage/{crudMode}/{id}") - public String editpage() { - if (pathMappingForm.crudMode != CommonConstants.EDIT_MODE) { - throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.EDIT_MODE, - pathMappingForm.crudMode }); - } - - loadPathMapping(); - - return "edit.jsp"; - } - - @Token(save = true, validate = false) - //@Execute(validator = false, input = "error.jsp") - public String editfromconfirm() { - pathMappingForm.crudMode = CommonConstants.EDIT_MODE; - - loadPathMapping(); - - return "edit.jsp"; - } - - @Token(save = false, validate = true, keep = true) - //@Execute(validator = true, input = "edit.jsp") - public String confirmfromcreate() { - return "confirm.jsp"; - } - - @Token(save = false, validate = true, keep = true) - //@Execute(validator = true, input = "edit.jsp") - public String confirmfromupdate() { - return "confirm.jsp"; - } - - @Token(save = true, validate = false) - //@Execute(validator = false, input = "error.jsp", urlPattern = "deletepage/{crudMode}/{id}") - public String deletepage() { - if (pathMappingForm.crudMode != CommonConstants.DELETE_MODE) { - throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.DELETE_MODE, - pathMappingForm.crudMode }); - } - - loadPathMapping(); - - return "confirm.jsp"; - } - - @Token(save = true, validate = false) - //@Execute(validator = false, input = "error.jsp") - public String deletefromconfirm() { - pathMappingForm.crudMode = CommonConstants.DELETE_MODE; - - loadPathMapping(); - - return "confirm.jsp"; - } - - @Token(save = false, validate = true) - //@Execute(validator = true, input = "edit.jsp") - public String create() { - try { - final PathMapping pathMapping = createPathMapping(); - pathMappingService.store(pathMapping); - SAStrutsUtil.addSessionMessage("success.crud_create_crud_table"); - - return displayList(true); - } catch (final ActionMessagesException e) { - logger.error(e.getMessage(), e); - throw e; - } catch (final CrudMessageException e) { - logger.error(e.getMessage(), e); - throw new ActionMessagesException(e.getMessageId(), e.getArgs()); - } catch (final Exception e) { - logger.error(e.getMessage(), e); - throw new ActionMessagesException("errors.crud_failed_to_create_crud_table"); - } - } - - @Token(save = false, validate = true) - //@Execute(validator = true, input = "edit.jsp") - public String update() { - try { - final PathMapping pathMapping = createPathMapping(); - pathMappingService.store(pathMapping); - SAStrutsUtil.addSessionMessage("success.crud_update_crud_table"); - - return displayList(true); - } catch (final ActionMessagesException e) { - logger.error(e.getMessage(), e); - throw e; - } catch (final CrudMessageException e) { - logger.error(e.getMessage(), e); - throw new ActionMessagesException(e.getMessageId(), e.getArgs()); - } catch (final Exception e) { - logger.error(e.getMessage(), e); - throw new ActionMessagesException("errors.crud_failed_to_update_crud_table"); - } - } - - protected Map createKeyMap() { - final Map keys = new HashMap(); - - keys.put("id", pathMappingForm.id); - - return keys; - } - - protected void loadPathMapping() { - - final PathMapping pathMapping = pathMappingService.getPathMapping(createKeyMap()); - if (pathMapping == null) { - // throw an exception - throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { pathMappingForm.id }); - } - - BeanUtil.copyBeanToBean(pathMapping, pathMappingForm, option -> option.exclude("searchParams", "mode")); - } - - protected PathMapping createPathMapping() { - PathMapping pathMapping; - final String username = systemHelper.getUsername(); - final long currentTime = systemHelper.getCurrentTimeAsLong(); - if (pathMappingForm.crudMode == CommonConstants.EDIT_MODE) { - pathMapping = pathMappingService.getPathMapping(createKeyMap()); - if (pathMapping == null) { - // throw an exception - throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { pathMappingForm.id }); - } - } else { - pathMapping = new PathMapping(); - pathMapping.setCreatedBy(username); - pathMapping.setCreatedTime(currentTime); - } - pathMapping.setUpdatedBy(username); - pathMapping.setUpdatedTime(currentTime); - BeanUtil.copyBeanToBean(pathMappingForm, pathMapping, option -> option.exclude(CommonConstants.COMMON_CONVERSION_RULE)); - - return pathMapping; - } - - //@Execute(validator = false, input = "error.jsp") - public String delete() { - if (pathMappingForm.crudMode != CommonConstants.DELETE_MODE) { - throw new SSCActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.DELETE_MODE, - pathMappingForm.crudMode }); - } - - try { - final PathMapping pathMapping = pathMappingService.getPathMapping(createKeyMap()); - if (pathMapping == null) { - // throw an exception - throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { pathMappingForm.id }); - } - - pathMappingService.delete(pathMapping); - SAStrutsUtil.addSessionMessage("success.crud_delete_crud_table"); - - return displayList(true); - } catch (final ActionMessagesException e) { - logger.error(e.getMessage(), e); - throw e; - } catch (final CrudMessageException e) { - logger.error(e.getMessage(), e); - throw new SSCActionMessagesException(e, e.getMessageId(), e.getArgs()); - } catch (final Exception e) { - logger.error(e.getMessage(), e); - throw new SSCActionMessagesException(e, "errors.crud_failed_to_delete_crud_table"); - } - } - -} diff --git a/src/main/java/org/codelibs/fess/app/web/admin/pathmapping/AdminPathmappingAction.java b/src/main/java/org/codelibs/fess/app/web/admin/pathmapping/AdminPathmappingAction.java new file mode 100644 index 000000000..fde12b878 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/admin/pathmapping/AdminPathmappingAction.java @@ -0,0 +1,273 @@ +/* + * Copyright 2009-2015 the CodeLibs Project and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +package org.codelibs.fess.app.web.admin.pathmapping; + +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Resource; + +import org.codelibs.fess.annotation.Token; +import org.codelibs.fess.app.pager.PathMappingPager; +import org.codelibs.fess.app.service.PathMappingService; +import org.codelibs.fess.app.web.base.FessAdminAction; +import org.codelibs.fess.crud.CommonConstants; +import org.codelibs.fess.es.exentity.PathMapping; +import org.codelibs.fess.helper.SystemHelper; +import org.lastaflute.web.Execute; +import org.lastaflute.web.callback.ActionRuntime; +import org.lastaflute.web.response.HtmlResponse; +import org.lastaflute.web.response.render.RenderData; +import org.lastaflute.web.validation.VaErrorHook; + +/** + * @author shinsuke + */ +public class AdminPathmappingAction extends FessAdminAction { + + // =================================================================================== + // Attribute + // ========= + @Resource + private PathMappingService pathMappingService; + @Resource + private PathMappingPager pathMappingPager; + @Resource + private SystemHelper systemHelper; + + // =================================================================================== + // Hook + // ====== + @Override + protected void setupHtmlData(ActionRuntime runtime) { + super.setupHtmlData(runtime); + runtime.registerData("helpLink", systemHelper.getHelpLink("pathMapping")); + } + + // =================================================================================== + // Search Execute + // ============== + @Execute + public HtmlResponse index(PathMappingSearchForm form) { + return asHtml(path_AdminPathmapping_IndexJsp).renderWith(data -> { + searchPaging(data, form); + }); + } + + @Execute + public HtmlResponse list(Integer pageNumber, PathMappingSearchForm form) { + pathMappingPager.setCurrentPageNumber(pageNumber); + return asHtml(path_AdminPathmapping_IndexJsp).renderWith(data -> { + searchPaging(data, form); + }); + } + + @Execute + public HtmlResponse search(PathMappingSearchForm form) { + copyBeanToBean(form.searchParams, pathMappingPager, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE)); + return asHtml(path_AdminPathmapping_IndexJsp).renderWith(data -> { + searchPaging(data, form); + }); + } + + @Execute + public HtmlResponse reset(PathMappingSearchForm form) { + pathMappingPager.clear(); + return asHtml(path_AdminPathmapping_IndexJsp).renderWith(data -> { + searchPaging(data, form); + }); + } + + @Execute + public HtmlResponse back(PathMappingSearchForm form) { + return asHtml(path_AdminPathmapping_IndexJsp).renderWith(data -> { + searchPaging(data, form); + }); + } + + protected void searchPaging(RenderData data, PathMappingSearchForm form) { + data.register("pathMappingItems", pathMappingService.getPathMappingList(pathMappingPager)); // page navi + + // restore from pager + copyBeanToBean(pathMappingPager, form.searchParams, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE)); + } + + // =================================================================================== + // Edit Execute + // ============ + // ----------------------------------------------------- + // Entry Page + // ---------- + @Token(save = true, validate = false) + @Execute + public HtmlResponse createpage(PathMappingEditForm form) { + form.crudMode = CommonConstants.CREATE_MODE; + return asHtml(path_AdminPathmapping_EditJsp); + } + + @Token(save = true, validate = false) + @Execute + public HtmlResponse editpage(int crudMode, String id, PathMappingEditForm form) { + form.crudMode = crudMode; + form.id = id; + verifyCrudMode(form, CommonConstants.EDIT_MODE); + loadPathMapping(form); + return asHtml(path_AdminPathmapping_EditJsp); + } + + @Token(save = true, validate = false) + @Execute + public HtmlResponse editagain(PathMappingEditForm form) { + return asHtml(path_AdminPathmapping_EditJsp); + } + + @Token(save = true, validate = false) + @Execute + public HtmlResponse editfromconfirm(PathMappingEditForm form) { + form.crudMode = CommonConstants.EDIT_MODE; + loadPathMapping(form); + return asHtml(path_AdminPathmapping_EditJsp); + } + + @Token(save = true, validate = false) + @Execute + public HtmlResponse deletepage(int crudMode, String id, PathMappingEditForm form) { + form.crudMode = crudMode; + form.id = id; + verifyCrudMode(form, CommonConstants.DELETE_MODE); + loadPathMapping(form); + return asHtml(path_AdminPathmapping_ConfirmJsp); + } + + @Token(save = true, validate = false) + @Execute + public HtmlResponse deletefromconfirm(PathMappingEditForm form) { + form.crudMode = CommonConstants.DELETE_MODE; + loadPathMapping(form); + return asHtml(path_AdminPathmapping_ConfirmJsp); + } + + // ----------------------------------------------------- + // Confirm + // ------- + @Execute + public HtmlResponse confirmpage(int crudMode, String id, PathMappingEditForm form) { + form.crudMode = crudMode; + form.id = id; + verifyCrudMode(form, CommonConstants.CONFIRM_MODE); + loadPathMapping(form); + return asHtml(path_AdminPathmapping_ConfirmJsp); + } + + @Token(save = false, validate = true, keep = true) + @Execute + public HtmlResponse confirmfromcreate(PathMappingEditForm form) { + validate(form, messages -> {}, toEditHtml()); + return asHtml(path_AdminPathmapping_ConfirmJsp); + } + + @Token(save = false, validate = true, keep = true) + @Execute + public HtmlResponse confirmfromupdate(PathMappingEditForm form) { + validate(form, messages -> {}, toEditHtml()); + return asHtml(path_AdminPathmapping_ConfirmJsp); + } + + // ----------------------------------------------------- + // Actually Crud + // ------------- + @Token(save = false, validate = true) + @Execute + public HtmlResponse create(PathMappingEditForm form) { + validate(form, messages -> {}, toEditHtml()); + pathMappingService.store(createPathMapping(form)); + saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL)); + return redirect(getClass()); + } + + @Token(save = false, validate = true) + @Execute + public HtmlResponse update(PathMappingEditForm form) { + validate(form, messages -> {}, toEditHtml()); + pathMappingService.store(createPathMapping(form)); + saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL)); + return redirect(getClass()); + } + + @Execute + public HtmlResponse delete(PathMappingEditForm form) { + verifyCrudMode(form, CommonConstants.DELETE_MODE); + pathMappingService.delete(getPathMapping(form)); + saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL)); + return redirect(getClass()); + } + + // =================================================================================== + // Assist Logic + // ============ + protected void loadPathMapping(PathMappingEditForm form) { + copyBeanToBean(getPathMapping(form), form, op -> op.exclude("crudMode")); + } + + protected PathMapping getPathMapping(PathMappingEditForm form) { + final PathMapping pathMapping = pathMappingService.getPathMapping(createKeyMap(form)); + if (pathMapping == null) { + throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml()); + } + return pathMapping; + } + + protected PathMapping createPathMapping(PathMappingEditForm form) { + PathMapping pathMapping; + final String username = systemHelper.getUsername(); + final long currentTime = systemHelper.getCurrentTimeAsLong(); + if (form.crudMode == CommonConstants.EDIT_MODE) { + pathMapping = getPathMapping(form); + } else { + pathMapping = new PathMapping(); + pathMapping.setCreatedBy(username); + pathMapping.setCreatedTime(currentTime); + } + pathMapping.setUpdatedBy(username); + pathMapping.setUpdatedTime(currentTime); + copyBeanToBean(form, pathMapping, op -> op.exclude(CommonConstants.COMMON_CONVERSION_RULE)); + return pathMapping; + } + + protected Map createKeyMap(PathMappingEditForm form) { + final Map keys = new HashMap(); + keys.put("id", form.id); + return keys; + } + + // =================================================================================== + // Small Helper + // ============ + protected void verifyCrudMode(PathMappingEditForm form, int expectedMode) { + if (form.crudMode != expectedMode) { + throwValidationError(messages -> { + messages.addErrorsCrudInvalidMode(GLOBAL, String.valueOf(expectedMode), String.valueOf(form.crudMode)); + }, toEditHtml()); + } + } + + protected VaErrorHook toEditHtml() { + return () -> { + return asHtml(path_AdminPathmapping_EditJsp); + }; + } +} diff --git a/src/main/java/org/codelibs/fess/app/web/admin/PathMappingForm.java b/src/main/java/org/codelibs/fess/app/web/admin/pathmapping/PathMappingEditForm.java similarity index 87% rename from src/main/java/org/codelibs/fess/app/web/admin/PathMappingForm.java rename to src/main/java/org/codelibs/fess/app/web/admin/pathmapping/PathMappingEditForm.java index 191944760..26689f18c 100644 --- a/src/main/java/org/codelibs/fess/app/web/admin/PathMappingForm.java +++ b/src/main/java/org/codelibs/fess/app/web/admin/pathmapping/PathMappingEditForm.java @@ -14,30 +14,23 @@ * governing permissions and limitations under the License. */ -package org.codelibs.fess.app.web.admin; +package org.codelibs.fess.app.web.admin.pathmapping; import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; import org.codelibs.fess.util.ComponentUtil; -public class PathMappingForm implements Serializable { +/** + * @author codelibs + * @author jflute + */ +public class PathMappingEditForm implements Serializable { private static final long serialVersionUID = 1L; - //@IntegerType - public String pageNumber; - - public Map searchParams = new HashMap(); - //@IntegerType public int crudMode; - public String getCurrentPageNumber() { - return pageNumber; - } - //@Required(target = "confirmfromupdate,update,delete") //@Maxbytelength(maxbytelength = 1000) public String id; diff --git a/src/main/java/org/codelibs/fess/app/web/admin/pathmapping/PathMappingSearchForm.java b/src/main/java/org/codelibs/fess/app/web/admin/pathmapping/PathMappingSearchForm.java new file mode 100644 index 000000000..1bb04869e --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/admin/pathmapping/PathMappingSearchForm.java @@ -0,0 +1,32 @@ +/* + * Copyright 2009-2015 the CodeLibs Project and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +package org.codelibs.fess.app.web.admin.pathmapping; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +/** + * @author codelibs + * @author jflute + */ +public class PathMappingSearchForm implements Serializable { + + private static final long serialVersionUID = 1L; + + public Map searchParams = new HashMap(); +} diff --git a/src/main/webapp/WEB-INF/view/common/admin2/sidebar.jsp b/src/main/webapp/WEB-INF/view/common/admin2/sidebar.jsp index a5fc2e5dc..884f5c274 100644 --- a/src/main/webapp/WEB-INF/view/common/admin2/sidebar.jsp +++ b/src/main/webapp/WEB-INF/view/common/admin2/sidebar.jsp @@ -97,12 +97,12 @@ -
  • class="active">class="active"> -
  • +
  • class="active">