com.greenpepper.server.domain.Project Maven / Gradle / Ivy
package com.greenpepper.server.domain;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.PROJECT_NAME_IDX;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.greenpepper.server.GreenPepperServerErrorKey;
import com.greenpepper.server.GreenPepperServerException;
/**
* Project Class.
* Definition of a project.
*
* Copyright (c) 2006 Pyxis technologies inc. All Rights Reserved.
*
* @author JCHUET
* @version $Id: $Id
*/
@Entity
@Table(name="PROJECT")
@SuppressWarnings("serial")
public class Project extends AbstractVersionedEntity implements Comparable
{
private String name;
private Set repositories = new HashSet();
private Set systemUnderTests = new HashSet();
/**
* newInstance.
*
* @param name a {@link java.lang.String} object.
* @return a {@link com.greenpepper.server.domain.Project} object.
*/
public static Project newInstance(String name)
{
Project project = new Project();
project.setName(name);
return project;
}
/**
* Getter for the field name
.
*
* @return a {@link java.lang.String} object.
*/
@Basic
@Column(name = "NAME", unique = true, nullable = false, length=255)
public String getName()
{
return name;
}
/**
* Getter for the field repositories
.
*
* @return a {@link java.util.Set} object.
*/
@OneToMany(mappedBy="project", cascade=CascadeType.ALL)
public Set getRepositories()
{
return repositories;
}
/**
* Getter for the field systemUnderTests
.
*
* @return a {@link java.util.Set} object.
*/
@OneToMany(mappedBy="project", cascade=CascadeType.ALL)
public Set getSystemUnderTests()
{
return systemUnderTests;
}
/**
* Setter for the field name
.
*
* @param name a {@link java.lang.String} object.
*/
public void setName(String name)
{
this.name = name;
}
/**
* Setter for the field repositories
.
*
* @param repositories a {@link java.util.Set} object.
*/
public void setRepositories(Set repositories)
{
this.repositories = repositories;
}
/**
* Setter for the field systemUnderTests
.
*
* @param systemUnderTests a {@link java.util.Set} object.
*/
public void setSystemUnderTests(Set systemUnderTests)
{
this.systemUnderTests = systemUnderTests;
}
/**
* addRepository.
*
* @param repo a {@link com.greenpepper.server.domain.Repository} object.
* @throws com.greenpepper.server.GreenPepperServerException if any.
*/
public void addRepository(Repository repo) throws GreenPepperServerException
{
if (findRepositoryByName(repo.getName()) != null)
{
throw new GreenPepperServerException( GreenPepperServerErrorKey.REPOSITORY_ALREADY_EXISTS, "Repository already exists");
}
repo.setProject(this);
repositories.add(repo);
}
/**
* removeRepository.
*
* @param repo a {@link com.greenpepper.server.domain.Repository} object.
* @throws com.greenpepper.server.GreenPepperServerException if any.
*/
public void removeRepository(Repository repo) throws GreenPepperServerException
{
if(!repositories.contains(repo))
{
throw new GreenPepperServerException( GreenPepperServerErrorKey.REPOSITORY_NOT_FOUND, "Repository not found");
}
repositories.remove(repo);
repo.setProject(null);
}
/**
* addSystemUnderTest.
*
* @param sut a {@link com.greenpepper.server.domain.SystemUnderTest} object.
* @throws com.greenpepper.server.GreenPepperServerException if any.
*/
public void addSystemUnderTest(SystemUnderTest sut) throws GreenPepperServerException
{
if (findSystemUnderTestByName(sut.getName()) != null)
{
throw new GreenPepperServerException( GreenPepperServerErrorKey.SUT_ALREADY_EXISTS, "Sut name already exists");
}
if(systemUnderTests.isEmpty()){ sut.setIsDefault(true); }
systemUnderTests.add(sut);
sut.setProject(this);
}
/**
* removeSystemUnderTest.
*
* @param sut a {@link com.greenpepper.server.domain.SystemUnderTest} object.
* @throws com.greenpepper.server.GreenPepperServerException if any.
*/
public void removeSystemUnderTest(SystemUnderTest sut) throws GreenPepperServerException
{
if(!systemUnderTests.contains(sut))
{
throw new GreenPepperServerException( GreenPepperServerErrorKey.SUT_NOT_FOUND, "Sut not found");
}
systemUnderTests.remove(sut);
if(sut.isDefault() && !systemUnderTests.isEmpty())
{
systemUnderTests.iterator().next().setIsDefault(true);
}
sut.setProject(null);
}
/**
* getDefaultSystemUnderTest.
*
* @return a {@link com.greenpepper.server.domain.SystemUnderTest} object.
*/
@Transient
public SystemUnderTest getDefaultSystemUnderTest()
{
for(SystemUnderTest sut : systemUnderTests)
{
if(sut.isDefault())
{
return sut;
}
}
return null;
}
/**
* marshallize.
*
* @return a {@link java.util.Vector} object.
*/
public Vector
© 2015 - 2025 Weber Informatics LLC | Privacy Policy