/*******************************************************************************
* Gisgraphy Project
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
*
* Copyright 2008 Gisgraphy project
* David Masclet <davidmasclet@gisgraphy.com>
*
*
*******************************************************************************/
package com.gisgraphy.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.springframework.security.core.GrantedAuthority;
/**
* This class is used to represent available roles in the database.
*
* @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a> Version by
* Dan Kibler dan@getrolling.com Extended to implement Acegi
* GrantedAuthority interface by David Carter david@carter.net
*/
@Entity
@Table(name = "role")
public class Role extends BaseObject implements Serializable, GrantedAuthority {
private static final long serialVersionUID = 3690197650654049848L;
private Long id;
private String name;
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;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
/**
* @see org.acegisecurity.GrantedAuthority#getAuthority()
* @return the name property (getAuthority required by Acegi's
* GrantedAuthority interface)
*/
@Transient
public String getAuthority() {
return getName();
}
@Column(length = 20)
public String getName() {
return this.name;
}
@Column(length = 64)
public String getDescription() {
return this.description;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
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();
}
public int compareTo(Object o) {
if (this == o) {
return 0;
}
if (!(o instanceof Role)) {
return -1;
}
final Role role = (Role) o;
if (name != null && role.name!=null && name.equals(role.name)){
return 0;
} else {
return -1;
}
}
}