diff --git a/Java/src/main/java/com/nuix/superutilities/SuperUtilities.java b/Java/src/main/java/com/nuix/superutilities/SuperUtilities.java index 8a4f86c..29f4589 100644 --- a/Java/src/main/java/com/nuix/superutilities/SuperUtilities.java +++ b/Java/src/main/java/com/nuix/superutilities/SuperUtilities.java @@ -26,6 +26,7 @@ import nuix.BulkAnnotater; import nuix.Case; +import nuix.ItemUtility; import nuix.Utilities; /*** @@ -244,9 +245,17 @@ public CaseHistoryHelper createCaseHistoryHelper(Case nuixCase, List eve /*** * Convenience method to obtain Nuix BulkAnnotater - * @return Nuix bulk annotater obtained from Utilities object + * @return Nuix BulkAnnotater obtained from Utilities object */ - public static BulkAnnotater getBulkAnnotater(){ + public static BulkAnnotater getBulkAnnotater() { return getInstance().getNuixUtilities().getBulkAnnotater(); } + + /*** + * Convenience method to obtain Nuix ItemUtility + * @return Nuix ItemUtility obtained from Utilities object + */ + public static ItemUtility getItemUtility() { + return getInstance().getNuixUtilities().getItemUtility(); + } } diff --git a/Java/src/main/java/com/nuix/superutilities/items/SuperItemUtility.java b/Java/src/main/java/com/nuix/superutilities/items/SuperItemUtility.java index 300481c..0ab8c10 100644 --- a/Java/src/main/java/com/nuix/superutilities/items/SuperItemUtility.java +++ b/Java/src/main/java/com/nuix/superutilities/items/SuperItemUtility.java @@ -1,5 +1,6 @@ package com.nuix.superutilities.items; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; @@ -15,6 +16,7 @@ import com.nuix.superutilities.SuperUtilities; +import nuix.Case; import nuix.Item; import nuix.ItemUtility; import nuix.TreePosition; @@ -44,7 +46,7 @@ public static SuperItemUtility getInstance(){ * @return A set at most 1 of each item in the provided input item collections */ public Set unionMany(List> itemCollections){ - ItemUtility iutil = SuperUtilities.getInstance().getNuixUtilities().getItemUtility(); + ItemUtility iutil = SuperUtilities.getItemUtility(); Set result = new HashSet(); for (int i = 0; i < itemCollections.size(); i++) { result = iutil.union(result, itemCollections.get(i)); @@ -129,10 +131,13 @@ public Set findContainerAncestors(Collection items){ public void splitAndMaintainFamilies(Collection items, int targetChunkSize, Consumer> chunkConsumer){ List currentSubSet = new ArrayList(); List sortedItems = new ArrayList(items); - sortedItems = SuperUtilities.getInstance().getNuixUtilities().getItemSorter().sortItemsByPosition(sortedItems); + sortedItems = SuperUtilities.getItemUtility().sortItemsByPosition(sortedItems); + + Item previousItem = null; for (int i = 0; i < sortedItems.size(); i++) { Item currentItem = sortedItems.get(i); - if(currentSubSet.size() >= targetChunkSize && currentItem.isTopLevel()){ + boolean canCutHere = previousItem == null || currentItem.getTopLevelItem() == null || (currentItem.getTopLevelItem() != previousItem.getTopLevelItem()); + if(currentSubSet.size() >= targetChunkSize && canCutHere){ chunkConsumer.accept(currentSubSet); currentSubSet = new ArrayList(); } @@ -144,6 +149,27 @@ public void splitAndMaintainFamilies(Collection items, int targetChunkSize } } + /*** + * Convenience method for removing items responsive to a query from another collection of items. Internally this + * method runs a search for the given query and then uses ItemUtility.difference to remove them from the provided + * input items, returning the differenced result. + * @param nuixCase The Nuix case (needed to run the search) + * @param inputItems The items from which you wish to remove items which are responsive to the given query + * @param itemsToRemoveQuery The query used to define items you wish to have removed form the input items + * @return The input items, with items responsive to the query removed + * @throws IOException Likely thrown if there is an issue with the provided query + */ + public Set removeItemsResponsiveToQuery(Case nuixCase, Collection inputItems, String itemsToRemoveQuery) throws IOException { + Set toRemove = nuixCase.searchUnsorted(itemsToRemoveQuery); + return SuperUtilities.getItemUtility().difference(inputItems, toRemove); + } + + public Set findFamiliesWithoutItemsResponsiveToQuery(Case nuixCase, Collection inputItems, String itemsToRemoveQuery) throws IOException { + Set topLevelItems = SuperUtilities.getItemUtility().findTopLevelItems(inputItems); + Set families = SuperUtilities.getItemUtility().findItemsAndDescendants(topLevelItems); + return removeItemsResponsiveToQuery(nuixCase,families,itemsToRemoveQuery); + } + /*** * Returns the file system path of an item's physical file ancestor. Begins by calling {@link #findPhysicalFileAncestor(Item)}. * If an physical file ancestor is located, then gets its URI and attempts to convert that to an actual file system path. diff --git a/Java/src/main/java/com/nuix/superutilities/misc/ZipHelper.java b/Java/src/main/java/com/nuix/superutilities/misc/ZipHelper.java index f8bfa1d..c074e91 100644 --- a/Java/src/main/java/com/nuix/superutilities/misc/ZipHelper.java +++ b/Java/src/main/java/com/nuix/superutilities/misc/ZipHelper.java @@ -27,7 +27,7 @@ public static void compressDirectoryToZipFile(String directory, String zipFile, zipStream.setLevel(Ints.constrainToRange(compressionLevel, 0, 9)); compressDirectoryToZipfile(directory,directory,zipStream); } finally { - IOUtils.closeQuietly(zipStream); + IOUtils.closeQuietly(zipStream); } } diff --git a/Java/src/main/java/com/nuix/superutilities/query/QueryHelper.java b/Java/src/main/java/com/nuix/superutilities/query/QueryHelper.java index e9416a0..6ff9b2d 100644 --- a/Java/src/main/java/com/nuix/superutilities/query/QueryHelper.java +++ b/Java/src/main/java/com/nuix/superutilities/query/QueryHelper.java @@ -118,6 +118,15 @@ public static String notJoinByOr(Collection expressions) { return String.format("NOT (%s)", joinByOr(expressions)); } + /*** + * Returns a query in the form: NOT (a AND b AND c) with a,b and c being expressions provided. + * @param expressions Expressions to be AND'ed and then NOT'ed. + * @return A query in the form: NOT (a AND b AND c) + */ + public static String notJoinByAnd(Collection expressions) { + return String.format("NOT (%s)", joinByAnd(expressions)); + } + /*** * Generates a query to find items which have a match for any of the provided named entities. * @param entityNames List of entity names to search for, must be values recognized by Nuix