diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/Artifacts.java b/Core/src/org/sleuthkit/autopsy/datamodel/Artifacts.java index 3af9d47f491e5ab9f4cf35b1aff3034e09ad2a73..2583501d068356a053fa02ad2d6ac31d9a0784ec 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/Artifacts.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/Artifacts.java @@ -248,7 +248,7 @@ private static TypeNodeKey getTypeKey(BlackboardArtifact.Type type, SleuthkitCas return new TypeNodeKey(emailNode, TSK_EMAIL_MSG); } else if (TSK_ACCOUNT.getTypeID() == typeId) { - Accounts.AccountsRootNode accountsNode = new Accounts(skCase, dsObjId).new AccountsRootNode(); + Accounts.AccountsRootNode accountsNode = new Accounts(dsObjId).new AccountsRootNode(); return new TypeNodeKey(accountsNode, TSK_ACCOUNT); } else if (TSK_KEYWORD_HIT.getTypeID() == typeId) { diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/accounts/Accounts.java b/Core/src/org/sleuthkit/autopsy/datamodel/accounts/Accounts.java index 7ed1d3b29030bbeccbc6ccc3f1591e383bebdc88..ff10dcc9cb5b236ed9a2aa8959fa8702220956d1 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/accounts/Accounts.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/accounts/Accounts.java @@ -103,7 +103,6 @@ final public class Accounts implements AutopsyVisitableItem { @NbBundle.Messages("AccountsRootNode.name=Accounts") //used for the viewArtifact navigation final public static String NAME = Bundle.AccountsRootNode_name(); - private SleuthkitCase skCase; private final long filteringDSObjId; // 0 if not filtering/grouping by data source private final EventBus reviewStatusBus = new EventBus("ReviewStatusBus"); @@ -124,8 +123,8 @@ final public class Accounts implements AutopsyVisitableItem { * * @param skCase The SleuthkitCase object to use for db queries. */ - public Accounts(SleuthkitCase skCase) { - this(skCase, 0); + public Accounts() { + this(0); } /** @@ -134,8 +133,7 @@ public Accounts(SleuthkitCase skCase) { * @param skCase The SleuthkitCase object to use for db queries. * @param objId Object id of the data source */ - public Accounts(SleuthkitCase skCase, long objId) { - this.skCase = skCase; + public Accounts(long objId) { this.filteringDSObjId = objId; this.rejectActionInstance = new RejectAccounts(); @@ -281,14 +279,14 @@ protected long fetchChildCount(SleuthkitCase skCase) throws TskCoreException { + " GROUP BY blackboard_artifacts.artifact_id\n" + ") res\n"; - try (SleuthkitCase.CaseDbQuery executeQuery = skCase.executeQuery(accountTypesInUseQuery); + try (SleuthkitCase.CaseDbQuery executeQuery = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(accountTypesInUseQuery); ResultSet resultSet = executeQuery.getResultSet()) { if (resultSet.next()) { return resultSet.getLong("count"); } - } catch (TskCoreException | SQLException ex) { + } catch (TskCoreException | SQLException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error querying for count of all account types", ex); } @@ -349,7 +347,7 @@ private void update() { + ") res\n" + "GROUP BY res.account_type"; - try (SleuthkitCase.CaseDbQuery executeQuery = skCase.executeQuery(accountTypesInUseQuery); + try (SleuthkitCase.CaseDbQuery executeQuery = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(accountTypesInUseQuery); ResultSet resultSet = executeQuery.getResultSet()) { counts.clear(); @@ -358,7 +356,7 @@ private void update() { Long count = resultSet.getLong("count"); counts.put(accountType, count); } - } catch (TskCoreException | SQLException ex) { + } catch (TskCoreException | SQLException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error querying for account_types", ex); } } @@ -416,12 +414,6 @@ public void propertyChange(PropertyChangeEvent evt) { } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } - } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { - // case was closed. Remove listeners so that we don't get called with a stale case handle - if (evt.getNewValue() == null) { - removeNotify(); - skCase = null; - } } } }; @@ -467,7 +459,7 @@ protected Node[] createNodesForKey(String accountTypeName) { } else { try { - Account.Type accountType = skCase.getCommunicationsManager().getAccountType(accountTypeName); + Account.Type accountType = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager().getAccountType(accountTypeName); if (accountType != null) { return getNodeArr(new DefaultAccountTypeNode(accountType)); } else { @@ -476,7 +468,7 @@ protected Node[] createNodesForKey(String accountTypeName) { + "Account type names must match an entry in the display_name column of the account_types table.\n" + "Accounts should be created using the CommunicationManager API."); } - } catch (TskCoreException ex) { + } catch (TskCoreException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error getting display name for account type. ", ex); } @@ -553,12 +545,6 @@ public void propertyChange(PropertyChangeEvent evt) { } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } - } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { - // case was closed. Remove listeners so that we don't get called with a stale case handle - if (evt.getNewValue() == null) { - removeNotify(); - skCase = null; - } } } }; @@ -591,14 +577,14 @@ protected boolean createKeys(List<Long> list) { + " AND blackboard_attributes.value_text = '" + accountType.getTypeName() + "'" //NON-NLS + getFilterByDataSourceClause() + getRejectedArtifactFilterClause(); //NON-NLS - try (SleuthkitCase.CaseDbQuery results = skCase.executeQuery(query); + try (SleuthkitCase.CaseDbQuery results = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query); ResultSet rs = results.getResultSet();) { List<Long> tempList = new ArrayList<>(); while (rs.next()) { tempList.add(rs.getLong("artifact_obj_id")); // NON-NLS } list.addAll(tempList); - } catch (TskCoreException | SQLException ex) { + } catch (TskCoreException | SQLException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error querying for account artifacts.", ex); //NON-NLS } @@ -608,8 +594,8 @@ protected boolean createKeys(List<Long> list) { @Override protected Node[] createNodesForKey(Long t) { try { - return new Node[]{new BlackboardArtifactNode(skCase.getBlackboard().getDataArtifactById(t))}; - } catch (TskCoreException ex) { + return new Node[]{new BlackboardArtifactNode(Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboard().getDataArtifactById(t))}; + } catch (TskCoreException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error get black board artifact with id " + t, ex); return new Node[0]; } @@ -731,12 +717,6 @@ public void propertyChange(PropertyChangeEvent evt) { } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } - } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { - // case was closed. Remove listeners so that we don't get called with a stale case handle - if (evt.getNewValue() == null) { - removeNotify(); - skCase = null; - } } } }; @@ -888,12 +868,6 @@ public void propertyChange(PropertyChangeEvent evt) { } catch (NoCurrentCaseException notUsed) { // Case is closed, do nothing. } - } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { - // case was closed. Remove listeners so that we don't get called with a stale case handle - if (evt.getNewValue() == null) { - removeNotify(); - skCase = null; - } } } }; @@ -930,46 +904,50 @@ void handleDataAdded(ModuleDataEvent event) { @Override protected boolean createKeys(List<FileWithCCN> list) { - String query - = "SELECT blackboard_artifacts.obj_id," //NON-NLS - + " solr_attribute.value_text AS solr_document_id, "; //NON-NLS - if (skCase.getDatabaseType().equals(DbType.POSTGRESQL)) { - query += " string_agg(blackboard_artifacts.artifact_id::character varying, ',') AS artifact_IDs, " //NON-NLS - + " string_agg(blackboard_artifacts.review_status_id::character varying, ',') AS review_status_ids, "; - } else { - query += " GROUP_CONCAT(blackboard_artifacts.artifact_id) AS artifact_IDs, " //NON-NLS - + " GROUP_CONCAT(blackboard_artifacts.review_status_id) AS review_status_ids, "; - } - query += " COUNT( blackboard_artifacts.artifact_id) AS hits " //NON-NLS - + " FROM blackboard_artifacts " //NON-NLS - + " LEFT JOIN blackboard_attributes as solr_attribute ON blackboard_artifacts.artifact_id = solr_attribute.artifact_id " //NON-NLS - + " AND solr_attribute.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_SEARCH_DOCUMENT_ID.getTypeID() //NON-NLS - + " LEFT JOIN blackboard_attributes as account_type ON blackboard_artifacts.artifact_id = account_type.artifact_id " //NON-NLS - + " AND account_type.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ACCOUNT_TYPE.getTypeID() //NON-NLS - + " AND account_type.value_text = '" + Account.Type.CREDIT_CARD.getTypeName() + "'" //NON-NLS - + " WHERE blackboard_artifacts.artifact_type_id = " + BlackboardArtifact.Type.TSK_ACCOUNT.getTypeID() //NON-NLS - + getFilterByDataSourceClause() - + getRejectedArtifactFilterClause() - + " GROUP BY blackboard_artifacts.obj_id, solr_document_id " //NON-NLS - + " ORDER BY hits DESC "; //NON-NLS - try (SleuthkitCase.CaseDbQuery results = skCase.executeQuery(query); - ResultSet resultSet = results.getResultSet();) { - while (resultSet.next()) { - long file_id = resultSet.getLong("obj_id"); - AbstractFile abstractFileById = skCase.getAbstractFileById(file_id); - if(abstractFileById != null) { - list.add(new FileWithCCN( - abstractFileById, - file_id, //NON-NLS - resultSet.getString("solr_document_id"), //NON-NLS - unGroupConcat(resultSet.getString("artifact_IDs"), Long::valueOf), //NON-NLS - resultSet.getLong("hits"), //NON-NLS - new HashSet<>(unGroupConcat(resultSet.getString("review_status_ids"), reviewStatusID -> BlackboardArtifact.ReviewStatus.withID(Integer.valueOf(reviewStatusID)))))); //NON-NLS + try { + String query + = "SELECT blackboard_artifacts.obj_id," //NON-NLS + + " solr_attribute.value_text AS solr_document_id, "; //NON-NLS + if (Case.getCurrentCaseThrows().getSleuthkitCase().getDatabaseType().equals(DbType.POSTGRESQL)) { + query += " string_agg(blackboard_artifacts.artifact_id::character varying, ',') AS artifact_IDs, " //NON-NLS + + " string_agg(blackboard_artifacts.review_status_id::character varying, ',') AS review_status_ids, "; + } else { + query += " GROUP_CONCAT(blackboard_artifacts.artifact_id) AS artifact_IDs, " //NON-NLS + + " GROUP_CONCAT(blackboard_artifacts.review_status_id) AS review_status_ids, "; + } + query += " COUNT( blackboard_artifacts.artifact_id) AS hits " //NON-NLS + + " FROM blackboard_artifacts " //NON-NLS + + " LEFT JOIN blackboard_attributes as solr_attribute ON blackboard_artifacts.artifact_id = solr_attribute.artifact_id " //NON-NLS + + " AND solr_attribute.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_SEARCH_DOCUMENT_ID.getTypeID() //NON-NLS + + " LEFT JOIN blackboard_attributes as account_type ON blackboard_artifacts.artifact_id = account_type.artifact_id " //NON-NLS + + " AND account_type.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ACCOUNT_TYPE.getTypeID() //NON-NLS + + " AND account_type.value_text = '" + Account.Type.CREDIT_CARD.getTypeName() + "'" //NON-NLS + + " WHERE blackboard_artifacts.artifact_type_id = " + BlackboardArtifact.Type.TSK_ACCOUNT.getTypeID() //NON-NLS + + getFilterByDataSourceClause() + + getRejectedArtifactFilterClause() + + " GROUP BY blackboard_artifacts.obj_id, solr_document_id " //NON-NLS + + " ORDER BY hits DESC "; //NON-NLS + try (SleuthkitCase.CaseDbQuery results = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query); + ResultSet resultSet = results.getResultSet();) { + while (resultSet.next()) { + long file_id = resultSet.getLong("obj_id"); + AbstractFile abstractFileById = Case.getCurrentCaseThrows().getSleuthkitCase().getAbstractFileById(file_id); + if (abstractFileById != null) { + list.add(new FileWithCCN( + abstractFileById, + file_id, //NON-NLS + resultSet.getString("solr_document_id"), //NON-NLS + unGroupConcat(resultSet.getString("artifact_IDs"), Long::valueOf), //NON-NLS + resultSet.getLong("hits"), //NON-NLS + new HashSet<>(unGroupConcat(resultSet.getString("review_status_ids"), reviewStatusID -> BlackboardArtifact.ReviewStatus.withID(Integer.valueOf(reviewStatusID)))))); //NON-NLS + } } + } catch (TskCoreException | SQLException ex) { + LOGGER.log(Level.SEVERE, "Error querying for files with ccn hits.", ex); //NON-NLS } - } catch (TskCoreException | SQLException ex) { - LOGGER.log(Level.SEVERE, "Error querying for files with ccn hits.", ex); //NON-NLS - + + } catch (NoCurrentCaseException ex) { + LOGGER.log(Level.SEVERE, "Error getting case.", ex); } return true; } @@ -980,12 +958,12 @@ protected Node[] createNodesForKey(FileWithCCN key) { try { List<Object> lookupContents = new ArrayList<>(); for (long artId : key.artifactIDs) { - lookupContents.add(skCase.getBlackboardArtifact(artId)); + lookupContents.add(Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboardArtifact(artId)); } AbstractFile abstractFileById = key.getFile(); lookupContents.add(abstractFileById); return new Node[]{new FileWithCCNNode(key, abstractFileById, lookupContents.toArray())}; - } catch (TskCoreException ex) { + } catch (TskCoreException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error getting content for file with ccn hits.", ex); //NON-NLS return new Node[0]; } @@ -1025,16 +1003,16 @@ private void updateDisplayName() { + getFilterByDataSourceClause() + getRejectedArtifactFilterClause() + " GROUP BY blackboard_artifacts.obj_id, solr_attribute.value_text ) AS foo"; - try (SleuthkitCase.CaseDbQuery results = skCase.executeQuery(query); + try (SleuthkitCase.CaseDbQuery results = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query); ResultSet resultSet = results.getResultSet();) { while (resultSet.next()) { - if (skCase.getDatabaseType().equals(DbType.POSTGRESQL)) { + if (Case.getCurrentCaseThrows().getSleuthkitCase().getDatabaseType().equals(DbType.POSTGRESQL)) { setDisplayName(Bundle.Accounts_ByFileNode_displayName(resultSet.getLong("count"))); } else { setDisplayName(Bundle.Accounts_ByFileNode_displayName(resultSet.getLong("count(*)"))); } } - } catch (TskCoreException | SQLException ex) { + } catch (TskCoreException | SQLException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error querying for files with ccn hits.", ex); //NON-NLS } @@ -1110,11 +1088,6 @@ public void propertyChange(PropertyChangeEvent evt) { } catch (NoCurrentCaseException notUsed) { //NOPMD empy catch clause // Case is closed, do nothing. } - } else if (eventType.equals(Case.Events.CURRENT_CASE.toString()) - && (evt.getNewValue() == null)) { - // case was closed. Remove listeners so that we don't get called with a stale case handle - removeNotify(); - skCase = null; } } }; @@ -1165,7 +1138,7 @@ protected boolean createKeys(List<BinResult> list) { + getRejectedArtifactFilterClause() + " GROUP BY BIN " //NON-NLS + " ORDER BY BIN "; //NON-NLS - try (SleuthkitCase.CaseDbQuery results = skCase.executeQuery(query); + try (SleuthkitCase.CaseDbQuery results = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query); ResultSet resultSet = results.getResultSet();) { //sort all te individual bins in to the ranges while (resultSet.next()) { @@ -1187,7 +1160,7 @@ protected boolean createKeys(List<BinResult> list) { } } binRanges.asMapOfRanges().values().forEach(list::add); - } catch (TskCoreException | SQLException ex) { + } catch (TskCoreException | SQLException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error querying for BINs.", ex); //NON-NLS } @@ -1230,12 +1203,12 @@ private void updateDisplayName() { + " AND blackboard_attributes.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CARD_NUMBER.getTypeID() //NON-NLS + getFilterByDataSourceClause() + getRejectedArtifactFilterClause(); //NON-NLS - try (SleuthkitCase.CaseDbQuery results = skCase.executeQuery(query); + try (SleuthkitCase.CaseDbQuery results = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query); ResultSet resultSet = results.getResultSet();) { while (resultSet.next()) { setDisplayName(Bundle.Accounts_ByBINNode_displayName(resultSet.getLong("BINs"))); } - } catch (TskCoreException | SQLException ex) { + } catch (TskCoreException | SQLException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error querying for BINs.", ex); //NON-NLS } } @@ -1375,7 +1348,7 @@ public long getHits() { public Set<BlackboardArtifact.ReviewStatus> getStatuses() { return Collections.unmodifiableSet(statuses); } - + AbstractFile getFile() { return file; } @@ -1487,8 +1460,8 @@ public Action[] getActions(boolean context) { Action[] actions = super.getActions(context); ArrayList<Action> arrayList = new ArrayList<>(); try { - arrayList.addAll(DataModelActionsFactory.getActions(Accounts.this.skCase.getContentById(fileKey.getObjID()), false)); - } catch (TskCoreException ex) { + arrayList.addAll(DataModelActionsFactory.getActions(Case.getCurrentCaseThrows().getSleuthkitCase().getContentById(fileKey.getObjID()), false)); + } catch (TskCoreException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error gettung content by id", ex); } @@ -1533,12 +1506,12 @@ protected boolean createKeys(List<DataArtifact> list) { + getFilterByDataSourceClause() + getRejectedArtifactFilterClause() + " ORDER BY blackboard_attributes.value_text"; //NON-NLS - try (SleuthkitCase.CaseDbQuery results = skCase.executeQuery(query); + try (SleuthkitCase.CaseDbQuery results = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query); ResultSet rs = results.getResultSet();) { while (rs.next()) { - list.add(skCase.getBlackboard().getDataArtifactById(rs.getLong("artifact_obj_id"))); //NON-NLS + list.add(Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboard().getDataArtifactById(rs.getLong("artifact_obj_id"))); //NON-NLS } - } catch (TskCoreException | SQLException ex) { + } catch (TskCoreException | SQLException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error querying for account artifacts.", ex); //NON-NLS } @@ -1596,12 +1569,12 @@ private void updateDisplayName() { + " AND blackboard_attributes.value_text >= '" + bin.getBINStart() + "' AND blackboard_attributes.value_text < '" + (bin.getBINEnd() + 1) + "'" //NON-NLS + getFilterByDataSourceClause() + getRejectedArtifactFilterClause(); - try (SleuthkitCase.CaseDbQuery results = skCase.executeQuery(query); + try (SleuthkitCase.CaseDbQuery results = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query); ResultSet resultSet = results.getResultSet();) { while (resultSet.next()) { setDisplayName(getBinRangeString(bin) + " (" + resultSet.getLong("count") + ")"); //NON-NLS } - } catch (TskCoreException | SQLException ex) { + } catch (TskCoreException | SQLException | NoCurrentCaseException ex) { LOGGER.log(Level.SEVERE, "Error querying for account artifacts.", ex); //NON-NLS }