modify webconfig action

This commit is contained in:
Shunji Makino 2015-08-27 17:51:25 +09:00
parent d1f26b6087
commit 4c8ce43557
6 changed files with 320 additions and 368 deletions

View file

@ -95,7 +95,6 @@
<exclude>org/codelibs/fess/app/web/admin/JobLogAction.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/WizardAction.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/SearchListForm.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/WebConfigForm.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/dict/UserDictForm.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/dict/SynonymForm.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/dict/UserDictAction.java</exclude>
@ -111,7 +110,6 @@
<exclude>org/codelibs/fess/app/web/admin/SystemAction.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/DataConfigAction.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/DictForm.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/WebConfigAction.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/SystemForm.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/SearchListAction.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/WebAuthenticationForm.java</exclude>

View file

@ -1,350 +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.CrawlingConfig;
import org.codelibs.fess.es.exentity.LabelType;
import org.codelibs.fess.es.exentity.RoleType;
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.WebConfigPager;
import org.codelibs.fess.app.service.FailureUrlService;
import org.codelibs.fess.app.service.LabelTypeService;
import org.codelibs.fess.app.service.RoleTypeService;
import org.codelibs.fess.app.service.WebConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WebConfigAction extends FessAdminAction {
private static final Logger logger = LoggerFactory.getLogger(WebConfigAction.class);
// for list
public List<WebConfig> webConfigItems;
// for edit/confirm/delete
//@ActionForm
@Resource
protected WebConfigForm webConfigForm;
@Resource
protected WebConfigService webConfigService;
@Resource
protected WebConfigPager webConfigPager;
@Resource
protected RoleTypeService roleTypeService;
@Resource
protected LabelTypeService labelTypeService;
@Resource
protected FailureUrlService failureUrlService;
@Resource
protected SystemHelper systemHelper;
public String getHelpLink() {
return systemHelper.getHelpLink("webConfig");
}
protected String displayList(final boolean redirect) {
// page navi
webConfigItems = webConfigService.getWebConfigList(webConfigPager);
// restore from pager
BeanUtil.copyBeanToBean(webConfigPager, webConfigForm.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(webConfigForm.pageNumber)) {
try {
webConfigPager.setCurrentPageNumber(Integer.parseInt(webConfigForm.pageNumber));
} catch (final NumberFormatException e) {
if (logger.isDebugEnabled()) {
logger.debug("Invalid value: " + webConfigForm.pageNumber, e);
}
}
}
return displayList(false);
}
//@Execute(validator = false, input = "error.jsp")
public String search() {
BeanUtil.copyBeanToBean(webConfigForm.searchParams, webConfigPager, option -> option.exclude(CommonConstants.PAGER_CONVERSION_RULE));
return displayList(false);
}
//@Execute(validator = false, input = "error.jsp")
public String reset() {
webConfigPager.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 (webConfigForm.crudMode != CommonConstants.CONFIRM_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.CONFIRM_MODE,
webConfigForm.crudMode });
}
loadWebConfig();
return "confirm.jsp";
}
@Token(save = true, validate = false)
//@Execute(validator = false, input = "error.jsp")
public String createpage() {
// page navi
webConfigForm.initialize();
webConfigForm.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 (webConfigForm.crudMode != CommonConstants.EDIT_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode",
new Object[] { CommonConstants.EDIT_MODE, webConfigForm.crudMode });
}
loadWebConfig();
return "edit.jsp";
}
@Token(save = true, validate = false)
//@Execute(validator = false, input = "error.jsp")
public String editfromconfirm() {
webConfigForm.crudMode = CommonConstants.EDIT_MODE;
loadWebConfig();
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 (webConfigForm.crudMode != CommonConstants.DELETE_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.DELETE_MODE,
webConfigForm.crudMode });
}
loadWebConfig();
return "confirm.jsp";
}
@Token(save = true, validate = false)
//@Execute(validator = false, input = "error.jsp")
public String deletefromconfirm() {
webConfigForm.crudMode = CommonConstants.DELETE_MODE;
loadWebConfig();
return "confirm.jsp";
}
@Token(save = false, validate = true)
//@Execute(validator = true, input = "edit.jsp")
public String create() {
try {
final WebConfig webConfig = createWebConfig();
webConfigService.store(webConfig);
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 WebConfig webConfig = createWebConfig();
webConfigService.store(webConfig);
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<String, String> createKeyMap() {
final Map<String, String> keys = new HashMap<String, String>();
keys.put("id", webConfigForm.id);
return keys;
}
protected void loadWebConfig() {
final CrawlingConfig webConfig = webConfigService.getWebConfig(createKeyMap());
if (webConfig == null) {
// throw an exception
throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { webConfigForm.id });
}
BeanUtil.copyBeanToBean(webConfig, webConfigForm, option -> option.exclude("searchParams", "mode"));
// normalize boost
if (webConfigForm.boost != null && webConfigForm.boost.indexOf('.') > 0) {
webConfigForm.boost = webConfigForm.boost.substring(0, webConfigForm.boost.indexOf('.'));
}
}
protected WebConfig createWebConfig() {
WebConfig webConfig;
final String username = systemHelper.getUsername();
final long currentTime = systemHelper.getCurrentTimeAsLong();
if (webConfigForm.crudMode == CommonConstants.EDIT_MODE) {
webConfig = webConfigService.getWebConfig(createKeyMap());
if (webConfig == null) {
// throw an exception
throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { webConfigForm.id });
}
} else {
webConfig = new WebConfig();
webConfig.setCreatedBy(username);
webConfig.setCreatedTime(currentTime);
}
webConfig.setUpdatedBy(username);
webConfig.setUpdatedTime(currentTime);
BeanUtil.copyBeanToBean(webConfigForm, webConfig, option -> option.exclude(CommonConstants.COMMON_CONVERSION_RULE));
return webConfig;
}
//@Execute(validator = false, input = "error.jsp")
public String delete() {
if (webConfigForm.crudMode != CommonConstants.DELETE_MODE) {
throw new SSCActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.DELETE_MODE,
webConfigForm.crudMode });
}
try {
final WebConfig webConfig = webConfigService.getWebConfig(createKeyMap());
if (webConfig == null) {
// throw an exception
throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { webConfigForm.id });
}
failureUrlService.deleteByConfigId(webConfig.getConfigId());
webConfigService.delete(webConfig);
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 List<RoleType> getRoleTypeItems() {
return roleTypeService.getRoleTypeList();
}
public List<LabelType> getLabelTypeItems() {
return labelTypeService.getLabelTypeList();
}
}

View file

@ -0,0 +1,279 @@
/*
* 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.webconfig;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.codelibs.fess.annotation.Token;
import org.codelibs.fess.app.pager.WebConfigPager;
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.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.validation.VaErrorHook;
/**
* @author shinsuke
*/
public class AdminWebconfigAction extends FessAdminAction {
// ===================================================================================
// Attribute
// =========
@Resource
private WebConfigService webConfigService;
@Resource
private WebConfigPager webConfigPager;
@Resource
private SystemHelper systemHelper;
// ===================================================================================
// Hook
// ======
@Override
protected void setupHtmlData(ActionRuntime runtime) {
super.setupHtmlData(runtime);
runtime.registerData("helpLink", systemHelper.getHelpLink("webConfig"));
}
// ===================================================================================
// Search Execute
// ==============
@Execute
public HtmlResponse index(WebConfigSearchForm form) {
return asHtml(path_AdminWebconfig_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse list(Integer pageNumber, WebConfigSearchForm form) {
webConfigPager.setCurrentPageNumber(pageNumber);
return asHtml(path_AdminWebconfig_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse search(WebConfigSearchForm form) {
copyBeanToBean(form.searchParams, webConfigPager, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE));
return asHtml(path_AdminWebconfig_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse reset(WebConfigSearchForm form) {
webConfigPager.clear();
return asHtml(path_AdminWebconfig_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse back(WebConfigSearchForm form) {
return asHtml(path_AdminWebconfig_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
protected void searchPaging(RenderData data, WebConfigSearchForm form) {
data.register("webConfigItems", webConfigService.getWebConfigList(webConfigPager)); // page navi
// restore from pager
copyBeanToBean(webConfigPager, form.searchParams, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE));
}
// ===================================================================================
// Edit Execute
// ============
// -----------------------------------------------------
// Entry Page
// ----------
@Token(save = true, validate = false)
@Execute
public HtmlResponse createpage(WebConfigEditForm form) {
form.crudMode = CommonConstants.CREATE_MODE;
return asHtml(path_AdminWebconfig_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editpage(int crudMode, String id, WebConfigEditForm form) {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CommonConstants.EDIT_MODE);
loadWebConfig(form);
return asHtml(path_AdminWebconfig_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editagain(WebConfigEditForm form) {
return asHtml(path_AdminWebconfig_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editfromconfirm(WebConfigEditForm form) {
form.crudMode = CommonConstants.EDIT_MODE;
loadWebConfig(form);
return asHtml(path_AdminWebconfig_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse deletepage(int crudMode, String id, WebConfigEditForm form) {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CommonConstants.DELETE_MODE);
loadWebConfig(form);
return asHtml(path_AdminWebconfig_ConfirmJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse deletefromconfirm(WebConfigEditForm form) {
form.crudMode = CommonConstants.DELETE_MODE;
loadWebConfig(form);
return asHtml(path_AdminWebconfig_ConfirmJsp);
}
// -----------------------------------------------------
// Confirm
// -------
@Execute
public HtmlResponse confirmpage(int crudMode, String id, WebConfigEditForm form) {
try {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CommonConstants.CONFIRM_MODE);
loadWebConfig(form);
return asHtml(path_AdminWebconfig_ConfirmJsp);
} catch (Exception e) {
e.printStackTrace();
return asHtml(path_AdminWebconfig_ConfirmJsp);
}
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromcreate(WebConfigEditForm form) {
validate(form, messages -> {}, toEditHtml());
return asHtml(path_AdminWebconfig_ConfirmJsp);
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromupdate(WebConfigEditForm form) {
validate(form, messages -> {}, toEditHtml());
return asHtml(path_AdminWebconfig_ConfirmJsp);
}
// -----------------------------------------------------
// Actually Crud
// -------------
@Token(save = false, validate = true)
@Execute
public HtmlResponse create(WebConfigEditForm form) {
validate(form, messages -> {}, toEditHtml());
webConfigService.store(createWebConfig(form));
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
return redirect(getClass());
}
@Token(save = false, validate = true)
@Execute
public HtmlResponse update(WebConfigEditForm form) {
validate(form, messages -> {}, toEditHtml());
webConfigService.store(createWebConfig(form));
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
return redirect(getClass());
}
@Execute
public HtmlResponse delete(WebConfigEditForm form) {
verifyCrudMode(form, CommonConstants.DELETE_MODE);
webConfigService.delete(getWebConfig(form));
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
return redirect(getClass());
}
// ===================================================================================
// Assist Logic
// ============
protected void loadWebConfig(WebConfigEditForm form) {
copyBeanToBean(getWebConfig(form), form, op -> op.exclude("crudMode"));
}
protected WebConfig getWebConfig(WebConfigEditForm form) {
final WebConfig webConfig = webConfigService.getWebConfig(createKeyMap(form));
if (webConfig == null) {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
}
return webConfig;
}
protected WebConfig createWebConfig(WebConfigEditForm form) {
WebConfig webConfig;
final String username = systemHelper.getUsername();
final long currentTime = systemHelper.getCurrentTimeAsLong();
if (form.crudMode == CommonConstants.EDIT_MODE) {
webConfig = getWebConfig(form);
} else {
webConfig = new WebConfig();
webConfig.setCreatedBy(username);
webConfig.setCreatedTime(currentTime);
}
webConfig.setUpdatedBy(username);
webConfig.setUpdatedTime(currentTime);
copyBeanToBean(form, webConfig, op -> op.exclude(CommonConstants.COMMON_CONVERSION_RULE));
return webConfig;
}
protected Map<String, String> createKeyMap(WebConfigEditForm form) {
final Map<String, String> keys = new HashMap<String, String>();
keys.put("id", form.id);
return keys;
}
// ===================================================================================
// Small Helper
// ============
protected void verifyCrudMode(WebConfigEditForm 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_AdminWebconfig_EditJsp);
};
}
}

View file

@ -14,18 +14,20 @@
* governing permissions and limitations under the License.
*/
package org.codelibs.fess.app.web.admin;
package org.codelibs.fess.app.web.admin.webconfig;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.codelibs.fess.util.ComponentUtil;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.Constants;
import org.codelibs.fess.annotation.UriType;
import org.codelibs.fess.util.ComponentUtil;
public class WebConfigForm implements Serializable {
/**
* @author codelibs
* @author jflute
*/
public class WebConfigEditForm implements Serializable {
private static final long serialVersionUID = 1L;
@ -33,18 +35,9 @@ public class WebConfigForm implements Serializable {
public String[] labelTypeIds;
//@IntegerType
public String pageNumber;
public Map<String, String> searchParams = new HashMap<String, String>();
//@IntegerType
public int crudMode;
public String getCurrentPageNumber() {
return pageNumber;
}
//@Required(target = "confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 1000)
public String id;

View file

@ -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.webconfig;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @author codelibs
* @author jflute
*/
public class WebConfigSearchForm implements Serializable {
private static final long serialVersionUID = 1L;
public Map<String, String> searchParams = new HashMap<String, String>();
}

View file

@ -65,10 +65,10 @@
></i> <span><la:message key="labels.menu_crawl" /></span> <i class="fa fa-angle-left pull-right"></i></a>
<ul class="treeview-menu">
<li <c:if test="${param.menuType=='webConfig'}">class="active"</c:if>><todo:link href="/admin/webConfig/index">
<li <c:if test="${param.menuType=='webConfig'}">class="active"</c:if>><la:link href="/admin/webconfig/index">
<i class='fa fa-angle-right'></i>
<span><la:message key="labels.menu.web" /></span>
</todo:link></li>
</la:link></li>
<li <c:if test="${param.menuType=='fileConfig'}">class="active"</c:if>><todo:link href="/admin/fileConfig/index">
<i class='fa fa-angle-right'></i>