Autopsy  4.18.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
TskDataModelChangedEvent.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 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.casemodule.events;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.function.Function;
25 import java.util.logging.Level;
26 import java.util.stream.Collectors;
31 import org.sleuthkit.datamodel.SleuthkitCase;
32 import org.sleuthkit.datamodel.TskCoreException;
33 
60 public abstract class TskDataModelChangedEvent<T, U> extends AutopsyEvent {
61 
62  private static final long serialVersionUID = 1L;
63  private static final Logger logger = Logger.getLogger(TskDataModelChangedEvent.class.getName());
64  private final boolean hasOldValue;
65  private final List<Long> oldValueIds;
66  private transient List<T> oldValueObjects;
67  private final boolean hasNewValue;
68  private final List<Long> newValueIds;
69  private transient List<U> newValueObjects;
70 
91  protected TskDataModelChangedEvent(String eventName, List<T> oldValueObjects, Function<T, Long> oldValueGetIdMethod, List<U> newValueObjects, Function<U, Long> newValueGetIdMethod) {
92  super(eventName, null, null);
93  oldValueIds = new ArrayList<>();
94  this.oldValueObjects = new ArrayList<>();
95  if (oldValueObjects != null) {
96  hasOldValue = true;
97  oldValueIds.addAll(oldValueObjects.stream()
98  .map(o -> oldValueGetIdMethod.apply(o))
99  .collect(Collectors.toList()));
100  this.oldValueObjects.addAll(oldValueObjects);
101  } else {
102  hasOldValue = false;
103  }
104  newValueIds = new ArrayList<>();
105  this.newValueObjects = new ArrayList<>();
106  if (newValueObjects != null) {
107  hasNewValue = true;
108  newValueIds.addAll(newValueObjects.stream()
109  .map(o -> newValueGetIdMethod.apply(o))
110  .collect(Collectors.toList()));
111  this.newValueObjects.addAll(newValueObjects);
112  } else {
113  hasNewValue = false;
114  }
115  }
116 
123  @Override
124  public List<T> getOldValue() {
125  if (hasOldValue) {
126  if (oldValueObjects == null) {
127  try {
128  Case currentCase = Case.getCurrentCaseThrows();
129  SleuthkitCase caseDb = currentCase.getSleuthkitCase();
130  oldValueObjects = getOldValueObjects(caseDb, oldValueIds);
131  } catch (NoCurrentCaseException | TskCoreException ex) {
132  logger.log(Level.SEVERE, String.format("Error getting oldValue() TSK Data Model objects for %s event (%s)", getPropertyName(), getSourceType()), ex);
133  return Collections.emptyList();
134  }
135  }
136  return Collections.unmodifiableList(oldValueObjects);
137  } else {
138  return Collections.emptyList();
139  }
140  }
141 
148  @Override
149  public List<U> getNewValue() {
150  if (hasNewValue) {
151  if (newValueObjects == null) {
152  try {
153  Case currentCase = Case.getCurrentCaseThrows();
154  SleuthkitCase caseDb = currentCase.getSleuthkitCase();
155  newValueObjects = getNewValueObjects(caseDb, newValueIds);
156  } catch (NoCurrentCaseException | TskCoreException ex) {
157  logger.log(Level.SEVERE, String.format("Error getting newValue() TSK Data Model objects for %s event (%s)", getPropertyName(), getSourceType()), ex);
158  return Collections.emptyList();
159  }
160  }
161  return Collections.unmodifiableList(newValueObjects);
162  } else {
163  return Collections.emptyList();
164  }
165  }
166 
182  protected List<T> getOldValueObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException {
183  return Collections.emptyList();
184  }
185 
201  protected List<U> getNewValueObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException {
202  return Collections.emptyList();
203  }
204 
205 }
List< T > getOldValueObjects(SleuthkitCase caseDb, List< Long > ids)
List< U > getNewValueObjects(SleuthkitCase caseDb, List< Long > ids)
TskDataModelChangedEvent(String eventName, List< T > oldValueObjects, Function< T, Long > oldValueGetIdMethod, List< U > newValueObjects, Function< U, Long > newValueGetIdMethod)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2021 Basis Technology. Generated on: Thu Jul 8 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.