diff --git a/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java b/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java index 858149a64f31..c76e818ebffd 100644 --- a/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java +++ b/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java @@ -20,6 +20,7 @@ import org.dspace.content.DSpaceObject; import org.dspace.content.Item; import org.dspace.handle.Handle; +import org.dspace.identifier.DOI; import org.dspace.storage.rdbms.DatabaseConfigVO; import org.hibernate.FlushMode; import org.hibernate.Hibernate; @@ -280,6 +281,11 @@ public void uncacheEntity(E entity) throws SQLExcep } } + if (entity instanceof DOI) { + DOI doi = (DOI) entity; + uncacheEntity(doi.getDSpaceObject()); + } + // ITEM if (entity instanceof Item) { Item item = (Item) entity; diff --git a/dspace-api/src/main/java/org/dspace/identifier/DOIServiceImpl.java b/dspace-api/src/main/java/org/dspace/identifier/DOIServiceImpl.java index 99643db33fa0..2e726234a284 100644 --- a/dspace-api/src/main/java/org/dspace/identifier/DOIServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/identifier/DOIServiceImpl.java @@ -161,7 +161,13 @@ public String formatIdentifier(String identifier) throws DOIIdentifierException @Override public List getDOIsByStatus(Context context, List statuses) throws SQLException { - return doiDAO.findByStatus(context, statuses); + return doiDAO.findByStatus(context, statuses, -1, -1); + } + + @Override + public List getDOIsByStatus(Context context, List statuses, int offset, int limit) + throws SQLException { + return doiDAO.findByStatus(context, statuses, offset, limit); } @Override diff --git a/dspace-api/src/main/java/org/dspace/identifier/dao/DOIDAO.java b/dspace-api/src/main/java/org/dspace/identifier/dao/DOIDAO.java index 8085c6599b69..df75ced157ab 100644 --- a/dspace-api/src/main/java/org/dspace/identifier/dao/DOIDAO.java +++ b/dspace-api/src/main/java/org/dspace/identifier/dao/DOIDAO.java @@ -31,7 +31,7 @@ public DOI findDOIByDSpaceObject(Context context, DSpaceObject dso, List findSimilarNotInState(Context context, String doi, List statuses, boolean dsoNotNull) throws SQLException; - public List findByStatus(Context context, List statuses) throws SQLException; + public List findByStatus(Context context, List statuses, int offset, int limit) throws SQLException; public DOI findDOIByDSpaceObject(Context context, DSpaceObject dso) throws SQLException; } diff --git a/dspace-api/src/main/java/org/dspace/identifier/dao/impl/DOIDAOImpl.java b/dspace-api/src/main/java/org/dspace/identifier/dao/impl/DOIDAOImpl.java index 784fec1d8894..0811a7adfb61 100644 --- a/dspace-api/src/main/java/org/dspace/identifier/dao/impl/DOIDAOImpl.java +++ b/dspace-api/src/main/java/org/dspace/identifier/dao/impl/DOIDAOImpl.java @@ -70,7 +70,7 @@ public DOI findDOIByDSpaceObject(Context context, DSpaceObject dso, List findByStatus(Context context, List statuses) throws SQLException { + public List findByStatus(Context context, List statuses, int offset, int limit) throws SQLException { CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context); CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, DOI.class); Root doiRoot = criteriaQuery.from(DOI.class); @@ -80,7 +80,7 @@ public List findByStatus(Context context, List statuses) throws SQ orPredicates.add(criteriaBuilder.equal(doiRoot.get(DOI_.status), status)); } criteriaQuery.where(criteriaBuilder.or(orPredicates.toArray(new Predicate[] {}))); - return list(context, criteriaQuery, false, DOI.class, -1, -1); + return list(context, criteriaQuery, false, DOI.class, limit, offset); } @Override diff --git a/dspace-api/src/main/java/org/dspace/identifier/doi/DOIOrganiser.java b/dspace-api/src/main/java/org/dspace/identifier/doi/DOIOrganiser.java index ad885314bb2b..a90ccc0980b2 100644 --- a/dspace-api/src/main/java/org/dspace/identifier/doi/DOIOrganiser.java +++ b/dspace-api/src/main/java/org/dspace/identifier/doi/DOIOrganiser.java @@ -132,6 +132,8 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args "Perform online deletion for all identifiers queued for deletion."); options.addOption("q", "quiet", false, "Turn the command line output off."); + options.addOption("o", "offset", true, "The records offset"); + options.addOption("li", "limit", true, "The records limit"); Option filterDoi = Option.builder().optionalArg(true).longOpt("filter").hasArg().argName("filterName") .desc("Use the specified filter name instead of the provider's filter. Defaults to a special " + @@ -212,6 +214,17 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args organiser.list("deletion", null, null, DOIIdentifierProvider.TO_BE_DELETED); } + int limit = -1; + int offset = -1; + + if (line.hasOption("li")) { + limit = Integer.valueOf(line.getOptionValue("li")); + } + + if (line.hasOption("o")) { + offset = Integer.valueOf(line.getOptionValue("o")); + } + DOIService doiService = IdentifierServiceFactory.getInstance().getDOIService(); // Do we get a filter? if (line.hasOption("filter")) { @@ -224,7 +237,7 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args if (line.hasOption('s')) { try { List dois = doiService - .getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_RESERVED)); + .getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_RESERVED), offset, limit); if (dois.isEmpty()) { System.err.println("There are no objects in the database " + "that could be reserved."); @@ -243,7 +256,7 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args if (line.hasOption('r')) { try { List dois = doiService - .getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_REGISTERED)); + .getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_REGISTERED), offset, limit); if (dois.isEmpty()) { System.err.println("There are no objects in the database " + "that could be registered."); @@ -265,7 +278,7 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args List dois = doiService.getDOIsByStatus(context, Arrays.asList( DOIIdentifierProvider.UPDATE_BEFORE_REGISTRATION, DOIIdentifierProvider.UPDATE_RESERVED, - DOIIdentifierProvider.UPDATE_REGISTERED)); + DOIIdentifierProvider.UPDATE_REGISTERED), offset, limit); if (dois.isEmpty()) { System.err.println("There are no objects in the database " + "whose metadata needs an update."); @@ -284,7 +297,7 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args if (line.hasOption('d')) { try { List dois = doiService - .getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_DELETED)); + .getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_DELETED), offset, limit); if (dois.isEmpty()) { System.err.println("There are no objects in the database " + "that could be deleted."); diff --git a/dspace-api/src/main/java/org/dspace/identifier/service/DOIService.java b/dspace-api/src/main/java/org/dspace/identifier/service/DOIService.java index 5bd68a90615f..e8236a013f7e 100644 --- a/dspace-api/src/main/java/org/dspace/identifier/service/DOIService.java +++ b/dspace-api/src/main/java/org/dspace/identifier/service/DOIService.java @@ -124,6 +124,18 @@ public String formatIdentifier(String identifier) */ public List getDOIsByStatus(Context context, List statuses) throws SQLException; + /** + * Find all DOIs that have one of a given set of statuses. + * @param context current DSpace session. + * @param statuses desired statuses. + * @param offset offset value + * @param limit limited number of items + * @return all DOIs having any of the given statuses. + * @throws SQLException passed through. + */ + public List getDOIsByStatus(Context context, List statuses, int offset, int limit) + throws SQLException; + /** * Find all DOIs that are similar to the specified pattern and not in the * specified states.