mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
feat: new parameter "fromdate" to evaluate items only from certain date
(cherry picked from commit a9e120f3d4
)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package org.dspace.app.mediafilter;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -37,8 +38,9 @@ import org.dspace.utils.DSpace;
|
||||
* MFM: -v verbose outputs all extracted text to STDOUT; -f force forces all
|
||||
* bitstreams to be processed, even if they have been before; -n noindex does not
|
||||
* recreate index after processing bitstreams; -i [identifier] limits processing
|
||||
* scope to a community, collection or item; and -m [max] limits processing to a
|
||||
* maximum number of items.
|
||||
* scope to a community, collection or item; -m [max] limits processing to a
|
||||
* maximum number of items; -fd [fromdate] takes only items starting from this date,
|
||||
* filtering by last_modified in the item table.
|
||||
*/
|
||||
public class MediaFilterScript extends DSpaceRunnable<MediaFilterScriptConfiguration> {
|
||||
|
||||
@@ -60,6 +62,7 @@ public class MediaFilterScript extends DSpaceRunnable<MediaFilterScriptConfigura
|
||||
private String[] filterNames;
|
||||
private String[] skipIds = null;
|
||||
private Map<String, List<String>> filterFormats = new HashMap<>();
|
||||
private LocalDate fromDate = null;
|
||||
|
||||
public MediaFilterScriptConfiguration getScriptConfiguration() {
|
||||
return new DSpace().getServiceManager()
|
||||
@@ -112,6 +115,10 @@ public class MediaFilterScript extends DSpaceRunnable<MediaFilterScriptConfigura
|
||||
skipIds = commandLine.getOptionValues('s');
|
||||
}
|
||||
|
||||
if (commandLine.hasOption('f')) {
|
||||
fromDate = LocalDate.parse(commandLine.getOptionValue('f'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -215,6 +222,10 @@ public class MediaFilterScript extends DSpaceRunnable<MediaFilterScriptConfigura
|
||||
mediaFilterService.setSkipList(Arrays.asList(skipIds));
|
||||
}
|
||||
|
||||
if (fromDate != null) {
|
||||
mediaFilterService.setFromDate(fromDate);
|
||||
}
|
||||
|
||||
Context c = null;
|
||||
|
||||
try {
|
||||
|
@@ -52,6 +52,8 @@ public class MediaFilterScriptConfiguration<T extends MediaFilterScript> extends
|
||||
.build();
|
||||
options.addOption(pluginOption);
|
||||
|
||||
options.addOption("fd", "fromdate", true, "Process only item from specified last modified date");
|
||||
|
||||
Option skipOption = Option.builder("s")
|
||||
.longOpt("skip")
|
||||
.hasArg()
|
||||
|
@@ -9,8 +9,11 @@ package org.dspace.app.mediafilter;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -93,6 +96,7 @@ public class MediaFilterServiceImpl implements MediaFilterService, InitializingB
|
||||
protected boolean isVerbose = false;
|
||||
protected boolean isQuiet = false;
|
||||
protected boolean isForce = false; // default to not forced
|
||||
protected LocalDate fromDate = null;
|
||||
|
||||
protected MediaFilterServiceImpl() {
|
||||
|
||||
@@ -120,6 +124,15 @@ public class MediaFilterServiceImpl implements MediaFilterService, InitializingB
|
||||
for (Community topLevelCommunity : topLevelCommunities) {
|
||||
applyFiltersCommunity(context, topLevelCommunity);
|
||||
}
|
||||
} else if (fromDate != null) {
|
||||
Iterator<Item> itemIterator =
|
||||
itemService.findByLastModifiedSince(
|
||||
context,
|
||||
Date.from(fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant())
|
||||
);
|
||||
while (itemIterator.hasNext() && processed < max2Process) {
|
||||
applyFiltersItem(context, itemIterator.next());
|
||||
}
|
||||
} else {
|
||||
//otherwise, just find every item and process
|
||||
Iterator<Item> itemIterator = itemService.findAll(context);
|
||||
@@ -588,4 +601,9 @@ public class MediaFilterServiceImpl implements MediaFilterService, InitializingB
|
||||
public void setLogHandler(DSpaceRunnableHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFromDate(LocalDate fromDate) {
|
||||
this.fromDate = fromDate;
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.mediafilter.service;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -149,4 +150,6 @@ public interface MediaFilterService {
|
||||
* @param handler
|
||||
*/
|
||||
public void setLogHandler(DSpaceRunnableHandler handler);
|
||||
|
||||
public void setFromDate(LocalDate fromDate);
|
||||
}
|
||||
|
Reference in New Issue
Block a user