diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index d4c83bd273..c23afe43d8 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -35,6 +35,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import static java.util.Objects.isNull; +import static java.util.Objects.nonNull; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.Lock; @@ -722,10 +723,10 @@ public final class DrawableDB { * clause * * @param sqlWhereClause a SQL where clause appropriate for the desired - * files (do not begin the WHERE clause with the word WHERE!) + * files (do not begin the WHERE clause with the word + * WHERE!) * - * @return a list of file ids each of which satisfy the given WHERE - * clause + * @return a list of file ids each of which satisfy the given WHERE clause * * @throws TskCoreException */ @@ -766,7 +767,8 @@ public final class DrawableDB { * Return the number of files matching the given clause. * * @param sqlWhereClause a SQL where clause appropriate for the desired - * files (do not begin the WHERE clause with the word WHERE!) + * files (do not begin the WHERE clause with the word + * WHERE!) * * @return Number of files matching the given where clause * @@ -1002,9 +1004,11 @@ public final class DrawableDB { try { PreparedStatement statement = null; - /* I hate this! not flexible/generic/maintainable we could have the + /* + * I hate this! not flexible/generic/maintainable we could have the * DrawableAttribute provide/create/configure the correct statement - * but they shouldn't be coupled like that -jm */ + * but they shouldn't be coupled like that -jm + */ switch (key.getAttribute().attrName) { case CATEGORY: return getFilesWithCategory((Category) key.getValue()); @@ -1202,12 +1206,14 @@ public final class DrawableDB { */ public long getCategoryCount(Category cat) { try { - return tskCase.getContentTagsByTagName(controller.getTagsManager().getTagName(cat)).stream() - .map(ContentTag::getContent) - .map(Content::getId) - .filter(this::isInDB) - .count(); - + TagName tagName = controller.getTagsManager().getTagName(cat); + if (nonNull(tagName)) { + return tskCase.getContentTagsByTagName(tagName).stream() + .map(ContentTag::getContent) + .map(Content::getId) + .filter(this::isInDB) + .count(); + } } catch (IllegalStateException ex) { LOGGER.log(Level.WARNING, "Case closed while getting files"); } catch (TskCoreException ex1) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index e1c7f802c3..41cd5d63a3 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; +import static java.util.Objects.nonNull; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ExecutorService; @@ -102,14 +103,18 @@ public class GroupManager { private final ObservableList analyzedGroups = FXCollections.observableArrayList(); private final ObservableList unmodifiableAnalyzedGroups = FXCollections.unmodifiableObservableList(analyzedGroups); - /** list of unseen groups */ + /** + * list of unseen groups + */ @ThreadConfined(type = ThreadType.JFX) private final ObservableList unSeenGroups = FXCollections.observableArrayList(); private final ObservableList unmodifiableUnSeenGroups = FXCollections.unmodifiableObservableList(unSeenGroups); private ReGroupTask groupByTask; - /* --- current grouping/sorting attributes --- */ + /* + * --- current grouping/sorting attributes --- + */ private volatile GroupSortBy sortBy = GroupSortBy.NONE; private volatile DrawableAttribute groupBy = DrawableAttribute.PATH; @@ -172,15 +177,17 @@ public class GroupManager { * using the current groupBy set for this manager, find groupkeys for all * the groups the given file is a part of * - * - * * @return a a set of {@link GroupKey}s representing the group(s) the given * file is a part of */ synchronized public Set> getGroupKeysForFileID(Long fileID) { try { - DrawableFile file = db.getFileFromID(fileID); - return getGroupKeysForFile(file); + if (nonNull(db)) { + DrawableFile file = db.getFileFromID(fileID); + return getGroupKeysForFile(file); + } else { + Logger.getLogger(GroupManager.class.getName()).log(Level.WARNING, "Failed to load file with id: {0} from database. There is no database assigned.", fileID); + } } catch (TskCoreException ex) { Logger.getLogger(GroupManager.class.getName()).log(Level.SEVERE, "failed to load file with id: " + fileID + " from database", ex); } @@ -191,8 +198,7 @@ public class GroupManager { * @param groupKey * * @return return the DrawableGroup (if it exists) for the given GroupKey, - * or - * null if no group exists for that key. + * or null if no group exists for that key. */ @Nullable public DrawableGroup getGroupForKey(@Nonnull GroupKey groupKey) { @@ -239,8 +245,8 @@ public class GroupManager { } /** - * 'mark' the given group as seen. This removes it from the queue of - * groups to review, and is persisted in the drawable db. + * 'mark' the given group as seen. This removes it from the queue of groups + * to review, and is persisted in the drawable db. * * @param group the {@link DrawableGroup} to mark as seen */ @@ -555,10 +561,9 @@ public class GroupManager { @Subscribe synchronized public void handleFileUpdate(Collection updatedFileIDs) { /** - * TODO: is there a way to optimize this to avoid quering to db - * so much. the problem is that as a new files are analyzed they - * might be in new groups( if we are grouping by say make or - * model) -jm + * TODO: is there a way to optimize this to avoid quering to db so much. + * the problem is that as a new files are analyzed they might be in new + * groups( if we are grouping by say make or model) -jm */ for (long fileId : updatedFileIDs) { @@ -579,18 +584,22 @@ public class GroupManager { private DrawableGroup popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { if (Objects.nonNull(task) && (task.isCancelled())) { - /* if this method call is part of a ReGroupTask and that task is + /* + * if this method call is part of a ReGroupTask and that task is * cancelled, no-op * * this allows us to stop if a regroup task has been cancelled (e.g. - * the user picked a different group by attribute, while the - * current task was still running) */ + * the user picked a different group by attribute, while the current + * task was still running) + */ } else { // no task or un-cancelled task if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { - /* for attributes other than path we can't be sure a group is - * fully analyzed because we don't know all the files that - * will be a part of that group,. just show them no matter what. */ + /* + * for attributes other than path we can't be sure a group is + * fully analyzed because we don't know all the files that will + * be a part of that group,. just show them no matter what. + */ try { Set fileIDs = getFileIDsInGroup(groupKey);