From 6e164dcfda9c5f8aa2912f9592f3ba39086639a5 Mon Sep 17 00:00:00 2001 From: Kelly Kelly Date: Fri, 21 Aug 2020 16:42:46 -0400 Subject: [PATCH 1/6] Added getArtifact method to DataSourceInfoUtilities --- .../datamodel/DataSourceInfoUtilities.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java index b72bc14330..32876fc2ed 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java @@ -20,13 +20,20 @@ package org.sleuthkit.autopsy.datasourcesummary.datamodel; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.TreeMap; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; import org.apache.commons.lang.StringUtils; +import org.bouncycastle.util.Arrays; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.datamodel.BlackboardArtifact; +import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.TskData; import org.sleuthkit.datamodel.DataSource; import org.sleuthkit.datamodel.TskData.TSK_FS_META_FLAG_ENUM; @@ -132,10 +139,112 @@ final class DataSourceInfoUtilities { static String getMetaFlagsContainsStatement(TSK_FS_META_FLAG_ENUM flag) { return "meta_flags & " + flag.getValue() + " > 0"; } + + enum SortOrder { + DECENDING, + ASCENDING + } + + /** + * Return a list of artifacts that have been sorted by their attribute + * of attributeType. + * + * Sorting on attributes of type byte[] and JSON is not currently + * supported. + * + * @param skCase SleuthkitCase instance. + * @param artifactType Type of artifacts to sort. + * @param dataSource Data Source that the artifact belongs to. + * @param attributeType Attribute type to sort by. + * @param sortOrder Sort order of the attributes, either ascending or + * descending. + * @param maxCount Maximum number of results to return. To return all + * values maxCount should be -1. + * + * @return A list of artifacts of type artifactType sorted by the attribute + * of attributeType in the given sortOrder. If no artifacts are + * found an empty list will be returned. + * + * @throws TskCoreException + */ + static List getArtifacts(SleuthkitCase skCase, BlackboardArtifact.Type artifactType, DataSource dataSource, BlackboardAttribute.Type attributeType, SortOrder sortOrder, int maxCount) throws TskCoreException { + if (maxCount < 1 && maxCount != -1) { + throw new IllegalArgumentException("Invalid maxCount passed to getArtifacts, value must be at greater 0"); + } + + TreeMap sortedMap = new TreeMap<>(new AttributeComparator(sortOrder)); + List artifactList = skCase.getBlackboard().getArtifacts(artifactType.getTypeID(), dataSource.getId()); + + for (BlackboardArtifact artifact : artifactList) { + BlackboardAttribute attribute = artifact.getAttribute(attributeType); + if (attribute != null) { + sortedMap.put(attribute, artifact); + } + } + + artifactList = new ArrayList<>(); + + for (BlackboardArtifact artifact : sortedMap.values()) { + artifactList.add(artifact); + if (maxCount != -1 && artifactList.size() == maxCount - 1) { + break; + } + } + return artifactList; + } /** * Empty private constructor */ private DataSourceInfoUtilities() { } + + /** + * Compares the value of two BlackboardAttributes that are of the same type. + * This comparator is specialized for data source summary and only supports + * the basic attribute types of string, integer, long, datetime (long), and + * double. + */ + private static class AttributeComparator implements Comparator { + + private final SortOrder direction; + + AttributeComparator(SortOrder direction) { + this.direction = direction; + } + + @Override + public int compare(BlackboardAttribute attribute1, BlackboardAttribute attribute2) { + if (attribute1.getAttributeType() != attribute2.getAttributeType()) { + throw new IllegalArgumentException("Unable to compare attributes of different types"); + } + + int result; + switch (attribute1.getValueType()) { + case STRING: + result = attribute1.getValueString().compareTo(attribute2.getValueString()); + break; + case INTEGER: + result = Integer.compare(attribute1.getValueInt(), attribute2.getValueInt()); + break; + case LONG: + case DATETIME: + result = Long.compare(attribute1.getValueLong(), attribute2.getValueLong()); + break; + case DOUBLE: + result = Double.compare(attribute1.getValueDouble(), attribute2.getValueDouble()); + break; + case BYTE: + case JSON: + default: + throw new IllegalArgumentException("Unable to compare attributes of type " + attribute1.getAttributeType().getTypeName()); + } + + if (direction == SortOrder.DECENDING) { + result *= -1; + } + + return result; + } + } } From b697a4472c2c4df2a5bd1d68d4822fe631e922bd Mon Sep 17 00:00:00 2001 From: Kelly Kelly Date: Mon, 24 Aug 2020 10:24:55 -0400 Subject: [PATCH 2/6] Fixed codacy issues --- .../datamodel/DataSourceInfoUtilities.java | 74 +++++++++++-------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java index 32876fc2ed..a83e087e81 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java @@ -29,7 +29,6 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; import org.apache.commons.lang.StringUtils; -import org.bouncycastle.util.Arrays; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.datamodel.BlackboardArtifact; @@ -139,18 +138,20 @@ final class DataSourceInfoUtilities { static String getMetaFlagsContainsStatement(TSK_FS_META_FLAG_ENUM flag) { return "meta_flags & " + flag.getValue() + " > 0"; } - + + /** + * Enum for specifying the sort order for getAttributes. + */ enum SortOrder { DECENDING, ASCENDING } - + /** - * Return a list of artifacts that have been sorted by their attribute - * of attributeType. - * - * Sorting on attributes of type byte[] and JSON is not currently - * supported. + * Return a list of artifacts that have been sorted by their attribute of + * attributeType. + * + * Sorting on attributes of type byte[] and JSON is not currently supported. * * @param skCase SleuthkitCase instance. * @param artifactType Type of artifacts to sort. @@ -189,7 +190,7 @@ final class DataSourceInfoUtilities { if (maxCount != -1 && artifactList.size() == maxCount - 1) { break; } - } + } return artifactList; } @@ -198,12 +199,15 @@ final class DataSourceInfoUtilities { */ private DataSourceInfoUtilities() { } - + /** * Compares the value of two BlackboardAttributes that are of the same type. * This comparator is specialized for data source summary and only supports * the basic attribute types of string, integer, long, datetime (long), and * double. + * + * Note: A runtime exception will be thrown from the compare if the attributes + * are not of the same type or if their type is not supported. */ private static class AttributeComparator implements Comparator { @@ -219,26 +223,7 @@ final class DataSourceInfoUtilities { throw new IllegalArgumentException("Unable to compare attributes of different types"); } - int result; - switch (attribute1.getValueType()) { - case STRING: - result = attribute1.getValueString().compareTo(attribute2.getValueString()); - break; - case INTEGER: - result = Integer.compare(attribute1.getValueInt(), attribute2.getValueInt()); - break; - case LONG: - case DATETIME: - result = Long.compare(attribute1.getValueLong(), attribute2.getValueLong()); - break; - case DOUBLE: - result = Double.compare(attribute1.getValueDouble(), attribute2.getValueDouble()); - break; - case BYTE: - case JSON: - default: - throw new IllegalArgumentException("Unable to compare attributes of type " + attribute1.getAttributeType().getTypeName()); - } + int result = compare(attribute1.getAttributeType(), attribute1, attribute2); if (direction == SortOrder.DECENDING) { result *= -1; @@ -246,5 +231,34 @@ final class DataSourceInfoUtilities { return result; } + + /** + * Compared two attributes of the given type. Note, that not all + * attribute types are supported. A runtime exception will be thrown + * if an unsupported attribute is supplied. + * + * @param type Attribute type. + * @param attribute1 First attribute to compare. + * @param attribute2 Second attribute to compare. + * + * @return Compare result. + */ + private int compare(BlackboardAttribute.Type type, BlackboardAttribute attribute1, BlackboardAttribute attribute2) { + switch (type.getValueType()) { + case STRING: + return attribute1.getValueString().compareTo(attribute2.getValueString()); + case INTEGER: + return Integer.compare(attribute1.getValueInt(), attribute2.getValueInt()); + case LONG: + case DATETIME: + return Long.compare(attribute1.getValueLong(), attribute2.getValueLong()); + case DOUBLE: + return Double.compare(attribute1.getValueDouble(), attribute2.getValueDouble()); + case BYTE: + case JSON: + default: + throw new IllegalArgumentException("Unable to compare attributes of type " + attribute1.getAttributeType().getTypeName()); + } + } } } From 4cfbe6d18b0d9f5a498da9e0bd2d1f5cf7fc72ae Mon Sep 17 00:00:00 2001 From: Kelly Kelly Date: Tue, 25 Aug 2020 14:58:12 -0400 Subject: [PATCH 3/6] Fixed bug and addressed review comment --- .../datamodel/DataSourceInfoUtilities.java | 68 ++++++++++++++++--- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java index a83e087e81..b042ed6c4d 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java @@ -143,13 +143,38 @@ final class DataSourceInfoUtilities { * Enum for specifying the sort order for getAttributes. */ enum SortOrder { - DECENDING, + DESCENDING, ASCENDING } + + /** + * Returns a list of all artifacts of the given type that have an attribute + * of the given type sorted by given attribute type value. Artifacts that + * do not have the given attribute will not be included in the list. + * + * Sorting on attributes of type byte[] and JSON is not currently supported. + * + * @param skCase SleuthkitCase instance. + * @param artifactType Type of artifacts to sort. + * @param dataSource Data Source that the artifact belongs to. + * @param attributeType Attribute type to sort by. + * @param sortOrder Sort order of the attributes, either ascending or + * descending. + * + * @return A list of artifacts of type artifactType sorted by the attribute + * of attributeType in the given sortOrder. If no artifacts are + * found an empty list will be returned. + * + * @throws TskCoreException + */ + static List getArtifacts(SleuthkitCase skCase, BlackboardArtifact.Type artifactType, DataSource dataSource, BlackboardAttribute.Type attributeType, SortOrder sortOrder) throws TskCoreException { + return getArtifacts(skCase, artifactType, dataSource, attributeType, sortOrder, 0); + } /** * Return a list of artifacts that have been sorted by their attribute of - * attributeType. + * attributeType. If an artifact of the given type does not have the + * given attribute it will not be included in the returned list. * * Sorting on attributes of type byte[] and JSON is not currently supported. * @@ -160,7 +185,7 @@ final class DataSourceInfoUtilities { * @param sortOrder Sort order of the attributes, either ascending or * descending. * @param maxCount Maximum number of results to return. To return all - * values maxCount should be -1. + * values maxCount should be 0. * * @return A list of artifacts of type artifactType sorted by the attribute * of attributeType in the given sortOrder. If no artifacts are @@ -169,27 +194,48 @@ final class DataSourceInfoUtilities { * @throws TskCoreException */ static List getArtifacts(SleuthkitCase skCase, BlackboardArtifact.Type artifactType, DataSource dataSource, BlackboardAttribute.Type attributeType, SortOrder sortOrder, int maxCount) throws TskCoreException { - if (maxCount < 1 && maxCount != -1) { + if (maxCount < 0 ) { throw new IllegalArgumentException("Invalid maxCount passed to getArtifacts, value must be at greater 0"); } - TreeMap sortedMap = new TreeMap<>(new AttributeComparator(sortOrder)); + TreeMap> sortedMap = new TreeMap<>(new AttributeComparator(sortOrder)); List artifactList = skCase.getBlackboard().getArtifacts(artifactType.getTypeID(), dataSource.getId()); for (BlackboardArtifact artifact : artifactList) { BlackboardAttribute attribute = artifact.getAttribute(attributeType); - if (attribute != null) { - sortedMap.put(attribute, artifact); + if (attribute == null) { + continue; } + + List mapArtifactList = sortedMap.get(attribute); + if(mapArtifactList == null) { + mapArtifactList = new ArrayList<>(); + sortedMap.put(attribute, mapArtifactList); + } + + mapArtifactList.add(artifact); } artifactList = new ArrayList<>(); - for (BlackboardArtifact artifact : sortedMap.values()) { - artifactList.add(artifact); - if (maxCount != -1 && artifactList.size() == maxCount - 1) { + for (List mapArtifactList : sortedMap.values()) { + + if(maxCount == artifactList.size()) { break; } + + if(maxCount == 0 || (artifactList.size() + mapArtifactList.size()) <= maxCount ) { + artifactList.addAll(mapArtifactList); + continue; + } + + for(BlackboardArtifact artifact: mapArtifactList) { + if(artifactList.size() < maxCount) { + artifactList.add(artifact); + } else { + break; + } + } } return artifactList; } @@ -225,7 +271,7 @@ final class DataSourceInfoUtilities { int result = compare(attribute1.getAttributeType(), attribute1, attribute2); - if (direction == SortOrder.DECENDING) { + if (direction == SortOrder.DESCENDING) { result *= -1; } From cf3bd7c831bcc2cb284706adb4db59f12ed3887f Mon Sep 17 00:00:00 2001 From: Kelly Kelly Date: Thu, 27 Aug 2020 10:32:23 -0400 Subject: [PATCH 4/6] fixed codacy issue --- .../datamodel/DataSourceInfoUtilities.java | 98 ++++++++++++------- 1 file changed, 65 insertions(+), 33 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java index b042ed6c4d..1cddd9dbc9 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java @@ -146,12 +146,12 @@ final class DataSourceInfoUtilities { DESCENDING, ASCENDING } - - /** + + /** * Returns a list of all artifacts of the given type that have an attribute - * of the given type sorted by given attribute type value. Artifacts that - * do not have the given attribute will not be included in the list. - * + * of the given type sorted by given attribute type value. Artifacts that do + * not have the given attribute will not be included in the list. + * * Sorting on attributes of type byte[] and JSON is not currently supported. * * @param skCase SleuthkitCase instance. @@ -173,8 +173,8 @@ final class DataSourceInfoUtilities { /** * Return a list of artifacts that have been sorted by their attribute of - * attributeType. If an artifact of the given type does not have the - * given attribute it will not be included in the returned list. + * attributeType. If an artifact of the given type does not have the given + * attribute it will not be included in the returned list. * * Sorting on attributes of type byte[] and JSON is not currently supported. * @@ -194,10 +194,36 @@ final class DataSourceInfoUtilities { * @throws TskCoreException */ static List getArtifacts(SleuthkitCase skCase, BlackboardArtifact.Type artifactType, DataSource dataSource, BlackboardAttribute.Type attributeType, SortOrder sortOrder, int maxCount) throws TskCoreException { - if (maxCount < 0 ) { + if (maxCount < 0) { throw new IllegalArgumentException("Invalid maxCount passed to getArtifacts, value must be at greater 0"); } + return createListFromMap(getArtifactMap(skCase, artifactType, dataSource, attributeType, sortOrder), maxCount); + } + + /** + * Empty private constructor + */ + private DataSourceInfoUtilities() { + } + + /** + * Create a Map of lists of artifacts sorted by the given attribute. + * + * @param skCase SleuthkitCase instance. + * @param artifactType Type of artifacts to sort. + * @param dataSource Data Source that the artifact belongs to. + * @param attributeType Attribute type to sort by. + * @param sortOrder Sort order of the attributes, either ascending or + * descending. + * + * @return A Map of lists of artifacts sorted by the value of attribute + * given type. Artifacts that do not have an attribute of the given + * type will not be included. + * + * @throws TskCoreException + */ + static private TreeMap> getArtifactMap(SleuthkitCase skCase, BlackboardArtifact.Type artifactType, DataSource dataSource, BlackboardAttribute.Type attributeType, SortOrder sortOrder) throws TskCoreException { TreeMap> sortedMap = new TreeMap<>(new AttributeComparator(sortOrder)); List artifactList = skCase.getBlackboard().getArtifacts(artifactType.getTypeID(), dataSource.getId()); @@ -206,31 +232,43 @@ final class DataSourceInfoUtilities { if (attribute == null) { continue; } - + List mapArtifactList = sortedMap.get(attribute); - if(mapArtifactList == null) { + if (mapArtifactList == null) { mapArtifactList = new ArrayList<>(); sortedMap.put(attribute, mapArtifactList); } - + mapArtifactList.add(artifact); } - artifactList = new ArrayList<>(); + return sortedMap; + } + + /** + * Creates the list of artifacts from the sorted map and the given count. + * + * @param sortedMap Sorted map of artifact lists. + * @param maxCount Maximum number of artifacts to return. + * + * @return List of artifacts, list will be empty if none were found. + */ + static private List createListFromMap(TreeMap> sortedMap, int maxCount) { + List artifactList = new ArrayList<>(); for (List mapArtifactList : sortedMap.values()) { - - if(maxCount == artifactList.size()) { + + if (maxCount == artifactList.size()) { break; } - - if(maxCount == 0 || (artifactList.size() + mapArtifactList.size()) <= maxCount ) { + + if (maxCount == 0 || (artifactList.size() + mapArtifactList.size()) <= maxCount) { artifactList.addAll(mapArtifactList); continue; } - - for(BlackboardArtifact artifact: mapArtifactList) { - if(artifactList.size() < maxCount) { + + for (BlackboardArtifact artifact : mapArtifactList) { + if (artifactList.size() < maxCount) { artifactList.add(artifact); } else { break; @@ -240,20 +278,14 @@ final class DataSourceInfoUtilities { return artifactList; } - /** - * Empty private constructor - */ - private DataSourceInfoUtilities() { - } - /** * Compares the value of two BlackboardAttributes that are of the same type. * This comparator is specialized for data source summary and only supports * the basic attribute types of string, integer, long, datetime (long), and * double. - * - * Note: A runtime exception will be thrown from the compare if the attributes - * are not of the same type or if their type is not supported. + * + * Note: A runtime exception will be thrown from the compare if the + * attributes are not of the same type or if their type is not supported. */ private static class AttributeComparator implements Comparator { @@ -280,13 +312,13 @@ final class DataSourceInfoUtilities { /** * Compared two attributes of the given type. Note, that not all - * attribute types are supported. A runtime exception will be thrown - * if an unsupported attribute is supplied. - * - * @param type Attribute type. + * attribute types are supported. A runtime exception will be thrown if + * an unsupported attribute is supplied. + * + * @param type Attribute type. * @param attribute1 First attribute to compare. * @param attribute2 Second attribute to compare. - * + * * @return Compare result. */ private int compare(BlackboardAttribute.Type type, BlackboardAttribute attribute1, BlackboardAttribute attribute2) { From 9c455f728d079309c0ae764294c9c7e4668036a9 Mon Sep 17 00:00:00 2001 From: Kelly Kelly Date: Thu, 27 Aug 2020 15:16:17 -0400 Subject: [PATCH 5/6] Fixed another codacy issue --- .../datamodel/DataSourceInfoUtilities.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java index 1cddd9dbc9..89e3c11b40 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java @@ -23,6 +23,8 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Map; +import java.util.SortedMap; import java.util.TreeMap; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; @@ -223,8 +225,8 @@ final class DataSourceInfoUtilities { * * @throws TskCoreException */ - static private TreeMap> getArtifactMap(SleuthkitCase skCase, BlackboardArtifact.Type artifactType, DataSource dataSource, BlackboardAttribute.Type attributeType, SortOrder sortOrder) throws TskCoreException { - TreeMap> sortedMap = new TreeMap<>(new AttributeComparator(sortOrder)); + static private SortedMap> getArtifactMap(SleuthkitCase skCase, BlackboardArtifact.Type artifactType, DataSource dataSource, BlackboardAttribute.Type attributeType, SortOrder sortOrder) throws TskCoreException { + SortedMap> sortedMap = new TreeMap<>(new AttributeComparator(sortOrder)); List artifactList = skCase.getBlackboard().getArtifacts(artifactType.getTypeID(), dataSource.getId()); for (BlackboardArtifact artifact : artifactList) { @@ -253,7 +255,7 @@ final class DataSourceInfoUtilities { * * @return List of artifacts, list will be empty if none were found. */ - static private List createListFromMap(TreeMap> sortedMap, int maxCount) { + static private List createListFromMap(SortedMap> sortedMap, int maxCount) { List artifactList = new ArrayList<>(); for (List mapArtifactList : sortedMap.values()) { From 024fb9325162380a1d4043895219bc389ab2a7d5 Mon Sep 17 00:00:00 2001 From: Kelly Kelly Date: Fri, 28 Aug 2020 10:12:06 -0400 Subject: [PATCH 6/6] Fixed codacy issue --- .../datamodel/DataSourceInfoUtilities.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java index 89e3c11b40..1346708843 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceInfoUtilities.java @@ -23,7 +23,6 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; import java.util.logging.Level; @@ -197,7 +196,7 @@ final class DataSourceInfoUtilities { */ static List getArtifacts(SleuthkitCase skCase, BlackboardArtifact.Type artifactType, DataSource dataSource, BlackboardAttribute.Type attributeType, SortOrder sortOrder, int maxCount) throws TskCoreException { if (maxCount < 0) { - throw new IllegalArgumentException("Invalid maxCount passed to getArtifacts, value must be at greater 0"); + throw new IllegalArgumentException("Invalid maxCount passed to getArtifacts, value must be equal to or greater than 0"); } return createListFromMap(getArtifactMap(skCase, artifactType, dataSource, attributeType, sortOrder), maxCount); @@ -259,15 +258,15 @@ final class DataSourceInfoUtilities { List artifactList = new ArrayList<>(); for (List mapArtifactList : sortedMap.values()) { - - if (maxCount == artifactList.size()) { - break; - } - + if (maxCount == 0 || (artifactList.size() + mapArtifactList.size()) <= maxCount) { artifactList.addAll(mapArtifactList); continue; } + + if (maxCount == artifactList.size()) { + break; + } for (BlackboardArtifact artifact : mapArtifactList) { if (artifactList.size() < maxCount) {