diff --git a/dspace-api/src/main/java/org/dspace/browse/ItemCountDAOSolr.java b/dspace-api/src/main/java/org/dspace/browse/ItemCountDAOSolr.java index 5071db0001..e4d0079fe2 100644 --- a/dspace-api/src/main/java/org/dspace/browse/ItemCountDAOSolr.java +++ b/dspace-api/src/main/java/org/dspace/browse/ItemCountDAOSolr.java @@ -105,7 +105,8 @@ public class ItemCountDAOSolr implements ItemCountDAO { DiscoveryConfigurationParameters.SORT.COUNT)); query.addFilterQueries("search.resourcetype:" + IndexableItem.TYPE); // count only items query.addFilterQueries("NOT(discoverable:false)"); // only discoverable - query.addFilterQueries("withdrawn:false"); // only discoverable + query.addFilterQueries("withdrawn:false"); // only not withdrawn + query.addFilterQueries("archived:true"); // only archived query.setMaxResults(0); DiscoverResult sResponse; diff --git a/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java index f005f22961..70bdf4b7d9 100644 --- a/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java @@ -1631,13 +1631,13 @@ prevent the generation of resource policy entry values with null dspace_object a @Override public int countItems(Context context, Collection collection) throws SQLException { - return itemDAO.countItems(context, collection, true, false); + return itemDAO.countItems(context, collection, true, false, true); } @Override public int countAllItems(Context context, Collection collection) throws SQLException { - return itemDAO.countItems(context, collection, true, false) + itemDAO.countItems(context, collection, - false, true); + return itemDAO.countItems(context, collection, true, false, true) + itemDAO.countItems(context, collection, + false, true, true); } @Override @@ -1646,7 +1646,7 @@ prevent the generation of resource policy entry values with null dspace_object a List collections = communityService.getAllCollections(context, community); // Now, lets count unique items across that list of collections - return itemDAO.countItems(context, collections, true, false); + return itemDAO.countItems(context, collections, true, false, true); } @Override @@ -1655,8 +1655,8 @@ prevent the generation of resource policy entry values with null dspace_object a List collections = communityService.getAllCollections(context, community); // Now, lets count unique items across that list of collections - return itemDAO.countItems(context, collections, true, false) + itemDAO.countItems(context, collections, - false, true); + return itemDAO.countItems(context, collections, true, false, true) + itemDAO.countItems(context, collections, + false, false, true); } @Override @@ -1699,19 +1699,19 @@ prevent the generation of resource policy entry values with null dspace_object a @Override public int countNotArchivedItems(Context context) throws SQLException { // return count of items not in archive and also not withdrawn - return itemDAO.countItems(context, false, false); + return itemDAO.countItems(context, false, false, true); } @Override public int countArchivedItems(Context context) throws SQLException { // return count of items in archive and also not withdrawn - return itemDAO.countItems(context, true, false); + return itemDAO.countItems(context, true, false, true); } @Override public int countWithdrawnItems(Context context) throws SQLException { // return count of items that are not in archive and withdrawn - return itemDAO.countItems(context, false, true); + return itemDAO.countItems(context, false, true, true ); } @Override diff --git a/dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java index 417c768882..bf83eec0e2 100644 --- a/dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java +++ b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java @@ -145,7 +145,7 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO { * @return item count * @throws SQLException if database error */ - int countItems(Context context, Collection collection, boolean includeArchived, boolean includeWithdrawn) + int countItems(Context context, Collection collection, boolean includeArchived, boolean includeWithdrawn, boolean discoverable) throws SQLException; /** @@ -162,7 +162,7 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO { * @throws SQLException if database error */ int countItems(Context context, List collections, boolean includeArchived, - boolean includeWithdrawn) throws SQLException; + boolean includeWithdrawn, boolean discoverable) throws SQLException; /** * Get all Items installed or withdrawn, discoverable, and modified since a Date. @@ -197,7 +197,7 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO { * @return count of items * @throws SQLException if database error */ - int countItems(Context context, boolean includeArchived, boolean includeWithdrawn) throws SQLException; + int countItems(Context context, boolean includeArchived, boolean includeWithdrawn, boolean discoverable) throws SQLException; /** * Count number of items from the specified submitter based on specific status flags @@ -209,7 +209,7 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO { * @return count of items * @throws SQLException if database error */ - int countItems(Context context, EPerson submitter, boolean includeArchived, boolean includeWithdrawn) + int countItems(Context context, EPerson submitter, boolean includeArchived, boolean includeWithdrawn, boolean discoverable) throws SQLException; } diff --git a/dspace-api/src/main/java/org/dspace/content/dao/impl/ItemDAOImpl.java b/dspace-api/src/main/java/org/dspace/content/dao/impl/ItemDAOImpl.java index 94d2bb80c4..a95f8b83c7 100644 --- a/dspace-api/src/main/java/org/dspace/content/dao/impl/ItemDAOImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/dao/impl/ItemDAOImpl.java @@ -401,7 +401,7 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO implements ItemDA } @Override - public int countItems(Context context, Collection collection, boolean includeArchived, boolean includeWithdrawn) + public int countItems(Context context, Collection collection, boolean includeArchived, boolean includeWithdrawn, boolean discoverable) throws SQLException { // Build query to select all Items have this "collection" in their list of collections // AND also have the inArchive or isWithdrawn set as specified @@ -412,6 +412,7 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO implements ItemDA criteriaQuery.where(criteriaBuilder.and( criteriaBuilder.equal(itemRoot.get(Item_.inArchive), includeArchived), criteriaBuilder.equal(itemRoot.get(Item_.withdrawn), includeWithdrawn), + criteriaBuilder.equal(itemRoot.get(Item_.discoverable), discoverable), criteriaBuilder.isMember(collection, itemRoot.get(Item_.collections)))); // Execute and return count return count(context, criteriaQuery, criteriaBuilder, itemRoot); @@ -419,16 +420,17 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO implements ItemDA @Override public int countItems(Context context, List collections, boolean includeArchived, - boolean includeWithdrawn) throws SQLException { + boolean includeWithdrawn, boolean discoverable) throws SQLException { if (collections.size() == 0) { return 0; } Query query = createQuery(context, "select count(distinct i) from Item i " + "join i.collections collection " + - "WHERE collection IN (:collections) AND i.inArchive=:in_archive AND i.withdrawn=:withdrawn"); + "WHERE collection IN (:collections) AND i.inArchive=:in_archive AND i.withdrawn=:withdrawn AND discoverable=:discoverable"); query.setParameter("collections", collections); query.setParameter("in_archive", includeArchived); query.setParameter("withdrawn", includeWithdrawn); + query.setParameter("discoverable", discoverable); return count(query); } @@ -450,24 +452,26 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO implements ItemDA } @Override - public int countItems(Context context, boolean includeArchived, boolean includeWithdrawn) throws SQLException { + public int countItems(Context context, boolean includeArchived, boolean includeWithdrawn, boolean discoverable) throws SQLException { Query query = createQuery(context, "SELECT count(*) FROM Item i " + - "WHERE i.inArchive=:in_archive AND i.withdrawn=:withdrawn"); + "WHERE i.inArchive=:in_archive AND i.withdrawn=:withdrawn AND discoverable=:discoverable"); query.setParameter("in_archive", includeArchived); query.setParameter("withdrawn", includeWithdrawn); + query.setParameter("discoverable", discoverable); return count(query); } @Override - public int countItems(Context context, EPerson submitter, boolean includeArchived, boolean includeWithdrawn) + public int countItems(Context context, EPerson submitter, boolean includeArchived, boolean includeWithdrawn, boolean discoverable) throws SQLException { Query query = createQuery(context, "SELECT count(*) FROM Item i join i.submitter submitter " + - "WHERE i.inArchive=:in_archive AND i.withdrawn=:withdrawn AND submitter = :submitter"); + "WHERE i.inArchive=:in_archive AND i.withdrawn=:withdrawn AND submitter = :submitter AND discoverable=:discoverable"); query.setParameter("submitter", submitter); query.setParameter("in_archive", includeArchived); query.setParameter("withdrawn", includeWithdrawn); + query.setParameter("discoverable", discoverable); return count(query); }