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

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.