19 package org.sleuthkit.autopsy.externalresults;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.logging.Level;
29 import org.openide.util.NbBundle;
54 private final List<ErrorInfo>
errors =
new ArrayList<>();
58 standardArtifactTypeIds.add(artifactType.getTypeID());
76 List<ErrorInfo> importErrors =
new ArrayList<>(this.
errors);
84 String localPath = fileData.getLocalPath();
86 File localFile =
new File(localPath);
87 if (localFile.exists()) {
89 if (!relativePath.isEmpty()) {
90 String parentFilePath = fileData.getParentPath();
92 if (parentFile != null) {
99 String errorMessage = NbBundle.getMessage(this.getClass(),
100 "ExternalResultsImporter.importDerivedFiles.errMsg1.text",
101 localPath, parentFilePath);
107 String errorMessage = NbBundle.getMessage(this.getClass(),
108 "ExternalResultsImporter.importDerivedFiles.errMsg2.text",
114 String errorMessage = NbBundle.getMessage(this.getClass(),
115 "ExternalResultsImporter.importDerivedFiles.errMsg3.text",
129 if (artifactTypeId == -1) {
130 artifactTypeId = caseDb.
addArtifactType(artifactData.getType(), artifactData.getType());
133 if (sourceFile != null) {
137 Collection<BlackboardAttribute> attributes =
new ArrayList<>();
139 int attributeTypeId = caseDb.
getAttrTypeID(attributeData.getType());
140 if (attributeTypeId == -1) {
141 attributeTypeId = caseDb.
addAttrType(attributeData.getType(), attributeData.getType());
143 switch (attributeData.getValueType()) {
145 attributes.add(
new BlackboardAttribute(attributeTypeId, attributeData.getSourceModule(), attributeData.getValue()));
148 int intValue = Integer.parseInt(attributeData.getValue());
149 attributes.add(
new BlackboardAttribute(attributeTypeId, attributeData.getSourceModule(), intValue));
152 long longValue = Long.parseLong(attributeData.getValue());
153 attributes.add(
new BlackboardAttribute(attributeTypeId, attributeData.getSourceModule(), longValue));
156 double doubleValue = Double.parseDouble(attributeData.getValue());
157 attributes.add(
new BlackboardAttribute(attributeTypeId, attributeData.getSourceModule(), doubleValue));
160 String errorMessage = NbBundle.getMessage(this.getClass(),
161 "ExternalResultsImporter.importArtifacts.caseErrMsg1.text",
162 attributeData.getType(), attributeData.getValue(),
163 artifactData.getType(), artifactData.getSourceFilePath(),
164 attributeData.getValueType());
172 if (standardArtifactTypeIds.contains(artifactTypeId)) {
176 String errorMessage = NbBundle.getMessage(this.getClass(),
177 "ExternalResultsImporter.importArtifacts.errMsg1.text",
178 artifactData.getType(), artifactData.getSourceFilePath());
183 String errorMessage = NbBundle.getMessage(this.getClass(),
184 "ExternalResultsImporter.importArtifacts.errMsg2.text",
185 artifactData.getType(), artifactData.getSourceFilePath());
194 String reportPath = report.getLocalPath();
196 File reportFile =
new File(reportPath);
197 if (reportFile.exists()) {
200 String errorMessage = NbBundle.getMessage(this.getClass(),
"ExternalResultsImporter.importReports.errMsg1.text", reportPath);
205 String errorMessage = NbBundle.getMessage(this.getClass(),
"ExternalResultsImporter.importReports.errMsg2.text", reportPath);
215 String fileName = filePath;
216 String parentPath =
"";
217 int charPos = filePath.lastIndexOf(
"/");
219 fileName = filePath.substring(charPos + 1);
220 parentPath = filePath.substring(0, charPos + 1);
223 String condition =
"name='" + fileName +
"' AND parent_path='" + parentPath +
"'";
225 if (!files.isEmpty()) {
227 if (files.size() > 1) {
228 String errorMessage = NbBundle.getMessage(this.getClass(),
"ExternalResultsImporter.findFileInCaseDatabase.errMsg1.text", filePath);
236 String relativePath =
"";
238 Path path = Paths.get(localPath);
239 if (path.isAbsolute()) {
240 Path pathBase = Paths.get(caseDirectoryPath);
242 Path pathRelative = pathBase.relativize(path);
243 relativePath = pathRelative.toString();
244 }
catch (IllegalArgumentException ex) {
245 String errorMessage = NbBundle.getMessage(this.getClass(),
246 "ExternalResultsImporter.getPathRelativeToCaseFolder.errMsg1.text",
247 localPath, caseDirectoryPath);
251 String errorMessage = NbBundle.getMessage(this.getClass(),
252 "ExternalResultsImporter.getPathRelativeToCaseFolder.errMsg2.text",
253 localPath, caseDirectoryPath);
270 this.errors.add(
new ErrorInfo(this.getClass().getName(), errorMessage));
275 this.errors.add(
new ErrorInfo(this.getClass().getName(), errorMessage));
void importArtifacts(ExternalResults results)
BlackboardArtifact newArtifact(int artifactTypeID)
int getArtifactTypeID(String artifactTypeName)
static final Logger logger
FileManager getFileManager()
void addAttributes(Collection< BlackboardAttribute > attributes)
static ARTIFACT_TYPE fromID(int ID)
int addArtifactType(String artifactTypeName, String displayName)
String getCaseDirectory()
void importDerivedFiles(ExternalResults results)
void addReport(String localPath, String srcModuleName, String reportName)
static final HashSet< Integer > standardArtifactTypeIds
synchronized DerivedFile addDerivedFile(String fileName, String localPath, long size, long ctime, long crtime, long atime, long mtime, boolean isFile, AbstractFile parentFile, String rederiveDetails, String toolName, String toolVersion, String otherDetails)
AbstractFile findFileInCaseDatabase(String filePath)
int getAttrTypeID(String attrTypeName)
int addAttrType(String attrTypeString, String displayName)
void recordError(String errorMessage, Exception ex)
void fireModuleDataEvent(ModuleDataEvent moduleDataEvent)
SleuthkitCase getSleuthkitCase()
void recordError(String errorMessage)
List< ErrorInfo > importResults(ExternalResults results)
void fireModuleContentEvent(ModuleContentEvent moduleContentEvent)
List< AbstractFile > findAllFilesWhere(String sqlWhereClause)
static Case getCurrentCase()
void importReports(ExternalResults results)
String getPathRelativeToCaseFolder(String localPath)
final List< ErrorInfo > errors
static Logger getLogger(String name)
static synchronized IngestServices getInstance()