/**
*
*/
package com.etong.common.system.domain;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import com.etong.common.system.domain.base.StringIdEntity;
import com.etong.common.system.validator.ByteLength;
/**
* @version 1.0
*/
@Entity
@Table(name="SYS_PERMISSIONS"/*, schema="UAWP"*/)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Permission extends StringIdEntity {
private static final long serialVersionUID = -806070358824673972L;
private Application application;//所属应用系统(全局权限此属性为空)
private PermissionType type;//权限类别
private String name;//权限名称
private String descriptor;//权限描述符
private String comment;//权限说明
private Set<Role> roles;//经过许可的角色
public Permission() {
super();
}
public Permission(PermissionType type) {
this.type = type;
}
public Permission(Application app, PermissionType type) {
this.application = app;
this.type = type;
}
/**
* @return 所属应用系统(全局权限此属性为空)
*/
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="app_id")
public Application getApplication() {
return application;
}
/**
* @param application 要设置的所属应用系统(全局权限此属性为空)
*/
public void setApplication(Application application) {
this.application = application;
}
/**
* @return 权限类别
*/
public PermissionType getType() {
return type;
}
/**
* @param type 要设置的权限类别
*/
public void setType(PermissionType type) {
this.type = type;
}
/**
* @return 权限名称
*/
@ByteLength(min=1, max=40)
@Column(length=40, nullable=false)
public String getName() {
return name;
}
/**
* @param name 要设置的权限名称
*/
public void setName(String name) {
this.name = name;
}
/**
* @return 权限描述符
*/
@ByteLength(min=1, max=127)
@Column(length=127, nullable=false)
public String getDescriptor() {
return descriptor;
}
/**
* @param descriptor 要设置的权限描述符
*/
public void setDescriptor(String descriptor) {
this.descriptor = descriptor;
}
/**
* @return 权限说明
*/
@ByteLength(max=40)
@Column(length=40)
public String getComment() {
return comment;
}
/**
* @param comment 要设置的权限说明
*/
public void setComment(String comment) {
this.comment = comment;
}
/**
* @return 经过许可的角色
*/
@ManyToMany(mappedBy="permissions", fetch=FetchType.LAZY)
public Set<Role> getRoles() {
if(roles == null) {
roles = new LinkedHashSet<Role>();
}
return roles;
}
/**
* @param roles 要设置的经过许可的角色
*/
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
public void addRole(Role role) {
this.getRoles().add(role);
role.getPermissions().add(this);
}
public void removeRole(Role role) {
this.getRoles().remove(role);
role.getPermissions().remove(this);
}
@Override
public int hashCode() {
int hash = this.descriptor == null ? 0 : this.descriptor.hashCode();
return hash * 37 + (getApplication() == null ? 0 : getApplication().hashCode());
}
@Override
public boolean equals(Object obj) {
if(obj == this) {
return true;
}
if(obj instanceof Permission) {
Permission that = (Permission)obj;
boolean eq = this.descriptor == null ? that.descriptor == null :
this.descriptor.equals(that.descriptor);
if(eq) {
eq = this.getApplication() == null ? that.getApplication() == null :
this.getApplication().equals(that.getApplication());
}
return eq;
}
return false;
}
public String toString() {
return new StringBuilder(Permission.class.getName())
.append("[id:").append(id)
.append(",name:").append(name)
.append(",descriptor:").append(descriptor)
.append(",type:").append(type)
.append(']').toString();
}
}
*
*/
package com.etong.common.system.domain;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import com.etong.common.system.domain.base.StringIdEntity;
import com.etong.common.system.validator.ByteLength;
/**
* @version 1.0
*/
@Entity
@Table(name="SYS_PERMISSIONS"/*, schema="UAWP"*/)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Permission extends StringIdEntity {
private static final long serialVersionUID = -806070358824673972L;
private Application application;//所属应用系统(全局权限此属性为空)
private PermissionType type;//权限类别
private String name;//权限名称
private String descriptor;//权限描述符
private String comment;//权限说明
private Set<Role> roles;//经过许可的角色
public Permission() {
super();
}
public Permission(PermissionType type) {
this.type = type;
}
public Permission(Application app, PermissionType type) {
this.application = app;
this.type = type;
}
/**
* @return 所属应用系统(全局权限此属性为空)
*/
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="app_id")
public Application getApplication() {
return application;
}
/**
* @param application 要设置的所属应用系统(全局权限此属性为空)
*/
public void setApplication(Application application) {
this.application = application;
}
/**
* @return 权限类别
*/
public PermissionType getType() {
return type;
}
/**
* @param type 要设置的权限类别
*/
public void setType(PermissionType type) {
this.type = type;
}
/**
* @return 权限名称
*/
@ByteLength(min=1, max=40)
@Column(length=40, nullable=false)
public String getName() {
return name;
}
/**
* @param name 要设置的权限名称
*/
public void setName(String name) {
this.name = name;
}
/**
* @return 权限描述符
*/
@ByteLength(min=1, max=127)
@Column(length=127, nullable=false)
public String getDescriptor() {
return descriptor;
}
/**
* @param descriptor 要设置的权限描述符
*/
public void setDescriptor(String descriptor) {
this.descriptor = descriptor;
}
/**
* @return 权限说明
*/
@ByteLength(max=40)
@Column(length=40)
public String getComment() {
return comment;
}
/**
* @param comment 要设置的权限说明
*/
public void setComment(String comment) {
this.comment = comment;
}
/**
* @return 经过许可的角色
*/
@ManyToMany(mappedBy="permissions", fetch=FetchType.LAZY)
public Set<Role> getRoles() {
if(roles == null) {
roles = new LinkedHashSet<Role>();
}
return roles;
}
/**
* @param roles 要设置的经过许可的角色
*/
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
public void addRole(Role role) {
this.getRoles().add(role);
role.getPermissions().add(this);
}
public void removeRole(Role role) {
this.getRoles().remove(role);
role.getPermissions().remove(this);
}
@Override
public int hashCode() {
int hash = this.descriptor == null ? 0 : this.descriptor.hashCode();
return hash * 37 + (getApplication() == null ? 0 : getApplication().hashCode());
}
@Override
public boolean equals(Object obj) {
if(obj == this) {
return true;
}
if(obj instanceof Permission) {
Permission that = (Permission)obj;
boolean eq = this.descriptor == null ? that.descriptor == null :
this.descriptor.equals(that.descriptor);
if(eq) {
eq = this.getApplication() == null ? that.getApplication() == null :
this.getApplication().equals(that.getApplication());
}
return eq;
}
return false;
}
public String toString() {
return new StringBuilder(Permission.class.getName())
.append("[id:").append(id)
.append(",name:").append(name)
.append(",descriptor:").append(descriptor)
.append(",type:").append(type)
.append(']').toString();
}
}