Autopsy  4.10.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestJobInfoPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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 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;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.text.DateFormat;
23 import java.text.SimpleDateFormat;
24 import java.util.ArrayList;
25 import java.util.Date;
26 import java.util.List;
27 import java.util.logging.Level;
28 import javax.swing.JOptionPane;
29 import javax.swing.event.ListSelectionEvent;
30 import javax.swing.table.AbstractTableModel;
31 import org.openide.util.NbBundle.Messages;
34 import org.sleuthkit.datamodel.IngestJobInfo;
35 import org.sleuthkit.datamodel.IngestModuleInfo;
36 import org.sleuthkit.datamodel.SleuthkitCase;
37 import org.sleuthkit.datamodel.TskCoreException;
38 import org.sleuthkit.datamodel.DataSource;
39 
43 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
44 public final class IngestJobInfoPanel extends javax.swing.JPanel {
45 
46  private static final Logger logger = Logger.getLogger(IngestJobInfoPanel.class.getName());
47  private List<IngestJobInfo> ingestJobs;
48  private final List<IngestJobInfo> ingestJobsForSelectedDataSource = new ArrayList<>();
49  private IngestJobTableModel ingestJobTableModel = new IngestJobTableModel();
50  private IngestModuleTableModel ingestModuleTableModel = new IngestModuleTableModel(null);
51  private final DateFormat datetimeFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
52  private DataSource selectedDataSource;
53 
57  public IngestJobInfoPanel() {
58  initComponents();
59  customizeComponents();
60  }
61 
62  @Messages({"IngestJobInfoPanel.loadIngestJob.error.text=Failed to load ingest jobs.",
63  "IngestJobInfoPanel.loadIngestJob.error.title=Load Failure"})
64  private void customizeComponents() {
65  refresh();
66  this.ingestJobTable.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
67  IngestJobInfo currJob = (ingestJobTable.getSelectedRow() < 0 ? null : this.ingestJobsForSelectedDataSource.get(ingestJobTable.getSelectedRow()));
68  this.ingestModuleTableModel = new IngestModuleTableModel(currJob);
69  this.ingestModuleTable.setModel(this.ingestModuleTableModel);
70  });
71 
72  IngestManager.getInstance().addIngestJobEventListener((PropertyChangeEvent evt) -> {
73  if (evt.getPropertyName().equals(IngestManager.IngestJobEvent.STARTED.toString())
74  || evt.getPropertyName().equals(IngestManager.IngestJobEvent.CANCELLED.toString())
75  || evt.getPropertyName().equals(IngestManager.IngestJobEvent.COMPLETED.toString())) {
76  refresh();
77  }
78  });
79  }
80 
86  public void updateIngestHistoryData(DataSource selectedDataSource) {
87  this.selectedDataSource = selectedDataSource;
88  ingestJobsForSelectedDataSource.clear();
89  if (selectedDataSource != null) {
90  for (IngestJobInfo jobInfo : ingestJobs) {
91  if (selectedDataSource.getId() == jobInfo.getObjectId()) {
92  ingestJobsForSelectedDataSource.add(jobInfo);
93  }
94  }
95  }
96  this.ingestJobTableModel = new IngestJobTableModel();
97  this.ingestJobTable.setModel(ingestJobTableModel);
98  //if there were ingest jobs select the first one by default
99  if (!ingestJobsForSelectedDataSource.isEmpty()) {
100  ingestJobTable.setRowSelectionInterval(0, 0);
101  }
102  this.repaint();
103  }
104 
108  private void refresh() {
109  try {
110  SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
111  this.ingestJobs = skCase.getIngestJobs();
112  updateIngestHistoryData(selectedDataSource);
113  } catch (TskCoreException | NoCurrentCaseException ex) {
114  logger.log(Level.SEVERE, "Failed to load ingest jobs.", ex);
115  JOptionPane.showMessageDialog(this, Bundle.IngestJobInfoPanel_loadIngestJob_error_text(), Bundle.IngestJobInfoPanel_loadIngestJob_error_title(), JOptionPane.ERROR_MESSAGE);
116  }
117  }
118 
119  @Messages({"IngestJobInfoPanel.IngestJobTableModel.StartTime.header=Start Time",
120  "IngestJobInfoPanel.IngestJobTableModel.EndTime.header=End Time",
121  "IngestJobInfoPanel.IngestJobTableModel.IngestStatus.header=Ingest Status"})
122  private class IngestJobTableModel extends AbstractTableModel {
123 
124  private final List<String> columnHeaders = new ArrayList<>();
125 
127  columnHeaders.add(Bundle.IngestJobInfoPanel_IngestJobTableModel_StartTime_header());
128  columnHeaders.add(Bundle.IngestJobInfoPanel_IngestJobTableModel_EndTime_header());
129  columnHeaders.add(Bundle.IngestJobInfoPanel_IngestJobTableModel_IngestStatus_header());
130  }
131 
132  @Override
133  public int getRowCount() {
134  return ingestJobsForSelectedDataSource.size();
135  }
136 
137  @Override
138  public int getColumnCount() {
139  return columnHeaders.size();
140  }
141 
142  @Override
143  public Object getValueAt(int rowIndex, int columnIndex) {
144  IngestJobInfo currIngestJob = ingestJobsForSelectedDataSource.get(rowIndex);
145  if (columnIndex == 0) {
146  return datetimeFormat.format(currIngestJob.getStartDateTime());
147  } else if (columnIndex == 1) {
148  Date endDate = currIngestJob.getEndDateTime();
149  if (endDate.getTime() == 0) {
150  return "N/A";
151  }
152  return datetimeFormat.format(currIngestJob.getEndDateTime());
153  } else if (columnIndex == 2) {
154  return currIngestJob.getStatus().getDisplayName();
155  }
156  return null;
157  }
158 
159  @Override
160  public String getColumnName(int column) {
161  return columnHeaders.get(column);
162  }
163 
164  }
165 
166  @Messages({"IngestJobInfoPanel.IngestModuleTableModel.ModuleName.header=Module Name",
167  "IngestJobInfoPanel.IngestModuleTableModel.ModuleVersion.header=Module Version"})
168  private class IngestModuleTableModel extends AbstractTableModel {
169 
170  private final List<String> columnHeaders = new ArrayList<>();
171  private final IngestJobInfo currJob;
172 
173  IngestModuleTableModel(IngestJobInfo currJob) {
174  columnHeaders.add(Bundle.IngestJobInfoPanel_IngestModuleTableModel_ModuleName_header());
175  columnHeaders.add(Bundle.IngestJobInfoPanel_IngestModuleTableModel_ModuleVersion_header());
176  this.currJob = currJob;
177  }
178 
179  @Override
180  public int getRowCount() {
181  if (currJob == null) {
182  return 0;
183  }
184  return currJob.getIngestModuleInfo().size();
185  }
186 
187  @Override
188  public int getColumnCount() {
189  return columnHeaders.size();
190  }
191 
192  @Override
193  public Object getValueAt(int rowIndex, int columnIndex) {
194  if (currJob != null) {
195  IngestModuleInfo currIngestModule = currJob.getIngestModuleInfo().get(rowIndex);
196  if (columnIndex == 0) {
197  return currIngestModule.getDisplayName();
198  } else if (columnIndex == 1) {
199  return currIngestModule.getVersion();
200  }
201  return null;
202  }
203  return null;
204  }
205 
206  @Override
207  public String getColumnName(int column) {
208  return columnHeaders.get(column);
209  }
210 
211  }
212 
218  @SuppressWarnings("unchecked")
219  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
220  private void initComponents() {
221 
222  jScrollPane1 = new javax.swing.JScrollPane();
223  ingestJobTable = new javax.swing.JTable();
224  jLabel1 = new javax.swing.JLabel();
225  jLabel2 = new javax.swing.JLabel();
226  jScrollPane2 = new javax.swing.JScrollPane();
227  ingestModuleTable = new javax.swing.JTable();
228 
229  jScrollPane1.setBorder(null);
230 
231  ingestJobTable.setModel(ingestJobTableModel);
232  ingestJobTable.getTableHeader().setReorderingAllowed(false);
233  jScrollPane1.setViewportView(ingestJobTable);
234  ingestJobTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
235 
236  org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(IngestJobInfoPanel.class, "IngestJobInfoPanel.jLabel1.text")); // NOI18N
237 
238  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(IngestJobInfoPanel.class, "IngestJobInfoPanel.jLabel2.text")); // NOI18N
239 
240  ingestModuleTable.setModel(ingestModuleTableModel);
241  jScrollPane2.setViewportView(ingestModuleTable);
242 
243  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
244  this.setLayout(layout);
245  layout.setHorizontalGroup(
246  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
247  .addGroup(layout.createSequentialGroup()
248  .addGap(15, 15, 15)
249  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250  .addComponent(jLabel2)
251  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE))
252  .addGap(8, 8, 8)
253  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
254  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
255  .addComponent(jLabel1))
256  .addContainerGap())
257  );
258  layout.setVerticalGroup(
259  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260  .addGroup(layout.createSequentialGroup()
261  .addGap(8, 8, 8)
262  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
263  .addComponent(jLabel1)
264  .addComponent(jLabel2))
265  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
266  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
267  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
268  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
269  .addGap(10, 10, 10))
270  );
271  }// </editor-fold>//GEN-END:initComponents
272 
273 
274  // Variables declaration - do not modify//GEN-BEGIN:variables
275  private javax.swing.JTable ingestJobTable;
276  private javax.swing.JTable ingestModuleTable;
277  private javax.swing.JLabel jLabel1;
278  private javax.swing.JLabel jLabel2;
279  private javax.swing.JScrollPane jScrollPane1;
280  private javax.swing.JScrollPane jScrollPane2;
281  // End of variables declaration//GEN-END:variables
282 }
static synchronized IngestManager getInstance()
void updateIngestHistoryData(DataSource selectedDataSource)
void addIngestJobEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.