diff --git a/Java/src/main/java/com/nuix/superutilities/regex/ItemRegexMatchCollection.java b/Java/src/main/java/com/nuix/superutilities/regex/ItemRegexMatchCollection.java index f4a384d..1d919c6 100644 --- a/Java/src/main/java/com/nuix/superutilities/regex/ItemRegexMatchCollection.java +++ b/Java/src/main/java/com/nuix/superutilities/regex/ItemRegexMatchCollection.java @@ -1,9 +1,11 @@ package com.nuix.superutilities.regex; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import nuix.Case; import nuix.Item; /*** @@ -12,7 +14,7 @@ * */ public class ItemRegexMatchCollection { - private Item item = null; + private String itemGuid = null; private List matchData = new ArrayList(); /*** @@ -20,15 +22,20 @@ public class ItemRegexMatchCollection { * @param item The item to associated. */ public ItemRegexMatchCollection(Item item){ - this.item = item; + this.itemGuid = item.getGuid(); } /*** * Gets the associated item. * @return The associated item. */ - public Item getItem(){ - return item; + public Item getItem(Case nuixCase){ + try { + return nuixCase.search(String.format("guid:%s", itemGuid)).get(0); + } catch (IOException e) { + e.printStackTrace(); + return null; + } } /*** @@ -66,7 +73,8 @@ public List getPropertyMatches(){ * @param matchEnd Offset in source text where this match ends */ public void addMatch(PatternInfo patternInfo, String location, boolean isContentMatch, String value, String valueContext, int matchStart, int matchEnd){ - matchData.add(new RegexMatch(patternInfo,location,isContentMatch,value,valueContext,matchStart,matchEnd)); + // Intern location in case there is a large amount of duplication of a small set of actual values + matchData.add(new RegexMatch(patternInfo,location.intern(),isContentMatch,value,valueContext,matchStart,matchEnd)); } /*** diff --git a/Java/src/main/java/com/nuix/superutilities/regex/RegexScanError.java b/Java/src/main/java/com/nuix/superutilities/regex/RegexScanError.java index c9c6c2a..8295e48 100644 --- a/Java/src/main/java/com/nuix/superutilities/regex/RegexScanError.java +++ b/Java/src/main/java/com/nuix/superutilities/regex/RegexScanError.java @@ -1,5 +1,8 @@ package com.nuix.superutilities.regex; +import java.io.IOException; + +import nuix.Case; import nuix.Item; /*** @@ -8,7 +11,7 @@ * */ public class RegexScanError { - private Item item = null; + private String itemGuid = null; private PatternInfo patternInfo = null; private String location = null; private Exception exception = null; @@ -21,7 +24,7 @@ public class RegexScanError { * @param exception The exception which was thrown */ public RegexScanError(Item item, PatternInfo patternInfo, String location, Exception exception){ - this.item = item; + this.itemGuid = item.getGuid(); this.patternInfo = patternInfo; this.location = location; this.exception = exception; @@ -31,8 +34,17 @@ public RegexScanError(Item item, PatternInfo patternInfo, String location, Excep * Gets the associated item * @return The associated item */ - public Item getItem() { - return item; + public Item getItem(Case nuixCase) { + try { + return nuixCase.search(String.format("guid:%s", itemGuid)).get(0); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + public String getItemGuid() { + return this.itemGuid; } /*** diff --git a/Java/src/main/java/com/nuix/superutilities/regex/RegexScanner.java b/Java/src/main/java/com/nuix/superutilities/regex/RegexScanner.java index db66ae0..1e6583a 100644 --- a/Java/src/main/java/com/nuix/superutilities/regex/RegexScanner.java +++ b/Java/src/main/java/com/nuix/superutilities/regex/RegexScanner.java @@ -21,6 +21,7 @@ import com.nuix.superutilities.misc.FormatUtility; import nuix.Item; +import nuix.ItemCustomMetadataMap; /*** * Class for scanning a series of items with a series of regular expressions. @@ -107,7 +108,7 @@ protected void fireScanError(RegexScanError error){ if(error.getLocation() != null){ errorMessage.add("\tLocation: "+error.getLocation()); } - errorMessage.add("\tItem GUID: "+error.getItem().getGuid()); + errorMessage.add("\tItem GUID: "+error.getItemGuid()); logger.error(errorMessage.toString()); logger.error(error.getException()); } @@ -444,12 +445,25 @@ protected ItemRegexMatchCollection scanItem(Item item) { * @return Map of "stringified" metadata properties for the specified item */ public static Map getStringProperties(Item item, Set specificProperties){ + // Note below String.intern use on property names which likely is highly repetitive + Map result = new HashMap(); - for (Entry entry : item.getProperties().entrySet()) { - if(specificProperties == null || specificProperties.contains(entry.getKey())){ - result.put(entry.getKey(), FormatUtility.getInstance().convertToString(entry.getValue())); + + if(specificProperties == null | specificProperties.size() == 0) { + // We're scanning all the properties + for (Entry entry : item.getProperties().entrySet()) { + result.put(entry.getKey().intern(), FormatUtility.getInstance().convertToString(entry.getValue())); + } + } else { + // We're just scanning specific properties + Map itemProperties = item.getProperties(); + for(String specificProperty : specificProperties) { + if(itemProperties.containsKey(specificProperty)) { + result.put(specificProperty.intern(), FormatUtility.getInstance().convertToString(itemProperties.get(specificProperty))); + } } } + return result; } @@ -462,11 +476,22 @@ public static Map getStringProperties(Item item, Set spec */ public static Map getStringCustomMetadata(Item item, Set specificFields){ Map result = new HashMap(); - for (Entry entry : item.getCustomMetadata().entrySet()) { - if(specificFields == null || specificFields.contains(entry.getKey())){ - result.put(entry.getKey(), FormatUtility.getInstance().convertToString(entry.getValue())); + + if(specificFields == null || specificFields.size() == 0) { + // We're scanning all the custom metadata fields + for (Entry entry : item.getCustomMetadata().entrySet()) { + result.put(entry.getKey().intern(), FormatUtility.getInstance().convertToString(entry.getValue())); + } + } else { + ItemCustomMetadataMap itemCustomMetadata = item.getCustomMetadata(); + // We're scanning specific custom metadata fields + for(String specificField : specificFields) { + if(itemCustomMetadata.containsKey(specificField)) { + result.put(specificField.intern(),FormatUtility.getInstance().convertToString(itemCustomMetadata.get(specificField))); + } } } + return result; }