Fix dspace-api module per new code style

This commit is contained in:
Tim Donohue
2018-02-14 10:53:46 -06:00
parent 8ffc97f7f9
commit 8a48f782ea
1051 changed files with 53347 additions and 63373 deletions

View File

@@ -7,19 +7,34 @@
*/
package org.dspace.content;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
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.
* <P>
@@ -35,49 +50,52 @@ import java.util.*;
* @version $Revision$
*/
@Entity
@Table(name="item")
public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
{
@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)
@Column(name = "item_id", insertable = false, updatable = false)
private Integer legacyId;
@Column(name= "in_archive")
@Column(name = "in_archive")
private boolean inArchive = false;
@Column(name= "discoverable")
@Column(name = "discoverable")
private boolean discoverable = false;
@Column(name= "withdrawn")
@Column(name = "withdrawn")
private boolean withdrawn = false;
@Column(name= "last_modified", columnDefinition="timestamp with time zone")
@Column(name = "last_modified", columnDefinition = "timestamp with time zone")
@Temporal(TemporalType.TIMESTAMP)
private Date lastModified = new Date();
@ManyToOne(fetch = FetchType.LAZY, cascade={CascadeType.PERSIST})
@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 */
/**
* 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})
/**
* 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") }
name = "collection2item",
joinColumns = {@JoinColumn(name = "item_id")},
inverseJoinColumns = {@JoinColumn(name = "collection_id")}
)
private final Set<Collection> collections = new HashSet<>();
@@ -90,10 +108,8 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
/**
* Protected constructor, create object using:
* {@link org.dspace.content.service.ItemService#create(Context, WorkspaceItem)}
*
*/
protected Item()
{
protected Item() {
}
@@ -102,8 +118,7 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
*
* @return true if the item is in the main archive
*/
public boolean isArchived()
{
public boolean isArchived() {
return inArchive;
}
@@ -112,14 +127,14 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
*
* @return true if the item has been withdrawn
*/
public boolean isWithdrawn()
{
public boolean isWithdrawn() {
return withdrawn;
}
/**
* Set an item to be withdrawn, do NOT make this method public, use itemService().withdraw() to withdraw an item
*
* @param withdrawn
*/
void setWithdrawn(boolean withdrawn) {
@@ -131,8 +146,7 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
*
* @return true if the item is discoverable
*/
public boolean isDiscoverable()
{
public boolean isDiscoverable() {
return discoverable;
}
@@ -141,10 +155,9 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
* last_modified is null
*
* @return the date the item was last modified, or the current date if the
* column is null.
* column is null.
*/
public Date getLastModified()
{
public Date getLastModified() {
return lastModified;
}
@@ -156,11 +169,9 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
* Set the "is_archived" flag. This is public and only
* <code>WorkflowItem.archive()</code> should set this.
*
* @param isArchived
* new value for the flag
* @param isArchived new value for the flag
*/
public void setArchived(boolean isArchived)
{
public void setArchived(boolean isArchived) {
this.inArchive = isArchived;
setModified();
}
@@ -168,11 +179,9 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
/**
* Set the "discoverable" flag. This is public and only
*
* @param discoverable
* new value for the flag
* @param discoverable new value for the flag
*/
public void setDiscoverable(boolean discoverable)
{
public void setDiscoverable(boolean discoverable) {
this.discoverable = discoverable;
setModified();
}
@@ -180,11 +189,9 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
/**
* Set the owning Collection for the item
*
* @param c
* Collection
* @param c Collection
*/
public void setOwningCollection(Collection c)
{
public void setOwningCollection(Collection c) {
this.owningCollection = c;
setModified();
}
@@ -194,8 +201,7 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
*
* @return Collection that is the owner of the item
*/
public Collection getOwningCollection()
{
public Collection getOwningCollection() {
return owningCollection;
}
@@ -204,8 +210,7 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
*
* @return the submitter
*/
public EPerson getSubmitter()
{
public EPerson getSubmitter() {
return submitter;
}
@@ -215,11 +220,9 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
* package. <code>update</code> must be called to write the change to the
* database.
*
* @param sub
* the submitter
* @param sub the submitter
*/
public void setSubmitter(EPerson sub)
{
public void setSubmitter(EPerson sub) {
this.submitter = sub;
setModified();
}
@@ -229,26 +232,23 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
*
* @return the collections this item is in, if any.
*/
public List<Collection> getCollections()
{
public List<Collection> getCollections() {
// We return a copy because we do not want people to add elements to this collection directly.
// We return a list to maintain backwards compatibility
Collection[] output = collections.toArray(new Collection[]{});
Collection[] output = collections.toArray(new Collection[] {});
Arrays.sort(output, new NameAscendingComparator());
return Arrays.asList(output);
}
void addCollection(Collection collection)
{
void addCollection(Collection collection) {
collections.add(collection);
}
void removeCollection(Collection collection)
{
void removeCollection(Collection collection) {
collections.remove(collection);
}
public void clearCollections(){
public void clearCollections() {
collections.clear();
}
@@ -266,26 +266,25 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
*
* @return the bundles in an unordered array
*/
public List<Bundle> getBundles()
{
public List<Bundle> getBundles() {
return bundles;
}
/**
* Add a bundle to the item, should not be made public since we don't want to skip business logic
*
* @param bundle the bundle to be added
*/
void addBundle(Bundle bundle)
{
void addBundle(Bundle bundle) {
bundles.add(bundle);
}
/**
* Remove a bundle from item, should not be made public since we don't want to skip business logic
*
* @param bundle the bundle to be removed
*/
void removeBundle(Bundle bundle)
{
void removeBundle(Bundle bundle) {
bundles.remove(bundle);
}
@@ -293,40 +292,34 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
* Return <code>true</code> if <code>other</code> is the same Item as
* this object, <code>false</code> otherwise
*
* @param obj
* object to compare to
* @param obj object to compare to
* @return <code>true</code> if object passed in represents the same item
* as this object
* 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;
}
@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;
}
return true;
}
@Override
public int hashCode()
{
int hash = 5;
hash += 71 * hash + getType();
hash += 71 * hash + getID().hashCode();
return hash;
}
@Override
public int hashCode() {
int hash = 5;
hash += 71 * hash + getType();
hash += 71 * hash + getID().hashCode();
return hash;
}
/**
* return type found in Constants
@@ -334,14 +327,12 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
* @return int Constants.ITEM
*/
@Override
public int getType()
{
public int getType() {
return Constants.ITEM;
}
@Override
public String getName()
{
public String getName() {
return getItemService().getMetadataFirstValue(this, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY);
}
@@ -350,10 +341,8 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
return legacyId;
}
public ItemService getItemService()
{
if(itemService == null)
{
public ItemService getItemService() {
if (itemService == null) {
itemService = ContentServiceFactory.getInstance().getItemService();
}
return itemService;