/**
* This file is part of OCPsoft SocialPM: Agile Project Management Tools (SocialPM)
*
* Copyright (c)2011 Lincoln Baxter, III <lincoln@ocpsoft.com> (OCPsoft)
* Copyright (c)2011 OCPsoft.com (http://ocpsoft.com)
*
* If you are developing and distributing open source applications under
* the GNU General Public License (GPL), then you are free to re-distribute SocialPM
* under the terms of the GPL, as follows:
*
* SocialPM 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 3 of the License, or
* (at your option) any later version.
*
* SocialPM 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 SocialPM. If not, see <http://www.gnu.org/licenses/>.
*
* For individuals or entities who wish to use SocialPM privately, or
* internally, the following terms do not apply:
*
* For OEMs, ISVs, and VARs who wish to distribute SocialPM with their
* products, or host their product online, OCPsoft provides flexible
* OEM commercial licenses.
*
* Optionally, Customers may choose a Commercial License. For additional
* details, contact an OCPsoft representative (sales@ocpsoft.com)
*/
package com.ocpsoft.socialpm.model.project;
import java.util.List;
import javax.persistence.CascadeType;
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 javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.jboss.errai.common.client.api.annotations.Portable;
import com.ocpsoft.socialpm.model.PersistentObject;
import com.ocpsoft.socialpm.model.project.story.Story;
@Portable
@Entity
@Table(name = "features", uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "project_id" }) })
public class Feature extends PersistentObject<Feature>
{
private static final long serialVersionUID = 2779206239693394734L;
@Column(length = 32)
private String name;
@Column(length = 512)
private String description;
public String getDescription()
{
return description;
}
public void setDescription(final String description)
{
this.description = description;
}
@ManyToOne
@JoinColumn(nullable = false, updatable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
@Index(name = "featureProjectIndex")
private Project project;
@Fetch(FetchMode.SUBSELECT)
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "features", cascade = {CascadeType.REFRESH, CascadeType.DETACH, CascadeType.MERGE})
private List<Story> stories;
public Feature()
{}
public boolean isEmpty()
{
return stories.isEmpty();
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = (prime * result) + ((name == null) ? 0 : name.hashCode());
result = (prime * result) + ((project == null) ? 0 : project.hashCode());
return result;
}
@Override
public boolean equals(final Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (!(obj instanceof Feature))
{
return false;
}
Feature other = (Feature) obj;
if (name == null)
{
if (other.name != null)
{
return false;
}
}
else if (!name.equals(other.name))
{
return false;
}
if (project == null)
{
if (other.project != null)
{
return false;
}
}
else if (!project.equals(other.project))
{
return false;
}
return true;
}
public String getName()
{
return name;
}
public void setName(final String name)
{
this.name = name;
}
public Project getProject()
{
return project;
}
public void setProject(final Project project)
{
this.project = project;
}
public List<Story> getStories()
{
return stories;
}
public void setStories(final List<Story> stories)
{
this.stories = stories;
}
@Override
public String toString()
{
return "Feature-" + name;
}
}