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;
 
   30 import org.openide.util.NbBundle.Messages;
 
   59     private final List<ErrorInfo> 
errors = 
new ArrayList<>();
 
   64             standardArtifactTypeIds.add(artifactType.getTypeID());
 
   85         List<ErrorInfo> importErrors = 
new ArrayList<>(this.
errors);
 
   93             String localPath = fileData.getLocalPath();
 
   95                 File localFile = 
new File(localPath);
 
   96                 if (localFile.exists()) {
 
   98                     if (!relativePath.isEmpty()) {
 
   99                         String parentFilePath = fileData.getParentPath();
 
  101                         if (parentFile != null) {
 
  109                             String errorMessage = NbBundle.getMessage(this.getClass(),
 
  110                                     "ExternalResultsImporter.importDerivedFiles.errMsg1.text",
 
  111                                     localPath, parentFilePath);
 
  117                     String errorMessage = NbBundle.getMessage(this.getClass(),
 
  118                             "ExternalResultsImporter.importDerivedFiles.errMsg2.text",
 
  124                 String errorMessage = NbBundle.getMessage(this.getClass(),
 
  125                         "ExternalResultsImporter.importDerivedFiles.errMsg3.text",
 
  133     @Messages({
"ExternalResultsImporter.indexError.message=Failed to index imported artifact for keyword search."})
 
  139                 int artifactTypeId = caseDb.
getArtifactType(artifactData.getType()).getTypeID();
 
  140                 if (artifactTypeId == -1) {
 
  144                 if (sourceFile != null) {
 
  148                     Collection<BlackboardAttribute> attributes = 
new ArrayList<>();
 
  151                         if (attributeType == null) {
 
  152                             switch (attributeData.getValueType()) {
 
  170                         switch (attributeData.getValueType()) {
 
  172                                 attributes.add(
new BlackboardAttribute(attributeType, attributeData.getSourceModule(), attributeData.getValue()));
 
  175                                 int intValue = Integer.parseInt(attributeData.getValue());
 
  176                                 attributes.add(
new BlackboardAttribute(attributeType, attributeData.getSourceModule(), intValue));
 
  179                                 long longValue = Long.parseLong(attributeData.getValue());
 
  180                                 attributes.add(
new BlackboardAttribute(attributeType, attributeData.getSourceModule(), longValue));
 
  183                                 double doubleValue = Double.parseDouble(attributeData.getValue());
 
  184                                 attributes.add(
new BlackboardAttribute(attributeType, attributeData.getSourceModule(), doubleValue));
 
  187                                 long dateTimeValue = Long.parseLong(attributeData.getValue());
 
  188                                 attributes.add(
new BlackboardAttribute(attributeType, attributeData.getSourceModule(), dateTimeValue));
 
  191                                 String errorMessage = NbBundle.getMessage(this.getClass(),
 
  192                                         "ExternalResultsImporter.importArtifacts.caseErrMsg1.text",
 
  193                                         attributeData.getType(), attributeData.getValue(),
 
  194                                         artifactData.getType(), artifactData.getSourceFilePath(),
 
  195                                         attributeData.getValueType());
 
  207                         logger.log(Level.SEVERE, 
"Unable to index blackboard artifact " + artifact.
getArtifactID(), ex); 
 
  209                             Bundle.ExternalResultsImporter_indexError_message(), artifact.
getDisplayName());
 
  212                     if (standardArtifactTypeIds.contains(artifactTypeId)) {
 
  216                     String errorMessage = NbBundle.getMessage(this.getClass(),
 
  217                             "ExternalResultsImporter.importArtifacts.errMsg1.text",
 
  218                             artifactData.getType(), artifactData.getSourceFilePath());
 
  223                 String errorMessage = NbBundle.getMessage(this.getClass(),
 
  224                         "ExternalResultsImporter.importArtifacts.errMsg2.text",
 
  225                         artifactData.getType(), artifactData.getSourceFilePath());
 
  234             String reportPath = report.getLocalPath();
 
  236                 File reportFile = 
new File(reportPath);
 
  237                 if (reportFile.exists()) {
 
  240                     String errorMessage = NbBundle.getMessage(this.getClass(), 
"ExternalResultsImporter.importReports.errMsg1.text", reportPath);
 
  245                 String errorMessage = NbBundle.getMessage(this.getClass(), 
"ExternalResultsImporter.importReports.errMsg2.text", reportPath);
 
  255         String fileName = filePath;
 
  256         String parentPath = 
"";
 
  257         int charPos = filePath.lastIndexOf(
"/");
 
  259             fileName = filePath.substring(charPos + 1);
 
  260             parentPath = filePath.substring(0, charPos + 1);
 
  263         String condition = 
"name='" + fileName + 
"' AND parent_path='" + parentPath + 
"'"; 
 
  265         if (!files.isEmpty()) {
 
  267             if (files.size() > 1) {
 
  268                 String errorMessage = NbBundle.getMessage(this.getClass(), 
"ExternalResultsImporter.findFileInCaseDatabase.errMsg1.text", filePath);
 
  276         String relativePath = 
"";
 
  278         Path path = Paths.get(localPath);
 
  279         if (path.isAbsolute()) {
 
  280             Path pathBase = Paths.get(caseDirectoryPath);
 
  282                 Path pathRelative = pathBase.relativize(path);
 
  283                 relativePath = pathRelative.toString();
 
  284             } 
catch (IllegalArgumentException ex) {
 
  285                 String errorMessage = NbBundle.getMessage(this.getClass(),
 
  286                         "ExternalResultsImporter.getPathRelativeToCaseFolder.errMsg1.text",
 
  287                         localPath, caseDirectoryPath);
 
  291             String errorMessage = NbBundle.getMessage(this.getClass(),
 
  292                     "ExternalResultsImporter.getPathRelativeToCaseFolder.errMsg2.text",
 
  293                     localPath, caseDirectoryPath);
 
  301         this.errors.add(
new ErrorInfo(this.getClass().getName(), errorMessage));
 
  306         this.errors.add(
new ErrorInfo(this.getClass().getName(), errorMessage));
 
void importArtifacts(ExternalResults results)
 
BlackboardArtifact newArtifact(int artifactTypeID)
 
static final Logger logger
 
FileManager getFileManager()
 
void addAttributes(Collection< BlackboardAttribute > attributes)
 
static ARTIFACT_TYPE fromID(int ID)
 
String getCaseDirectory()
 
void importDerivedFiles(ExternalResults results)
 
void addReport(String localPath, String srcModuleName, String reportName)
 
static final HashSet< Integer > standardArtifactTypeIds
 
static TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE fromLabel(String typeName)
 
BlackboardAttribute.Type addArtifactAttributeType(String attrTypeString, TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE valueType, String displayName)
 
AbstractFile findFileInCaseDatabase(String filePath)
 
BlackboardAttribute.Type getAttributeType(String attrTypeName)
 
BlackboardArtifact.Type getArtifactType(String artTypeName)
 
void recordError(String errorMessage, Exception ex)
 
void fireModuleDataEvent(ModuleDataEvent moduleDataEvent)
 
SleuthkitCase getSleuthkitCase()
 
void recordError(String errorMessage)
 
List< ErrorInfo > importResults(ExternalResults results)
 
Blackboard getBlackboard()
 
void fireModuleContentEvent(ModuleContentEvent moduleContentEvent)
 
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, TskData.EncodingType encodingType)
 
static void error(String title, String message)
 
synchronized void indexArtifact(BlackboardArtifact artifact)
 
List< AbstractFile > findAllFilesWhere(String sqlWhereClause)
 
static Case getCurrentCase()
 
synchronized static Logger getLogger(String name)
 
void importReports(ExternalResults results)
 
String getPathRelativeToCaseFolder(String localPath)
 
final List< ErrorInfo > errors
 
BlackboardArtifact.Type addBlackboardArtifactType(String artifactTypeName, String displayName)
 
static synchronized IngestServices getInstance()