Java tutorial
/* * Copyright 2012 Eng Kam Hon (kamhon@gmail.com) * * 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 net.kamhon.ieagle.function.user.vo; import java.util.ArrayList; import java.util.List; import java.util.Set; import javax.persistence.Access; import javax.persistence.AccessType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; import javax.persistence.Transient; import net.kamhon.ieagle.FrameworkConst; import net.kamhon.ieagle.vo.Manipulateable; import net.kamhon.ieagle.vo.annotation.ToTrim; import net.kamhon.ieagle.vo.annotation.ToUpperCase; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.HashCodeBuilder; @Entity @Table(name = "app_user_menu") @Access(AccessType.FIELD) public class UserMenu extends net.kamhon.ieagle.vo.VoBase implements Manipulateable { private static final long serialVersionUID = 1L; @Id @Column(name = "menu_id") private Long menuId; @Column(name = "parent_id") private Long parentId; @ManyToOne @JoinColumn(name = "parent_id", insertable = false, updatable = false, nullable = true) private UserMenu parentMenu; @Column(name = "sort_seq", nullable = false) private Long sortSeq; @ToTrim @Column(name = "menu_name", length = 50, nullable = false) private String menuName; @ToTrim @Column(name = "menu_desc", length = 100) private String menuDesc; @ToTrim @Column(name = "menu_url", length = 200) private String menuUrl; @Column(name = "is_auth_needed") private Boolean isAuthNeeded; @ToTrim @ToUpperCase @Column(name = "access_code", length = 30) private String accessCode; @Column(name = "create_mode", nullable = false) private Boolean createMode; @Column(name = "read_mode", nullable = false) private Boolean readMode; @Column(name = "update_mode", nullable = false) private Boolean updateMode; @Column(name = "delete_mode", nullable = false) private Boolean deleteMode; @Column(name = "admin_mode", nullable = false) private Boolean adminMode; @Column(name = "tree_level") private Integer treeLevel; @ToTrim @ToUpperCase @Column(name = "tree_config") private String treeConfig; @ToTrim @ToUpperCase @Column(name = "menu_target", length = 50) private String menuTarget; @ToTrim @ToUpperCase @Column(name = "status", length = 1, nullable = false) private String status; @Transient private List<UserMenu> subMenus = new ArrayList<UserMenu>(); @OneToMany(mappedBy = "parentMenu", fetch = FetchType.LAZY) @OrderBy(value = "menuId") private Set<UserMenu> childMenus; public UserMenu() { } public UserMenu(Long menuId) { this.menuId = menuId; } public UserMenu(boolean defaultValue) { if (defaultValue) { isAuthNeeded = true; createMode = false; readMode = false; updateMode = false; deleteMode = false; adminMode = false; status = FrameworkConst.STATUS_APPROVED; } } public Long getMenuId() { return menuId; } public Long getParentId() { return parentId; } public Long getSortSeq() { return sortSeq; } public String getMenuName() { return menuName; } public String getMenuDesc() { return menuDesc; } public String getMenuUrl() { return menuUrl; } public Boolean getIsAuthNeeded() { return isAuthNeeded; } public String getAccessCode() { return accessCode; } public Boolean getCreateMode() { return createMode; } public Boolean getReadMode() { return readMode; } public Boolean getUpdateMode() { return updateMode; } public Boolean getDeleteMode() { return deleteMode; } public Boolean getAdminMode() { return adminMode; } public Integer getTreeLevel() { return treeLevel; } public String getTreeConfig() { return treeConfig; } public String getMenuTarget() { return menuTarget; } public String getStatus() { return status; } public void setMenuId(Long menuId) { this.menuId = menuId; } public void setParentId(Long parentId) { this.parentId = parentId; } public void setSortSeq(Long sortSeq) { this.sortSeq = sortSeq; } public void setMenuName(String menuName) { this.menuName = menuName; } public void setMenuDesc(String menuDesc) { this.menuDesc = menuDesc; } public void setMenuUrl(String menuUrl) { this.menuUrl = menuUrl; } public void setIsAuthNeeded(Boolean isAuthNeeded) { this.isAuthNeeded = isAuthNeeded; } public void setAccessCode(String accessCode) { this.accessCode = accessCode; } public void setCreateMode(Boolean createMode) { this.createMode = createMode; } public void setReadMode(Boolean readMode) { this.readMode = readMode; } public void setUpdateMode(Boolean updateMode) { this.updateMode = updateMode; } public void setDeleteMode(Boolean deleteMode) { this.deleteMode = deleteMode; } public void setAdminMode(Boolean adminMode) { this.adminMode = adminMode; } public void setTreeLevel(Integer treeLevel) { this.treeLevel = treeLevel; } public void setTreeConfig(String treeConfig) { this.treeConfig = treeConfig; } public void setMenuTarget(String menuTarget) { this.menuTarget = menuTarget; } public void setStatus(String status) { this.status = status; } public List<UserMenu> getSubMenus() { return subMenus; } public void setSubMenus(List<UserMenu> subMenus) { this.subMenus = subMenus; } public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final UserMenu other = (UserMenu) obj; if (this.menuId == null) { if (other.menuId != null) return false; } else if (!this.menuId.equals(other.menuId)) return false; return true; } public int hashCode() { HashCodeBuilder hashCode = new HashCodeBuilder(); if (menuId != null) hashCode.append(menuId); return hashCode.toHashCode(); } public UserMenu getParentMenu() { return parentMenu; } public void setParentMenu(UserMenu parentMenu) { this.parentMenu = parentMenu; } public Set<UserMenu> getChildMenus() { return childMenus; } public void setChildMenus(Set<UserMenu> childMenus) { this.childMenus = childMenus; } public boolean isApproveable() { return false; } public boolean isDeleteable() { return false; } public boolean isEditable() { return true; } @Transient public String getAcrud() { if (StringUtils.isBlank(accessCode)) { return ""; } Boolean t = new Boolean(true); String s = ""; s += t.equals(adminMode) ? "Y" : "N"; s += t.equals(createMode) ? "Y" : "N"; s += t.equals(readMode) ? "Y" : "N"; s += t.equals(updateMode) ? "Y" : "N"; s += t.equals(deleteMode) ? "Y" : "N"; return s; } public void setAcrud(String acrud) { } }