/** * The contents of this file are subject to the license and copyright * detailed in the LICENSE and NOTICE files at the root of the source * tree and available online at * * http://www.dspace.org/license/ */ package org.dspace.content; import org.dspace.content.comparator.NameAscendingComparator; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.CollectionService; import org.dspace.core.*; import org.dspace.eperson.Group; import org.hibernate.proxy.HibernateProxyHelper; import javax.persistence.*; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * Class representing a collection. *
* The collection's metadata (name, introductory text etc), workflow groups, and
* default group of submitters are loaded into memory. Changes to metadata are
* not written to the database until
* The default group of submitters for collection 100 is the one called
*
* The default group of administrators for collection 100 is the one called
* update
is called. If you
* create or remove a workflow group, the change is only reflected in the
* database after calling update
. The default group of
* submitters is slightly different - creating or removing this has instant
* effect.
*
* @author Robert Tansley
* @version $Revision$
*/
@Entity
@Table(name="collection")
public class Collection extends DSpaceObject implements DSpaceObjectLegacySupport
{
@Column(name="collection_id", insertable = false, updatable = false)
private Integer legacyId;
/** The logo bitstream */
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "logo_bitstream_id")
private Bitstream logo;
/** The item template */
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "template_item_id")
private Item template;
/**
* Groups corresponding to workflow steps - NOTE these start from one, so
* workflowGroups[0] corresponds to workflow_step_1.
*/
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "workflow_step_1")
private Group workflowStep1;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "workflow_step_2")
private Group workflowStep2;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "workflow_step_3")
private Group workflowStep3;
@OneToOne
@JoinColumn(name = "submitter")
/** The default group of administrators */
private Group submitters;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "admin")
/** The default group of administrators */
private Group admins;
@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST})
@JoinTable(
name = "community2collection",
joinColumns = {@JoinColumn(name = "collection_id") },
inverseJoinColumns = {@JoinColumn(name = "community_id") }
)
private final Listnull
is returned if the
* collection does not have a logo.
*
* @return the logo of the collection, or null
*/
public Bitstream getLogo()
{
return logo;
}
protected void setLogo(Bitstream logo) {
this.logo = logo;
setModified();
}
/**
* Get the default group of submitters, if there is one. Note that the
* authorization system may allow others to submit to the collection, so
* this is not necessarily a definitive list of potential submitters.
* collection_100_submit
.
*
* @return the default group of submitters, or null
if there
* is no default group.
*/
public Group getSubmitters()
{
return submitters;
}
/**
* Set the default group of submitters
*
* Package protected in order to preven unauthorized calls to this method
*
* @param submitters the group of submitters
*/
void setSubmitters(Group submitters) {
this.submitters = submitters;
setModified();
}
/**
* Get the default group of administrators, if there is one. Note that the
* authorization system may allow others to be administrators for the
* collection.
* collection_100_admin
.
*
* @return group of administrators, or null
if there is no
* default group.
*/
public Group getAdministrators()
{
return admins;
}
void setAdmins(Group admins) {
this.admins = admins;
setModified();
}
public Group getWorkflowStep1() {
return workflowStep1;
}
public Group getWorkflowStep2() {
return workflowStep2;
}
public Group getWorkflowStep3() {
return workflowStep3;
}
void setWorkflowStep1(Group workflowStep1) {
this.workflowStep1 = workflowStep1;
setModified();
}
void setWorkflowStep2(Group workflowStep2) {
this.workflowStep2 = workflowStep2;
setModified();
}
void setWorkflowStep3(Group workflowStep3) {
this.workflowStep3 = workflowStep3;
setModified();
}
/**
* Get the license that users must grant before submitting to this
* collection.
*
* @return the license for this collection
*/
public String getLicenseCollection()
{
return getCollectionService().getMetadata(this, "license");
}
/**
* Set the license for this collection. Passing in null
means
* that the site-wide default will be used.
*
* @param context context
* @param license the license, or null
* @throws SQLException if database error
*/
public void setLicense(Context context, String license) throws SQLException {
getCollectionService().setMetadata(context, this, "license", license);
}
/**
* Get the template item for this collection. null
is
* returned if the collection does not have a template. Submission
* mechanisms may copy this template to provide a convenient starting point
* for a submission.
*
* @return the item template, or null
* @throws SQLException if database error
*/
public Item getTemplateItem() throws SQLException
{
return template;
}
void setTemplateItem(Item template) {
this.template = template;
setModified();
}
/**
* Get the communities this collection appears in
*
* @return array of Community
objects
* @throws SQLException if database error
*/
public Listtrue
if other
is the same Collection
* as this object, false
otherwise
*
* @param other
* object to compare to
*
* @return true
if object passed in represents the same
* collection as this object
*/
@Override
public boolean equals(Object other)
{
if (other == null)
{
return false;
}
Class> objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(other);
if (this.getClass() != objClass)
{
return false;
}
final Collection otherCollection = (Collection) other;
if (!this.getID().equals(otherCollection.getID() ))
{
return false;
}
return true;
}
@Override
public int hashCode()
{
int hash = 5;
hash += 71 * hash + getType();
hash += 71 * hash + getID().hashCode();
return hash;
}
/**
* return type found in Constants
*
* @return int Constants.COLLECTION
*/
@Override
public int getType()
{
return Constants.COLLECTION;
}
public void setWorkflowGroup(int step, Group g)
{
getCollectionService().setWorkflowGroup(this, step, g);
}
@Override
public Integer getLegacyId() {
return legacyId;
}
private CollectionService getCollectionService() {
if(collectionService == null)
{
collectionService = ContentServiceFactory.getInstance().getCollectionService();
}
return collectionService;
}
}