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.HashSet; import java.util.Set; import javax.persistence.Access; import javax.persistence.AccessType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.Transient; import net.kamhon.ieagle.function.master.vo.Dept; import net.kamhon.ieagle.security.UserDetails; 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.builder.HashCodeBuilder; import org.hibernate.annotations.GenericGenerator; import com.opensymphony.xwork2.conversion.annotations.Conversion; @Entity @Inheritance(strategy = InheritanceType.JOINED) @Table(name = "app_user") @Access(AccessType.FIELD) @Conversion public class User extends UserDetails implements Manipulateable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") @Column(name = "user_id", unique = true, nullable = false, length = 32) protected String userId; @ToUpperCase @Column(name = "staff_code", length = 20) protected String staffCode; @Column(name = "comp_id", nullable = false, length = 32) protected String compId; @ToUpperCase @Column(name = "username", length = 30, nullable = false) protected String username; @Column(name = "dept_id") protected String deptId; @ManyToOne @JoinColumn(name = "dept_id", insertable = false, updatable = false, nullable = true) protected Dept dept; @Column(name = "root_loc_id") protected Long rootLocId; @Column(name = "loc_id") protected Long locId; // @ManyToOne(optional = true) // @JoinColumn(name = "loc_id", insertable = false, updatable = false) @Transient protected UserLoc userLoc; @ToUpperCase @ToTrim @Column(name = "fullname", length = 100) protected String fullname; @Column(name = "password", length = 32) protected String password; @ToUpperCase @Column(name = "email", length = 50) protected String email; @Column(name = "retry") protected Integer retry; @ToUpperCase @ToTrim @Column(name = "user_type", length = 20, nullable = false) protected String userType; @ToUpperCase @Column(name = "status", length = 1) protected String status; @Column(name = "retired") protected Boolean retired; @ManyToMany(targetEntity = UserRole.class) @JoinTable(name = "app_user_in_role", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "role_id") }) // @Transient protected Set<UserRole> userRoles = new HashSet<UserRole>(); // @ManyToOne(optional = true) // @JoinColumn(name = "add_by", insertable = false, updatable = false) @Transient protected User userAdd; // @ManyToOne(optional = true) // @JoinColumn(name = "update_by", insertable = false, updatable = false) @Transient protected User userUpdate; public User() { } public User(String userId) { this.userId = userId; } public User(boolean defaultValue) { if (defaultValue) { staffCode = ""; retry = 0; retired = false; status = "A"; rootLocId = 1L; locId = 1L; userType = "HQ"; } } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getStaffCode() { return staffCode; } public String getUsername() { return username; } public String getFullname() { return fullname; } public String getPassword() { return password; } public String getEmail() { return email; } public Integer getRetry() { return retry; } public String getStatus() { return status; } public Boolean getRetired() { return retired; } public void setStaffCode(String staffCode) { this.staffCode = staffCode; } public String getCompId() { return compId; } public void setCompId(String compId) { this.compId = compId; } public void setUsername(String username) { this.username = username; } public String getDeptId() { return deptId; } public void setDeptId(String deptId) { this.deptId = deptId; } public void setFullname(String fullname) { this.fullname = fullname; } public void setPassword(String password) { this.password = password; } public void setEmail(String email) { this.email = email; } public void setRetry(Integer retry) { this.retry = retry; } public void setStatus(String status) { this.status = status; } public void setRetired(Boolean retired) { this.retired = retired; } public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final User other = (User) obj; if (this.userId == null) { if (other.userId != null) return false; } else if (!this.userId.equals(other.userId)) return false; return true; } public int hashCode() { HashCodeBuilder hashCode = new HashCodeBuilder(); if (userId != null) hashCode.append(userId); return hashCode.toHashCode(); } @Override public boolean isEnabled() { return true; } public Set<UserRole> getUserRoles() { return userRoles; } public void setUserRoles(Set<UserRole> userRoles) { this.userRoles = userRoles; } public boolean isApproveable() { return false; } public boolean isDeleteable() { return true; } public boolean isEditable() { return true; } public User getUserAdd() { return userAdd; } public void setUserAdd(User userAdd) { this.userAdd = userAdd; } public User getUserUpdate() { return userUpdate; } public void setUserUpdate(User userUpdate) { this.userUpdate = userUpdate; } public Dept getDept() { return dept; } public void setDept(Dept dept) { this.dept = dept; } public Long getRootLocId() { return rootLocId; } public void setRootLocId(Long rootLocId) { this.rootLocId = rootLocId; } public Long getLocId() { return locId; } public void setLocId(Long locId) { this.locId = locId; } public UserLoc getUserLoc() { return userLoc; } public void setUserLoc(UserLoc userLoc) { this.userLoc = userLoc; } public String getUserType() { return userType; } public void setUserType(String userType) { this.userType = userType; } }