Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
BlackboardArtifactDateComparator.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 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 obt ain 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.relationships;
20 
21 import java.util.Comparator;
22 import java.util.logging.Level;
24 import org.sleuthkit.datamodel.BlackboardArtifact;
25 import org.sleuthkit.datamodel.BlackboardAttribute;
26 import org.sleuthkit.datamodel.TskCoreException;
27 
33 class BlackboardArtifactDateComparator implements Comparator<BlackboardArtifact> {
34  static final int ACCENDING = 1;
35  static final int DECENDING = -1;
36 
37  private static final Logger logger = Logger.getLogger(BlackboardArtifactDateComparator.class.getName());
38 
39  private final int direction;
40 
41  BlackboardArtifactDateComparator(int direction) {
42  this.direction = direction;
43  }
44 
45  @Override
46  public int compare(BlackboardArtifact bba1, BlackboardArtifact bba2) {
47 
48  BlackboardAttribute attribute1 = getTimeAttributeForArtifact(bba1);
49  BlackboardAttribute attribute2 = getTimeAttributeForArtifact(bba2);
50  // Inializing to Long.MAX_VALUE so that if a BlackboardArtifact of
51  // any unexpected type is passed in, it will bubble to the top of
52  // the list.
53  long dateTime1 = Long.MAX_VALUE;
54  long dateTime2 = Long.MAX_VALUE;
55 
56  if (attribute1 != null) {
57  dateTime1 = attribute1.getValueLong();
58  }
59 
60  if (attribute2 != null) {
61  dateTime2 = attribute2.getValueLong();
62  }
63 
64  return Long.compare(dateTime1, dateTime2) * direction;
65  }
66 
67  private BlackboardAttribute getTimeAttributeForArtifact(BlackboardArtifact artifact) {
68  if(artifact == null) {
69  return null;
70  }
71 
72  BlackboardAttribute attribute = null;
73 
74  BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
75  if (fromID != null) {
76  try {
77  switch (fromID) {
78  case TSK_EMAIL_MSG:
79  attribute = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT));
80  break;
81  case TSK_MESSAGE:
82  attribute = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME));
83  break;
84  case TSK_CALLLOG:
85  attribute = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_START));
86  break;
87  default:
88  attribute = null;
89  break;
90  }
91  } catch (TskCoreException ex) {
92  logger.log(Level.WARNING, String.format("Unable to compare attributes for artifact %d", artifact.getArtifactID()), ex);
93  }
94  }
95 
96  return attribute;
97  }
98 }

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.