Level up counting items methods - both now use the same flags from Item model (discoverable, archived, withdrawn)

This commit is contained in:
damian
2024-05-24 14:31:32 +02:00
parent d07aab6025
commit 01be5eee41
4 changed files with 26 additions and 21 deletions

View File

@@ -105,7 +105,8 @@ public class ItemCountDAOSolr implements ItemCountDAO {
DiscoveryConfigurationParameters.SORT.COUNT)); DiscoveryConfigurationParameters.SORT.COUNT));
query.addFilterQueries("search.resourcetype:" + IndexableItem.TYPE); // count only items query.addFilterQueries("search.resourcetype:" + IndexableItem.TYPE); // count only items
query.addFilterQueries("NOT(discoverable:false)"); // only discoverable 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); query.setMaxResults(0);
DiscoverResult sResponse; DiscoverResult sResponse;

View File

@@ -1631,13 +1631,13 @@ prevent the generation of resource policy entry values with null dspace_object a
@Override @Override
public int countItems(Context context, Collection collection) throws SQLException { 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 @Override
public int countAllItems(Context context, Collection collection) throws SQLException { public int countAllItems(Context context, Collection collection) throws SQLException {
return itemDAO.countItems(context, collection, true, false) + itemDAO.countItems(context, collection, return itemDAO.countItems(context, collection, true, false, true) + itemDAO.countItems(context, collection,
false, true); false, true, true);
} }
@Override @Override
@@ -1646,7 +1646,7 @@ prevent the generation of resource policy entry values with null dspace_object a
List<Collection> collections = communityService.getAllCollections(context, community); List<Collection> collections = communityService.getAllCollections(context, community);
// Now, lets count unique items across that list of collections // 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 @Override
@@ -1655,8 +1655,8 @@ prevent the generation of resource policy entry values with null dspace_object a
List<Collection> collections = communityService.getAllCollections(context, community); List<Collection> collections = communityService.getAllCollections(context, community);
// Now, lets count unique items across that list of collections // Now, lets count unique items across that list of collections
return itemDAO.countItems(context, collections, true, false) + itemDAO.countItems(context, collections, return itemDAO.countItems(context, collections, true, false, true) + itemDAO.countItems(context, collections,
false, true); false, false, true);
} }
@Override @Override
@@ -1699,19 +1699,19 @@ prevent the generation of resource policy entry values with null dspace_object a
@Override @Override
public int countNotArchivedItems(Context context) throws SQLException { public int countNotArchivedItems(Context context) throws SQLException {
// return count of items not in archive and also not withdrawn // 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 @Override
public int countArchivedItems(Context context) throws SQLException { public int countArchivedItems(Context context) throws SQLException {
// return count of items in archive and also not withdrawn // return count of items in archive and also not withdrawn
return itemDAO.countItems(context, true, false); return itemDAO.countItems(context, true, false, true);
} }
@Override @Override
public int countWithdrawnItems(Context context) throws SQLException { public int countWithdrawnItems(Context context) throws SQLException {
// return count of items that are not in archive and withdrawn // 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 @Override

View File

@@ -145,7 +145,7 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO<Item> {
* @return item count * @return item count
* @throws SQLException if database error * @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; throws SQLException;
/** /**
@@ -162,7 +162,7 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO<Item> {
* @throws SQLException if database error * @throws SQLException if database error
*/ */
int countItems(Context context, List<Collection> collections, boolean includeArchived, int countItems(Context context, List<Collection> 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. * Get all Items installed or withdrawn, discoverable, and modified since a Date.
@@ -197,7 +197,7 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO<Item> {
* @return count of items * @return count of items
* @throws SQLException if database error * @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 * Count number of items from the specified submitter based on specific status flags
@@ -209,7 +209,7 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO<Item> {
* @return count of items * @return count of items
* @throws SQLException if database error * @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; throws SQLException;
} }

View File

@@ -401,7 +401,7 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
} }
@Override @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 { throws SQLException {
// Build query to select all Items have this "collection" in their list of collections // Build query to select all Items have this "collection" in their list of collections
// AND also have the inArchive or isWithdrawn set as specified // AND also have the inArchive or isWithdrawn set as specified
@@ -412,6 +412,7 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
criteriaQuery.where(criteriaBuilder.and( criteriaQuery.where(criteriaBuilder.and(
criteriaBuilder.equal(itemRoot.get(Item_.inArchive), includeArchived), criteriaBuilder.equal(itemRoot.get(Item_.inArchive), includeArchived),
criteriaBuilder.equal(itemRoot.get(Item_.withdrawn), includeWithdrawn), criteriaBuilder.equal(itemRoot.get(Item_.withdrawn), includeWithdrawn),
criteriaBuilder.equal(itemRoot.get(Item_.discoverable), discoverable),
criteriaBuilder.isMember(collection, itemRoot.get(Item_.collections)))); criteriaBuilder.isMember(collection, itemRoot.get(Item_.collections))));
// Execute and return count // Execute and return count
return count(context, criteriaQuery, criteriaBuilder, itemRoot); return count(context, criteriaQuery, criteriaBuilder, itemRoot);
@@ -419,16 +420,17 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
@Override @Override
public int countItems(Context context, List<Collection> collections, boolean includeArchived, public int countItems(Context context, List<Collection> collections, boolean includeArchived,
boolean includeWithdrawn) throws SQLException { boolean includeWithdrawn, boolean discoverable) throws SQLException {
if (collections.size() == 0) { if (collections.size() == 0) {
return 0; return 0;
} }
Query query = createQuery(context, "select count(distinct i) from Item i " + Query query = createQuery(context, "select count(distinct i) from Item i " +
"join i.collections collection " + "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("collections", collections);
query.setParameter("in_archive", includeArchived); query.setParameter("in_archive", includeArchived);
query.setParameter("withdrawn", includeWithdrawn); query.setParameter("withdrawn", includeWithdrawn);
query.setParameter("discoverable", discoverable);
return count(query); return count(query);
} }
@@ -450,24 +452,26 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
} }
@Override @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, Query query = createQuery(context,
"SELECT count(*) FROM Item i " + "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("in_archive", includeArchived);
query.setParameter("withdrawn", includeWithdrawn); query.setParameter("withdrawn", includeWithdrawn);
query.setParameter("discoverable", discoverable);
return count(query); return count(query);
} }
@Override @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 { throws SQLException {
Query query = createQuery(context, Query query = createQuery(context,
"SELECT count(*) FROM Item i join i.submitter submitter " + "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("submitter", submitter);
query.setParameter("in_archive", includeArchived); query.setParameter("in_archive", includeArchived);
query.setParameter("withdrawn", includeWithdrawn); query.setParameter("withdrawn", includeWithdrawn);
query.setParameter("discoverable", discoverable);
return count(query); return count(query);
} }