From 0c8c9a3bd568d05204a5e6e7580ccd650f949a70 Mon Sep 17 00:00:00 2001 From: Raman Date: Thu, 7 Mar 2019 06:25:34 -0500 Subject: [PATCH 1/2] 1183: Mark group as 'unseen' for all examiners --- .../imagegallery/actions/NextUnseenGroup.java | 2 +- .../imagegallery/datamodel/DrawableDB.java | 47 ++++++++++++++----- .../datamodel/grouping/GroupManager.java | 39 +++++++++++---- 3 files changed, 67 insertions(+), 21 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java index c11005045d..d8f6178eb4 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java @@ -88,7 +88,7 @@ public class NextUnseenGroup extends Action { if (group.isPresent()) { // NOTE: We need to wait for current group to be marked as seen because the 'advance' // method grabs the top of the unseen list - groupManager.markGroupSeen(group.get(), true) + groupManager.markGroupSeen(group.get()) .addListener(this::advanceToNextUnseenGroup, MoreExecutors.newDirectExecutorService()); return; } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index 427c729a8b..7400b12818 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -1141,23 +1141,22 @@ public final class DrawableDB { } /** - * Record in the DB that the group with the given key has the given seen - * state for the given examiner id. + * Record in the DB that the group with the given key is seen + * by given examiner id. * - * @param groupKey - * @param seen - * @param examinerID + * @param groupKey key identifying the group. + * @param examinerID examiner id. * * @throws TskCoreException */ - public void markGroupSeen(GroupKey groupKey, boolean seen, long examinerID) throws TskCoreException { + public void markGroupSeen(GroupKey groupKey, long examinerID) throws TskCoreException { /* * Check the groupSeenCache to see if the seen status for this group was set recently. - * If recently set to the same value, there's no need to update it + * If recently set to seen, there's no need to update it */ Boolean cachedValue = groupSeenCache.getIfPresent(groupKey); - if (cachedValue != null && cachedValue == seen) { + if (cachedValue != null && cachedValue == true) { return; } @@ -1168,17 +1167,41 @@ public final class DrawableDB { SleuthkitCase.escapeSingleQuotes(groupKey.getValueDisplayName()), groupKey.getAttribute() == DrawableAttribute.PATH ? groupKey.getDataSourceObjId() : 0); - String insertSQL = String.format(" (group_id, examiner_id, seen) VALUES (%s, %d, %d)", innerQuery, examinerID, seen ? 1 : 0); + String insertSQL = String.format(" (group_id, examiner_id, seen) VALUES (%s, %d, %d)", innerQuery, examinerID, 1); if (DbType.POSTGRESQL == tskCase.getDatabaseType()) { - insertSQL += String.format(" ON CONFLICT (group_id, examiner_id) DO UPDATE SET seen = %d", seen ? 1 : 0); + insertSQL += String.format(" ON CONFLICT (group_id, examiner_id) DO UPDATE SET seen = %d", 1); } tskCase.getCaseDbAccessManager().insertOrUpdate(GROUPS_SEEN_TABLENAME, insertSQL); - groupSeenCache.put(groupKey, seen); - + groupSeenCache.put(groupKey, true); } + /** + * Record in the DB that given group is unseen. + * The group is marked unseen for ALL examiners that have seen the group. + * + * @param groupKey key identifying the group. + * + * @throws TskCoreException + */ + public void markGroupUnseen(GroupKey groupKey) throws TskCoreException { + + /* + * Check the groupSeenCache to see if the seen status for this group was set recently. + * If recently set to unseen, there's no need to update it + */ + Boolean cachedValue = groupSeenCache.getIfPresent(groupKey); + if (cachedValue != null && cachedValue == false) { + return; + } + + String updateSQL = String.format(" SET seen = 0 WHERE group_id in ( " + getGroupIdQuery(groupKey) + ")" ); + tskCase.getCaseDbAccessManager().update(GROUPS_SEEN_TABLENAME, updateSQL); + + groupSeenCache.put(groupKey, false); + } + /** * Sets the isAnalysed flag in the groups table for the given group to true. * 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 15fdc291e9..508da04d05 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -264,24 +264,23 @@ public class GroupManager { } /** - * 'Save' the given group as seen in the drawable db. + * Marks the given group as 'seen' by the current examiner, in drawable db. * * @param group The DrawableGroup to mark as seen. - * @param seen The seen state to set for the given group. * * @return A ListenableFuture that encapsulates saving the seen state to the * DB. * * */ - public ListenableFuture markGroupSeen(DrawableGroup group, boolean seen) { + public ListenableFuture markGroupSeen(DrawableGroup group) { return exec.submit(() -> { try { Examiner examiner = controller.getSleuthKitCase().getCurrentExaminer(); - getDrawableDB().markGroupSeen(group.getGroupKey(), seen, examiner.getId()); + getDrawableDB().markGroupSeen(group.getGroupKey(), examiner.getId()); // only update and reshuffle if its new results - if (group.isSeen() != seen) { - group.setSeen(seen); + if (group.isSeen() != true) { + group.setSeen(true); updateUnSeenGroups(group); } } catch (TskCoreException ex) { @@ -290,6 +289,30 @@ public class GroupManager { }); } + /** + * Marks the given group as unseen in the drawable db. + * + * @param group The DrawableGroup. + * + * @return A ListenableFuture that encapsulates saving the seen state to the + * DB. + */ + public ListenableFuture markGroupUnseen(DrawableGroup group) { + return exec.submit(() -> { + try { + + getDrawableDB().markGroupUnseen(group.getGroupKey()); + // only update and reshuffle if its new results + if (group.isSeen() != false) { + group.setSeen(false); + updateUnSeenGroups(group); + } + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, String.format("Error setting group: %s to unseen.", group.getGroupKey().getValue().toString()), ex); //NON-NLS + } + }); + } + /** * Update unseenGroups list accordingly based on the current status of * 'group'. Removes it if it is seen or adds it if it is unseen. @@ -325,7 +348,7 @@ public class GroupManager { // If we're grouping by category, we don't want to remove empty groups. if (group.getFileIDs().isEmpty()) { - markGroupSeen(group, true); + markGroupSeen(group); if (groupKey.getAttribute() != DrawableAttribute.CATEGORY) { if (analyzedGroups.contains(group)) { analyzedGroups.remove(group); @@ -570,7 +593,7 @@ public class GroupManager { // reset the seen status for the group (if it is currently considered analyzed) if (group != null) { - markGroupSeen(group, false); + markGroupUnseen(group); } } From bfe607b02909db4abe42238f3ca749145c4f7c25 Mon Sep 17 00:00:00 2001 From: Raman Date: Thu, 7 Mar 2019 14:23:16 -0500 Subject: [PATCH 2/2] Address review comments. --- .../autopsy/imagegallery/datamodel/DrawableDB.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index 7400b12818..d25e8e8659 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -1161,15 +1161,15 @@ public final class DrawableDB { } // query to find the group id from attribute/value - String innerQuery = String.format("( SELECT group_id FROM " + GROUPS_TABLENAME - + " WHERE attribute = \'%s\' AND value = \'%s\' and data_source_obj_id = %d )", + String innerQuery = String.format("( SELECT group_id FROM " + GROUPS_TABLENAME //NON-NLS + + " WHERE attribute = \'%s\' AND value = \'%s\' and data_source_obj_id = %d )", //NON-NLS SleuthkitCase.escapeSingleQuotes(groupKey.getAttribute().attrName.toString()), SleuthkitCase.escapeSingleQuotes(groupKey.getValueDisplayName()), groupKey.getAttribute() == DrawableAttribute.PATH ? groupKey.getDataSourceObjId() : 0); - String insertSQL = String.format(" (group_id, examiner_id, seen) VALUES (%s, %d, %d)", innerQuery, examinerID, 1); + String insertSQL = String.format(" (group_id, examiner_id, seen) VALUES (%s, %d, %d)", innerQuery, examinerID, 1); //NON-NLS if (DbType.POSTGRESQL == tskCase.getDatabaseType()) { - insertSQL += String.format(" ON CONFLICT (group_id, examiner_id) DO UPDATE SET seen = %d", 1); + insertSQL += String.format(" ON CONFLICT (group_id, examiner_id) DO UPDATE SET seen = %d", 1); //NON-NLS } tskCase.getCaseDbAccessManager().insertOrUpdate(GROUPS_SEEN_TABLENAME, insertSQL); @@ -1196,7 +1196,7 @@ public final class DrawableDB { return; } - String updateSQL = String.format(" SET seen = 0 WHERE group_id in ( " + getGroupIdQuery(groupKey) + ")" ); + String updateSQL = String.format(" SET seen = 0 WHERE group_id in ( " + getGroupIdQuery(groupKey) + ")" ); //NON-NLS tskCase.getCaseDbAccessManager().update(GROUPS_SEEN_TABLENAME, updateSQL); groupSeenCache.put(groupKey, false);