diff --git a/mycore-base/src/main/java/org/mycore/frontend/cli/MCRCommandUtils.java b/mycore-base/src/main/java/org/mycore/frontend/cli/MCRCommandUtils.java
index efe2d85be2..6adf6fc781 100644
--- a/mycore-base/src/main/java/org/mycore/frontend/cli/MCRCommandUtils.java
+++ b/mycore-base/src/main/java/org/mycore/frontend/cli/MCRCommandUtils.java
@@ -223,18 +223,30 @@ public static Transformer getTransformer(String style, String defaultStyle, Map<
*
* This method iterates over all available objects IDs, filters them using a given filter and
* maps them to a MCRBase-object using the given mapper. For each such object, the corresponding XML
- * representation is created and the given XPath applied. If the Xpath evaluates to a non-empty result,
+ * representation is created and the given XPath applied. If the XPath evaluates to a non-empty result,
* the corresponding object ID is selected and included in the result list.
*/
public static List selectWithXpath(String xPath, Predicate filter,
Function mapper) {
+ List objectIds = MCRXMLMetadataManager.getInstance().listIDs();
+ return filterWithXpath(objectIds, xPath, filter, mapper);
+ }
+
+ /**
+ * Select MCRObjectIDs by applying a XPath to the corresponding MCRBase-objects XML representation.
+ *
+ * This method iterates over all given objects IDs, filters them using a given filter and
+ * maps them to a MCRBase-object using the given mapper. For each such object, the corresponding XML
+ * representation is created and the given XPath applied. If the XPath evaluates to a non-empty result,
+ * the corresponding object ID is selected and included in the result list.
+ */
+ public static List filterWithXpath(List objectIds, String xPath, Predicate filter,
+ Function mapper) {
XPathExpression xPathExpression = XPathFactory.instance()
.compile(xPath, Filters.fpassthrough(), null, MCRConstants.getStandardNamespaces());
- return MCRXMLMetadataManager
- .getInstance()
- .listIDs()
+ return objectIds
.stream()
.filter(filter)
.map(MCRObjectID::getInstance)
diff --git a/mycore-base/src/main/java/org/mycore/frontend/cli/MCRDerivateCommands.java b/mycore-base/src/main/java/org/mycore/frontend/cli/MCRDerivateCommands.java
index e31fbc1c12..12a51bbb7d 100644
--- a/mycore-base/src/main/java/org/mycore/frontend/cli/MCRDerivateCommands.java
+++ b/mycore-base/src/main/java/org/mycore/frontend/cli/MCRDerivateCommands.java
@@ -87,6 +87,7 @@
* @author Frank Lützenkirchen
*/
@MCRCommandGroup(name = "Derivate Commands")
+@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public class MCRDerivateCommands extends MCRAbstractCommands {
/** The logger */
@@ -105,14 +106,27 @@ public class MCRDerivateCommands extends MCRAbstractCommands {
@MCRCommand(
syntax = "select derivates with xpath {0}",
- help = "Selects MCRDerivates with XPath {0}, if that XPath evaluates to a non-empty result list" +
+ help = "Selects MCRDerivates with XPath {0}," +
+ " if that XPath evaluates to a non-empty result list" +
" (this command may take a while, use with care in case of a large number of objects)",
order = 10)
- public static void selectObjectsWithXpath(String xPath) {
+ public static void selectDerivatesWithXpath(String xPath) {
MCRBasicCommands.setSelectedValues(MCRCommandUtils.selectWithXpath(
xPath, DERIVATE_ID_PREDICATE, MCRMetadataManager::retrieveMCRDerivate));
}
+ @MCRCommand(
+ syntax = "filter derivate selection with xpath {0}",
+ help = "Filters the selection as MCRDerivates with XPath {0}," +
+ " if that XPath evaluates to a non-empty result list" +
+ " (this command may take a while, use with care in case of a large number of objects)",
+ order = 10)
+ public static void filterDerivateSelectionWithXpath(String xPath) {
+ MCRBasicCommands.setSelectedValues(MCRCommandUtils.filterWithXpath(
+ MCRBasicCommands.getSelectedValues(),
+ xPath, DERIVATE_ID_PREDICATE, MCRMetadataManager::retrieveMCRDerivate));
+ }
+
/**
* deletes all MCRDerivate from the datastore.
*/
diff --git a/mycore-base/src/main/java/org/mycore/frontend/cli/MCRObjectCommands.java b/mycore-base/src/main/java/org/mycore/frontend/cli/MCRObjectCommands.java
index 6c43ed9747..9a16e7a9b2 100644
--- a/mycore-base/src/main/java/org/mycore/frontend/cli/MCRObjectCommands.java
+++ b/mycore-base/src/main/java/org/mycore/frontend/cli/MCRObjectCommands.java
@@ -110,6 +110,7 @@
* @author Robert Stephan
*/
@MCRCommandGroup(name = "Object Commands")
+@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public class MCRObjectCommands extends MCRAbstractCommands {
private static final String EXPORT_OBJECT_TO_DIRECTORY_WITH_STYLESHEET_COMMAND =
@@ -144,7 +145,8 @@ public static List getSelectedObjectIDs() {
@MCRCommand(
syntax = "select objects with xpath {0}",
- help = "Selects MCRObjects with XPath {0}, if that XPath evaluates to a non-empty result list" +
+ help = "Selects MCRObjects with XPath {0}," +
+ " if that XPath evaluates to a non-empty result list" +
" (this command may take a while, use with care in case of a large number of objects)",
order = 10)
public static void selectWithXpath(String xPath) {
@@ -152,9 +154,22 @@ public static void selectWithXpath(String xPath) {
xPath, OBJECT_ID_PREDICATE, MCRMetadataManager::retrieveMCRObject));
}
+ @MCRCommand(
+ syntax = "filter object selection with xpath {0}",
+ help = "Filters the selection as MCRObjects with XPath {0}," +
+ " if that XPath evaluates to a non-empty result list" +
+ " (this command may take a while, use with care in case of a large number of objects)",
+ order = 11)
+ public static void filterObjectSelectionWithXpath(String xPath) {
+ MCRBasicCommands.setSelectedValues(MCRCommandUtils.filterWithXpath(
+ MCRBasicCommands.getSelectedValues(),
+ xPath, OBJECT_ID_PREDICATE, MCRMetadataManager::retrieveMCRObject));
+ }
+
@MCRCommand(
syntax = "select expanded objects with xpath {0}",
- help = "Selects expanded MCRObjects with XPath {0}, if that XPath evaluates to a non-empty result list" +
+ help = "Selects expanded MCRObjects with XPath {0}," +
+ " if that XPath evaluates to a non-empty result list" +
" (this command may take a while, use with care in case of a large number of objects)",
order = 10)
public static void selectExpandedObjectsWithXpath(String xPath) {
@@ -162,6 +177,18 @@ public static void selectExpandedObjectsWithXpath(String xPath) {
xPath, OBJECT_ID_PREDICATE, MCRMetadataManager::retrieveMCRExpandedObject));
}
+ @MCRCommand(
+ syntax = "filter expanded object selection with xpath {0}",
+ help = "Filters the selection as expanded MCRObjects with XPath {0}," +
+ " if that XPath evaluates to a non-empty result list"
+ + " (this command may take a while, use with care in case of a large number of objects)",
+ order = 10)
+ public static void filterExpandedObjectSelectionWithXpath(String xPath) {
+ MCRBasicCommands.setSelectedValues(MCRCommandUtils.filterWithXpath(
+ MCRBasicCommands.getSelectedValues(),
+ xPath, OBJECT_ID_PREDICATE, MCRMetadataManager::retrieveMCRExpandedObject));
+ }
+
@MCRCommand(
syntax = "select descendants of object {0}",
help = "Selects MCRObjects that are descendants of {0} (children, grandchildren, ...) and {0} itself.",