/*
* ====================================================================
*
* Copyright (C) 2007 - 2012 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 java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
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.Index;
/**
* Class Category.
*
* @author Tobia di Pisa (tobia.dipisa at geo-solutions.it)
* @author Emanuele Tajariol (etj at geo-solutions.it)
*/
@Entity(name = "Category")
@Table(name = "gs_category", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }) })
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "gs_category")
@XmlRootElement(name = "Category")
public class Category implements Serializable {
private static final long serialVersionUID = -6161770040532770363L;
@Id
@GeneratedValue
private Long id;
@Column(name = "name", nullable = false, updatable = false)
@Index(name = "idx_category_type")
private String name;
/*
* Only To allow the CASCADING operation
*/
@OneToMany(mappedBy = "category", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
private List<Resource> resource;
// /*
// * Only To allow the CASCADING operation
// */
// @OneToMany(mappedBy = "category", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
// private List<SecurityRule> security;
/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the resource
*/
@XmlTransient
public List<Resource> getResource() {
return resource;
}
/**
* @param resource the resource to set
*/
public void setResource(List<Resource> resource) {
this.resource = resource;
}
// /**
// * @return the security
// */
// @XmlTransient
// public List<SecurityRule> getSecurity() {
// return security;
// }
//
// /**
// * @param security the security to set
// */
// public void setSecurity(List<SecurityRule> security) {
// this.security = security;
// }
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/*
* (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);
}
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) + ((resource == null) ? 0 : resource.hashCode());
// result = (prime * result)
// + ((security == null) ? 0 : security.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;
}
Category other = (Category) 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 (resource == null) {
if (other.resource != null) {
return false;
}
} else if (!resource.equals(other.resource)) {
return false;
}
// if ( security == null ) {
// if ( other.security != null ) {
// return false;
// }
// } else if ( !security.equals(other.security) ) {
// return false;
// }
return true;
}
}