|
@@ -16,9 +16,6 @@
|
|
|
|
|
|
package org.codelibs.fess.app.web.admin.fileconfig;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import org.codelibs.fess.Constants;
|
|
@@ -28,9 +25,13 @@ import org.codelibs.fess.app.service.FileConfigService;
|
|
|
import org.codelibs.fess.app.service.LabelTypeService;
|
|
|
import org.codelibs.fess.app.service.RoleTypeService;
|
|
|
import org.codelibs.fess.app.web.CrudMode;
|
|
|
+import org.codelibs.fess.app.web.admin.fileconfig.CreateForm;
|
|
|
+import org.codelibs.fess.app.web.admin.fileconfig.EditForm;
|
|
|
+import org.codelibs.fess.app.web.admin.fileconfig.SearchForm;
|
|
|
import org.codelibs.fess.app.web.base.FessAdminAction;
|
|
|
import org.codelibs.fess.es.exentity.FileConfig;
|
|
|
import org.codelibs.fess.helper.SystemHelper;
|
|
|
+import org.dbflute.optional.OptionalEntity;
|
|
|
import org.lastaflute.web.Execute;
|
|
|
import org.lastaflute.web.callback.ActionRuntime;
|
|
|
import org.lastaflute.web.response.HtmlResponse;
|
|
@@ -51,11 +52,11 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
@Resource
|
|
|
private FileConfigPager fileConfigPager;
|
|
|
@Resource
|
|
|
- private SystemHelper systemHelper;
|
|
|
+ private RoleTypeService roleTypeService;
|
|
|
@Resource
|
|
|
- protected RoleTypeService roleTypeService;
|
|
|
+ private LabelTypeService labelTypeService;
|
|
|
@Resource
|
|
|
- protected LabelTypeService labelTypeService;
|
|
|
+ private SystemHelper systemHelper;
|
|
|
|
|
|
// ===================================================================================
|
|
|
// Hook
|
|
@@ -70,14 +71,14 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
// Search Execute
|
|
|
// ==============
|
|
|
@Execute
|
|
|
- public HtmlResponse index(final FileConfigSearchForm form) {
|
|
|
+ public HtmlResponse index(final SearchForm form) {
|
|
|
return asHtml(path_AdminFileconfig_IndexJsp).renderWith(data -> {
|
|
|
searchPaging(data, form);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@Execute
|
|
|
- public HtmlResponse list(final Integer pageNumber, final FileConfigSearchForm form) {
|
|
|
+ public HtmlResponse list(final Integer pageNumber, final SearchForm form) {
|
|
|
fileConfigPager.setCurrentPageNumber(pageNumber);
|
|
|
return asHtml(path_AdminFileconfig_IndexJsp).renderWith(data -> {
|
|
|
searchPaging(data, form);
|
|
@@ -85,15 +86,15 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
}
|
|
|
|
|
|
@Execute
|
|
|
- public HtmlResponse search(final FileConfigSearchForm form) {
|
|
|
- copyBeanToBean(form.searchParams, fileConfigPager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
|
|
|
+ public HtmlResponse search(final SearchForm form) {
|
|
|
+ copyBeanToBean(form, fileConfigPager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
|
|
|
return asHtml(path_AdminFileconfig_IndexJsp).renderWith(data -> {
|
|
|
searchPaging(data, form);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@Execute
|
|
|
- public HtmlResponse reset(final FileConfigSearchForm form) {
|
|
|
+ public HtmlResponse reset(final SearchForm form) {
|
|
|
fileConfigPager.clear();
|
|
|
return asHtml(path_AdminFileconfig_IndexJsp).renderWith(data -> {
|
|
|
searchPaging(data, form);
|
|
@@ -101,17 +102,17 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
}
|
|
|
|
|
|
@Execute
|
|
|
- public HtmlResponse back(final FileConfigSearchForm form) {
|
|
|
+ public HtmlResponse back(final SearchForm form) {
|
|
|
return asHtml(path_AdminFileconfig_IndexJsp).renderWith(data -> {
|
|
|
searchPaging(data, form);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- protected void searchPaging(final RenderData data, final FileConfigSearchForm form) {
|
|
|
+ protected void searchPaging(final RenderData data, final SearchForm form) {
|
|
|
data.register("fileConfigItems", fileConfigService.getFileConfigList(fileConfigPager)); // page navi
|
|
|
|
|
|
// restore from pager
|
|
|
- copyBeanToBean(fileConfigPager, form.searchParams, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
|
|
|
+ copyBeanToBean(fileConfigPager, form, op -> op.include("id"));
|
|
|
}
|
|
|
|
|
|
// ===================================================================================
|
|
@@ -122,21 +123,42 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
// ----------
|
|
|
@Token(save = true, validate = false)
|
|
|
@Execute
|
|
|
- public HtmlResponse createpage(final FileConfigEditForm form) {
|
|
|
- form.initialize();
|
|
|
- form.crudMode = CrudMode.CREATE;
|
|
|
- return asHtml(path_AdminFileconfig_EditJsp).renderWith(data -> {
|
|
|
+ public HtmlResponse createpage() {
|
|
|
+ return asHtml(path_AdminFileconfig_EditJsp).useForm(CreateForm.class, op -> {
|
|
|
+ op.setup(form -> {
|
|
|
+ form.initialize();
|
|
|
+ form.crudMode = CrudMode.CREATE;
|
|
|
+ });
|
|
|
+ }).renderWith(data -> {
|
|
|
+ registerRolesAndLabels(data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Token(save = true, validate = false)
|
|
|
+ @Execute
|
|
|
+ public HtmlResponse editpage(final int crudMode, final String id) {
|
|
|
+ verifyCrudMode(crudMode, CrudMode.EDIT);
|
|
|
+ return asHtml(path_AdminFileconfig_EditJsp).useForm(EditForm.class, op -> {
|
|
|
+ op.setup(form -> {
|
|
|
+ fileConfigService.getFileConfig(id).ifPresent(entity -> {
|
|
|
+ copyBeanToBean(entity, form, copyOp -> {
|
|
|
+ copyOp.excludeNull();
|
|
|
+ });
|
|
|
+ }).orElse(() -> {
|
|
|
+ throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
|
|
+ });
|
|
|
+ form.crudMode = crudMode;
|
|
|
+ });
|
|
|
+ }).renderWith(data -> {
|
|
|
registerRolesAndLabels(data);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@Token(save = true, validate = false)
|
|
|
@Execute
|
|
|
- public HtmlResponse editpage(final int crudMode, final String id, final FileConfigEditForm form) {
|
|
|
- form.crudMode = crudMode;
|
|
|
- form.id = id;
|
|
|
- verifyCrudMode(form, CrudMode.EDIT);
|
|
|
- loadFileConfig(form);
|
|
|
+ public HtmlResponse createagain(final CreateForm form) {
|
|
|
+ verifyCrudMode(form.crudMode, CrudMode.CREATE);
|
|
|
+ validate(form, messages -> {}, toEditHtml());
|
|
|
return asHtml(path_AdminFileconfig_EditJsp).renderWith(data -> {
|
|
|
registerRolesAndLabels(data);
|
|
|
});
|
|
@@ -144,7 +166,9 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
|
|
|
@Token(save = true, validate = false)
|
|
|
@Execute
|
|
|
- public HtmlResponse editagain(final FileConfigEditForm form) {
|
|
|
+ public HtmlResponse editagain(final EditForm form) {
|
|
|
+ verifyCrudMode(form.crudMode, CrudMode.EDIT);
|
|
|
+ validate(form, messages -> {}, toEditHtml());
|
|
|
return asHtml(path_AdminFileconfig_EditJsp).renderWith(data -> {
|
|
|
registerRolesAndLabels(data);
|
|
|
});
|
|
@@ -152,9 +176,15 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
|
|
|
@Token(save = true, validate = false)
|
|
|
@Execute
|
|
|
- public HtmlResponse editfromconfirm(final FileConfigEditForm form) {
|
|
|
+ public HtmlResponse editfromconfirm(final EditForm form) {
|
|
|
+ validate(form, messages -> {}, toEditHtml());
|
|
|
form.crudMode = CrudMode.EDIT;
|
|
|
- loadFileConfig(form);
|
|
|
+ final String id = form.id;
|
|
|
+ fileConfigService.getFileConfig(id).ifPresent(entity -> {
|
|
|
+ copyBeanToBean(entity, form, op -> {});
|
|
|
+ }).orElse(() -> {
|
|
|
+ throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
|
|
+ });
|
|
|
return asHtml(path_AdminFileconfig_EditJsp).renderWith(data -> {
|
|
|
registerRolesAndLabels(data);
|
|
|
});
|
|
@@ -162,21 +192,35 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
|
|
|
@Token(save = true, validate = false)
|
|
|
@Execute
|
|
|
- public HtmlResponse deletepage(final int crudMode, final String id, final FileConfigEditForm form) {
|
|
|
- form.crudMode = crudMode;
|
|
|
- form.id = id;
|
|
|
- verifyCrudMode(form, CrudMode.DELETE);
|
|
|
- loadFileConfig(form);
|
|
|
- return asHtml(path_AdminFileconfig_ConfirmJsp).renderWith(data -> {
|
|
|
+ public HtmlResponse deletepage(final int crudMode, final String id) {
|
|
|
+ verifyCrudMode(crudMode, CrudMode.DELETE);
|
|
|
+ return asHtml(path_AdminFileconfig_ConfirmJsp).useForm(EditForm.class, op -> {
|
|
|
+ op.setup(form -> {
|
|
|
+ fileConfigService.getFileConfig(id).ifPresent(entity -> {
|
|
|
+ copyBeanToBean(entity, form, copyOp -> {
|
|
|
+ copyOp.excludeNull();
|
|
|
+ });
|
|
|
+ }).orElse(() -> {
|
|
|
+ throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
|
|
+ });
|
|
|
+ form.crudMode = crudMode;
|
|
|
+ });
|
|
|
+ }).renderWith(data -> {
|
|
|
registerRolesAndLabels(data);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@Token(save = true, validate = false)
|
|
|
@Execute
|
|
|
- public HtmlResponse deletefromconfirm(final FileConfigEditForm form) {
|
|
|
+ public HtmlResponse deletefromconfirm(final EditForm form) {
|
|
|
+ validate(form, messages -> {}, toEditHtml());
|
|
|
form.crudMode = CrudMode.DELETE;
|
|
|
- loadFileConfig(form);
|
|
|
+ final String id = form.id;
|
|
|
+ fileConfigService.getFileConfig(id).ifPresent(entity -> {
|
|
|
+ copyBeanToBean(entity, form, op -> {});
|
|
|
+ }).orElse(() -> {
|
|
|
+ throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
|
|
+ });
|
|
|
return asHtml(path_AdminFileconfig_ConfirmJsp).renderWith(data -> {
|
|
|
registerRolesAndLabels(data);
|
|
|
});
|
|
@@ -186,25 +230,29 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
// Confirm
|
|
|
// -------
|
|
|
@Execute
|
|
|
- public HtmlResponse confirmpage(final int crudMode, final String id, final FileConfigEditForm form) {
|
|
|
- try {
|
|
|
- form.crudMode = crudMode;
|
|
|
- form.id = id;
|
|
|
- verifyCrudMode(form, CrudMode.CONFIRM);
|
|
|
- loadFileConfig(form);
|
|
|
- return asHtml(path_AdminFileconfig_ConfirmJsp).renderWith(data -> {
|
|
|
- registerRolesAndLabels(data);
|
|
|
+ public HtmlResponse confirmpage(final int crudMode, final String id) {
|
|
|
+ verifyCrudMode(crudMode, CrudMode.CONFIRM);
|
|
|
+ return asHtml(path_AdminFileconfig_ConfirmJsp).useForm(EditForm.class, op -> {
|
|
|
+ op.setup(form -> {
|
|
|
+ fileConfigService.getFileConfig(id).ifPresent(entity -> {
|
|
|
+ copyBeanToBean(entity, form, copyOp -> {
|
|
|
+ copyOp.excludeNull();
|
|
|
+ });
|
|
|
+ form.crudMode = crudMode;
|
|
|
+ }).orElse(() -> {
|
|
|
+ throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
|
|
+ });
|
|
|
});
|
|
|
- } catch (final Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return asHtml(path_AdminFileconfig_ConfirmJsp);
|
|
|
- }
|
|
|
+ }).renderWith(data -> {
|
|
|
+ registerRolesAndLabels(data);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Token(save = false, validate = true, keep = true)
|
|
|
@Execute
|
|
|
- public HtmlResponse confirmfromcreate(final FileConfigEditForm form) {
|
|
|
+ public HtmlResponse confirmfromcreate(final CreateForm form) {
|
|
|
validate(form, messages -> {}, toEditHtml());
|
|
|
+ form.crudMode = CrudMode.CREATE;
|
|
|
return asHtml(path_AdminFileconfig_ConfirmJsp).renderWith(data -> {
|
|
|
registerRolesAndLabels(data);
|
|
|
});
|
|
@@ -212,8 +260,9 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
|
|
|
@Token(save = false, validate = true, keep = true)
|
|
|
@Execute
|
|
|
- public HtmlResponse confirmfromupdate(final FileConfigEditForm form) {
|
|
|
+ public HtmlResponse confirmfromupdate(final EditForm form) {
|
|
|
validate(form, messages -> {}, toEditHtml());
|
|
|
+ form.crudMode = CrudMode.EDIT;
|
|
|
return asHtml(path_AdminFileconfig_ConfirmJsp).renderWith(data -> {
|
|
|
registerRolesAndLabels(data);
|
|
|
});
|
|
@@ -224,66 +273,78 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
// -------------
|
|
|
@Token(save = false, validate = true)
|
|
|
@Execute
|
|
|
- public HtmlResponse create(final FileConfigEditForm form) {
|
|
|
+ public HtmlResponse create(final CreateForm form) {
|
|
|
+ verifyCrudMode(form.crudMode, CrudMode.CREATE);
|
|
|
validate(form, messages -> {}, toEditHtml());
|
|
|
- fileConfigService.store(createFileConfig(form));
|
|
|
- saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
|
|
|
+ createFileConfig(form).ifPresent(entity -> {
|
|
|
+ copyBeanToBean(form, entity, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
|
|
|
+ fileConfigService.store(entity);
|
|
|
+ saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
|
|
|
+ }).orElse(() -> {
|
|
|
+ throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL), toEditHtml());
|
|
|
+ });
|
|
|
return redirect(getClass());
|
|
|
}
|
|
|
|
|
|
@Token(save = false, validate = true)
|
|
|
@Execute
|
|
|
- public HtmlResponse update(final FileConfigEditForm form) {
|
|
|
+ public HtmlResponse update(final EditForm form) {
|
|
|
+ verifyCrudMode(form.crudMode, CrudMode.EDIT);
|
|
|
validate(form, messages -> {}, toEditHtml());
|
|
|
- fileConfigService.store(createFileConfig(form));
|
|
|
- saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
|
|
|
+ createFileConfig(form).ifPresent(entity -> {
|
|
|
+ copyBeanToBean(form, entity, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
|
|
|
+ fileConfigService.store(entity);
|
|
|
+ saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
|
|
|
+ }).orElse(() -> {
|
|
|
+ throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
|
|
|
+ });
|
|
|
return redirect(getClass());
|
|
|
}
|
|
|
|
|
|
@Execute
|
|
|
- public HtmlResponse delete(final FileConfigEditForm form) {
|
|
|
- verifyCrudMode(form, CrudMode.DELETE);
|
|
|
- fileConfigService.delete(getFileConfig(form));
|
|
|
- saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
|
|
|
+ public HtmlResponse delete(final EditForm form) {
|
|
|
+ verifyCrudMode(form.crudMode, CrudMode.DELETE);
|
|
|
+ validate(form, messages -> {}, toEditHtml());
|
|
|
+ final String id = form.id;
|
|
|
+ fileConfigService.getFileConfig(id).ifPresent(entity -> {
|
|
|
+ fileConfigService.delete(entity);
|
|
|
+ saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
|
|
|
+ }).orElse(() -> {
|
|
|
+ throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
|
|
+ });
|
|
|
return redirect(getClass());
|
|
|
}
|
|
|
|
|
|
// ===================================================================================
|
|
|
// Assist Logic
|
|
|
// ============
|
|
|
- protected void loadFileConfig(final FileConfigEditForm form) {
|
|
|
- copyBeanToBean(getFileConfig(form), form, op -> op.exclude("crudMode"));
|
|
|
- }
|
|
|
-
|
|
|
- protected FileConfig getFileConfig(final FileConfigEditForm form) {
|
|
|
- final FileConfig fileConfig = fileConfigService.getFileConfig(createKeyMap(form));
|
|
|
- if (fileConfig == null) {
|
|
|
- throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
|
|
|
- }
|
|
|
- return fileConfig;
|
|
|
- }
|
|
|
-
|
|
|
- protected FileConfig createFileConfig(final FileConfigEditForm form) {
|
|
|
- FileConfig fileConfig;
|
|
|
+ protected OptionalEntity<FileConfig> createFileConfig(final CreateForm form) {
|
|
|
final String username = systemHelper.getUsername();
|
|
|
final long currentTime = systemHelper.getCurrentTimeAsLong();
|
|
|
- if (form.crudMode == CrudMode.EDIT) {
|
|
|
- fileConfig = getFileConfig(form);
|
|
|
- } else {
|
|
|
- fileConfig = new FileConfig();
|
|
|
- fileConfig.setCreatedBy(username);
|
|
|
- fileConfig.setCreatedTime(currentTime);
|
|
|
+ switch (form.crudMode) {
|
|
|
+ case CrudMode.CREATE:
|
|
|
+ if (form instanceof CreateForm) {
|
|
|
+ final FileConfig entity = new FileConfig();
|
|
|
+ entity.setCreatedBy(username);
|
|
|
+ entity.setCreatedTime(currentTime);
|
|
|
+ entity.setUpdatedBy(username);
|
|
|
+ entity.setUpdatedTime(currentTime);
|
|
|
+ return OptionalEntity.of(entity);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CrudMode.EDIT:
|
|
|
+ if (form instanceof EditForm) {
|
|
|
+ return fileConfigService.getFileConfig(((EditForm) form).id).map(entity -> {
|
|
|
+ entity.setUpdatedBy(username);
|
|
|
+ entity.setUpdatedTime(currentTime);
|
|
|
+ return entity;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
- fileConfig.setUpdatedBy(username);
|
|
|
- fileConfig.setUpdatedTime(currentTime);
|
|
|
- copyBeanToBean(form, fileConfig, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
|
|
|
- return fileConfig;
|
|
|
- }
|
|
|
-
|
|
|
- protected Map<String, String> createKeyMap(final FileConfigEditForm form) {
|
|
|
- final Map<String, String> keys = new HashMap<String, String>();
|
|
|
- keys.put("id", form.id);
|
|
|
- return keys;
|
|
|
+ return OptionalEntity.empty();
|
|
|
}
|
|
|
|
|
|
protected void registerRolesAndLabels(final RenderData data) {
|
|
@@ -294,10 +355,10 @@ public class AdminFileconfigAction extends FessAdminAction {
|
|
|
// ===================================================================================
|
|
|
// Small Helper
|
|
|
// ============
|
|
|
- protected void verifyCrudMode(final FileConfigEditForm form, final int expectedMode) {
|
|
|
- if (form.crudMode != expectedMode) {
|
|
|
+ protected void verifyCrudMode(final int crudMode, final int expectedMode) {
|
|
|
+ if (crudMode != expectedMode) {
|
|
|
throwValidationError(messages -> {
|
|
|
- messages.addErrorsCrudInvalidMode(GLOBAL, String.valueOf(expectedMode), String.valueOf(form.crudMode));
|
|
|
+ messages.addErrorsCrudInvalidMode(GLOBAL, String.valueOf(expectedMode), String.valueOf(crudMode));
|
|
|
}, toEditHtml());
|
|
|
}
|
|
|
}
|