diff --git a/Toolbox Migration/pom.xml b/Toolbox Migration/pom.xml
index f73cce1..b119636 100644
--- a/Toolbox Migration/pom.xml
+++ b/Toolbox Migration/pom.xml
@@ -6,6 +6,11 @@
0.0.1-SNAPSHOT
+
+ log4j
+ log4j
+ 1.2.16
+
commons-io
commons-io
diff --git a/Toolbox Migration/src/com/bayer/edam/ToolboxFileExporter.java b/Toolbox Migration/src/com/bayer/edam/ToolboxFileExporter.java
index dfaf46d..25d70b0 100644
--- a/Toolbox Migration/src/com/bayer/edam/ToolboxFileExporter.java
+++ b/Toolbox Migration/src/com/bayer/edam/ToolboxFileExporter.java
@@ -5,19 +5,28 @@ import java.io.File;
import java.io.InputStreamReader;
import java.util.List;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Layout;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+
import com.univocity.parsers.csv.CsvParser;
import com.univocity.parsers.csv.CsvParserSettings;
public class ToolboxFileExporter {
+ private static Logger log = Logger.getLogger(ToolboxFileExporter.class);
+
private List rows;
private String baseDir = "I:\\Toolbox\\Assets";
// Formatdatei generiert mit
- // bcp "SELECT OriginalImage FROM AssetImages WHERE AssetID=586" queryout Image.jpg -S MOVNCG -d Bayertoolbox_prod -T -x
+ // bcp "SELECT OriginalImage FROM AssetImages WHERE AssetID=586" queryout Image.jpg -S MOVNCG -d Bayertoolbox_prod -T
// Geben Sie den Dateispeichertyp des Felds OriginalImage ein [varbinary(max)]: x
- // Geben Sie die Präfixlänge des OriginalImage-Felds ein [8]:
+ // Geben Sie die Präfixlänge des OriginalImage-Felds ein [8]: 0
// Geben Sie das Feldabschlusszeichen ein [none]:
// Abruf:
@@ -39,18 +48,20 @@ public class ToolboxFileExporter {
}
private void getImage(String assetId, String originalFilenname) throws Exception {
- System.out.println("AssetID: " + assetId + " OriginalFilename: '" + originalFilenname + "'");
-
-
- // TODO Check if file already exists (bcp just overwrites existing files)
-
- Process process = Runtime.getRuntime().exec(command1 + assetId + command2 + assetId + command3, null, workingDir);
- process.waitFor();
- BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
-
- String s;
- while ((s = reader.readLine()) != null) {
- System.out.println(s);
+ if (new File(baseDir + File.separator + assetId).exists()) {
+ log.error("File for asset " + assetId + " already present, skipping");
+ }
+ else {
+ log.info("Download for asset " + assetId + ", OriginalFilename: '" + originalFilenname + "'");
+ Process process = Runtime.getRuntime().exec(command1 + assetId + command2 + assetId + command3, null, workingDir);
+ process.waitFor();
+ if (0 < process.exitValue()) {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ String s;
+ while ((s = reader.readLine()) != null) {
+ log.error(s);
+ }
+ }
}
}
@@ -68,6 +79,10 @@ public class ToolboxFileExporter {
public static void main(String[] args) {
+ Layout layout = new PatternLayout("%p %m%n"); // "%d{ISO8601} - %p %m%n"
+ BasicConfigurator.configure(new ConsoleAppender(layout));
+ log.setLevel(Level.DEBUG);
+
try {
new ToolboxFileExporter();
} catch (Exception e) {