migrating preview actions to lasta way

This commit is contained in:
jflute 2015-08-02 21:44:59 +09:00
parent 65300af2b7
commit bb2ae07102
10 changed files with 509 additions and 437 deletions

View file

@ -1,326 +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.KeyMatch;
import org.codelibs.fess.exception.SSCActionMessagesException;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.pager.KeyMatchPager;
import org.codelibs.fess.service.KeyMatchService;
import org.codelibs.fess.util.ComponentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class KeyMatchAction extends FessAdminAction {
private static final Logger logger = LoggerFactory.getLogger(KeyMatchAction.class);
// for list
public List<KeyMatch> keyMatchItems;
// for edit/confirm/delete
//@ActionForm
@Resource
protected KeyMatchForm keyMatchForm;
@Resource
protected KeyMatchService keyMatchService;
@Resource
protected KeyMatchPager keyMatchPager;
@Resource
protected SystemHelper systemHelper;
public String getHelpLink() {
return systemHelper.getHelpLink("keyMatch");
}
protected String displayList(final boolean redirect) {
// page navi
keyMatchItems = keyMatchService.getKeyMatchList(keyMatchPager);
// restore from pager
BeanUtil.copyBeanToBean(keyMatchPager, keyMatchForm.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(keyMatchForm.pageNumber)) {
try {
keyMatchPager.setCurrentPageNumber(Integer.parseInt(keyMatchForm.pageNumber));
} catch (final NumberFormatException e) {
if (logger.isDebugEnabled()) {
logger.debug("Invalid value: " + keyMatchForm.pageNumber, e);
}
}
}
return displayList(false);
}
//@Execute(validator = false, input = "error.jsp")
public String search() {
BeanUtil.copyBeanToBean(keyMatchForm.searchParams, keyMatchPager, option -> option.exclude(CommonConstants.PAGER_CONVERSION_RULE));
return displayList(false);
}
//@Execute(validator = false, input = "error.jsp")
public String reset() {
keyMatchPager.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 (keyMatchForm.crudMode != CommonConstants.CONFIRM_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.CONFIRM_MODE,
keyMatchForm.crudMode });
}
loadKeyMatch();
return "confirm.jsp";
}
@Token(save = true, validate = false)
//@Execute(validator = false, input = "error.jsp")
public String createpage() {
// page navi
keyMatchForm.initialize();
keyMatchForm.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 (keyMatchForm.crudMode != CommonConstants.EDIT_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.EDIT_MODE, keyMatchForm.crudMode });
}
loadKeyMatch();
return "edit.jsp";
}
@Token(save = true, validate = false)
//@Execute(validator = false, input = "error.jsp")
public String editfromconfirm() {
keyMatchForm.crudMode = CommonConstants.EDIT_MODE;
loadKeyMatch();
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 (keyMatchForm.crudMode != CommonConstants.DELETE_MODE) {
throw new ActionMessagesException("errors.crud_invalid_mode",
new Object[] { CommonConstants.DELETE_MODE, keyMatchForm.crudMode });
}
loadKeyMatch();
return "confirm.jsp";
}
@Token(save = true, validate = false)
//@Execute(validator = false, input = "error.jsp")
public String deletefromconfirm() {
keyMatchForm.crudMode = CommonConstants.DELETE_MODE;
loadKeyMatch();
return "confirm.jsp";
}
protected Map<String, String> createKeyMap() {
final Map<String, String> keys = new HashMap<String, String>();
keys.put("id", keyMatchForm.id);
return keys;
}
protected void loadKeyMatch() {
final KeyMatch keyMatch = keyMatchService.getKeyMatch(createKeyMap());
if (keyMatch == null) {
// throw an exception
throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { keyMatchForm.id });
}
BeanUtil.copyBeanToBean(keyMatch, keyMatchForm, option -> option.exclude("searchParams", "mode"));
}
protected KeyMatch createKeyMatch() {
KeyMatch keyMatch;
final String username = systemHelper.getUsername();
final long currentTime = systemHelper.getCurrentTimeAsLong();
if (keyMatchForm.crudMode == CommonConstants.EDIT_MODE) {
keyMatch = keyMatchService.getKeyMatch(createKeyMap());
if (keyMatch == null) {
// throw an exception
throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { keyMatchForm.id });
}
} else {
keyMatch = new KeyMatch();
keyMatch.setCreatedBy(username);
keyMatch.setCreatedTime(currentTime);
}
keyMatch.setUpdatedBy(username);
keyMatch.setUpdatedTime(currentTime);
BeanUtil.copyBeanToBean(keyMatchForm, keyMatch, option -> option.exclude(CommonConstants.COMMON_CONVERSION_RULE));
return keyMatch;
}
@Token(save = false, validate = true)
//@Execute(validator = true, input = "edit.jsp")
public String create() {
ComponentUtil.getKeyMatchHelper().update();
try {
final KeyMatch keyMatch = createKeyMatch();
keyMatchService.store(keyMatch);
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 KeyMatch keyMatch = createKeyMatch();
keyMatchService.store(keyMatch);
SAStrutsUtil.addSessionMessage("success.crud_update_crud_table");
final String result = displayList(true);
ComponentUtil.getKeyMatchHelper().update();
return result;
} 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");
}
}
//@Execute(validator = false, input = "error.jsp")
public String delete() {
if (keyMatchForm.crudMode != CommonConstants.DELETE_MODE) {
throw new SSCActionMessagesException("errors.crud_invalid_mode", new Object[] { CommonConstants.DELETE_MODE,
keyMatchForm.crudMode });
}
try {
final KeyMatch keyMatch = keyMatchService.getKeyMatch(createKeyMap());
if (keyMatch == null) {
// throw an exception
throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { keyMatchForm.id });
}
keyMatchService.delete(keyMatch);
SAStrutsUtil.addSessionMessage("success.crud_delete_crud_table");
ComponentUtil.getKeyMatchHelper().update();
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");
}
}
}

View file

@ -14,7 +14,7 @@
* governing permissions and limitations under the License.
*/
package org.codelibs.fess.app.web.admin;
package org.codelibs.fess.app.web.admin.design;
import java.io.File;
import java.io.FileInputStream;
@ -38,13 +38,11 @@ import org.codelibs.fess.annotation.Token;
import org.codelibs.fess.app.web.base.FessAdminAction;
import org.codelibs.fess.crud.util.SAStrutsUtil;
import org.codelibs.fess.helper.SystemHelper;
import org.lastaflute.di.util.LdiFileUtil;
import org.lastaflute.web.Execute;
import org.lastaflute.web.callback.ActionRuntime;
import org.lastaflute.web.response.ActionResponse;
import org.lastaflute.web.response.HtmlResponse;
import org.lastaflute.web.response.StreamResponse;
import org.lastaflute.web.servlet.request.ResponseManager;
import org.lastaflute.web.util.LaServletContextUtil;
import org.lastaflute.web.validation.VaErrorHook;
import org.slf4j.Logger;
@ -55,39 +53,65 @@ import org.slf4j.LoggerFactory;
* @author jflute
*/
public class AdminDesignAction extends FessAdminAction implements Serializable {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(AdminDesignAction.class);
// ===================================================================================
// Attribute
// =========
@Resource
private ResponseManager responseManager;
@Resource
private DynamicProperties crawlerProperties;
@Resource
private SystemHelper systemHelper;
// ===================================================================================
// Hook
// ======
@Override
public ActionResponse hookBefore(ActionRuntime runtime) {
checkEditorStatus(runtime);
return super.hookBefore(runtime);
}
private void checkEditorStatus(ActionRuntime runtime) {
if (cannotEdit()) {
throwValidationError(messages -> messages.addErrorsDesignEditorDisabled(GLOBAL), toMainHtml());
}
}
@Override
public void hookFinally(ActionRuntime runtime) {
super.hookFinally(runtime);
if (runtime.isForwardToHtml()) {
runtime.registerData("fileNameItems", loadFileNameItems());
runtime.registerData("editable", cannotEdit());
}
}
private List<String> loadFileNameItems() {
final File baseDir = new File(getServletContext().getRealPath("/"));
final List<String> fileNameItems = new ArrayList<String>();
final List<File> fileList = getAccessibleFileList(baseDir);
final int length = baseDir.getAbsolutePath().length();
for (final File file : fileList) {
fileNameItems.add(file.getAbsolutePath().substring(length));
}
return fileNameItems;
}
// ===================================================================================
// Execute
// =======
@Token(save = true, validate = false)
@Execute
public HtmlResponse index() {
return asHtml(path_AdminDesign_AdminDesignJsp).useForm(AdminDesignForm.class);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse back() {
return asHtml(path_AdminDesign_AdminDesignJsp).useForm(AdminDesignForm.class);
return asHtml(path_AdminDesign_AdminDesignJsp).useForm(DesignForm.class);
}
@Execute
public HtmlResponse upload(AdminDesignForm form) {
validate(form, messages -> {}, toMainHtml());
public HtmlResponse upload(DesignForm form) {
validate(form, messages -> {} , toMainHtml());
final String uploadedFileName = form.designFile.getFileName();
String fileName = form.designFileName;
if (StringUtil.isBlank(fileName)) {
@ -131,8 +155,9 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
}
try {
LdiFileUtil.write(uploadFile.getAbsolutePath(), form.designFile.getFileData());
SAStrutsUtil.addSessionMessage("success.upload_design_file", fileName);
write(uploadFile.getAbsolutePath(), form.designFile.getFileData());
final String currentFileName = fileName;
saveInfo(messages -> messages.addSuccessUploadDesignFile(GLOBAL, currentFileName));
} catch (final Exception e) {
logger.error("Failed to write an image file: {}", fileName, e);
throwValidationError(messages -> messages.addErrorsFailedToWriteDesignImageFile(GLOBAL), toMainHtml());
@ -153,54 +178,8 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
return false;
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse edit(AdminDesignForm form) {
final String jspType = "view";
final File jspFile = getJspFile(form, jspType);
try {
form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
} catch (final UnsupportedEncodingException e) {
throw new FessSystemException("Invalid encoding", e);
}
return asHtml(path_AdminDesign_AdminDesignEditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editAsUseDefault(AdminDesignForm form) {
final String jspType = "orig/view";
final File jspFile = getJspFile(form, jspType);
try {
form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
} catch (final UnsupportedEncodingException e) {
throw new FessSystemException("Invalid encoding", e);
}
return asHtml(path_AdminDesign_AdminDesignEditJsp);
}
@Token(save = false, validate = true)
@Execute
public HtmlResponse update(AdminDesignForm form) {
final String jspType = "view";
final File jspFile = getJspFile(form, jspType);
if (form.content == null) {
form.content = StringUtil.EMPTY;
}
try {
LdiFileUtil.write(jspFile.getAbsolutePath(), form.content.getBytes(Constants.UTF_8));
SAStrutsUtil.addSessionMessage("success.update_design_jsp_file", systemHelper.getDesignJspFileName(form.fileName));
} catch (final Exception e) {
logger.error("Failed to update {}", form.fileName, e);
throwValidationError(messages -> messages.addErrorsFailedToUpdateJspFile(GLOBAL), toMainHtml());
}
return redirect(getClass());
}
@Execute
public StreamResponse download(AdminDesignForm form) {
public StreamResponse download(DesignForm form) {
final File file = getTargetFile(form);
if (file == null) {
throwValidationError(messages -> messages.addErrorsTargetFileDoesNotExist(GLOBAL, form.fileName), toMainHtml());
@ -217,7 +196,7 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
@Token(save = false, validate = true)
@Execute
public HtmlResponse delete(AdminDesignForm form) {
public HtmlResponse delete(DesignForm form) {
final File file = getTargetFile(form);
if (file == null) {
throwValidationError(messages -> messages.addErrorsTargetFileDoesNotExist(GLOBAL, form.fileName), toMainHtml());
@ -230,45 +209,65 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
return redirect(getClass());
}
// ===================================================================================
// Hook
// ======
@Override
public ActionResponse hookBefore(ActionRuntime runtime) {
checkEditorStatus(runtime);
return super.hookBefore(runtime);
// -----------------------------------------------------
// Edit
// ------
@Token(save = true, validate = false)
@Execute
public HtmlResponse edit(DesignEditForm form) {
final String jspType = "view";
final File jspFile = getJspFile(form.fileName, jspType);
try {
form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
} catch (final UnsupportedEncodingException e) {
throw new FessSystemException("Invalid encoding", e);
}
return asHtml(path_AdminDesign_AdminDesignEditJsp);
}
private void checkEditorStatus(ActionRuntime runtime) {
if (cannotEdit()) {
throwValidationError(messages -> messages.addErrorsDesignEditorDisabled(GLOBAL), toMainHtml());
@Token(save = true, validate = false)
@Execute
public HtmlResponse editAsUseDefault(DesignEditForm form) {
final String jspType = "orig/view";
final File jspFile = getJspFile(form.fileName, jspType);
try {
form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
} catch (final UnsupportedEncodingException e) {
throw new FessSystemException("Invalid encoding", e);
}
return asHtml(path_AdminDesign_AdminDesignEditJsp);
}
@Override
public void hookFinally(ActionRuntime runtime) {
super.hookFinally(runtime);
if (runtime.isForwardToHtml()) {
runtime.registerData("fileNameItems", loadFileNameItems());
runtime.registerData("editable", cannotEdit());
@Token(save = false, validate = true)
@Execute
public HtmlResponse update(DesignEditForm form) {
final String jspType = "view";
final File jspFile = getJspFile(form.fileName, jspType);
if (form.content == null) {
form.content = StringUtil.EMPTY;
}
try {
write(jspFile.getAbsolutePath(), form.content.getBytes(Constants.UTF_8));
saveInfo(messages -> messages.addSuccessUpdateDesignJspFile(GLOBAL, systemHelper.getDesignJspFileName(form.fileName)));
} catch (final Exception e) {
logger.error("Failed to update {}", form.fileName, e);
throwValidationError(messages -> messages.addErrorsFailedToUpdateJspFile(GLOBAL), toMainHtml());
}
return redirect(getClass());
}
private List<String> loadFileNameItems() {
final File baseDir = new File(getServletContext().getRealPath("/"));
final List<String> fileNameItems = new ArrayList<String>();
final List<File> fileList = getAccessibleFileList(baseDir);
final int length = baseDir.getAbsolutePath().length();
for (final File file : fileList) {
fileNameItems.add(file.getAbsolutePath().substring(length));
}
return fileNameItems;
@Token(save = true, validate = false)
@Execute
public HtmlResponse back() {
return asHtml(path_AdminDesign_AdminDesignJsp).useForm(DesignForm.class);
}
// ===================================================================================
// Assist Logic
// ============
private File getTargetFile(AdminDesignForm form) {
private File getTargetFile(DesignForm form) {
final File baseDir = new File(getServletContext().getRealPath("/"));
final File targetFile = new File(getServletContext().getRealPath(form.fileName));
final List<File> fileList = getAccessibleFileList(baseDir);
@ -293,8 +292,8 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
return fileList;
}
private File getJspFile(final AdminDesignForm form, final String jspType) {
final String jspFileName = systemHelper.getDesignJspFileName(form.fileName);
private File getJspFile(String fileName, String jspType) {
final String jspFileName = systemHelper.getDesignJspFileName(fileName);
if (jspFileName == null) {
throwValidationError(messages -> messages.addErrorsInvalidDesignJspFileName(GLOBAL), toMainHtml());
}
@ -310,7 +309,7 @@ public class AdminDesignAction extends FessAdminAction implements Serializable {
return asHtml(path_AdminDesign_AdminDesignJsp);
};
}
private boolean cannotEdit() {
return Constants.FALSE.equals(crawlerProperties.getProperty(Constants.WEB_DESIGN_EDITOR_PROPERTY, Constants.TRUE));
}

View file

@ -0,0 +1,27 @@
/*
* 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.design;
/**
* @author codelibs
* @author jflute
*/
public class DesignEditForm {
public String fileName;
public String content;
}

View file

@ -14,17 +14,20 @@
* governing permissions and limitations under the License.
*/
package org.codelibs.fess.app.web.admin;
package org.codelibs.fess.app.web.admin.design;
import java.io.Serializable;
import org.codelibs.fess.mylasta.tentative.Required;
import org.lastaflute.web.ruts.multipart.MultipartFormFile;
public class AdminDesignForm implements Serializable {
public class DesignForm implements Serializable {
private static final long serialVersionUID = 1L;
// TODO jflute target needed? (2015/07/25)
//@Required(target = "upload")
@Required
public MultipartFormFile designFile;
public String designFileName;
@ -32,7 +35,4 @@ public class AdminDesignForm implements Serializable {
// TODO jflute unneeded? no validator at the method (2015/07/25)
//@Required(target = "edit,editAsUseDefault,download,delete")
public String fileName;
public String content;
}

View file

@ -0,0 +1,285 @@
/*
* 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.keymatch;
import java.util.HashMap;
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.util.SAStrutsUtil;
import org.codelibs.fess.es.exentity.KeyMatch;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.pager.KeyMatchPager;
import org.codelibs.fess.service.KeyMatchService;
import org.codelibs.fess.util.ComponentUtil;
import org.lastaflute.web.Execute;
import org.lastaflute.web.callback.ActionRuntime;
import org.lastaflute.web.response.HtmlResponse;
import org.lastaflute.web.response.render.RenderData;
/**
* @author codelibs
* @author jflute
*/
public class AdminKeyMatchAction extends FessAdminAction {
// ===================================================================================
// Attribute
// =========
@Resource
private KeyMatchService keyMatchService;
@Resource
private KeyMatchPager keyMatchPager;
@Resource
private SystemHelper systemHelper;
// ===================================================================================
// Hook
// ======
@Override
protected void setupHtmlData(ActionRuntime runtime) {
super.setupHtmlData(runtime);
runtime.registerData("helpLink", getHelpLink());
}
private String getHelpLink() {
return systemHelper.getHelpLink("keyMatch");
}
// ===================================================================================
// Search Execute
// ==============
@Execute
public HtmlResponse index(KeyMatchSearchForm form) {
return asHtml(path_AdminKeyMatch_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse list(Integer pageNumber, KeyMatchSearchForm form) {
keyMatchPager.setCurrentPageNumber(pageNumber);
return asHtml(path_AdminKeyMatch_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse search(KeyMatchSearchForm form) {
BeanUtil.copyBeanToBean(form.searchParams, keyMatchPager, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE));
return asHtml(path_AdminKeyMatch_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse reset(KeyMatchSearchForm form) {
keyMatchPager.clear();
return asHtml(path_AdminKeyMatch_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse back(KeyMatchSearchForm form) {
return asHtml(path_AdminKeyMatch_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
protected void searchPaging(RenderData data, KeyMatchSearchForm form) {
data.register("keyMatchItems", keyMatchService.getKeyMatchList(keyMatchPager)); // page navi
// restore from pager
BeanUtil.copyBeanToBean(keyMatchPager, form.searchParams, op -> op.exclude(CommonConstants.PAGER_CONVERSION_RULE));
}
// ===================================================================================
// Edit Execute
// ============
// -----------------------------------------------------
// Entry Page
// ----------
@Token(save = true, validate = false)
@Execute
public HtmlResponse createpage(KeyMatchEditForm form) {
form.crudMode = CommonConstants.CREATE_MODE;
return asHtml(path_AdminKeyMatch_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editpage(int crudMode, String id, KeyMatchEditForm form) {
verifyCrudMode(form, CommonConstants.EDIT_MODE);
loadKeyMatch(form);
return asHtml(path_AdminKeyMatch_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editagain(KeyMatchEditForm form) {
return asHtml(path_AdminKeyMatch_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editfromconfirm(KeyMatchEditForm form) {
form.crudMode = CommonConstants.EDIT_MODE;
loadKeyMatch(form);
return asHtml(path_AdminKeyMatch_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse deletepage(int crudMode, String id, KeyMatchEditForm form) {
verifyCrudMode(form, CommonConstants.DELETE_MODE);
loadKeyMatch(form);
return asHtml(path_AdminKeyMatch_ConfirmJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse deletefromconfirm(KeyMatchEditForm form) {
form.crudMode = CommonConstants.DELETE_MODE;
loadKeyMatch(form);
return asHtml(path_AdminKeyMatch_ConfirmJsp);
}
// -----------------------------------------------------
// Confirm
// -------
@Execute
public HtmlResponse confirmpage(int crudMode, String id, KeyMatchEditForm form) {
verifyCrudMode(form, CommonConstants.CONFIRM_MODE);
loadKeyMatch(form);
return asHtml(path_AdminKeyMatch_ConfirmJsp);
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromcreate(KeyMatchEditForm form) {
validate(form, messages -> {} , () -> {
return asHtml(path_AdminKeyMatch_EditJsp);
});
return asHtml(path_AdminKeyMatch_ConfirmJsp);
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromupdate(KeyMatchEditForm form) {
validate(form, messages -> {} , () -> {
return asHtml(path_AdminKeyMatch_EditJsp);
});
return asHtml(path_AdminKeyMatch_ConfirmJsp);
}
// -----------------------------------------------------
// Actually Crud
// -------------
@Token(save = false, validate = true)
@Execute
public HtmlResponse create(KeyMatchEditForm form) {
validate(form, messages -> {} , () -> {
return asHtml(path_AdminKeyMatch_EditJsp);
});
keyMatchService.store(createKeyMatch(form));
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
ComponentUtil.getKeyMatchHelper().update();
return redirect(getClass());
}
@Token(save = false, validate = true)
@Execute
public HtmlResponse update(KeyMatchEditForm form) {
validate(form, messages -> {} , () -> {
return asHtml(path_AdminKeyMatch_EditJsp);
});
keyMatchService.store(createKeyMatch(form));
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
ComponentUtil.getKeyMatchHelper().update();
return redirect(getClass());
}
@Execute
public HtmlResponse delete(KeyMatchEditForm form) {
verifyCrudMode(form, CommonConstants.DELETE_MODE);
keyMatchService.delete(getKeyMatch(form));
SAStrutsUtil.addSessionMessage("success.crud_delete_crud_table");
ComponentUtil.getKeyMatchHelper().update();
return redirect(getClass());
}
// ===================================================================================
// Assist Logic
// ============
protected void verifyCrudMode(KeyMatchEditForm form, int expectedMode) {
if (form.crudMode != expectedMode) {
throwValidationError(messages -> {
messages.addErrorsCrudInvalidMode(GLOBAL, String.valueOf(expectedMode), String.valueOf(form.crudMode));
} , () -> {
return asHtml(path_AdminKeyMatch_EditJsp);
});
}
}
// -----------------------------------------------------
// Key Match
// ---------
protected void loadKeyMatch(KeyMatchEditForm form) {
final KeyMatch keyMatch = getKeyMatch(form);
// TODO jflute modeがいない...crudModeの間違い (2015/08/02)
BeanUtil.copyBeanToBean(keyMatch, form, option -> option.exclude("mode"));
}
protected KeyMatch getKeyMatch(KeyMatchEditForm form) {
final KeyMatch keyMatch = keyMatchService.getKeyMatch(createKeyMap(form));
if (keyMatch == null) {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), () -> {
return asHtml(path_AdminKeyMatch_EditJsp);
});
}
return keyMatch;
}
protected KeyMatch createKeyMatch(KeyMatchEditForm form) {
KeyMatch keyMatch;
final String username = systemHelper.getUsername();
final long currentTime = systemHelper.getCurrentTimeAsLong();
if (form.crudMode == CommonConstants.EDIT_MODE) {
keyMatch = getKeyMatch(form);
} else {
keyMatch = new KeyMatch();
keyMatch.setCreatedBy(username);
keyMatch.setCreatedTime(currentTime);
}
keyMatch.setUpdatedBy(username);
keyMatch.setUpdatedTime(currentTime);
BeanUtil.copyBeanToBean(form, keyMatch, op -> op.exclude(CommonConstants.COMMON_CONVERSION_RULE));
return keyMatch;
}
protected Map<String, String> createKeyMap(KeyMatchEditForm form) {
final Map<String, String> keys = new HashMap<String, String>();
keys.put("id", form.id);
return keys;
}
}

View file

@ -14,7 +14,7 @@
* governing permissions and limitations under the License.
*/
package org.codelibs.fess.app.web.admin;
package org.codelibs.fess.app.web.admin.keymatch;
import java.io.Serializable;
import java.util.HashMap;
@ -22,22 +22,17 @@ import java.util.Map;
import org.codelibs.fess.util.ComponentUtil;
public class KeyMatchForm implements Serializable {
/**
* @author codelibs
* @author jflute
*/
public class KeyMatchEditForm implements Serializable {
private static final long serialVersionUID = 1L;
//@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.keymatch;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @author codelibs
* @author jflute
*/
public class KeyMatchSearchForm implements Serializable {
private static final long serialVersionUID = 1L;
public Map<String, String> searchParams = new HashMap<String, String>();
}

View file

@ -15,6 +15,29 @@
*/
package org.codelibs.fess.app.web.base;
import javax.annotation.Resource;
import org.codelibs.fess.mylasta.action.FessMessages;
import org.lastaflute.di.util.LdiFileUtil;
import org.lastaflute.web.servlet.session.SessionManager;
import org.lastaflute.web.validation.VaMessenger;
/**
* @author codelibs
* @author jflute
*/
public abstract class FessAdminAction extends FessBaseAction {
@Resource
private SessionManager sessionManager;
protected void write(String path, byte[] data) {
LdiFileUtil.write(path, data);
}
protected void saveInfo(VaMessenger<FessMessages> validationMessagesLambda) {
FessMessages messages = createMessages();
validationMessagesLambda.message(messages);
sessionManager.info().save(messages);
}
}

View file

@ -104,7 +104,14 @@ public abstract class FessBaseAction extends TypicalAction // has several interf
@Override
public void hookFinally(ActionRuntime runtime) {
super.hookFinally(runtime);
if (runtime.isForwardToHtml()) {
setupHtmlData(runtime);
}
}
protected void setupHtmlData(ActionRuntime runtime) {
}
// ===================================================================================
// Access Context

View file

@ -0,0 +1,30 @@
/*
* Copyright 2012 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.mylasta.tentative;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* TODO jflute LastaFluteで対応するまで暫定
* @author jflute
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Required {
}