/*******************************************************************************
* ===========================================================
* Ankush : Big Data Cluster Management Solution
* ===========================================================
*
* (C) Copyright 2014, by Impetus Technologies
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License (LGPL v3) as
* published by the Free Software Foundation;
*
* This software is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
******************************************************************************/
package com.impetus.ankush.common.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.springframework.security.core.GrantedAuthority;
/**
* This class is used to represent available roles in the database.
*
*/
@Entity
@Table(name = "role")
@NamedQueries({ @NamedQuery(name = "findRoleByName", query = "select r from Role r where r.name = :name ") })
public class Role extends BaseObject implements GrantedAuthority {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 3690197650654049848L;
/** The id. */
private Long id;
/** The name. */
private String name;
/** The description. */
private String description;
/**
* Default constructor - creates a new instance with no values set.
*/
public Role() {
}
/**
* Create a new instance and set the name.
*
* @param name
* name of the role.
*/
public Role(final String name) {
this.name = name;
}
/**
* Gets the id.
*
* @return the id
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
/**
* Gets the authority.
*
* @return the name property (getAuthority required by Acegi's GrantedAuthority interface)
* @see org.springframework.security.core.GrantedAuthority#getAuthority()
*/
@Transient
@JsonIgnore
public String getAuthority() {
return getName();
}
/**
* Gets the name.
*
* @return the name
*/
@Column(length = 20)
public String getName() {
return this.name;
}
/**
* Gets the description.
*
* @return the description
*/
@Column(length = 64)
public String getDescription() {
return this.description;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Sets the description.
*
* @param description the new description
*/
public void setDescription(String description) {
this.description = description;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Role)) {
return false;
}
final Role role = (Role) o;
return !(name != null ? !name.equals(role.name) : role.name != null);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return (name != null ? name.hashCode() : 0);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).append(this.name).toString();
}
}