All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.greenpepper.server.domain.Repository Maven / Gradle / Ivy

There is a newer version: 4.2.4
Show newest version
package com.greenpepper.server.domain;

import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REPOSITORY_BASEREPO_URL_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REPOSITORY_BASETEST_URL_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REPOSITORY_BASE_URL_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REPOSITORY_CONTENTTYPE_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REPOSITORY_MAX_USERS_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REPOSITORY_NAME_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REPOSITORY_PASSWORD_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REPOSITORY_PROJECT_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REPOSITORY_TYPE_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REPOSITORY_UID_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REPOSITORY_USERNAME_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.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import com.greenpepper.repository.DocumentRepository;
import com.greenpepper.runner.FactoryConverter;
import com.greenpepper.server.GreenPepperServerErrorKey;
import com.greenpepper.server.GreenPepperServerException;
import com.greenpepper.server.domain.component.ContentType;
import com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller;
import org.apache.commons.lang3.StringUtils;


/**
 * Repository Class.
 * Definition of the repository.
 * 

* Copyright (c) 2006 Pyxis technologies inc. All Rights Reserved. * * @author JCHUET * @version $Id: $Id */ @Entity @Table(name="REPOSITORY", uniqueConstraints = {@UniqueConstraint(columnNames={"NAME", "PROJECT_ID"})}) @SuppressWarnings("serial") public class Repository extends AbstractVersionedEntity implements Comparable { private String name; private String uid; private String baseUrl; private String repositoryBaseUrl; private String testBaseUrl; private ContentType contentType = ContentType.UNKNOWN; private String username; private String password; private Project project; private RepositoryType type; private Set requirements = new HashSet(); private Set specifications = new HashSet(); private int maxUsers; /** *

newInstance.

* * @param uid a {@link java.lang.String} object. * @return a {@link com.greenpepper.server.domain.Repository} object. */ public static Repository newInstance(String uid) { Repository repository = new Repository(); repository.setUid(uid); return repository; } /** *

Getter for the field name.

* * @return a {@link java.lang.String} object. */ @Basic @Column(name = "NAME", nullable = false, length=255) public String getName() { return this.name; } /** *

Getter for the field uid.

* * @return a {@link java.lang.String} object. */ @Basic @Column(name = "UIDENT", unique = true, nullable = false, length=255) public String getUid() { return this.uid; } /** *

Getter for the field baseUrl.

* * @return a {@link java.lang.String} object. */ @Basic @Column(name = "BASE_URL", nullable = false, length=255) public String getBaseUrl() { return this.baseUrl; } /** *

getBaseRepositoryUrl.

* * @return a {@link java.lang.String} object. */ @Basic @Column(name = "BASE_REPOSITORY_URL", nullable = false, length=255) public String getBaseRepositoryUrl() { return this.repositoryBaseUrl; } /** *

getBaseTestUrl.

* * @return a {@link java.lang.String} object. */ @Basic @Column(name = "BASE_TEST_URL", nullable = false, length=255) public String getBaseTestUrl() { return this.testBaseUrl; } /** *

Getter for the field username.

* * @return a {@link java.lang.String} object. */ @Basic @Column(name = "USERNAME", nullable = true, length=15) public String getUsername() { return username; } /** *

Getter for the field password.

* * @return a {@link java.lang.String} object. */ @Basic @Column(name = "PASSWORD", nullable = true, length=15) public String getPassword() { return password; } /** *

Getter for the field project.

* * @return a {@link com.greenpepper.server.domain.Project} object. */ @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) @JoinColumn(name="PROJECT_ID") public Project getProject() { return project; } /** *

Getter for the field type.

* * @return a {@link com.greenpepper.server.domain.RepositoryType} object. */ @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) @JoinColumn(name="REPOSITORY_TYPE_ID") public RepositoryType getType() { return this.type; } /** *

Getter for the field requirements.

* * @return a {@link java.util.Set} object. */ @OneToMany(mappedBy="repository", cascade=CascadeType.ALL) public Set getRequirements() { return this.requirements; } /** *

Getter for the field specifications.

* * @return a {@link java.util.Set} object. */ @OneToMany(mappedBy="repository", cascade=CascadeType.ALL) public Set getSpecifications() { return specifications; } /** *

Getter for the field contentType.

* * @return a {@link com.greenpepper.server.domain.component.ContentType} object. */ public ContentType getContentType() { return contentType; } /** *

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 uid.

* * @param uid a {@link java.lang.String} object. */ public void setUid(String uid) { this.uid = uid; } /** *

Setter for the field baseUrl.

* * @param baseUrl a {@link java.lang.String} object. */ public void setBaseUrl(String baseUrl) { this.baseUrl = baseUrl; } /** *

setBaseRepositoryUrl.

* * @param repositoryBaseUrl a {@link java.lang.String} object. */ public void setBaseRepositoryUrl(String repositoryBaseUrl) { this.repositoryBaseUrl = repositoryBaseUrl; } /** *

setBaseTestUrl.

* * @param testBaseUrl a {@link java.lang.String} object. */ public void setBaseTestUrl(String testBaseUrl) { this.testBaseUrl = testBaseUrl; } /** *

Setter for the field username.

* * @param username a {@link java.lang.String} object. */ public void setUsername(String username) { this.username = username; } /** *

Setter for the field password.

* * @param password a {@link java.lang.String} object. */ public void setPassword(String password) { this.password = password; } /** *

Setter for the field contentType.

* * @param contentType a {@link com.greenpepper.server.domain.component.ContentType} object. */ public void setContentType(ContentType contentType) { this.contentType = contentType; } /** *

Setter for the field project.

* * @param project a {@link com.greenpepper.server.domain.Project} object. */ public void setProject(Project project) { this.project = project; } /** *

Setter for the field type.

* * @param type a {@link com.greenpepper.server.domain.RepositoryType} object. */ public void setType(RepositoryType type) { this.type = type; } /** *

Setter for the field requirements.

* * @param requirements a {@link java.util.Set} object. */ public void setRequirements(Set requirements) { this.requirements = requirements; } /** *

Setter for the field specifications.

* * @param specifications a {@link java.util.Set} object. */ public void setSpecifications(Set specifications) { this.specifications = specifications; } /** *

addRequirement.

* * @param requirement a {@link com.greenpepper.server.domain.Requirement} object. * @throws com.greenpepper.server.GreenPepperServerException if any. */ public void addRequirement(Requirement requirement) throws GreenPepperServerException { if(requirements.contains(requirement) || requirementNameExists(requirement.getName())) throw new GreenPepperServerException( GreenPepperServerErrorKey.REQUIREMENT_ALREADY_EXISTS, "Requirement already exists"); requirement.setRepository(this); requirements.add(requirement); } /** *

removeRequirement.

* * @param requirement a {@link com.greenpepper.server.domain.Requirement} object. * @throws com.greenpepper.server.GreenPepperServerException if any. */ public void removeRequirement(Requirement requirement) throws GreenPepperServerException { if(!requirements.contains(requirement) ) throw new GreenPepperServerException( GreenPepperServerErrorKey.REQUIREMENT_NOT_FOUND, "Requirement not found"); requirements.remove(requirement); requirement.setRepository(null); } /** *

addSpecification.

* * @param specification a {@link com.greenpepper.server.domain.Specification} object. * @throws com.greenpepper.server.GreenPepperServerException if any. */ public void addSpecification(Specification specification) throws GreenPepperServerException { if(specifications.contains(specification) || specificationNameExists(specification.getName())) throw new GreenPepperServerException( GreenPepperServerErrorKey.SPECIFICATION_ALREADY_EXISTS, "Specification already exists"); specification.setRepository(this); specifications.add(specification); } /** *

removeSpecification.

* * @param specification a {@link com.greenpepper.server.domain.Specification} object. * @throws com.greenpepper.server.GreenPepperServerException if any. */ public void removeSpecification(Specification specification) throws GreenPepperServerException { if(!specifications.contains(specification)) throw new GreenPepperServerException( GreenPepperServerErrorKey.SPECIFICATION_NOT_FOUND, "Specification not found"); specifications.remove(specification); specification.setRepository(null); } /** *

Getter for the field maxUsers.

* * @return a int. */ @Transient public int getMaxUsers() { return maxUsers; } /** *

Setter for the field maxUsers.

* * @param maxUsers a int. */ public void setMaxUsers(int maxUsers) { this.maxUsers = maxUsers; } /** *

resolveName.

* * @param document a {@link com.greenpepper.server.domain.Document} object. * @return a {@link java.lang.String} object. * @throws com.greenpepper.server.GreenPepperServerException if any. */ public String resolveName(Document document) throws GreenPepperServerException { return type.resolveName(document); } /** *

asCmdLineOption.

* * @param env a {@link com.greenpepper.server.domain.EnvironmentType} object. * @return a {@link java.lang.String} object. */ public String asCmdLineOption(EnvironmentType env) { return type.asFactoryArguments(this, env, false, null, null); } /** *

asDocumentRepository.

* * @param env a {@link com.greenpepper.server.domain.EnvironmentType} object. * @return a {@link com.greenpepper.repository.DocumentRepository} object. * @throws java.lang.Exception if any. */ public DocumentRepository asDocumentRepository(EnvironmentType env) throws Exception { return asDocumentRepository(env, null, null); } /** *

asDocumentRepository.

* * @param env a {@link com.greenpepper.server.domain.EnvironmentType} object. * @param user a {@link java.lang.String} object. * @param pwd a {@link java.lang.String} object. * @return a {@link com.greenpepper.repository.DocumentRepository} object. * @throws java.lang.Exception if any. */ public DocumentRepository asDocumentRepository(EnvironmentType env, String user, String pwd) throws Exception { return (DocumentRepository)new FactoryConverter().convert(type.asFactoryArguments(this, env, true, user, pwd)); } /** *

marshallize.

* * @return a {@link java.util.Vector} object. */ public Vector marshallize() { Vector parameters = new Vector(); parameters.add(REPOSITORY_NAME_IDX, StringUtils.defaultString(name)); parameters.add(REPOSITORY_UID_IDX, StringUtils.defaultString(uid)); parameters.add(REPOSITORY_PROJECT_IDX, project != null ? project.marshallize() : Project.newInstance("").marshallize()); parameters.add(REPOSITORY_TYPE_IDX, type != null ? type.marshallize() : RepositoryType.newInstance("").marshallize()); parameters.add(REPOSITORY_CONTENTTYPE_IDX, contentType.toString()); parameters.add(REPOSITORY_BASE_URL_IDX, StringUtils.defaultString(getBaseUrl())); parameters.add(REPOSITORY_BASEREPO_URL_IDX, StringUtils.defaultString(getBaseRepositoryUrl())); parameters.add(REPOSITORY_BASETEST_URL_IDX, StringUtils.defaultString(getBaseTestUrl())); parameters.add(REPOSITORY_USERNAME_IDX, StringUtils.defaultString(username)); parameters.add(REPOSITORY_PASSWORD_IDX, StringUtils.defaultString(password)); parameters.add(REPOSITORY_MAX_USERS_IDX, maxUsers); return parameters; } /** {@inheritDoc} */ public int compareTo(Object o) { return getName().compareTo(((Repository)o).getName()); } /** {@inheritDoc} */ public boolean equals(Object o) { if(o == null || !(o instanceof Repository)) { return false; } Repository repoCompared = (Repository)o; return getUid().equals(repoCompared.getUid()); } /** *

hashCode.

* * @return a int. */ public int hashCode() { return getUid() == null ? 0 : getUid().hashCode(); } private boolean requirementNameExists(String requirementName) { for (Requirement requirement : requirements) if (requirement.getName().equalsIgnoreCase(requirementName)) return true; return false; } private boolean specificationNameExists(String specificationName) { for (Specification specification : specifications) if (specification.getName().equalsIgnoreCase(specificationName)) return true; return false; } }