Permission

/**
 * 
 */
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();
}


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值