FileCrawlingConfigAction.java

This commit is contained in:
Shunji Makino 2015-03-26 14:10:26 +09:00
parent f2fe66d8a5
commit da92b33d1b
3 changed files with 243 additions and 30 deletions

View file

@ -17,7 +17,6 @@
package org.codelibs.fess.action.admin;
import java.io.BufferedWriter;
import java.io.Serializable;
import java.io.OutputStreamWriter;
import java.util.Date;
import java.util.HashMap;
@ -31,6 +30,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.codelibs.core.util.StringUtil;
import org.codelibs.fess.Constants;
import org.codelibs.fess.action.base.FessAdminAction;
import org.codelibs.fess.crud.CommonConstants;
import org.codelibs.fess.crud.CrudMessageException;
import org.codelibs.fess.crud.util.SAStrutsUtil;
@ -42,7 +42,6 @@ import org.codelibs.fess.service.FavoriteLogService;
import org.codelibs.sastruts.core.annotation.Token;
import org.codelibs.sastruts.core.exception.SSCActionMessagesException;
import org.seasar.framework.beans.util.Beans;
import org.seasar.framework.util.StringUtil;
import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
import org.seasar.struts.exception.ActionMessagesException;
@ -56,7 +55,7 @@ import com.ibm.icu.text.SimpleDateFormat;
public class FavoriteLogAction extends FessAdminAction {
private static final Logger logger = LoggerFactory.getLogger(FavoriteLogAction.class);
// for list
public List<FavoriteLog> favoriteLogItems;
@ -72,14 +71,14 @@ public class FavoriteLogAction extends FessAdminAction {
@Resource
protected FavoriteLogPager favoriteLogPager;
@Resource
protected SystemHelper systemHelper;
public String getHelpLink() {
return systemHelper.getHelpLink("favoriteLog");
}
protected String displayList(final boolean redirect) {
// page navi
favoriteLogItems = favoriteLogService.getFavoriteLogList(favoriteLogPager);
@ -108,8 +107,8 @@ public class FavoriteLogAction extends FessAdminAction {
try {
favoriteLogPager.setCurrentPageNumber(Integer.parseInt(favoriteLogForm.pageNumber));
} catch (final NumberFormatException e) {
if (log.isDebugEnabled()) {
log.debug("Invalid value: " + favoriteLogForm.pageNumber, e);
if (logger.isDebugEnabled()) {
logger.debug("Invalid value: " + favoriteLogForm.pageNumber, e);
}
}
}
@ -234,13 +233,13 @@ public class FavoriteLogAction extends FessAdminAction {
return displayList(true);
} catch (final ActionMessagesException e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw e;
} catch (final CrudMessageException e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw new ActionMessagesException(e.getMessageId(), e.getArgs());
} catch (final Exception e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw new ActionMessagesException("errors.crud_failed_to_create_crud_table");
}
}
@ -255,13 +254,13 @@ public class FavoriteLogAction extends FessAdminAction {
return displayList(true);
} catch (final ActionMessagesException e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw e;
} catch (final CrudMessageException e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw new ActionMessagesException(e.getMessageId(), e.getArgs());
} catch (final Exception e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw new ActionMessagesException("errors.crud_failed_to_update_crud_table");
}
}
@ -289,13 +288,13 @@ public class FavoriteLogAction extends FessAdminAction {
return displayList(true);
} catch (final ActionMessagesException e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw e;
} catch (final CrudMessageException e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw new ActionMessagesException(e.getMessageId(), e.getArgs());
} catch (final Exception e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw new ActionMessagesException("errors.crud_failed_to_delete_crud_table");
}
}
@ -344,7 +343,6 @@ public class FavoriteLogAction extends FessAdminAction {
return keys;
}
@Execute(validator = false, input = "error.jsp")
public String deleteall() {
@ -366,7 +364,7 @@ public class FavoriteLogAction extends FessAdminAction {
favoriteLogService.dump(writer, favoriteLogPager);
writer.flush();
} catch (final Exception e) {
log.error("Could not create FessSearchLog.csv.", e);
logger.error("Could not create FessSearchLog.csv.", e);
throw new SSCActionMessagesException(e, "errors.could_not_create_search_log_csv");
} finally {
IOUtils.closeQuietly(writer);

View file

@ -18,31 +18,55 @@ package org.codelibs.fess.action.admin;
import java.time.LocalDateTime;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codelibs.fess.action.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.action.admin.BsFileCrawlingConfigAction;
import org.codelibs.fess.crud.util.SAStrutsUtil;
import org.codelibs.fess.db.exentity.FileCrawlingConfig;
import org.codelibs.fess.db.exentity.LabelType;
import org.codelibs.fess.db.exentity.RoleType;
import org.codelibs.fess.form.admin.FileCrawlingConfigForm;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.pager.FileCrawlingConfigPager;
import org.codelibs.fess.service.FailureUrlService;
import org.codelibs.fess.service.FileCrawlingConfigService;
import org.codelibs.fess.service.LabelTypeService;
import org.codelibs.fess.service.RoleTypeService;
import org.codelibs.sastruts.core.annotation.Token;
import org.codelibs.sastruts.core.exception.SSCActionMessagesException;
import org.seasar.framework.beans.util.Beans;
import org.seasar.framework.util.StringUtil;
import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
import org.seasar.struts.exception.ActionMessagesException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FileCrawlingConfigAction extends BsFileCrawlingConfigAction {
private static final long serialVersionUID = 1L;
public class FileCrawlingConfigAction extends FessAdminAction {
private static final Log log = LogFactory.getLog(FileCrawlingConfigAction.class);
private static final Logger logger = LoggerFactory.getLogger(FileCrawlingConfigAction.class);
// for list
public List<FileCrawlingConfig> fileCrawlingConfigItems;
// for edit/confirm/delete
@ActionForm
@Resource
protected FileCrawlingConfigForm fileCrawlingConfigForm;
@Resource
protected FileCrawlingConfigService fileCrawlingConfigService;
@Resource
protected FileCrawlingConfigPager fileCrawlingConfigPager;
@Resource
protected RoleTypeService roleTypeService;
@ -59,8 +83,201 @@ public class FileCrawlingConfigAction extends BsFileCrawlingConfigAction {
public String getHelpLink() {
return systemHelper.getHelpLink("fileCrawlingConfig");
}
protected String displayList(final boolean redirect) {
// page navi
fileCrawlingConfigItems = fileCrawlingConfigService.getFileCrawlingConfigList(fileCrawlingConfigPager);
@Override
// restore from pager
Beans.copy(fileCrawlingConfigPager, fileCrawlingConfigForm.searchParams).excludes(CommonConstants.PAGER_CONVERSION_RULE)
.execute();
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(fileCrawlingConfigForm.pageNumber)) {
try {
fileCrawlingConfigPager.setCurrentPageNumber(Integer.parseInt(fileCrawlingConfigForm.pageNumber));
} catch (final NumberFormatException e) {
if (logger.isDebugEnabled()) {
logger.debug("Invalid value: " + fileCrawlingConfigForm.pageNumber, e);
}
}
}
return displayList(false);
}
@Execute(validator = false, input = "error.jsp")
public String search() {
Beans.copy(fileCrawlingConfigForm.searchParams, fileCrawlingConfigPager).excludes(CommonConstants.PAGER_CONVERSION_RULE)
.execute();
return displayList(false);
}
@Execute(validator = false, input = "error.jsp")
public String reset() {
fileCrawlingConfigPager.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 (fileCrawlingConfigForm.crudMode != CommonConstants.CONFIRM_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.CONFIRM_MODE,
fileCrawlingConfigForm.crudMode });
}
loadFileCrawlingConfig();
return "confirm.jsp";
}
@Token(save = true, validate = false)
@Execute(validator = false, input = "error.jsp")
public String createpage() {
// page navi
fileCrawlingConfigForm.initialize();
fileCrawlingConfigForm.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 (fileCrawlingConfigForm.crudMode != CommonConstants.EDIT_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.EDIT_MODE,
fileCrawlingConfigForm.crudMode });
}
loadFileCrawlingConfig();
return "edit.jsp";
}
@Token(save = true, validate = false)
@Execute(validator = false, input = "error.jsp")
public String editfromconfirm() {
fileCrawlingConfigForm.crudMode = CommonConstants.EDIT_MODE;
loadFileCrawlingConfig();
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 (fileCrawlingConfigForm.crudMode != CommonConstants.DELETE_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.DELETE_MODE,
fileCrawlingConfigForm.crudMode });
}
loadFileCrawlingConfig();
return "confirm.jsp";
}
@Token(save = true, validate = false)
@Execute(validator = false, input = "error.jsp")
public String deletefromconfirm() {
fileCrawlingConfigForm.crudMode = CommonConstants.DELETE_MODE;
loadFileCrawlingConfig();
return "confirm.jsp";
}
@Token(save = false, validate = true)
@Execute(validator = true, input = "edit.jsp")
public String create() {
try {
final FileCrawlingConfig fileCrawlingConfig = createFileCrawlingConfig();
fileCrawlingConfigService.store(fileCrawlingConfig);
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 FileCrawlingConfig fileCrawlingConfig = createFileCrawlingConfig();
fileCrawlingConfigService.store(fileCrawlingConfig);
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", fileCrawlingConfigForm.id);
return keys;
}
protected void loadFileCrawlingConfig() {
final FileCrawlingConfig fileCrawlingConfig = fileCrawlingConfigService.getFileCrawlingConfig(createKeyMap());
@ -77,7 +294,6 @@ public class FileCrawlingConfigAction extends BsFileCrawlingConfigAction {
}
}
@Override
protected FileCrawlingConfig createFileCrawlingConfig() {
FileCrawlingConfig fileCrawlingConfig;
final String username = systemHelper.getUsername();
@ -100,7 +316,6 @@ public class FileCrawlingConfigAction extends BsFileCrawlingConfigAction {
return fileCrawlingConfig;
}
@Override
@Execute(validator = false, input = "error.jsp")
public String delete() {
if (fileCrawlingConfigForm.crudMode != CommonConstants.DELETE_MODE) {
@ -127,13 +342,13 @@ public class FileCrawlingConfigAction extends BsFileCrawlingConfigAction {
return displayList(true);
} catch (final ActionMessagesException e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw e;
} catch (final CrudMessageException e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw new SSCActionMessagesException(e, e.getMessageId(), e.getArgs());
} catch (final Exception e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
throw new SSCActionMessagesException(e, "errors.crud_failed_to_delete_crud_table");
}
}