1 /*
2 *
3 * Autopsy Forensic Browser
4 *
5 * Copyright 2012-2014 Basis Technology Corp.
6 *
7 * Copyright 2012 42six Solutions.
8 * Contact: aebadirad <at> 42six <dot> com
9 * Project Contact/Architect: carrier <at> sleuthkit <dot> org
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23 package org.sleuthkit.autopsy.recentactivity;
24
25 import java.sql.ResultSet;
26 import java.sql.ResultSetMetaData;
27 import java.sql.SQLException;
28 import java.util.*;
29 import java.util.logging.Level;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
40
41 abstract class Extract {
42
43 protected Case currentCase = Case.getCurrentCase();
44 protected SleuthkitCase tskCase = currentCase.getSleuthkitCase();
45 private final Logger logger = Logger.getLogger(this.getClass().getName());
46 private final ArrayList<String> errorMessages = new ArrayList<>();
47 String moduleName = "";
48 boolean dataFound = false;
49
50 Extract() {
51 }
52
53 void init() throws IngestModuleException {
54 }
55
56 abstract void process(
Content dataSource, IngestJobContext context);
57
58 void complete() {
59 }
60
66 List<String> getErrorMessages() {
67 return errorMessages;
68 }
69
75 protected void addErrorMessage(String message) {
76 errorMessages.add(message);
77 }
78
92 try {
95 // index the artifact for keyword search
96 this.indexArtifact(bbart);
97 return bbart;
99 logger.log(Level.SEVERE, "Error while trying to add an artifact", ex); //NON-NLS
100 }
101 return null;
102 }
103
109 @Messages({"Extract.indexError.message=Failed to index artifact for keyword search."})
111 Blackboard blackboard = Case.getCurrentCase().getServices().getBlackboard();
112 try {
113 // index the artifact for keyword search
114 blackboard.indexArtifact(bbart);
115 } catch (Blackboard.BlackboardException ex) {
116 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + bbart.
getDisplayName(), ex);
//NON-NLS
117 MessageNotifyUtil.Notify.error(Bundle.Extract_indexError_message(), bbart.
getDisplayName());
118 }
119 }
120
132 protected List<HashMap<String, Object>> dbConnect(String path, String query) {
133 ResultSet temprs;
134 List<HashMap<String, Object>> list;
135 String connectionString = "jdbc:sqlite:" + path; //NON-NLS
136 try {
137 SQLiteDBConnect tempdbconnect = new SQLiteDBConnect("org.sqlite.JDBC", connectionString); //NON-NLS
138 temprs = tempdbconnect.executeQry(query);
139 list = this.resultSetToArrayList(temprs);
140 tempdbconnect.closeConnection();
141 } catch (SQLException ex) {
142 logger.log(Level.SEVERE, "Error while trying to read into a sqlite db." + connectionString, ex); //NON-NLS
143 errorMessages.add(NbBundle.getMessage(this.getClass(), "Extract.dbConn.errMsg.failedToQueryDb", getName()));
144 return Collections.<HashMap<String, Object>>emptyList();
145 }
146 return list;
147 }
148
156 private List<HashMap<String, Object>> resultSetToArrayList(ResultSet rs) throws SQLException {
157 ResultSetMetaData md = rs.getMetaData();
158 int columns = md.getColumnCount();
159 List<HashMap<String, Object>> list = new ArrayList<>(50);
160 while (rs.next()) {
161 HashMap<String, Object> row = new HashMap<>(columns);
162 for (int i = 1; i <= columns; ++i) {
163 if (rs.getObject(i) == null) {
164 row.put(md.getColumnName(i), "");
165 } else {
166 row.put(md.getColumnName(i), rs.getObject(i));
167 }
168 }
169 list.add(row);
170 }
171
172 return list;
173 }
174
180 protected String getName() {
181 return moduleName;
182 }
183
184 public boolean foundData() {
185 return dataFound;
186 }
187 }
void addAttributes(Collection< BlackboardAttribute > attributes)
BlackboardArtifact newArtifact(int artifactTypeID)