modify failureUrl action

This commit is contained in:
Keiichi Watanabe 2015-09-17 17:56:38 +09:00
parent add923ba7a
commit 42729c49d1
6 changed files with 208 additions and 338 deletions

View file

@ -103,11 +103,9 @@
<exclude>org/codelibs/fess/app/web/admin/DocumentForm.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/DataForm.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/IndexAction.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/FailureUrlAction.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/DictAction.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/DataAction.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/WizardForm.java</exclude>
<exclude>org/codelibs/fess/app/web/admin/FailureUrlForm.java</exclude>
</excludes>
</configuration>
</plugin>

View file

@ -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.crud.CommonConstants;
import org.codelibs.fess.crud.CrudMessageException;
import org.codelibs.fess.crud.util.SAStrutsUtil;
import org.codelibs.fess.es.exentity.FailureUrl;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.app.pager.FailureUrlPager;
import org.codelibs.fess.app.service.FailureUrlService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FailureUrlAction extends FessAdminAction {
private static final Logger logger = LoggerFactory.getLogger(FailureUrlAction.class);
// for list
public List<FailureUrl> failureUrlItems;
// for edit/confirm/delete
//@ActionForm
@Resource
protected FailureUrlForm failureUrlForm;
@Resource
protected FailureUrlService failureUrlService;
@Resource
protected FailureUrlPager failureUrlPager;
@Resource
protected SystemHelper systemHelper;
public String getHelpLink() {
return systemHelper.getHelpLink("failureUrl");
}
protected String displayList(final boolean redirect) {
// page navi
failureUrlItems = failureUrlService.getFailureUrlList(failureUrlPager);
// restore from pager
BeanUtil.copyBeanToBean(failureUrlPager, failureUrlForm.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(failureUrlForm.pageNumber)) {
try {
failureUrlPager.setCurrentPageNumber(Integer.parseInt(failureUrlForm.pageNumber));
} catch (final NumberFormatException e) {
if (logger.isDebugEnabled()) {
logger.debug("Invalid value: " + failureUrlForm.pageNumber, e);
}
}
}
return displayList(false);
}
//@Execute(validator = false, input = "error.jsp")
public String search() {
BeanUtil.copyBeanToBean(failureUrlForm.searchParams, failureUrlPager,
option -> option.exclude(CommonConstants.PAGER_CONVERSION_RULE));
return displayList(false);
}
//@Execute(validator = false, input = "error.jsp")
public String reset() {
failureUrlPager.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 (failureUrlForm.crudMode != CommonConstants.CONFIRM_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.CONFIRM_MODE,
failureUrlForm.crudMode });
}
loadFailureUrl();
return "confirm.jsp";
}
@Token(save = true, validate = false)
//@Execute(validator = false, input = "error.jsp")
public String createpage() {
// page navi
failureUrlForm.initialize();
failureUrlForm.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 (failureUrlForm.crudMode != CommonConstants.EDIT_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode",
new Object[] { CommonConstants.EDIT_MODE, failureUrlForm.crudMode });
}
loadFailureUrl();
return "edit.jsp";
}
@Token(save = true, validate = false)
//@Execute(validator = false, input = "error.jsp")
public String editfromconfirm() {
failureUrlForm.crudMode = CommonConstants.EDIT_MODE;
loadFailureUrl();
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 (failureUrlForm.crudMode != CommonConstants.DELETE_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.DELETE_MODE,
failureUrlForm.crudMode });
}
loadFailureUrl();
return "confirm.jsp";
}
@Token(save = true, validate = false)
//@Execute(validator = false, input = "error.jsp")
public String deletefromconfirm() {
failureUrlForm.crudMode = CommonConstants.DELETE_MODE;
loadFailureUrl();
return "confirm.jsp";
}
@Token(save = false, validate = true)
//@Execute(validator = true, input = "edit.jsp")
public String create() {
try {
final FailureUrl failureUrl = createFailureUrl();
failureUrlService.store(failureUrl);
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 FailureUrl failureUrl = createFailureUrl();
failureUrlService.store(failureUrl);
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");
}
}
@Token(save = false, validate = true)
//@Execute(validator = false, input = "error.jsp")
public String delete() {
if (failureUrlForm.crudMode != CommonConstants.DELETE_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.DELETE_MODE,
failureUrlForm.crudMode });
}
try {
final FailureUrl failureUrl = failureUrlService.getFailureUrl(createKeyMap());
if (failureUrl == null) {
// throw an exception
throw new ActionMessagesException("errors.crud_could_not_find_crud_table",
new Object[] { failureUrlForm.id });
}
failureUrlService.delete(failureUrl);
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 ActionMessagesException(e.getMessageId(), e.getArgs());
} catch (final Exception e) {
logger.error(e.getMessage(), e);
throw new ActionMessagesException("errors.crud_failed_to_delete_crud_table");
}
}
protected void loadFailureUrl() {
final FailureUrl failureUrl = failureUrlService.getFailureUrl(createKeyMap());
if (failureUrl == null) {
// throw an exception
throw new ActionMessagesException("errors.crud_could_not_find_crud_table",
new Object[] { failureUrlForm.id });
}
BeanUtil.copyBeanToBean(failureUrl, failureUrlForm, option -> option.exclude("searchParams", "mode"));
}
protected FailureUrl createFailureUrl() {
FailureUrl failureUrl;
if (failureUrlForm.crudMode == CommonConstants.EDIT_MODE) {
failureUrl = failureUrlService.getFailureUrl(createKeyMap());
if (failureUrl == null) {
// throw an exception
throw new ActionMessagesException("errors.crud_could_not_find_crud_table",
new Object[] { failureUrlForm.id });
}
} else {
failureUrl = new FailureUrl();
}
BeanUtil.copyBeanToBean(failureUrlForm, failureUrl, option -> option.exclude("searchParams", "mode"));
return failureUrl;
}
protected Map<String, String> createKeyMap() {
final Map<String, String> keys = new HashMap<String, String>();
keys.put("id", failureUrlForm.id);
return keys;
}
//@Execute(validator = false, input = "error.jsp")
public String deleteall() {
failureUrlService.deleteAll(failureUrlPager);
SAStrutsUtil.addSessionMessage("success.failure_url_delete_all");
return displayList(true);
}
}

View file

@ -0,0 +1,164 @@
/*
* 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.failureurl;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.codelibs.fess.annotation.Token;
import org.codelibs.fess.app.pager.FailureUrlPager;
import org.codelibs.fess.app.service.FailureUrlService;
import org.codelibs.fess.app.web.base.FessAdminAction;
import org.codelibs.fess.crud.CommonConstants;
import org.codelibs.fess.es.exentity.FailureUrl;
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 codelibs
* @author Keiichi Watanabe
*/
public class AdminFailureurlAction extends FessAdminAction {
// ===================================================================================
// Attribute
// =========
@Resource
private FailureUrlService failureUrlService;
@Resource
private FailureUrlPager failureUrlPager;
@Resource
private SystemHelper systemHelper;
// ===================================================================================
// Hook
// ======
@Override
protected void setupHtmlData(final ActionRuntime runtime) {
super.setupHtmlData(runtime);
runtime.registerData("helpLink", systemHelper.getHelpLink("failureUrl"));
}
// ===================================================================================
// Search Execute
// ==============
@Execute
public HtmlResponse index(final FailureUrlSearchForm form) {
return asHtml(path_AdminFailureurl_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse list(final Integer pageNumber, final FailureUrlSearchForm form) {
failureUrlPager.setCurrentPageNumber(pageNumber);
return asHtml(path_AdminFailureurl_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse search(final FailureUrlSearchForm form) {
copyBeanToBean(form.searchParams, failureUrlPager, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE));
return asHtml(path_AdminFailureurl_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse reset(final FailureUrlSearchForm form) {
failureUrlPager.clear();
return asHtml(path_AdminFailureurl_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse back(final FailureUrlSearchForm form) {
return asHtml(path_AdminFailureurl_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
protected void searchPaging(final RenderData data, final FailureUrlSearchForm form) {
data.register("failureUrlItems", failureUrlService.getFailureUrlList(failureUrlPager)); // page navi
// restore from pager
copyBeanToBean(failureUrlPager, form.searchParams, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE));
}
// -----------------------------------------------------
// Confirm
// -------
@Execute
public HtmlResponse confirmpage(final int crudMode, final String id, final FailureUrlEditForm form) {
// TODO
// form.crudMode = crudMode;
// form.id = id;
// verifyCrudMode(form, CommonConstants.CONFIRM_MODE);
loadFailureUrl(form);
return asHtml(path_AdminFailureurl_ConfirmJsp);
}
// -----------------------------------------------------
// Actually Crud (only Delete)
// -------------
@Execute
public HtmlResponse delete(final FailureUrlEditForm form) {
// TODO verifyCrudMode(form, CommonConstants.DELETE_MODE);
failureUrlService.delete(getFailureUrl(form));
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
return redirect(getClass());
}
@Execute
public HtmlResponse deleteall(final FailureUrlEditForm form) {
failureUrlService.deleteAll(failureUrlPager);
saveInfo(messages -> messages.addSuccessFailureUrlDeleteAll(GLOBAL));
return redirect(getClass());
}
// ===================================================================================
// Assist Logic
// ============
protected void loadFailureUrl(final FailureUrlEditForm form) {
copyBeanToBean(getFailureUrl(form), form, op -> op.exclude("crudMode"));
}
protected FailureUrl getFailureUrl(final FailureUrlEditForm form) {
final FailureUrl failureUrl = failureUrlService.getFailureUrl(createKeyMap(form));
if (failureUrl == null) {
// TODO
}
return failureUrl;
}
protected Map<String, String> createKeyMap(final FailureUrlEditForm form) {
final Map<String, String> keys = new HashMap<String, String>();
keys.put("id", form.id);
return keys;
}
}

View file

@ -14,13 +14,19 @@
* governing permissions and limitations under the License.
*/
package org.codelibs.fess.app.web.admin;
package org.codelibs.fess.app.web.admin.failureurl;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
public class FailureUrlForm implements Serializable {
import org.codelibs.fess.util.ComponentUtil;
/**
* @author codelibs
* @author Keiichi Watanabe
*/
public class FailureUrlEditForm implements Serializable {
private static final long serialVersionUID = 1L;
@ -33,7 +39,8 @@ public class FailureUrlForm implements Serializable {
public Map<String, String> searchParams = new HashMap<String, String>();
//@IntegerType
//@IntegerType
// TODO necessary?
public int crudMode;
public String getCurrentPageNumber() {

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

View file

@ -216,10 +216,10 @@
<span><la:message key="labels.menu.log" /></span>
</la:link></li>
<li <c:if test="${param.menuType=='failureUrl'}">class="active"</c:if>><todo:link href="/admin/failureUrl/index">
<li <c:if test="${param.menuType=='failureUrl'}">class="active"</c:if>><la:link href="/admin/failureurl/index">
<i class='fa fa-angle-right'></i>
<span><la:message key="labels.menu.failure_url" /></span>
</todo:link></li>
</la:link></li>
<li <c:if test="${param.menuType=='searchList'}">class="active"</c:if>><todo:link href="/admin/searchList/index">
<i class='fa fa-angle-right'></i>