mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 14:03:17 +00:00
DS-3406: Ordering sub communities and collections
This commit is contained in:

committed by
Tim Donohue

parent
821678dae4
commit
a588d42f5a
@@ -12,13 +12,14 @@ import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.core.*;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.annotations.Sort;
|
||||
import org.hibernate.annotations.SortType;
|
||||
import org.hibernate.proxy.HibernateProxyHelper;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Class representing a collection.
|
||||
@@ -85,7 +86,8 @@ public class Collection extends DSpaceObject implements DSpaceObjectLegacySuppor
|
||||
joinColumns = {@JoinColumn(name = "collection_id") },
|
||||
inverseJoinColumns = {@JoinColumn(name = "community_id") }
|
||||
)
|
||||
private final List<Community> communities = new ArrayList<>();
|
||||
@Sort(type = SortType.COMPARATOR, comparator = NameAscendingComparator.class)
|
||||
private Set<Community> communities = new TreeSet<>(new NameAscendingComparator());
|
||||
|
||||
@Transient
|
||||
private transient CollectionService collectionService;
|
||||
@@ -265,8 +267,8 @@ public class Collection extends DSpaceObject implements DSpaceObjectLegacySuppor
|
||||
*/
|
||||
public List<Community> getCommunities() throws SQLException
|
||||
{
|
||||
Collections.sort(communities, new NameAscendingComparator());
|
||||
return communities;
|
||||
// We return a copy because we do not want people to add elements to this collection directly.
|
||||
return Arrays.asList(communities.toArray(new Community[]{}));
|
||||
}
|
||||
|
||||
void addCommunity(Community community) {
|
||||
|
@@ -750,8 +750,8 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
||||
while (owningCommunities.hasNext())
|
||||
{
|
||||
Community owningCommunity = owningCommunities.next();
|
||||
owningCommunities.remove();
|
||||
owningCommunity.getCollections().remove(collection);
|
||||
collection.removeCommunity(owningCommunity);
|
||||
owningCommunity.removeCollection(collection);
|
||||
}
|
||||
|
||||
collectionDAO.delete(context, collection);
|
||||
|
@@ -14,6 +14,9 @@ import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
import org.dspace.core.*;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.annotations.Sort;
|
||||
import org.hibernate.annotations.SortType;
|
||||
import org.hibernate.proxy.HibernateProxyHelper;
|
||||
|
||||
import javax.persistence.*;
|
||||
@@ -45,13 +48,16 @@ public class Community extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
joinColumns = {@JoinColumn(name = "parent_comm_id") },
|
||||
inverseJoinColumns = {@JoinColumn(name = "child_comm_id") }
|
||||
)
|
||||
private final List<Community> subCommunities = new ArrayList<>();
|
||||
@Sort(type = SortType.COMPARATOR, comparator = NameAscendingComparator.class)
|
||||
private Set<Community> subCommunities = new TreeSet<Community>(new NameAscendingComparator());
|
||||
|
||||
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "subCommunities")
|
||||
private List<Community> parentCommunities = new ArrayList<>();
|
||||
@Sort(type = SortType.COMPARATOR, comparator = NameAscendingComparator.class)
|
||||
private Set<Community> parentCommunities = new TreeSet<Community>(new NameAscendingComparator());;
|
||||
|
||||
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "communities", cascade = {CascadeType.PERSIST})
|
||||
private final List<Collection> collections = new ArrayList<>();
|
||||
@Sort(type = SortType.COMPARATOR, comparator = NameAscendingComparator.class)
|
||||
private Set<Collection> collections =new TreeSet<Collection>(new NameAscendingComparator());;
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "admin")
|
||||
@@ -86,13 +92,13 @@ public class Community extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
|
||||
void addSubCommunity(Community subCommunity)
|
||||
{
|
||||
getSubcommunities().add(subCommunity);
|
||||
subCommunities.add(subCommunity);
|
||||
setModified();
|
||||
}
|
||||
|
||||
void removeSubCommunity(Community subCommunity)
|
||||
{
|
||||
getSubcommunities().remove(subCommunity);
|
||||
subCommunities.remove(subCommunity);
|
||||
setModified();
|
||||
}
|
||||
|
||||
@@ -141,18 +147,18 @@ public class Community extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
*/
|
||||
public List<Collection> getCollections()
|
||||
{
|
||||
Collections.sort(collections, new NameAscendingComparator());
|
||||
return collections;
|
||||
// We return a copy because we do not want people to add elements to this collection directly.
|
||||
return Arrays.asList(collections.toArray(new Collection[]{}));
|
||||
}
|
||||
|
||||
void addCollection(Collection collection)
|
||||
{
|
||||
getCollections().add(collection);
|
||||
collections.add(collection);
|
||||
}
|
||||
|
||||
void removeCollection(Collection collection)
|
||||
{
|
||||
getCollections().remove(collection);
|
||||
collections.remove(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,8 +170,8 @@ public class Community extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
*/
|
||||
public List<Community> getSubcommunities()
|
||||
{
|
||||
Collections.sort(subCommunities, new NameAscendingComparator());
|
||||
return subCommunities;
|
||||
// We return a copy because we do not want people to add elements to this collection directly.
|
||||
return Arrays.asList(subCommunities.toArray(new Community[]{}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,12 +182,12 @@ public class Community extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
*/
|
||||
public List<Community> getParentCommunities()
|
||||
{
|
||||
Collections.sort(parentCommunities, new NameAscendingComparator());
|
||||
return parentCommunities;
|
||||
// We return a copy because we do not want people to add elements to this collection directly.
|
||||
return Arrays.asList(parentCommunities.toArray(new Community[]{}));
|
||||
}
|
||||
|
||||
void addParentCommunity(Community parentCommunity) {
|
||||
getParentCommunities().add(parentCommunity);
|
||||
parentCommunities.add(parentCommunity);
|
||||
}
|
||||
|
||||
void clearParentCommunities(){
|
||||
@@ -189,6 +195,11 @@ public class Community extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
this.parentCommunities = null;
|
||||
}
|
||||
|
||||
public void removeParentCommunity(Community parentCommunity)
|
||||
{
|
||||
this.parentCommunities.remove(parentCommunity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true</code> if <code>other</code> is the same Community
|
||||
* as this object, <code>false</code> otherwise
|
||||
|
@@ -455,7 +455,7 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
||||
|
||||
rawDelete(context, childCommunity);
|
||||
|
||||
childCommunity.getParentCommunities().remove(parentCommunity);
|
||||
childCommunity.removeParentCommunity(parentCommunity);
|
||||
parentCommunity.removeSubCommunity(childCommunity);
|
||||
|
||||
log.info(LogManager.getHeader(context, "remove_subcommunity",
|
||||
@@ -492,7 +492,7 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
||||
Iterator<Community> subcommunities = community.getSubcommunities().iterator();
|
||||
while (subcommunities.hasNext()) {
|
||||
Community subCommunity = subcommunities.next();
|
||||
subcommunities.remove();
|
||||
community.removeSubCommunity(subCommunity);
|
||||
delete(context, subCommunity);
|
||||
}
|
||||
// now let the parent remove the community
|
||||
@@ -535,7 +535,7 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
||||
while (collections.hasNext())
|
||||
{
|
||||
Collection collection = collections.next();
|
||||
collections.remove();
|
||||
community.removeCollection(collection);
|
||||
removeCollection(context, community, collection);
|
||||
}
|
||||
// delete subcommunities
|
||||
@@ -544,7 +544,7 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
||||
while (subCommunities.hasNext())
|
||||
{
|
||||
Community subComm = subCommunities.next();
|
||||
subCommunities.remove();
|
||||
community.removeSubCommunity(subComm);
|
||||
delete(context, subComm);
|
||||
}
|
||||
|
||||
|
@@ -13,13 +13,12 @@ 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.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Class representing an item in DSpace.
|
||||
@@ -80,7 +79,8 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
joinColumns = {@JoinColumn(name = "item_id") },
|
||||
inverseJoinColumns = {@JoinColumn(name = "collection_id") }
|
||||
)
|
||||
private final List<Collection> collections = new ArrayList<>();
|
||||
@Sort(type = SortType.COMPARATOR, comparator = NameAscendingComparator.class)
|
||||
private final Set<Collection> collections = new TreeSet<>(new NameAscendingComparator());
|
||||
|
||||
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "items")
|
||||
private final List<Bundle> bundles = new ArrayList<>();
|
||||
@@ -232,18 +232,22 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
*/
|
||||
public List<Collection> getCollections()
|
||||
{
|
||||
Collections.sort(collections, new NameAscendingComparator());
|
||||
return collections;
|
||||
// We return a copy because we do not want people to add elements to this collection directly.
|
||||
return Arrays.asList(collections.toArray(new Collection[]{}));
|
||||
}
|
||||
|
||||
void addCollection(Collection collection)
|
||||
{
|
||||
getCollections().add(collection);
|
||||
collections.add(collection);
|
||||
}
|
||||
|
||||
void removeCollection(Collection collection)
|
||||
{
|
||||
getCollections().remove(collection);
|
||||
collections.remove(collection);
|
||||
}
|
||||
|
||||
public void clearCollections(){
|
||||
collections.clear();
|
||||
}
|
||||
|
||||
public Collection getTemplateItemOf() {
|
||||
|
@@ -656,7 +656,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
||||
}
|
||||
|
||||
//Only clear collections after we have removed everything else from the item
|
||||
item.getCollections().clear();
|
||||
item.clearCollections();
|
||||
item.setOwningCollection(null);
|
||||
|
||||
// Finally remove item row
|
||||
|
Reference in New Issue
Block a user