Skip to content

Commit

Permalink
relatively small cumulative changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JuicyDragon committed Jun 24, 2021
1 parent 4cc9ee8 commit ef90197
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
13 changes: 11 additions & 2 deletions Java/src/main/java/com/nuix/superutilities/SuperUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import nuix.BulkAnnotater;
import nuix.Case;
import nuix.ItemUtility;
import nuix.Utilities;

/***
Expand Down Expand Up @@ -244,9 +245,17 @@ public CaseHistoryHelper createCaseHistoryHelper(Case nuixCase, List<String> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,6 +16,7 @@

import com.nuix.superutilities.SuperUtilities;

import nuix.Case;
import nuix.Item;
import nuix.ItemUtility;
import nuix.TreePosition;
Expand Down Expand Up @@ -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<Item> unionMany(List<Collection<Item>> itemCollections){
ItemUtility iutil = SuperUtilities.getInstance().getNuixUtilities().getItemUtility();
ItemUtility iutil = SuperUtilities.getItemUtility();
Set<Item> result = new HashSet<Item>();
for (int i = 0; i < itemCollections.size(); i++) {
result = iutil.union(result, itemCollections.get(i));
Expand Down Expand Up @@ -129,10 +131,13 @@ public Set<Item> findContainerAncestors(Collection<Item> items){
public void splitAndMaintainFamilies(Collection<Item> items, int targetChunkSize, Consumer<Collection<Item>> chunkConsumer){
List<Item> currentSubSet = new ArrayList<Item>();
List<Item> sortedItems = new ArrayList<Item>(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<Item>();
}
Expand All @@ -144,6 +149,27 @@ public void splitAndMaintainFamilies(Collection<Item> 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<Item> removeItemsResponsiveToQuery(Case nuixCase, Collection<Item> inputItems, String itemsToRemoveQuery) throws IOException {
Set<Item> toRemove = nuixCase.searchUnsorted(itemsToRemoveQuery);
return SuperUtilities.getItemUtility().difference(inputItems, toRemove);
}

public Set<Item> findFamiliesWithoutItemsResponsiveToQuery(Case nuixCase, Collection<Item> inputItems, String itemsToRemoveQuery) throws IOException {
Set<Item> topLevelItems = SuperUtilities.getItemUtility().findTopLevelItems(inputItems);
Set<Item> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ public static String notJoinByOr(Collection<String> expressions) {
return String.format("NOT (%s)", joinByOr(expressions));
}

/***
* Returns a query in the form: <code>NOT (a AND b AND c)</code> 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: <code>NOT (a AND b AND c)</code>
*/
public static String notJoinByAnd(Collection<String> 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
Expand Down

0 comments on commit ef90197

Please sign in to comment.