diff --git a/pom.xml b/pom.xml index d7c5d7808..8f840970e 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,6 @@ org/codelibs/fess/app/web/admin/DictForm.java org/codelibs/fess/app/web/admin/SystemForm.java org/codelibs/fess/app/web/admin/SearchListAction.java - org/codelibs/fess/app/web/admin/WebAuthenticationForm.java org/codelibs/fess/app/web/admin/SuggestElevateWordForm.java org/codelibs/fess/app/web/admin/CrawlAction.java org/codelibs/fess/app/web/admin/DocumentForm.java @@ -120,7 +119,6 @@ org/codelibs/fess/app/web/admin/SuggestElevateWordAction.java org/codelibs/fess/app/web/admin/LogForm.java org/codelibs/fess/app/web/admin/SystemInfoAction.java - org/codelibs/fess/app/web/admin/WebAuthenticationAction.java org/codelibs/fess/app/web/admin/DataAction.java org/codelibs/fess/app/web/admin/CrawlingSessionAction.java org/codelibs/fess/app/web/admin/FileConfigAction.java diff --git a/src/main/java/org/codelibs/fess/app/service/WebConfigService.java b/src/main/java/org/codelibs/fess/app/service/WebConfigService.java index ee2e9ab21..2ac66c316 100644 --- a/src/main/java/org/codelibs/fess/app/service/WebConfigService.java +++ b/src/main/java/org/codelibs/fess/app/service/WebConfigService.java @@ -278,4 +278,11 @@ public class WebConfigService implements Serializable { cb.query().docMeta().setId_Equal(id); }).orElse(null);//TODO } + + public List getWebConfigList() { + return webConfigBhv.selectList(cb -> { + // cb.query().addOrderBy_SortOrder_Asc(); + // cb.query().addOrderBy_Name_Asc(); + }); + } } diff --git a/src/main/java/org/codelibs/fess/app/web/admin/WebAuthenticationAction.java b/src/main/java/org/codelibs/fess/app/web/admin/WebAuthenticationAction.java deleted file mode 100644 index e8733d58f..000000000 --- a/src/main/java/org/codelibs/fess/app/web/admin/WebAuthenticationAction.java +++ /dev/null @@ -1,373 +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.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; - -import org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration; -import org.codelibs.core.beans.util.BeanUtil; -import org.codelibs.core.lang.StringUtil; -import org.codelibs.fess.Constants; -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.WebAuthentication; -import org.codelibs.fess.es.exentity.WebConfig; -import org.codelibs.fess.exception.SSCActionMessagesException; -import org.codelibs.fess.helper.SystemHelper; -import org.codelibs.fess.app.pager.WebAuthenticationPager; -import org.codelibs.fess.app.service.WebAuthenticationService; -import org.codelibs.fess.app.service.WebConfigService; -import org.lastaflute.web.util.LaRequestUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class WebAuthenticationAction extends FessAdminAction { - - private static final Logger logger = LoggerFactory.getLogger(WebAuthenticationAction.class); - - // for list - - public List webAuthenticationItems; - - // for edit/confirm/delete - - //@ActionForm - @Resource - protected WebAuthenticationForm webAuthenticationForm; - - @Resource - protected WebAuthenticationService webAuthenticationService; - - @Resource - protected WebAuthenticationPager webAuthenticationPager; - - @Resource - protected WebConfigService webConfigService; - - @Resource - protected SystemHelper systemHelper; - - protected String displayList(final boolean redirect) { - // page navi - webAuthenticationItems = webAuthenticationService.getWebAuthenticationList(webAuthenticationPager); - - // restore from pager - BeanUtil.copyBeanToBean(webAuthenticationPager, webAuthenticationForm.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(webAuthenticationForm.pageNumber)) { - try { - webAuthenticationPager.setCurrentPageNumber(Integer.parseInt(webAuthenticationForm.pageNumber)); - } catch (final NumberFormatException e) { - if (logger.isDebugEnabled()) { - logger.debug("Invalid value: " + webAuthenticationForm.pageNumber, e); - } - } - } - - return displayList(false); - } - - //@Execute(validator = false, input = "error.jsp") - public String search() { - BeanUtil.copyBeanToBean(webAuthenticationForm.searchParams, webAuthenticationPager, - option -> option.exclude(CommonConstants.PAGER_CONVERSION_RULE)); - - return displayList(false); - } - - //@Execute(validator = false, input = "error.jsp") - public String reset() { - webAuthenticationPager.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 (webAuthenticationForm.crudMode != CommonConstants.CONFIRM_MODE) { - throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.CONFIRM_MODE, - webAuthenticationForm.crudMode }); - } - - loadWebAuthentication(); - - return "confirm.jsp"; - } - - @Token(save = true, validate = false) - //@Execute(validator = false, input = "error.jsp") - public String createpage() { - // page navi - webAuthenticationForm.initialize(); - webAuthenticationForm.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 (webAuthenticationForm.crudMode != CommonConstants.EDIT_MODE) { - throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.EDIT_MODE, - webAuthenticationForm.crudMode }); - } - - loadWebAuthentication(); - - return "edit.jsp"; - } - - @Token(save = true, validate = false) - //@Execute(validator = false, input = "error.jsp") - public String editfromconfirm() { - webAuthenticationForm.crudMode = CommonConstants.EDIT_MODE; - - loadWebAuthentication(); - - 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 (webAuthenticationForm.crudMode != CommonConstants.DELETE_MODE) { - throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.DELETE_MODE, - webAuthenticationForm.crudMode }); - } - - loadWebAuthentication(); - - return "confirm.jsp"; - } - - @Token(save = true, validate = false) - //@Execute(validator = false, input = "error.jsp") - public String deletefromconfirm() { - webAuthenticationForm.crudMode = CommonConstants.DELETE_MODE; - - loadWebAuthentication(); - - return "confirm.jsp"; - } - - @Token(save = false, validate = true) - //@Execute(validator = true, input = "edit.jsp") - public String create() { - try { - final WebAuthentication webAuthentication = createWebAuthentication(); - webAuthenticationService.store(webAuthentication); - 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 WebAuthentication webAuthentication = createWebAuthentication(); - webAuthenticationService.store(webAuthentication); - 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", webAuthenticationForm.id); - - return keys; - } - - public String getHelpLink() { - return systemHelper.getHelpLink("webAuthentication"); - } - - protected void loadWebAuthentication() { - - final WebAuthentication webAuthentication = webAuthenticationService.getWebAuthentication(createKeyMap()); - if (webAuthentication == null) { - // throw an exception - throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { webAuthenticationForm.id }); - } - - BeanUtil.copyBeanToBean(webAuthentication, webAuthenticationForm, option -> option.excludes("searchParams", "mode")); - if ("-1".equals(webAuthenticationForm.port)) { - webAuthenticationForm.port = StringUtil.EMPTY; - } - } - - protected WebAuthentication createWebAuthentication() { - WebAuthentication webAuthentication; - final String username = systemHelper.getUsername(); - final long currentTime = systemHelper.getCurrentTimeAsLong(); - if (webAuthenticationForm.crudMode == CommonConstants.EDIT_MODE) { - webAuthentication = webAuthenticationService.getWebAuthentication(createKeyMap()); - if (webAuthentication == null) { - // throw an exception - throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { webAuthenticationForm.id }); - } - } else { - webAuthentication = new WebAuthentication(); - webAuthentication.setCreatedBy(username); - webAuthentication.setCreatedTime(currentTime); - } - webAuthentication.setUpdatedBy(username); - webAuthentication.setUpdatedTime(currentTime); - if (StringUtil.isBlank(webAuthenticationForm.port)) { - webAuthenticationForm.port = "-1"; - } - BeanUtil.copyBeanToBean(webAuthenticationForm, webAuthentication, option -> option.exclude(CommonConstants.COMMON_CONVERSION_RULE)); - - return webAuthentication; - } - - @Token(save = false, validate = true) - //@Execute(validator = false, input = "error.jsp") - public String delete() { - if (webAuthenticationForm.crudMode != CommonConstants.DELETE_MODE) { - throw new SSCActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.DELETE_MODE, - webAuthenticationForm.crudMode }); - } - - try { - final WebAuthentication webAuthentication = webAuthenticationService.getWebAuthentication(createKeyMap()); - if (webAuthentication == null) { - // throw an exception - throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { webAuthenticationForm.id }); - } - - webAuthenticationService.delete(webAuthentication); - 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"); - } - } - - public boolean isDisplayCreateLink() { - return !webConfigService.getAllWebConfigList(false, false, false, null).isEmpty(); - } - - public List> getWebConfigItems() { - final List> items = new ArrayList>(); - final List webConfigList = webConfigService.getAllWebConfigList(false, false, false, null); - for (final WebConfig webConfig : webConfigList) { - items.add(createItem(webConfig.getName(), webConfig.getId().toString())); - } - return items; - } - - public List> getProtocolSchemeItems() { - final List> items = new ArrayList>(); - items.add(createItem( - MessageResourcesUtil.getMessage(LaRequestUtil.getRequest().getLocale(), "labels.web_authentication_scheme_basic"), - Constants.BASIC)); - items.add(createItem( - MessageResourcesUtil.getMessage(LaRequestUtil.getRequest().getLocale(), "labels.web_authentication_scheme_digest"), - Constants.DIGEST)); - items.add(createItem( - MessageResourcesUtil.getMessage(LaRequestUtil.getRequest().getLocale(), "labels.web_authentication_scheme_ntlm"), - Constants.NTLM)); - return items; - } - - protected Map createItem(final String label, final String value) { - final Map map = new HashMap(2); - map.put("label", label); - map.put("value", value); - return map; - } -} diff --git a/src/main/java/org/codelibs/fess/app/web/admin/webauthentication/AdminWebauthenticationAction.java b/src/main/java/org/codelibs/fess/app/web/admin/webauthentication/AdminWebauthenticationAction.java new file mode 100644 index 000000000..cd9b5a423 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/admin/webauthentication/AdminWebauthenticationAction.java @@ -0,0 +1,320 @@ +/* + * 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.webauthentication; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; + +import org.codelibs.fess.annotation.Token; +import org.codelibs.fess.app.pager.WebAuthenticationPager; +import org.codelibs.fess.app.service.WebAuthenticationService; +import org.codelibs.fess.app.service.WebConfigService; +import org.codelibs.fess.app.web.base.FessAdminAction; +import org.codelibs.fess.crud.CommonConstants; +import org.codelibs.fess.es.exentity.WebAuthentication; +import org.codelibs.fess.es.exentity.WebConfig; +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.util.LaRequestUtil; +import org.lastaflute.web.validation.VaErrorHook; + +/** + * @author shinsuke + */ +public class AdminWebauthenticationAction extends FessAdminAction { + + // =================================================================================== + // Attribute + // ========= + @Resource + private WebAuthenticationService webAuthenticationService; + @Resource + private WebAuthenticationPager webAuthenticationPager; + @Resource + private SystemHelper systemHelper; + + @Resource + protected WebConfigService webConfigService; + + // =================================================================================== + // Hook + // ====== + @Override + protected void setupHtmlData(final ActionRuntime runtime) { + super.setupHtmlData(runtime); + runtime.registerData("helpLink", systemHelper.getHelpLink("webAuthentication")); + } + + // =================================================================================== + // Search Execute + // ============== + @Execute + public HtmlResponse index(final WebAuthenticationSearchForm form) { + return asHtml(path_AdminWebauthentication_IndexJsp).renderWith(data -> { + searchPaging(data, form); + }); + } + + @Execute + public HtmlResponse list(final Integer pageNumber, final WebAuthenticationSearchForm form) { + webAuthenticationPager.setCurrentPageNumber(pageNumber); + return asHtml(path_AdminWebauthentication_IndexJsp).renderWith(data -> { + searchPaging(data, form); + }); + } + + @Execute + public HtmlResponse search(final WebAuthenticationSearchForm form) { + copyBeanToBean(form.searchParams, webAuthenticationPager, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE)); + return asHtml(path_AdminWebauthentication_IndexJsp).renderWith(data -> { + searchPaging(data, form); + }); + } + + @Execute + public HtmlResponse reset(final WebAuthenticationSearchForm form) { + webAuthenticationPager.clear(); + return asHtml(path_AdminWebauthentication_IndexJsp).renderWith(data -> { + searchPaging(data, form); + }); + } + + @Execute + public HtmlResponse back(final WebAuthenticationSearchForm form) { + return asHtml(path_AdminWebauthentication_IndexJsp).renderWith(data -> { + searchPaging(data, form); + }); + } + + protected void searchPaging(final RenderData data, final WebAuthenticationSearchForm form) { + data.register("webAuthenticationItems", webAuthenticationService.getWebAuthenticationList(webAuthenticationPager)); // page navi + data.register("displayCreateLink", !webConfigService.getAllWebConfigList(false, false, false, null).isEmpty()); + // restore from pager + copyBeanToBean(webAuthenticationPager, form.searchParams, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE)); + } + + // =================================================================================== + // Edit Execute + // ============ + // ----------------------------------------------------- + // Entry Page + // ---------- + @Token(save = true, validate = false) + @Execute + public HtmlResponse createpage(final WebAuthenticationEditForm form) { + form.initialize(); + form.crudMode = CommonConstants.CREATE_MODE; + return asHtml(path_AdminWebauthentication_EditJsp).renderWith(data -> { + data.register("webConfigItems", webConfigService.getAllWebConfigList()); + }); + } + + @Token(save = true, validate = false) + @Execute + public HtmlResponse editpage(final int crudMode, final String id, final WebAuthenticationEditForm form) { + form.crudMode = crudMode; + form.id = id; + verifyCrudMode(form, CommonConstants.EDIT_MODE); + loadWebAuthentication(form); + return asHtml(path_AdminWebauthentication_EditJsp).renderWith(data -> { + data.register("webConfigItems", webConfigService.getAllWebConfigList()); + }); + } + + @Token(save = true, validate = false) + @Execute + public HtmlResponse editagain(final WebAuthenticationEditForm form) { + return asHtml(path_AdminWebauthentication_EditJsp); + } + + @Token(save = true, validate = false) + @Execute + public HtmlResponse editfromconfirm(final WebAuthenticationEditForm form) { + form.crudMode = CommonConstants.EDIT_MODE; + loadWebAuthentication(form); + return asHtml(path_AdminWebauthentication_EditJsp); + } + + @Token(save = true, validate = false) + @Execute + public HtmlResponse deletepage(final int crudMode, final String id, final WebAuthenticationEditForm form) { + form.crudMode = crudMode; + form.id = id; + verifyCrudMode(form, CommonConstants.DELETE_MODE); + loadWebAuthentication(form); + return asHtml(path_AdminWebauthentication_ConfirmJsp); + } + + @Token(save = true, validate = false) + @Execute + public HtmlResponse deletefromconfirm(final WebAuthenticationEditForm form) { + form.crudMode = CommonConstants.DELETE_MODE; + loadWebAuthentication(form); + return asHtml(path_AdminWebauthentication_ConfirmJsp); + } + + // ----------------------------------------------------- + // Confirm + // ------- + @Execute + public HtmlResponse confirmpage(final int crudMode, final String id, final WebAuthenticationEditForm form) { + form.crudMode = crudMode; + form.id = id; + verifyCrudMode(form, CommonConstants.CONFIRM_MODE); + loadWebAuthentication(form); + return asHtml(path_AdminWebauthentication_ConfirmJsp); + } + + @Token(save = false, validate = true, keep = true) + @Execute + public HtmlResponse confirmfromcreate(final WebAuthenticationEditForm form) { + validate(form, messages -> {}, toEditHtml()); + return asHtml(path_AdminWebauthentication_ConfirmJsp); + } + + @Token(save = false, validate = true, keep = true) + @Execute + public HtmlResponse confirmfromupdate(final WebAuthenticationEditForm form) { + validate(form, messages -> {}, toEditHtml()); + return asHtml(path_AdminWebauthentication_ConfirmJsp); + } + + // ----------------------------------------------------- + // Actually Crud + // ------------- + @Token(save = false, validate = true) + @Execute + public HtmlResponse create(final WebAuthenticationEditForm form) { + validate(form, messages -> {}, toEditHtml()); + webAuthenticationService.store(createWebAuthentication(form)); + saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL)); + return redirect(getClass()); + } + + @Token(save = false, validate = true) + @Execute + public HtmlResponse update(final WebAuthenticationEditForm form) { + validate(form, messages -> {}, toEditHtml()); + webAuthenticationService.store(createWebAuthentication(form)); + saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL)); + return redirect(getClass()); + } + + @Execute + public HtmlResponse delete(final WebAuthenticationEditForm form) { + verifyCrudMode(form, CommonConstants.DELETE_MODE); + webAuthenticationService.delete(getWebAuthentication(form)); + saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL)); + return redirect(getClass()); + } + + //=================================================================================== + // Assist Logic + // ============ + // public boolean isDisplayCreateLink() { + // return !webConfigService.getAllWebConfigList(false, false, false, null).isEmpty(); + // } + // + // public List> getWebConfigItems() { + // final List> items = new ArrayList>(); + // final List webConfigList = webConfigService.getAllWebConfigList(false, false, false, null); + // for (final WebConfig webConfig : webConfigList) { + // items.add(createItem(webConfig.getName(), webConfig.getId().toString())); + // } + // return items; + // } + // + // public List> getProtocolSchemeItems() { + // final List> items = new ArrayList>(); + // items.add(createItem( + // MessageResourcesUtil.getMessage(LaRequestUtil.getRequest().getLocale(), "labels.web_authentication_scheme_basic"), + // Constants.BASIC)); + // items.add(createItem( + // MessageResourcesUtil.getMessage(LaRequestUtil.getRequest().getLocale(), "labels.web_authentication_scheme_digest"), + // Constants.DIGEST)); + // items.add(createItem( + // MessageResourcesUtil.getMessage(LaRequestUtil.getRequest().getLocale(), "labels.web_authentication_scheme_ntlm"), + // Constants.NTLM)); + // return items; + // } + // + // protected Map createItem(final String label, final String value) { + // final Map map = new HashMap(2); + // map.put("label", label); + // map.put("value", value); + // return map; + // } + + protected void loadWebAuthentication(final WebAuthenticationEditForm form) { + copyBeanToBean(getWebAuthentication(form), form, op -> op.exclude("crudMode")); + } + + protected WebAuthentication getWebAuthentication(final WebAuthenticationEditForm form) { + final WebAuthentication webAuthentication = webAuthenticationService.getWebAuthentication(createKeyMap(form)); + if (webAuthentication == null) { + throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml()); + } + return webAuthentication; + } + + protected WebAuthentication createWebAuthentication(final WebAuthenticationEditForm form) { + WebAuthentication webAuthentication; + final String username = systemHelper.getUsername(); + final long currentTime = systemHelper.getCurrentTimeAsLong(); + if (form.crudMode == CommonConstants.EDIT_MODE) { + webAuthentication = getWebAuthentication(form); + } else { + webAuthentication = new WebAuthentication(); + webAuthentication.setCreatedBy(username); + webAuthentication.setCreatedTime(currentTime); + } + webAuthentication.setUpdatedBy(username); + webAuthentication.setUpdatedTime(currentTime); + copyBeanToBean(form, webAuthentication, op -> op.exclude(CommonConstants.COMMON_CONVERSION_RULE)); + return webAuthentication; + } + + protected Map createKeyMap(final WebAuthenticationEditForm form) { + final Map keys = new HashMap(); + keys.put("id", form.id); + return keys; + } + + // =================================================================================== + // Small Helper + // ============ + protected void verifyCrudMode(final WebAuthenticationEditForm form, final 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_AdminWebauthentication_EditJsp); + }; + } +} diff --git a/src/main/java/org/codelibs/fess/app/web/admin/WebAuthenticationForm.java b/src/main/java/org/codelibs/fess/app/web/admin/webauthentication/WebAuthenticationEditForm.java similarity index 88% rename from src/main/java/org/codelibs/fess/app/web/admin/WebAuthenticationForm.java rename to src/main/java/org/codelibs/fess/app/web/admin/webauthentication/WebAuthenticationEditForm.java index 69a5be92e..c15e5391f 100644 --- a/src/main/java/org/codelibs/fess/app/web/admin/WebAuthenticationForm.java +++ b/src/main/java/org/codelibs/fess/app/web/admin/webauthentication/WebAuthenticationEditForm.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.webauthentication; import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; import org.codelibs.fess.util.ComponentUtil; -public class WebAuthenticationForm implements Serializable { +/** + * @author codelibs + * @author jflute + */ +public class WebAuthenticationEditForm 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/webauthentication/WebAuthenticationSearchForm.java b/src/main/java/org/codelibs/fess/app/web/admin/webauthentication/WebAuthenticationSearchForm.java new file mode 100644 index 000000000..1ea2a125f --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/admin/webauthentication/WebAuthenticationSearchForm.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.webauthentication; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +/** + * @author codelibs + * @author jflute + */ +public class WebAuthenticationSearchForm implements Serializable { + + private static final long serialVersionUID = 1L; + + public Map searchParams = new HashMap(); +} diff --git a/src/main/webapp/WEB-INF/view/admin/webauthentication/index.jsp b/src/main/webapp/WEB-INF/view/admin/webauthentication/index.jsp index 822867980..788b3c329 100644 --- a/src/main/webapp/WEB-INF/view/admin/webauthentication/index.jsp +++ b/src/main/webapp/WEB-INF/view/admin/webauthentication/index.jsp @@ -32,7 +32,7 @@
- + 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 f5544697b..688b41b2c 100644 --- a/src/main/webapp/WEB-INF/view/common/admin2/sidebar.jsp +++ b/src/main/webapp/WEB-INF/view/common/admin2/sidebar.jsp @@ -104,12 +104,12 @@ -
  • class="active">class="active"> -
  • +
  • class="active">