option to add timestamp to case folders

This commit is contained in:
Karl Mortensen 2015-07-31 13:36:08 -04:00
parent 38003c1809
commit 2a876ff4c9
2 changed files with 30 additions and 9 deletions

View File

@ -81,6 +81,7 @@ public class SingleUserCaseImporter implements Runnable {
private PrintWriter writer;
private XMLCaseManagement oldXmlCaseManagement;
private XMLCaseManagement newXmlCaseManagement;
private boolean addTimestamp;
/**
* SingleUserCaseImporter constructor
@ -94,11 +95,13 @@ public class SingleUserCaseImporter implements Runnable {
* @param copySourceImages true if images should be copied
* @param deleteCase true if the old version of the case should be deleted
* after import
* @param addTimestamp true if the output case name should end in a
* timestamp, false otherwise
* @param callback a callback from the calling panel for notification when
* the conversion has completed. This is a Runnable on a different thread.
*/
public SingleUserCaseImporter(String caseInput, String caseOutput, String imageInput, String imageOutput, CaseDbConnectionInfo database,
boolean copySourceImages, boolean deleteCase, ConversionDoneCallback callback) {
boolean copySourceImages, boolean deleteCase, ConversionDoneCallback callback, boolean addTimestamp) {
this.caseInputFolder = caseInput;
this.caseOutputFolder = caseOutput;
this.imageInputFolder = imageInput;
@ -107,6 +110,7 @@ public class SingleUserCaseImporter implements Runnable {
this.deleteCase = deleteCase;
this.db = database;
this.notifyOnComplete = callback;
this.addTimestamp = addTimestamp;
}
/**
@ -303,7 +307,8 @@ public class SingleUserCaseImporter implements Runnable {
* Handles case folder, PosgreSql database, and Solr core name deconfliction
*
* @param caseOutputFolder the case output folder
* @param caseFolder the case folder name, including timestamp
* @param caseFolder the case folder name, including timestamp deconflicted
* folder name
* @return the deconflicted caseFolder name to use. Includes timestamp.
* @throws Exception
*/
@ -332,6 +337,9 @@ public class SingleUserCaseImporter implements Runnable {
sanitizedCaseName = temp;
}
if (addTimestamp && !TimeStampUtils.endsWithTimeStamp(sanitizedCaseName)) {
sanitizedCaseName += "_" + TimeStampUtils.createTimeStamp();
}
// create output folders just in case
Paths.get(caseOutputFolder, sanitizedCaseName).toFile().mkdirs();
return sanitizedCaseName;
@ -363,14 +371,14 @@ public class SingleUserCaseImporter implements Runnable {
}
source = input.resolve(AIM_LOG_FILE_NAME);
destination = Paths.get(caseOutputFolder, newCaseFolder, AIM_LOG_FILE_NAME);
if (source.toFile().exists()) {
destination = Paths.get(caseOutputFolder, newCaseFolder, AIM_LOG_FILE_NAME);
FileUtils.copyFile(source.toFile(), destination.toFile());
try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(destination.toString(), true)))) {
out.println(NbBundle.getMessage(SingleUserCaseImporter.class, "SingleUserCaseImporter.ConvertedToMultiUser") + new Date());
} catch (IOException e) {
// if unable to log it, no problem
}
}
try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(destination.toString(), true)))) {
out.println(NbBundle.getMessage(SingleUserCaseImporter.class, "SingleUserCaseImporter.ConvertedToMultiUser") + new Date());
} catch (IOException e) {
// if unable to log it, no problem
}
// Remove the single-user .aut file, database, Timeline database and log

View File

@ -18,6 +18,8 @@
*/
package org.sleuthkit.autopsy.coreutils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -30,7 +32,8 @@ public final class TimeStampUtils {
// Sample case name with time stamp: Case 1_2015_02_02_12_10_31 for case "Case 1"
private static final Pattern timeStampPattern = Pattern.compile("\\d{4}_\\d{2}_\\d{2}_\\d{2}_\\d{2}_\\d{2}$");
private static final int LENGTH_OF_DATE_TIME_STAMP = 20; // length of the above time stamp
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
/**
* Checks whether a string ends with a time stamp defined by pattern.
*
@ -50,4 +53,14 @@ public final class TimeStampUtils {
public static int getTimeStampLength() {
return LENGTH_OF_DATE_TIME_STAMP;
}
/**
* Create a timestamp using the current time
*
* @return the timestamp as a String
*/
public static String createTimeStamp() {
return dateFormat.format(Calendar.getInstance().getTime());
}
}