mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-11 20:13:17 +00:00
Item counters added to Communities and Collections REST API
This commit is contained in:
@@ -29,6 +29,7 @@ import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.browse.ItemCountException;
|
||||
import org.dspace.content.comparator.NameAscendingComparator;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
@@ -336,4 +337,12 @@ public class Collection extends DSpaceObject implements DSpaceObjectLegacySuppor
|
||||
return collectionService;
|
||||
}
|
||||
|
||||
public int getAllItems() {
|
||||
try {
|
||||
return collectionService.countArchivedItem(this);
|
||||
} catch (ItemCountException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -31,6 +31,8 @@ import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.authorize.service.ResourcePolicyService;
|
||||
import org.dspace.browse.ItemCountException;
|
||||
import org.dspace.browse.ItemCounter;
|
||||
import org.dspace.content.dao.CollectionDAO;
|
||||
import org.dspace.content.service.BitstreamService;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
@@ -1047,4 +1049,12 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
||||
return (int) resp.getTotalSearchResults();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countArchivedItem(Collection collection) throws ItemCountException {
|
||||
//TODO load ItemCounter on bean creation
|
||||
Context context = new Context();
|
||||
return new ItemCounter(context).getCount(collection);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.dspace.browse.ItemCountException;
|
||||
import org.dspace.content.comparator.NameAscendingComparator;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
@@ -264,4 +265,11 @@ public class Community extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
return communityService;
|
||||
}
|
||||
|
||||
public int getAllItems() {
|
||||
try {
|
||||
return communityService.getArchivedItems(this);
|
||||
} catch (ItemCountException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ import org.dspace.authorize.AuthorizeConfiguration;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.browse.ItemCountException;
|
||||
import org.dspace.browse.ItemCounter;
|
||||
import org.dspace.content.dao.CommunityDAO;
|
||||
import org.dspace.content.service.BitstreamService;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
@@ -76,9 +78,9 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
||||
protected IdentifierService identifierService;
|
||||
@Autowired(required = true)
|
||||
protected SubscribeService subscribeService;
|
||||
|
||||
protected CommunityServiceImpl() {
|
||||
super();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -708,4 +710,11 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
||||
public int countTotal(Context context) throws SQLException {
|
||||
return communityDAO.countRows(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArchivedItems(Community community) throws ItemCountException {
|
||||
//TODO load ItemCounter on bean creation
|
||||
Context context = new Context();
|
||||
return new ItemCounter(context).getCount(community);
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ package org.dspace.content.dao;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Item;
|
||||
@@ -53,4 +54,6 @@ public interface CollectionDAO extends DSpaceObjectLegacySupportDAO<Collection>
|
||||
int countRows(Context context) throws SQLException;
|
||||
|
||||
List<Map.Entry<Collection, Long>> getCollectionsWithBitstreamSizesTotal(Context context) throws SQLException;
|
||||
|
||||
int countArchivedItems(Context context, UUID id) throws SQLException;
|
||||
}
|
||||
|
@@ -7,11 +7,9 @@
|
||||
*/
|
||||
package org.dspace.content.dao.impl;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.sql.SQLException;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
@@ -182,4 +180,12 @@ public class CollectionDAOImpl extends AbstractHibernateDSODAO<Collection> imple
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countArchivedItems(Context context, UUID collectionId) throws SQLException {
|
||||
return ((BigInteger) getHibernateSession(context)
|
||||
.createNativeQuery("select count(*) from collection2item ci left join item i on i.uuid = ci.item_id where i.in_archive and uuid(ci.collection_id)=uuid(:collectionId)")
|
||||
.setParameter("collectionId", collectionId.toString())
|
||||
.getSingleResult()).intValue();
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.browse.ItemCountException;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
@@ -455,4 +456,5 @@ public interface CollectionService
|
||||
public int countCollectionsWithSubmit(String q, Context context, Community community, String entityType)
|
||||
throws SQLException, SearchServiceException;
|
||||
|
||||
int countArchivedItem(Collection collection) throws ItemCountException;
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.browse.ItemCountException;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
@@ -292,4 +293,6 @@ public interface CommunityService extends DSpaceObjectService<Community>, DSpace
|
||||
public List<Community> findAuthorizedGroupMapped(Context context, List<Integer> actions) throws SQLException;
|
||||
|
||||
int countTotal(Context context) throws SQLException;
|
||||
|
||||
int getArchivedItems(Community community) throws ItemCountException;
|
||||
}
|
||||
|
@@ -8,7 +8,9 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.CollectionRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.IndexableObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -22,6 +24,12 @@ import org.springframework.stereotype.Component;
|
||||
public class CollectionConverter extends DSpaceObjectConverter<Collection, CollectionRest>
|
||||
implements IndexableObjectConverter<Collection, CollectionRest> {
|
||||
|
||||
@Override
|
||||
public CollectionRest convert(Collection collection, Projection projection) {
|
||||
CollectionRest resource = super.convert(collection, projection);
|
||||
resource.setArchivedItems(collection.getAllItems());
|
||||
return resource;
|
||||
}
|
||||
@Override
|
||||
protected CollectionRest newInstance() {
|
||||
return new CollectionRest();
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.CommunityRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.discovery.IndexableObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -23,6 +24,12 @@ public class CommunityConverter
|
||||
extends DSpaceObjectConverter<Community, CommunityRest>
|
||||
implements IndexableObjectConverter<Community, CommunityRest> {
|
||||
|
||||
public CommunityRest convert(Community community, Projection projection) {
|
||||
CommunityRest resource = super.convert(community, projection);
|
||||
resource.setArchivedItems(community.getAllItems());
|
||||
return resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommunityRest newInstance() {
|
||||
return new CommunityRest();
|
||||
|
@@ -74,4 +74,16 @@ public class CollectionRest extends DSpaceObjectRest {
|
||||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
private int archivedItems;
|
||||
|
||||
public int getArchivedItems() {
|
||||
return archivedItems;
|
||||
}
|
||||
|
||||
public void setArchivedItems(int archivedItems) {
|
||||
this.archivedItems = archivedItems;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -58,4 +58,14 @@ public class CommunityRest extends DSpaceObjectRest {
|
||||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
private int archivedItems;
|
||||
|
||||
public int getArchivedItems() {
|
||||
return archivedItems;
|
||||
}
|
||||
|
||||
public void setArchivedItems(int archivedItems) {
|
||||
this.archivedItems = archivedItems;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user