Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AccountDeviceInstanceKey.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.communications;
20 
21 import java.util.Objects;
22 import java.util.logging.Level;
26 import org.sleuthkit.datamodel.AccountDeviceInstance;
27 import org.sleuthkit.datamodel.CommunicationsFilter;
28 import org.sleuthkit.datamodel.DataSource;
29 import org.sleuthkit.datamodel.SleuthkitCase;
30 import org.sleuthkit.datamodel.TskCoreException;
31 
38 final class AccountDeviceInstanceKey {
39 
40  private static final Logger logger = Logger.getLogger(AccountDeviceInstanceKey.class.getName());
41 
42  private final AccountDeviceInstance accountDeviceInstance;
43  private final CommunicationsFilter filter;
44  private final long messageCount;
45  private final String dataSourceName;
46 
47  AccountDeviceInstanceKey(AccountDeviceInstance accountDeviceInstance, CommunicationsFilter filter, long msgCount) {
48  this.accountDeviceInstance = accountDeviceInstance;
49  this.filter = filter;
50  this.messageCount = msgCount;
51  this.dataSourceName = getDataSourceName(accountDeviceInstance);
52  }
53 
54  AccountDeviceInstance getAccountDeviceInstance() {
55  return accountDeviceInstance;
56  }
57 
58  CommunicationsFilter getCommunicationsFilter() {
59  return filter;
60  }
61 
62  long getMessageCount() {
63  return messageCount;
64  }
65 
66  String getDataSourceName() {
67  return dataSourceName;
68  }
69 
70  @Override
71  public String toString() {
72  return accountDeviceInstance.getAccount().getTypeSpecificID();
73  }
74 
75  @Override
76  public int hashCode() {
77  int hash = 7;
78  hash = 37 * hash + Objects.hashCode(this.accountDeviceInstance);
79  hash = 37 * hash + (int) (this.messageCount ^ (this.messageCount >>> 32));
80  hash = 37 * hash + Objects.hashCode(this.dataSourceName);
81  return hash;
82  }
83 
84  @Override
85  public boolean equals(Object obj) {
86  if (this == obj) {
87  return true;
88  }
89  if (obj == null) {
90  return false;
91  }
92  if (getClass() != obj.getClass()) {
93  return false;
94  }
95  final AccountDeviceInstanceKey other = (AccountDeviceInstanceKey) obj;
96  if (this.getMessageCount() != other.getMessageCount()) {
97  return false;
98  }
99  if (!Objects.equals(this.getDataSourceName(), other.getDataSourceName())) {
100  return false;
101  }
102  return Objects.equals(this.getAccountDeviceInstance(), other.getAccountDeviceInstance());
103  }
104 
105  private static String getDataSourceName(AccountDeviceInstance accountDeviceInstance) {
106  try {
107  SleuthkitCase db = Case.getCurrentCaseThrows().getSleuthkitCase();
108  for (DataSource dataSource : db.getDataSources()) {
109  if (dataSource.getDeviceId().equals(accountDeviceInstance.getDeviceId())) {
110  return db.getContentById(dataSource.getId()).getName();
111  }
112  }
113  } catch (NoCurrentCaseException | TskCoreException ex) {
114  logger.log(Level.SEVERE, "Error getting datasource name, falling back on device ID.", ex);
115  }
116  return accountDeviceInstance.getDeviceId();
117  }
118 
119 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.