Logging
This commit is contained in:
@@ -6,6 +6,11 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
|
||||
@@ -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<String[]> 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) {
|
||||
|
||||
Reference in New Issue
Block a user