/*
* ====================================================================
*
* Copyright (C) 2007 - 2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* GPLv3 + Classpath exception
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.
*
* ====================================================================
*
* This software consists of voluntary contributions made by developers
* of GeoSolutions. For more information on GeoSolutions, please see
* <http://www.geo-solutions.it/>.
*
*/
package it.geosolutions.geostore.core.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Index;
/**
* Class Attribute.
*
* @author Tobia di Pisa (tobia.dipisa at geo-solutions.it)
*
*/
@Entity(name = "UserAttribute")
@Table(name = "gs_user_attribute", uniqueConstraints = { @UniqueConstraint(columnNames = { "name",
"user_id" }) })
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "gs_user_attribute")
@XmlRootElement(name = "UserAttribute")
public class UserAttribute implements Serializable {
private static final long serialVersionUID = 8215714782335367731L;
@Id
@GeneratedValue
private Long id;
@Column(name = "name", nullable = false, updatable = true)
@Index(name = "idx_user_attribute_name")
private String name;
@Column(name = "string", nullable = true, updatable = true)
@Index(name = "idx_user_attribute_text")
private String value;
@ManyToOne(optional = false)
@Index(name = "idx_attribute_user")
@ForeignKey(name = "fk_uattrib_user")
private User user;
/**
* @return the id
*/
@XmlTransient
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
/**
* @return the user
*/
@XmlTransient
public User getUser() {
return user;
}
/**
* @param user the user to set
*/
public void setUser(User user) {
this.user = user;
}
/*
* (non-Javadoc) @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName()).append('[');
if (id != null) {
builder.append("id=").append(id);
}
if (name != null) {
builder.append(", ");
builder.append("name=").append(name);
}
if (value != null) {
builder.append(", ");
builder.append("value=").append(value);
}
builder.append(']');
return builder.toString();
}
/*
* (non-Javadoc) @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + ((id == null) ? 0 : id.hashCode());
result = (prime * result) + ((name == null) ? 0 : name.hashCode());
result = (prime * result) + ((user == null) ? 0 : user.hashCode());
result = (prime * result) + ((value == null) ? 0 : value.hashCode());
return result;
}
/*
* (non-Javadoc) @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
UserAttribute other = (UserAttribute) obj;
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
if (user == null) {
if (other.user != null) {
return false;
}
} else if (!user.equals(other.user)) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
}