/** * 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.ItemService; import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.eperson.EPerson; import org.hibernate.annotations.Sort; import org.hibernate.annotations.SortType; import org.hibernate.proxy.HibernateProxyHelper; import javax.persistence.*; import java.util.*; /** * Class representing an item in DSpace. *
* This class holds in memory the item Dublin Core metadata, the bundles in the
* item, and the bitstreams in those bundles. When modifying the item, if you
* modify the Dublin Core or the "in archive" flag, you must call
* update
for the changes to be written to the database.
* Creating, adding or removing bundles or bitstreams has immediate effect in
* the database.
*
* @author Robert Tansley
* @author Martin Hald
* @version $Revision$
*/
@Entity
@Table(name="item")
public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
{
/**
* Wild card for Dublin Core metadata qualifiers/languages
*/
public static final String ANY = "*";
@Column(name="item_id", insertable = false, updatable = false)
private Integer legacyId;
@Column(name= "in_archive")
private boolean inArchive = false;
@Column(name= "discoverable")
private boolean discoverable = false;
@Column(name= "withdrawn")
private boolean withdrawn = false;
@Column(name= "last_modified", columnDefinition="timestamp with time zone")
@Temporal(TemporalType.TIMESTAMP)
private Date lastModified = new Date();
@ManyToOne(fetch = FetchType.LAZY, cascade={CascadeType.PERSIST})
@JoinColumn(name = "owning_collection")
private Collection owningCollection;
@OneToOne(fetch = FetchType.LAZY, mappedBy = "template")
private Collection templateItemOf;
/** The e-person who submitted this item */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "submitter_id")
private EPerson submitter = null;
/** The bundles in this item - kept in sync with DB */
@ManyToMany(fetch = FetchType.LAZY, cascade={CascadeType.PERSIST})
@JoinTable(
name = "collection2item",
joinColumns = {@JoinColumn(name = "item_id") },
inverseJoinColumns = {@JoinColumn(name = "collection_id") }
)
private final SetWorkflowItem.archive()
should set this.
*
* @param isArchived
* new value for the flag
*/
public void setArchived(boolean isArchived)
{
this.inArchive = isArchived;
setModified();
}
/**
* Set the "discoverable" flag. This is public and only
*
* @param discoverable
* new value for the flag
*/
public void setDiscoverable(boolean discoverable)
{
this.discoverable = discoverable;
setModified();
}
/**
* Set the owning Collection for the item
*
* @param c
* Collection
*/
public void setOwningCollection(Collection c)
{
this.owningCollection = c;
setModified();
}
/**
* Get the owning Collection for the item
*
* @return Collection that is the owner of the item
*/
public Collection getOwningCollection()
{
return owningCollection;
}
/**
* Get the e-person that originally submitted this item
*
* @return the submitter
*/
public EPerson getSubmitter()
{
return submitter;
}
/**
* Set the e-person that originally submitted this item. This is a public
* method since it is handled by the WorkspaceItem class in the ingest
* package. update
must be called to write the change to the
* database.
*
* @param sub
* the submitter
*/
public void setSubmitter(EPerson sub)
{
this.submitter = sub;
setModified();
}
/**
* Get the collections this item is in. The order is sorted ascending by collection name.
*
* @return the collections this item is in, if any.
*/
public Listtrue
if other
is the same Item as
* this object, false
otherwise
*
* @param obj
* object to compare to
* @return true
if object passed in represents the same item
* as this object
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
Class> objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
if (this.getClass() != objClass)
{
return false;
}
final Item otherItem = (Item) obj;
if (!this.getID().equals(otherItem.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.ITEM
*/
@Override
public int getType()
{
return Constants.ITEM;
}
@Override
public String getName()
{
return getItemService().getMetadataFirstValue(this, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY);
}
@Override
public Integer getLegacyId() {
return legacyId;
}
public ItemService getItemService()
{
if(itemService == null)
{
itemService = ContentServiceFactory.getInstance().getItemService();
}
return itemService;
}
}