From 531c1a88eed0c50752f5c9482de84dc9afbe122f Mon Sep 17 00:00:00 2001 From: tliero Date: Wed, 14 Jun 2017 08:43:45 +0200 Subject: [PATCH] initial commit --- Toolbox Migration/.classpath | 20 +++++ Toolbox Migration/.gitignore | 2 + Toolbox Migration/.project | 23 ++++++ .../.settings/org.eclipse.jdt.core.prefs | 12 +++ .../.settings/org.eclipse.m2e.core.prefs | 4 + Toolbox Migration/bcp.fmt | Bin 0 -> 676 bytes Toolbox Migration/pom.xml | 35 ++++++++ .../com/bayer/edam/ToolboxFileExporter.java | 77 ++++++++++++++++++ 8 files changed, 173 insertions(+) create mode 100644 Toolbox Migration/.classpath create mode 100644 Toolbox Migration/.gitignore create mode 100644 Toolbox Migration/.project create mode 100644 Toolbox Migration/.settings/org.eclipse.jdt.core.prefs create mode 100644 Toolbox Migration/.settings/org.eclipse.m2e.core.prefs create mode 100644 Toolbox Migration/bcp.fmt create mode 100644 Toolbox Migration/pom.xml create mode 100644 Toolbox Migration/src/com/bayer/edam/ToolboxFileExporter.java diff --git a/Toolbox Migration/.classpath b/Toolbox Migration/.classpath new file mode 100644 index 0000000..a92a607 --- /dev/null +++ b/Toolbox Migration/.classpath @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Toolbox Migration/.gitignore b/Toolbox Migration/.gitignore new file mode 100644 index 0000000..09e3bc9 --- /dev/null +++ b/Toolbox Migration/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/Toolbox Migration/.project b/Toolbox Migration/.project new file mode 100644 index 0000000..8fabfc0 --- /dev/null +++ b/Toolbox Migration/.project @@ -0,0 +1,23 @@ + + + Toolbox Migration + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/Toolbox Migration/.settings/org.eclipse.jdt.core.prefs b/Toolbox Migration/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..f4217b0 --- /dev/null +++ b/Toolbox Migration/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Toolbox Migration/.settings/org.eclipse.m2e.core.prefs b/Toolbox Migration/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..14b697b --- /dev/null +++ b/Toolbox Migration/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/Toolbox Migration/bcp.fmt b/Toolbox Migration/bcp.fmt new file mode 100644 index 0000000000000000000000000000000000000000..4f504d6163fe35ca1f44e4f80d4b60c5d685acd1 GIT binary patch literal 676 zcmZvaTTjAJ5QOL1#Q#8iw}AR!2tv3j2^MT6;*&uw*r=ei-u}G$?KuWXASZ`zXD>55 z<>$Mqx<2)+Cl&OrL`!8#wa{EA+EZD9N<8bTX;(X{s;QQS>S~}!=W6JZKHop5(|R71 zb6!+Yk(22TB!OW<9Pms*mM~=8DU|{53vjD_MMvgTcr8U8z+ci4*;~DledI2fbq_Kn zTDr+Oyz4qDXtF&v^?b-qz&+&G`e#h?EM=lGTlE#MsorOf?Uutj2T$PgZWQn%QU^!O zjrIyPysI9WK4^ic{pY4vY04_h`@*HfWkP1>ptki8O$ocD>|pgn$6@ovx?y5Rp-%Dr z%yk}9Q(Q4uiMJ^-odaF1>P(@j?rX%pAuKU(BdS`=_g~()Lp8{IWPq*|x6F+RU!mum fpE*Cw`^~LlUBJ+!(&j|E-lFwim1*Dnch&R@n>A+b literal 0 HcmV?d00001 diff --git a/Toolbox Migration/pom.xml b/Toolbox Migration/pom.xml new file mode 100644 index 0000000..f73cce1 --- /dev/null +++ b/Toolbox Migration/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + ToolboxMigration + ToolboxMigration + 0.0.1-SNAPSHOT + + + + commons-io + commons-io + 2.5 + + + com.univocity + univocity-parsers + 2.4.1 + jar + + + + + src + + + maven-compiler-plugin + 3.5.1 + + 1.7 + 1.7 + + + + + \ No newline at end of file diff --git a/Toolbox Migration/src/com/bayer/edam/ToolboxFileExporter.java b/Toolbox Migration/src/com/bayer/edam/ToolboxFileExporter.java new file mode 100644 index 0000000..a07dfbe --- /dev/null +++ b/Toolbox Migration/src/com/bayer/edam/ToolboxFileExporter.java @@ -0,0 +1,77 @@ +package com.bayer.edam; + +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStreamReader; +import java.util.List; + +import com.univocity.parsers.csv.CsvParser; +import com.univocity.parsers.csv.CsvParserSettings; + +public class ToolboxFileExporter { + + + private List rows; + private String baseDir = "I:\\ToolboxAssets"; + + // Formatdatei generiert mit + // bcp "SELECT OriginalImage FROM AssetImages WHERE AssetID=586" queryout Image.jpg -S MOVNCG -d Bayertoolbox_prod -T -x + // Geben Sie den Dateispeichertyp des Felds OriginalImage ein [varbinary(max)]: x + // Geben Sie die Präfixlänge des OriginalImage-Felds ein [8]: + // Geben Sie das Feldabschlusszeichen ein [none]: + + // Abruf: + // bcp "SELECT OriginalImage FROM AssetImages WHERE AssetID=586" queryout Image5.jpg -S MOVNCG -d Bayertoolbox_prod -T -f bcp.fmt + + private String command1 = "bcp \"SELECT OriginalImage FROM AssetImages WHERE AssetID="; + private String command2 = "\" queryout "; + private String command3 = " -S MOVNCG -d Bayertoolbox_prod -T -f bcp.fmt"; + + private File workingDir = new File(baseDir); + + public ToolboxFileExporter() throws Exception { + readList(); + + for (int i=0; i < 3; i++) { + getImage(rows.get(188+i)[1]); + } + + } + + private void getImage(String assetId) throws Exception { + System.out.println("AssetID: " + assetId); + + // TODO Check if file already exists (bcp just overwrites existing files) + + Process process = Runtime.getRuntime().exec(command1 + assetId + command2 + "Test5.jpg" + command3, null, workingDir); + process.waitFor(); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + + String s; + while ((s = reader.readLine()) != null) { + System.out.println(s); + } + } + + private void readList() { + CsvParserSettings settings = new CsvParserSettings(); + settings.getFormat().setLineSeparator("\r\n"); + settings.getFormat().setDelimiter(';'); + settings.getFormat().setCharToEscapeQuoteEscaping('"'); + settings.setHeaderExtractionEnabled(false); + + CsvParser parser = new CsvParser(settings); + + rows = parser.parseAll(new File("I:\\ToolboxAssets\\AssetImages.csv")); + } + + + public static void main(String[] args) { + try { + new ToolboxFileExporter(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +}