Merge pull request #331 from kw-udon/dev

Refactoring: role type, overlapping host, label type
This commit is contained in:
Shinsuke Sugaya 2015-10-17 08:56:10 +09:00
commit bb6579614e
21 changed files with 823 additions and 580 deletions

View file

@ -35,6 +35,7 @@ import org.codelibs.fess.helper.LabelTypeHelper;
import org.codelibs.fess.util.ComponentUtil;
import org.dbflute.cbean.result.ListResultBean;
import org.dbflute.cbean.result.PagingResultBean;
import org.dbflute.optional.OptionalEntity;
public class LabelTypeService implements Serializable {
@ -189,24 +190,8 @@ public class LabelTypeService implements Serializable {
}
}
public LabelType getLabelType(final Map<String, String> keys) {
final LabelType labelType = labelTypeBhv.selectEntity(cb -> {
cb.query().docMeta().setId_Equal(keys.get("id"));
setupEntityCondition(cb, keys);
}).orElse(null);//TODO
if (labelType != null) {
final List<LabelToRole> wctrtmList = labelToRoleBhv.selectList(wctrtmCb -> {
wctrtmCb.query().setLabelTypeId_Equal(labelType.getId());
});
if (!wctrtmList.isEmpty()) {
final List<String> roleTypeIds = new ArrayList<String>(wctrtmList.size());
for (final LabelToRole mapping : wctrtmList) {
roleTypeIds.add(mapping.getRoleTypeId());
}
labelType.setRoleTypeIds(roleTypeIds.toArray(new String[roleTypeIds.size()]));
}
}
return labelType;
public OptionalEntity<LabelType> getLabelType(final String id) {
return labelTypeBhv.selectByPK(id);
}
}

View file

@ -29,6 +29,7 @@ import org.codelibs.fess.es.cbean.OverlappingHostCB;
import org.codelibs.fess.es.exbhv.OverlappingHostBhv;
import org.codelibs.fess.es.exentity.OverlappingHost;
import org.dbflute.cbean.result.PagingResultBean;
import org.dbflute.optional.OptionalEntity;
public class OverlappingHostService implements Serializable {
@ -57,17 +58,8 @@ public class OverlappingHostService implements Serializable {
return overlappingHostList;
}
public OverlappingHost getOverlappingHost(final Map<String, String> keys) {
final OverlappingHost overlappingHost = overlappingHostBhv.selectEntity(cb -> {
cb.query().docMeta().setId_Equal(keys.get("id"));
setupEntityCondition(cb, keys);
}).orElse(null);//TODO
if (overlappingHost == null) {
// TODO exception?
return null;
}
return overlappingHost;
public OptionalEntity<OverlappingHost> getOverlappingHost(final String id) {
return overlappingHostBhv.selectByPK(id);
}
public void store(final OverlappingHost overlappingHost) {

View file

@ -29,6 +29,7 @@ import org.codelibs.fess.es.cbean.RoleTypeCB;
import org.codelibs.fess.es.exbhv.RoleTypeBhv;
import org.codelibs.fess.es.exentity.RoleType;
import org.dbflute.cbean.result.PagingResultBean;
import org.dbflute.optional.OptionalEntity;
public class RoleTypeService implements Serializable {
@ -57,17 +58,8 @@ public class RoleTypeService implements Serializable {
return roleTypeList;
}
public RoleType getRoleType(final Map<String, String> keys) {
final RoleType roleType = roleTypeBhv.selectEntity(cb -> {
cb.query().docMeta().setId_Equal(keys.get("id"));
setupEntityCondition(cb, keys);
}).orElse(null);//TODO
if (roleType == null) {
// TODO exception?
return null;
}
return roleType;
public OptionalEntity<RoleType> getRoleType(final String id) {
return roleTypeBhv.selectByPK(id);
}
public void store(final RoleType roleType) {

View file

@ -16,8 +16,6 @@
package org.codelibs.fess.app.web.admin.labeltype;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
@ -27,9 +25,13 @@ import org.codelibs.fess.app.pager.LabelTypePager;
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.labeltype.CreateForm;
import org.codelibs.fess.app.web.admin.labeltype.EditForm;
import org.codelibs.fess.app.web.admin.labeltype.SearchForm;
import org.codelibs.fess.app.web.base.FessAdminAction;
import org.codelibs.fess.es.exentity.LabelType;
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;
@ -39,6 +41,7 @@ import org.lastaflute.web.validation.VaErrorHook;
/**
* @author shinsuke
* @author Shunji Makino
* @author Keiichi Watanabe
*/
public class AdminLabeltypeAction extends FessAdminAction {
@ -50,9 +53,9 @@ public class AdminLabeltypeAction extends FessAdminAction {
@Resource
private LabelTypePager labelTypePager;
@Resource
private SystemHelper systemHelper;
private RoleTypeService roleTypeService;
@Resource
protected RoleTypeService roleTypeService;
private SystemHelper systemHelper;
// ===================================================================================
// Hook
@ -67,14 +70,14 @@ public class AdminLabeltypeAction extends FessAdminAction {
// Search Execute
// ==============
@Execute
public HtmlResponse index(final LabelTypeSearchForm form) {
public HtmlResponse index(final SearchForm form) {
return asHtml(path_AdminLabeltype_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse list(final Integer pageNumber, final LabelTypeSearchForm form) {
public HtmlResponse list(final Integer pageNumber, final SearchForm form) {
labelTypePager.setCurrentPageNumber(pageNumber);
return asHtml(path_AdminLabeltype_IndexJsp).renderWith(data -> {
searchPaging(data, form);
@ -82,15 +85,15 @@ public class AdminLabeltypeAction extends FessAdminAction {
}
@Execute
public HtmlResponse search(final LabelTypeSearchForm form) {
copyBeanToBean(form.searchParams, labelTypePager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
public HtmlResponse search(final SearchForm form) {
copyBeanToBean(form, labelTypePager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
return asHtml(path_AdminLabeltype_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse reset(final LabelTypeSearchForm form) {
public HtmlResponse reset(final SearchForm form) {
labelTypePager.clear();
return asHtml(path_AdminLabeltype_IndexJsp).renderWith(data -> {
searchPaging(data, form);
@ -98,17 +101,17 @@ public class AdminLabeltypeAction extends FessAdminAction {
}
@Execute
public HtmlResponse back(final LabelTypeSearchForm form) {
public HtmlResponse back(final SearchForm form) {
return asHtml(path_AdminLabeltype_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
protected void searchPaging(final RenderData data, final LabelTypeSearchForm form) {
protected void searchPaging(final RenderData data, final SearchForm form) {
data.register("labelTypeItems", labelTypeService.getLabelTypeList(labelTypePager)); // page navi
// restore from pager
copyBeanToBean(labelTypePager, form.searchParams, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
copyBeanToBean(labelTypePager, form, op -> op.include("id"));
}
// ===================================================================================
@ -119,63 +122,106 @@ public class AdminLabeltypeAction extends FessAdminAction {
// ----------
@Token(save = true, validate = false)
@Execute
public HtmlResponse createpage(final LabelTypeEditForm form) {
form.initialize();
form.crudMode = CrudMode.CREATE;
return asHtml(path_AdminLabeltype_EditJsp).renderWith(data -> {
data.register("roleTypeItems", roleTypeService.getRoleTypeList());
public HtmlResponse createpage() {
return asHtml(path_AdminLabeltype_EditJsp).useForm(CreateForm.class, op -> {
op.setup(form -> {
form.initialize();
form.crudMode = CrudMode.CREATE;
});
}).renderWith(data -> {
registerItems(data);
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editpage(final int crudMode, final String id, final LabelTypeEditForm form) {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CrudMode.EDIT);
loadLabelType(form);
return asHtml(path_AdminLabeltype_EditJsp).renderWith(data -> {
data.register("roleTypeItems", roleTypeService.getRoleTypeList());
public HtmlResponse editpage(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.EDIT);
return asHtml(path_AdminLabeltype_EditJsp).useForm(EditForm.class, op -> {
op.setup(form -> {
labelTypeService.getLabelType(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
form.crudMode = crudMode;
});
}).renderWith(data -> {
registerItems(data);
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editagain(final LabelTypeEditForm form) {
public HtmlResponse createagain(final CreateForm form) {
verifyCrudMode(form.crudMode, CrudMode.CREATE);
validate(form, messages -> {}, toEditHtml());
return asHtml(path_AdminLabeltype_EditJsp).renderWith(data -> {
data.register("roleTypeItems", roleTypeService.getRoleTypeList());
registerItems(data);
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editfromconfirm(final LabelTypeEditForm form) {
public HtmlResponse editagain(final EditForm form) {
verifyCrudMode(form.crudMode, CrudMode.EDIT);
validate(form, messages -> {}, toEditHtml());
return asHtml(path_AdminLabeltype_EditJsp).renderWith(data -> {
registerItems(data);
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editfromconfirm(final EditForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.EDIT;
loadLabelType(form);
final String id = form.id;
labelTypeService.getLabelType(id).ifPresent(entity -> {
copyBeanToBean(entity, form, op -> {});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
return asHtml(path_AdminLabeltype_EditJsp).renderWith(data -> {
data.register("roleTypeItems", roleTypeService.getRoleTypeList());
registerItems(data);
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse deletepage(final int crudMode, final String id, final LabelTypeEditForm form) {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CrudMode.DELETE);
loadLabelType(form);
return asHtml(path_AdminLabeltype_ConfirmJsp).renderWith(data -> {
data.register("roleTypeItems", roleTypeService.getRoleTypeList());
public HtmlResponse deletepage(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.DELETE);
return asHtml(path_AdminLabeltype_ConfirmJsp).useForm(EditForm.class, op -> {
op.setup(form -> {
labelTypeService.getLabelType(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
form.crudMode = crudMode;
});
}).renderWith(data -> {
registerItems(data);
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse deletefromconfirm(final LabelTypeEditForm form) {
public HtmlResponse deletefromconfirm(final EditForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.DELETE;
loadLabelType(form);
final String id = form.id;
labelTypeService.getLabelType(id).ifPresent(entity -> {
copyBeanToBean(entity, form, op -> {});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
return asHtml(path_AdminLabeltype_ConfirmJsp).renderWith(data -> {
data.register("roleTypeItems", roleTypeService.getRoleTypeList());
registerItems(data);
});
}
@ -183,31 +229,41 @@ public class AdminLabeltypeAction extends FessAdminAction {
// Confirm
// -------
@Execute
public HtmlResponse confirmpage(final int crudMode, final String id, final LabelTypeEditForm form) {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CrudMode.CONFIRM);
loadLabelType(form);
return asHtml(path_AdminLabeltype_ConfirmJsp).renderWith(data -> {
data.register("roleTypeItems", roleTypeService.getRoleTypeList());
public HtmlResponse confirmpage(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.CONFIRM);
return asHtml(path_AdminLabeltype_ConfirmJsp).useForm(EditForm.class, op -> {
op.setup(form -> {
labelTypeService.getLabelType(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
});
form.crudMode = crudMode;
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
});
}).renderWith(data -> {
registerItems(data);
});
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromcreate(final LabelTypeEditForm form) {
public HtmlResponse confirmfromcreate(final CreateForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.CREATE;
return asHtml(path_AdminLabeltype_ConfirmJsp).renderWith(data -> {
data.register("roleTypeItems", roleTypeService.getRoleTypeList());
registerItems(data);
});
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromupdate(final LabelTypeEditForm form) {
public HtmlResponse confirmfromupdate(final EditForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.EDIT;
return asHtml(path_AdminLabeltype_ConfirmJsp).renderWith(data -> {
data.register("roleTypeItems", roleTypeService.getRoleTypeList());
registerItems(data);
});
}
@ -216,75 +272,91 @@ public class AdminLabeltypeAction extends FessAdminAction {
// -------------
@Token(save = false, validate = true)
@Execute
public HtmlResponse create(final LabelTypeEditForm form) {
public HtmlResponse create(final CreateForm form) {
verifyCrudMode(form.crudMode, CrudMode.CREATE);
validate(form, messages -> {}, toEditHtml());
labelTypeService.store(createLabelType(form));
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
createLabelType(form).ifPresent(entity -> {
copyBeanToBean(form, entity, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
labelTypeService.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 LabelTypeEditForm form) {
public HtmlResponse update(final EditForm form) {
verifyCrudMode(form.crudMode, CrudMode.EDIT);
validate(form, messages -> {}, toEditHtml());
labelTypeService.store(createLabelType(form));
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
createLabelType(form).ifPresent(entity -> {
copyBeanToBean(form, entity, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
labelTypeService.store(entity);
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
});
return redirect(getClass());
}
@Execute
public HtmlResponse delete(final LabelTypeEditForm form) {
verifyCrudMode(form, CrudMode.DELETE);
labelTypeService.delete(getLabelType(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;
labelTypeService.getLabelType(id).ifPresent(entity -> {
labelTypeService.delete(entity);
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
return redirect(getClass());
}
// ===================================================================================
// Assist Logic
// ============
protected void loadLabelType(final LabelTypeEditForm form) {
copyBeanToBean(getLabelType(form), form, op -> op.exclude("crudMode"));
}
protected LabelType getLabelType(final LabelTypeEditForm form) {
final LabelType labelType = labelTypeService.getLabelType(createKeyMap(form));
if (labelType == null) {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
}
return labelType;
}
protected LabelType createLabelType(final LabelTypeEditForm form) {
LabelType labelType;
protected OptionalEntity<LabelType> createLabelType(final CreateForm form) {
final String username = systemHelper.getUsername();
final long currentTime = systemHelper.getCurrentTimeAsLong();
if (form.crudMode == CrudMode.EDIT) {
labelType = getLabelType(form);
} else {
labelType = new LabelType();
labelType.setCreatedBy(username);
labelType.setCreatedTime(currentTime);
switch (form.crudMode) {
case CrudMode.CREATE:
if (form instanceof CreateForm) {
final LabelType entity = new LabelType();
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 labelTypeService.getLabelType(((EditForm) form).id).map(entity -> {
entity.setUpdatedBy(username);
entity.setUpdatedTime(currentTime);
return entity;
});
}
break;
default:
break;
}
labelType.setUpdatedBy(username);
labelType.setUpdatedTime(currentTime);
copyBeanToBean(form, labelType, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
return labelType;
return OptionalEntity.empty();
}
protected Map<String, String> createKeyMap(final LabelTypeEditForm form) {
final Map<String, String> keys = new HashMap<String, String>();
keys.put("id", form.id);
return keys;
protected void registerItems(final RenderData data) {
data.register("roleTypeItems", roleTypeService.getRoleTypeList());
}
// ===================================================================================
// Small Helper
// ============
protected void verifyCrudMode(final LabelTypeEditForm 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());
}
}

View file

@ -0,0 +1,78 @@
/*
* 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.labeltype;
import java.io.Serializable;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.codelibs.fess.app.web.CrudMode;
import org.codelibs.fess.util.ComponentUtil;
import org.lastaflute.web.validation.Required;
/**
* @author codelibs
* @author Shunji Makino
* @author Keiichi Watanabe
*/
public class CreateForm implements Serializable {
private static final long serialVersionUID = 1L;
public String[] roleTypeIds;
public Integer crudMode;
@Required
@Size(max = 100)
public String name;
@Required
@Size(max = 20)
@Pattern(regexp = "^[a-zA-Z0-9_-| ]+$")
public String value;
@Required
@Size(max = 4000)
public String includedPaths;
@Required
@Size(max = 4000)
public String excludedPaths;
@Required
@Min(value = 0)
@Max(value = 2147483647)
public Integer sortOrder;
@Required
@Size(max = 1000)
public String createdBy;
@Required
public Long createdTime;
public void initialize() {
crudMode = CrudMode.CREATE;
sortOrder = 0;
createdBy = ComponentUtil.getSystemHelper().getUsername();
createdTime = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
}
}

View file

@ -0,0 +1,42 @@
/*
* 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.labeltype;
import javax.validation.constraints.Size;
import org.lastaflute.web.validation.Required;
/**
* @author Keiichi Watanabe
*/
public class EditForm extends CreateForm {
private static final long serialVersionUID = 1L;
@Required
@Size(max = 1000)
public String id;
@Size(max = 1000)
public String updatedBy;
public Long updatedTime;
@Required
public Integer versionNo;
}

View file

@ -1,91 +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.labeltype;
import java.io.Serializable;
import org.codelibs.fess.util.ComponentUtil;
/**
* @author codelibs
* @author Shunji Makino
*/
public class LabelTypeEditForm implements Serializable {
private static final long serialVersionUID = 1L;
public String[] roleTypeIds;
//@IntegerType
public int crudMode;
//@Required(target = "confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 1000)
public String id;
//@Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 100)
public String name;
//@Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 20)
//@Mask(mask = "^[a-zA-Z0-9_-]+$", msg = @Msg(key = "errors.alphaDigitOnly"))
public String value;
//@Maxbytelength(maxbytelength = 4000)
public String includedPaths;
//@Maxbytelength(maxbytelength = 4000)
public String excludedPaths;
//@Required(target = "confirmfromupdate,update,delete")
//@IntRange(min = 0, max = 2147483647)
public String sortOrder;
//@Required(target = "confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 255)
public String createdBy;
//@Required(target = "confirmfromupdate,update,delete")
//@LongType
public String createdTime;
//@Maxbytelength(maxbytelength = 255)
public String updatedBy;
//@LongType
public String updatedTime;
//@Required(target = "confirmfromupdate,update,delete")
//@IntegerType
public String versionNo;
public void initialize() {
id = null;
name = null;
value = null;
includedPaths = null;
excludedPaths = null;
sortOrder = null;
createdBy = "system";
createdTime = Long.toString(ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
updatedBy = null;
updatedTime = null;
versionNo = null;
sortOrder = "0";
}
}

View file

@ -17,16 +17,14 @@
package org.codelibs.fess.app.web.admin.labeltype;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @author codelibs
* @author Shunji Makino
*/
public class LabelTypeSearchForm implements Serializable {
public class SearchForm implements Serializable {
private static final long serialVersionUID = 1L;
public Map<String, String> searchParams = new HashMap<String, String>();
public String id;
}

View file

@ -16,9 +16,6 @@
package org.codelibs.fess.app.web.admin.overlappinghost;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.codelibs.fess.Constants;
@ -29,6 +26,7 @@ import org.codelibs.fess.app.web.CrudMode;
import org.codelibs.fess.app.web.base.FessAdminAction;
import org.codelibs.fess.es.exentity.OverlappingHost;
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;
@ -64,14 +62,14 @@ public class AdminOverlappinghostAction extends FessAdminAction {
// Search Execute
// ==============
@Execute
public HtmlResponse index(final OverlappingHostSearchForm form) {
public HtmlResponse index(final SearchForm form) {
return asHtml(path_AdminOverlappinghost_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse list(final Integer pageNumber, final OverlappingHostSearchForm form) {
public HtmlResponse list(final Integer pageNumber, final SearchForm form) {
overlappingHostPager.setCurrentPageNumber(pageNumber);
return asHtml(path_AdminOverlappinghost_IndexJsp).renderWith(data -> {
searchPaging(data, form);
@ -79,15 +77,15 @@ public class AdminOverlappinghostAction extends FessAdminAction {
}
@Execute
public HtmlResponse search(final OverlappingHostSearchForm form) {
copyBeanToBean(form.searchParams, overlappingHostPager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
public HtmlResponse search(final SearchForm form) {
copyBeanToBean(form, overlappingHostPager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
return asHtml(path_AdminOverlappinghost_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse reset(final OverlappingHostSearchForm form) {
public HtmlResponse reset(final SearchForm form) {
overlappingHostPager.clear();
return asHtml(path_AdminOverlappinghost_IndexJsp).renderWith(data -> {
searchPaging(data, form);
@ -95,17 +93,17 @@ public class AdminOverlappinghostAction extends FessAdminAction {
}
@Execute
public HtmlResponse back(final OverlappingHostSearchForm form) {
public HtmlResponse back(final SearchForm form) {
return asHtml(path_AdminOverlappinghost_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
protected void searchPaging(final RenderData data, final OverlappingHostSearchForm form) {
protected void searchPaging(final RenderData data, final SearchForm form) {
data.register("overlappingHostItems", overlappingHostService.getOverlappingHostList(overlappingHostPager)); // page navi
// restore from pager
copyBeanToBean(overlappingHostPager, form.searchParams, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
copyBeanToBean(overlappingHostPager, form, op -> op.include("id"));
}
// ===================================================================================
@ -116,51 +114,92 @@ public class AdminOverlappinghostAction extends FessAdminAction {
// ----------
@Token(save = true, validate = false)
@Execute
public HtmlResponse createpage(final OverlappingHostEditForm form) {
form.initialize();
form.crudMode = CrudMode.CREATE;
public HtmlResponse createpage() {
return asHtml(path_AdminOverlappinghost_EditJsp).useForm(CreateForm.class, op -> {
op.setup(form -> {
form.initialize();
form.crudMode = CrudMode.CREATE;
});
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editpage(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.EDIT);
return asHtml(path_AdminOverlappinghost_EditJsp).useForm(EditForm.class, op -> {
op.setup(form -> {
overlappingHostService.getOverlappingHost(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
form.crudMode = crudMode;
});
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse createagain(final CreateForm form) {
verifyCrudMode(form.crudMode, CrudMode.CREATE);
validate(form, messages -> {}, toEditHtml());
return asHtml(path_AdminOverlappinghost_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editpage(final int crudMode, final String id, final OverlappingHostEditForm form) {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CrudMode.EDIT);
loadOverlappingHost(form);
public HtmlResponse editagain(final EditForm form) {
verifyCrudMode(form.crudMode, CrudMode.EDIT);
validate(form, messages -> {}, toEditHtml());
return asHtml(path_AdminOverlappinghost_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editagain(final OverlappingHostEditForm form) {
return asHtml(path_AdminOverlappinghost_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editfromconfirm(final OverlappingHostEditForm form) {
public HtmlResponse editfromconfirm(final EditForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.EDIT;
loadOverlappingHost(form);
final String id = form.id;
overlappingHostService.getOverlappingHost(id).ifPresent(entity -> {
copyBeanToBean(entity, form, op -> {});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
return asHtml(path_AdminOverlappinghost_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse deletepage(final int crudMode, final String id, final OverlappingHostEditForm form) {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CrudMode.DELETE);
loadOverlappingHost(form);
return asHtml(path_AdminOverlappinghost_ConfirmJsp);
public HtmlResponse deletepage(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.DELETE);
return asHtml(path_AdminOverlappinghost_ConfirmJsp).useForm(EditForm.class, op -> {
op.setup(form -> {
overlappingHostService.getOverlappingHost(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
form.crudMode = crudMode;
});
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse deletefromconfirm(final OverlappingHostEditForm form) {
public HtmlResponse deletefromconfirm(final EditForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.DELETE;
loadOverlappingHost(form);
final String id = form.id;
overlappingHostService.getOverlappingHost(id).ifPresent(entity -> {
copyBeanToBean(entity, form, op -> {});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
return asHtml(path_AdminOverlappinghost_ConfirmJsp);
}
@ -168,25 +207,35 @@ public class AdminOverlappinghostAction extends FessAdminAction {
// Confirm
// -------
@Execute
public HtmlResponse confirmpage(final int crudMode, final String id, final OverlappingHostEditForm form) {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CrudMode.CONFIRM);
loadOverlappingHost(form);
public HtmlResponse confirmpage(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.CONFIRM);
return asHtml(path_AdminOverlappinghost_ConfirmJsp).useForm(EditForm.class, op -> {
op.setup(form -> {
overlappingHostService.getOverlappingHost(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
});
form.crudMode = crudMode;
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
});
});
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromcreate(final CreateForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.CREATE;
return asHtml(path_AdminOverlappinghost_ConfirmJsp);
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromcreate(final OverlappingHostEditForm form) {
validate(form, messages -> {}, toEditHtml());
return asHtml(path_AdminOverlappinghost_ConfirmJsp);
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromupdate(final OverlappingHostEditForm form) {
public HtmlResponse confirmfromupdate(final EditForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.EDIT;
return asHtml(path_AdminOverlappinghost_ConfirmJsp);
}
@ -195,75 +244,87 @@ public class AdminOverlappinghostAction extends FessAdminAction {
// -------------
@Token(save = false, validate = true)
@Execute
public HtmlResponse create(final OverlappingHostEditForm form) {
public HtmlResponse create(final CreateForm form) {
verifyCrudMode(form.crudMode, CrudMode.CREATE);
validate(form, messages -> {}, toEditHtml());
overlappingHostService.store(createOverlappingHost(form));
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
createOverlappingHost(form).ifPresent(entity -> {
copyBeanToBean(form, entity, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
overlappingHostService.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 OverlappingHostEditForm form) {
public HtmlResponse update(final EditForm form) {
verifyCrudMode(form.crudMode, CrudMode.EDIT);
validate(form, messages -> {}, toEditHtml());
overlappingHostService.store(createOverlappingHost(form));
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
createOverlappingHost(form).ifPresent(entity -> {
copyBeanToBean(form, entity, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
overlappingHostService.store(entity);
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
});
return redirect(getClass());
}
@Execute
public HtmlResponse delete(final OverlappingHostEditForm form) {
verifyCrudMode(form, CrudMode.DELETE);
overlappingHostService.delete(getOverlappingHost(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;
overlappingHostService.getOverlappingHost(id).ifPresent(entity -> {
overlappingHostService.delete(entity);
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
return redirect(getClass());
}
// ===================================================================================
// Assist Logic
// ============
protected void loadOverlappingHost(final OverlappingHostEditForm form) {
copyBeanToBean(getOverlappingHost(form), form, op -> op.exclude("crudMode"));
}
protected OverlappingHost getOverlappingHost(final OverlappingHostEditForm form) {
final OverlappingHost overlappingHost = overlappingHostService.getOverlappingHost(createKeyMap(form));
if (overlappingHost == null) {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
}
return overlappingHost;
}
protected OverlappingHost createOverlappingHost(final OverlappingHostEditForm form) {
OverlappingHost overlappingHost;
protected OptionalEntity<OverlappingHost> createOverlappingHost(final CreateForm form) {
final String username = systemHelper.getUsername();
final long currentTime = systemHelper.getCurrentTimeAsLong();
if (form.crudMode == CrudMode.EDIT) {
overlappingHost = getOverlappingHost(form);
} else {
overlappingHost = new OverlappingHost();
overlappingHost.setCreatedBy(username);
overlappingHost.setCreatedTime(currentTime);
switch (form.crudMode) {
case CrudMode.CREATE:
if (form instanceof CreateForm) {
final OverlappingHost entity = new OverlappingHost();
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 overlappingHostService.getOverlappingHost(((EditForm) form).id).map(entity -> {
entity.setUpdatedBy(username);
entity.setUpdatedTime(currentTime);
return entity;
});
}
break;
default:
break;
}
overlappingHost.setUpdatedBy(username);
overlappingHost.setUpdatedTime(currentTime);
copyBeanToBean(form, overlappingHost, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
return overlappingHost;
}
protected Map<String, String> createKeyMap(final OverlappingHostEditForm form) {
final Map<String, String> keys = new HashMap<String, String>();
keys.put("id", form.id);
return keys;
return OptionalEntity.empty();
}
// ===================================================================================
// Small Helper
// ============
protected void verifyCrudMode(final OverlappingHostEditForm 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());
}
}

View file

@ -0,0 +1,65 @@
/*
* 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.overlappinghost;
import java.io.Serializable;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;
import org.codelibs.fess.app.web.CrudMode;
import org.codelibs.fess.util.ComponentUtil;
import org.lastaflute.web.validation.Required;
/**
* @author codelibs
* @author Keiichi Watanabe
*/
public class CreateForm implements Serializable {
private static final long serialVersionUID = 1L;
public Integer crudMode;
@Required
@Size(max = 1000)
public String regularName;
@Required
@Size(max = 1000)
public String overlappingName;
@Required
@Min(value = 0)
@Max(value = 2147483647)
public Integer sortOrder;
@Required
@Size(max = 1000)
public String createdBy;
@Required
public Long createdTime;
public void initialize() {
crudMode = CrudMode.CREATE;
sortOrder = 0;
createdBy = ComponentUtil.getSystemHelper().getUsername();
createdTime = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
}
}

View file

@ -0,0 +1,42 @@
/*
* 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.overlappinghost;
import javax.validation.constraints.Size;
import org.lastaflute.web.validation.Required;
/**
* @author Keiichi Watanabe
*/
public class EditForm extends CreateForm {
private static final long serialVersionUID = 1L;
@Required
@Size(max = 1000)
public String id;
@Size(max = 1000)
public String updatedBy;
public Long updatedTime;
@Required
public Integer versionNo;
}

View file

@ -1,80 +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.overlappinghost;
import java.io.Serializable;
import org.codelibs.fess.util.ComponentUtil;
/**
* @author codelibs
* @author Keiichi Watanabe
*/
public class OverlappingHostEditForm implements Serializable {
private static final long serialVersionUID = 1L;
//@IntegerType
public int crudMode;
//@Required(target = "confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 1000)
public String id;
//@Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 1000)
public String regularName;
//@Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 1000)
public String overlappingName;
//@Required(target = "confirmfromupdate,update,delete")
//@IntRange(min = 0, max = 2147483647)
public String sortOrder;
//@Required(target = "confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 255)
public String createdBy;
//@Required(target = "confirmfromupdate,update,delete")
//@LongType
public String createdTime;
//@Maxbytelength(maxbytelength = 255)
public String updatedBy;
//@LongType
public String updatedTime;
//@Required(target = "confirmfromupdate,update,delete")
//@IntegerType
public String versionNo;
public void initialize() {
id = null;
regularName = null;
overlappingName = null;
sortOrder = null;
createdBy = "system";
createdTime = Long.toString(ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
updatedBy = null;
updatedTime = null;
versionNo = null;
sortOrder = "0";
}
}

View file

@ -17,16 +17,14 @@
package org.codelibs.fess.app.web.admin.overlappinghost;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @author codelibs
* @author Keiichi Watanabe
*/
public class OverlappingHostSearchForm implements Serializable {
public class SearchForm implements Serializable {
private static final long serialVersionUID = 1L;
public Map<String, String> searchParams = new HashMap<String, String>();
public String id;
}

View file

@ -16,9 +16,6 @@
package org.codelibs.fess.app.web.admin.roletype;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.codelibs.fess.Constants;
@ -29,6 +26,7 @@ import org.codelibs.fess.app.web.CrudMode;
import org.codelibs.fess.app.web.base.FessAdminAction;
import org.codelibs.fess.es.exentity.RoleType;
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;
@ -64,14 +62,14 @@ public class AdminRoletypeAction extends FessAdminAction {
// Search Execute
// ==============
@Execute
public HtmlResponse index(final RoleTypeSearchForm form) {
public HtmlResponse index(final SearchForm form) {
return asHtml(path_AdminRoletype_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse list(final Integer pageNumber, final RoleTypeSearchForm form) {
public HtmlResponse list(final Integer pageNumber, final SearchForm form) {
roleTypePager.setCurrentPageNumber(pageNumber);
return asHtml(path_AdminRoletype_IndexJsp).renderWith(data -> {
searchPaging(data, form);
@ -79,15 +77,15 @@ public class AdminRoletypeAction extends FessAdminAction {
}
@Execute
public HtmlResponse search(final RoleTypeSearchForm form) {
copyBeanToBean(form.searchParams, roleTypePager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
public HtmlResponse search(final SearchForm form) {
copyBeanToBean(form, roleTypePager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
return asHtml(path_AdminRoletype_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
@Execute
public HtmlResponse reset(final RoleTypeSearchForm form) {
public HtmlResponse reset(final SearchForm form) {
roleTypePager.clear();
return asHtml(path_AdminRoletype_IndexJsp).renderWith(data -> {
searchPaging(data, form);
@ -95,17 +93,17 @@ public class AdminRoletypeAction extends FessAdminAction {
}
@Execute
public HtmlResponse back(final RoleTypeSearchForm form) {
public HtmlResponse back(final SearchForm form) {
return asHtml(path_AdminRoletype_IndexJsp).renderWith(data -> {
searchPaging(data, form);
});
}
protected void searchPaging(final RenderData data, final RoleTypeSearchForm form) {
protected void searchPaging(final RenderData data, final SearchForm form) {
data.register("roleTypeItems", roleTypeService.getRoleTypeList(roleTypePager)); // page navi
// restore from pager
copyBeanToBean(roleTypePager, form.searchParams, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
copyBeanToBean(roleTypePager, form, op -> op.include("id"));
}
// ===================================================================================
@ -116,50 +114,92 @@ public class AdminRoletypeAction extends FessAdminAction {
// ----------
@Token(save = true, validate = false)
@Execute
public HtmlResponse createpage(final RoleTypeEditForm form) {
form.crudMode = CrudMode.CREATE;
public HtmlResponse createpage() {
return asHtml(path_AdminRoletype_EditJsp).useForm(CreateForm.class, op -> {
op.setup(form -> {
form.initialize();
form.crudMode = CrudMode.CREATE;
});
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editpage(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.EDIT);
return asHtml(path_AdminRoletype_EditJsp).useForm(EditForm.class, op -> {
op.setup(form -> {
roleTypeService.getRoleType(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
form.crudMode = crudMode;
});
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse createagain(final CreateForm form) {
verifyCrudMode(form.crudMode, CrudMode.CREATE);
validate(form, messages -> {}, toEditHtml());
return asHtml(path_AdminRoletype_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editpage(final int crudMode, final String id, final RoleTypeEditForm form) {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CrudMode.EDIT);
loadRoleType(form);
public HtmlResponse editagain(final EditForm form) {
verifyCrudMode(form.crudMode, CrudMode.EDIT);
validate(form, messages -> {}, toEditHtml());
return asHtml(path_AdminRoletype_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editagain(final RoleTypeEditForm form) {
return asHtml(path_AdminRoletype_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse editfromconfirm(final RoleTypeEditForm form) {
public HtmlResponse editfromconfirm(final EditForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.EDIT;
loadRoleType(form);
final String id = form.id;
roleTypeService.getRoleType(id).ifPresent(entity -> {
copyBeanToBean(entity, form, op -> {});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
return asHtml(path_AdminRoletype_EditJsp);
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse deletepage(final int crudMode, final String id, final RoleTypeEditForm form) {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CrudMode.DELETE);
loadRoleType(form);
return asHtml(path_AdminRoletype_ConfirmJsp);
public HtmlResponse deletepage(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.DELETE);
return asHtml(path_AdminRoletype_ConfirmJsp).useForm(EditForm.class, op -> {
op.setup(form -> {
roleTypeService.getRoleType(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
form.crudMode = crudMode;
});
});
}
@Token(save = true, validate = false)
@Execute
public HtmlResponse deletefromconfirm(final RoleTypeEditForm form) {
public HtmlResponse deletefromconfirm(final EditForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.DELETE;
loadRoleType(form);
final String id = form.id;
roleTypeService.getRoleType(id).ifPresent(entity -> {
copyBeanToBean(entity, form, op -> {});
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
return asHtml(path_AdminRoletype_ConfirmJsp);
}
@ -167,25 +207,35 @@ public class AdminRoletypeAction extends FessAdminAction {
// Confirm
// -------
@Execute
public HtmlResponse confirmpage(final int crudMode, final String id, final RoleTypeEditForm form) {
form.crudMode = crudMode;
form.id = id;
verifyCrudMode(form, CrudMode.CONFIRM);
loadRoleType(form);
public HtmlResponse confirmpage(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.CONFIRM);
return asHtml(path_AdminRoletype_ConfirmJsp).useForm(EditForm.class, op -> {
op.setup(form -> {
roleTypeService.getRoleType(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
});
form.crudMode = crudMode;
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
});
});
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromcreate(final CreateForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.CREATE;
return asHtml(path_AdminRoletype_ConfirmJsp);
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromcreate(final RoleTypeEditForm form) {
validate(form, messages -> {}, toEditHtml());
return asHtml(path_AdminRoletype_ConfirmJsp);
}
@Token(save = false, validate = true, keep = true)
@Execute
public HtmlResponse confirmfromupdate(final RoleTypeEditForm form) {
public HtmlResponse confirmfromupdate(final EditForm form) {
validate(form, messages -> {}, toEditHtml());
form.crudMode = CrudMode.EDIT;
return asHtml(path_AdminRoletype_ConfirmJsp);
}
@ -194,75 +244,87 @@ public class AdminRoletypeAction extends FessAdminAction {
// -------------
@Token(save = false, validate = true)
@Execute
public HtmlResponse create(final RoleTypeEditForm form) {
public HtmlResponse create(final CreateForm form) {
verifyCrudMode(form.crudMode, CrudMode.CREATE);
validate(form, messages -> {}, toEditHtml());
roleTypeService.store(createRoleType(form));
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
createRoleType(form).ifPresent(entity -> {
copyBeanToBean(form, entity, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
roleTypeService.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 RoleTypeEditForm form) {
public HtmlResponse update(final EditForm form) {
verifyCrudMode(form.crudMode, CrudMode.EDIT);
validate(form, messages -> {}, toEditHtml());
roleTypeService.store(createRoleType(form));
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
createRoleType(form).ifPresent(entity -> {
copyBeanToBean(form, entity, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
roleTypeService.store(entity);
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
});
return redirect(getClass());
}
@Execute
public HtmlResponse delete(final RoleTypeEditForm form) {
verifyCrudMode(form, CrudMode.DELETE);
roleTypeService.delete(getRoleType(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;
roleTypeService.getRoleType(id).ifPresent(entity -> {
roleTypeService.delete(entity);
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
});
return redirect(getClass());
}
// ===================================================================================
// Assist Logic
// ============
protected void loadRoleType(final RoleTypeEditForm form) {
copyBeanToBean(getRoleType(form), form, op -> op.exclude("crudMode"));
}
protected RoleType getRoleType(final RoleTypeEditForm form) {
final RoleType roleType = roleTypeService.getRoleType(createKeyMap(form));
if (roleType == null) {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
}
return roleType;
}
protected RoleType createRoleType(final RoleTypeEditForm form) {
RoleType roleType;
protected OptionalEntity<RoleType> createRoleType(final CreateForm form) {
final String username = systemHelper.getUsername();
final long currentTime = systemHelper.getCurrentTimeAsLong();
if (form.crudMode == CrudMode.EDIT) {
roleType = getRoleType(form);
} else {
roleType = new RoleType();
roleType.setCreatedBy(username);
roleType.setCreatedTime(currentTime);
switch (form.crudMode) {
case CrudMode.CREATE:
if (form instanceof CreateForm) {
final RoleType entity = new RoleType();
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 roleTypeService.getRoleType(((EditForm) form).id).map(entity -> {
entity.setUpdatedBy(username);
entity.setUpdatedTime(currentTime);
return entity;
});
}
break;
default:
break;
}
roleType.setUpdatedBy(username);
roleType.setUpdatedTime(currentTime);
copyBeanToBean(form, roleType, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
return roleType;
}
protected Map<String, String> createKeyMap(final RoleTypeEditForm form) {
final Map<String, String> keys = new HashMap<String, String>();
keys.put("id", form.id);
return keys;
return OptionalEntity.empty();
}
// ===================================================================================
// Small Helper
// ============
protected void verifyCrudMode(final RoleTypeEditForm 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());
}
}

View file

@ -0,0 +1,67 @@
/*
* 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.roletype;
import java.io.Serializable;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.codelibs.fess.app.web.CrudMode;
import org.codelibs.fess.util.ComponentUtil;
import org.lastaflute.web.validation.Required;
/**
* @author codelibs
* @author Keiichi Watanabe
*/
public class CreateForm implements Serializable {
private static final long serialVersionUID = 1L;
public Integer crudMode;
@Required
@Size(max = 100)
public String name;
@Required
@Size(max = 20)
@Pattern(regexp = "^[a-zA-Z0-9_-| ]+$")
public String value;
@Required
@Min(value = 0)
@Max(value = 2147483647)
public Integer sortOrder;
@Required
@Size(max = 1000)
public String createdBy;
@Required
public Long createdTime;
public void initialize() {
crudMode = CrudMode.CREATE;
sortOrder = 0;
createdBy = ComponentUtil.getSystemHelper().getUsername();
createdTime = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
}
}

View file

@ -0,0 +1,42 @@
/*
* 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.roletype;
import javax.validation.constraints.Size;
import org.lastaflute.web.validation.Required;
/**
* @author Keiichi Watanabe
*/
public class EditForm extends CreateForm {
private static final long serialVersionUID = 1L;
@Required
@Size(max = 1000)
public String id;
@Size(max = 1000)
public String updatedBy;
public Long updatedTime;
@Required
public Integer versionNo;
}

View file

@ -1,81 +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.roletype;
import java.io.Serializable;
import org.codelibs.fess.util.ComponentUtil;
/**
* @author codelibs
* @author Keiichi Watanabe
*/
public class RoleTypeEditForm implements Serializable {
private static final long serialVersionUID = 1L;
//@IntegerType
public int crudMode;
//@Required(target = "confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 1000)
public String id;
//@Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 100)
public String name;
//@Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 20)
//@Mask(mask = "^[a-zA-Z0-9_-| ]+$", msg = @Msg(key = "errors.alphaDigitSpaceOnly"))
public String value;
//@Required(target = "confirmfromupdate,update,delete")
//@IntRange(min = 0, max = 2147483647)
public String sortOrder;
//@Required(target = "confirmfromupdate,update,delete")
//@Maxbytelength(maxbytelength = 255)
public String createdBy;
//@Required(target = "confirmfromupdate,update,delete")
//@LongType
public String createdTime;
//@Maxbytelength(maxbytelength = 255)
public String updatedBy;
//@LongType
public String updatedTime;
//@Required(target = "confirmfromupdate,update,delete")
//@IntegerType
public String versionNo;
public void initialize() {
id = null;
name = null;
value = null;
sortOrder = null;
createdBy = "system";
createdTime = Long.toString(ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
updatedBy = null;
updatedTime = null;
versionNo = null;
sortOrder = "0";
}
}

View file

@ -17,16 +17,15 @@
package org.codelibs.fess.app.web.admin.roletype;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @author codelibs
* @author Keiichi Watanabe
*/
public class RoleTypeSearchForm implements Serializable {
public class SearchForm implements Serializable {
private static final long serialVersionUID = 1L;
public Map<String, String> searchParams = new HashMap<String, String>();
}
public String id;
}

View file

@ -134,7 +134,7 @@
<%-- Box Footer --%>
<div class="box-footer">
<c:if test="${crudMode == 1}">
<input type="submit" class="btn" name="editagain" value="<la:message key="labels.labeltype_button_back"/>" />
<input type="submit" class="btn" name="createagain" value="<la:message key="labels.labeltype_button_back"/>" />
<input type="submit" class="btn btn-primary" name="create"
value="<la:message key="labels.labeltype_button_create"/>"
/>

View file

@ -106,7 +106,7 @@
<%-- Box Footer --%>
<div class="box-footer">
<c:if test="${crudMode == 1}">
<input type="submit" class="btn" name="editagain" value="<la:message key="labels.overlapping_host_button_back"/>" />
<input type="submit" class="btn" name="createagain" value="<la:message key="labels.overlapping_host_button_back"/>" />
<input type="submit" class="btn btn-primary" name="create"
value="<la:message key="labels.overlapping_host_button_create"/>"
/>

View file

@ -106,7 +106,7 @@
<%-- Box Footer --%>
<div class="box-footer">
<c:if test="${crudMode == 1}">
<input type="submit" class="btn" name="editagain" value="<la:message key="labels.roletype_button_back"/>" />
<input type="submit" class="btn" name="createagain" value="<la:message key="labels.roletype_button_back"/>" />
<input type="submit" class="btn btn-primary" name="create"
value="<la:message key="labels.roletype_button_create"/>"
/>