Added image.loading call. Modified image.loading so that it doesn't overwrite existing images.
authorAntonio Moreno <antonio.moreno@openbravo.com>
Tue, 15 Sep 2009 13:27:15 +0200
changeset 4928 29f64b67fcb8
parent 4927 f011e8d56e91
child 4929 983cbb91ddd9
Added image.loading call. Modified image.loading so that it doesn't overwrite existing images.
build.xml
src/org/openbravo/erpCommon/utility/ImageToDatabaseLoader.java
--- a/build.xml	Tue Sep 15 12:08:17 2009 +0200
+++ b/build.xml	Tue Sep 15 13:27:15 2009 +0200
@@ -258,6 +258,7 @@
 
     <ant dir="${base.src}" target="smartbuild" inheritAll="true" inheritRefs="true" />
 
+    <antcall target="image.loading" />
     <antcall target="build.deploy" />
     <!-- only restart tomcat if the restart prop was set to true -->
     <condition property="dorestart">
@@ -296,6 +297,7 @@
   <target name="compile.complete.deploy">
     <antcall target="compile.complete.development" />
     <antcall target="compile.complete.war" />
+    <antcall target="image.loading" />
   </target>
 
   <target name="compile.complete.development" depends="init" if="mode.class">
--- a/src/org/openbravo/erpCommon/utility/ImageToDatabaseLoader.java	Tue Sep 15 12:08:17 2009 +0200
+++ b/src/org/openbravo/erpCommon/utility/ImageToDatabaseLoader.java	Tue Sep 15 13:27:15 2009 +0200
@@ -26,22 +26,28 @@
       String properties[] = propertyNames.split(",");
       Image[] images = new Image[paths.length];
       for (int i = 0; i < paths.length; i++) {
-        File f = new File(basePath + File.separator + paths[i]);
-        InputStream is = new FileInputStream(f);
-        byte[] bytes = new byte[(int) f.length()];
-        int offset = 0;
-        int numRead = 0;
-        while (offset < bytes.length
-            && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
-          offset += numRead;
+        if (OBDal.getInstance().get(SystemInformation.class, "0").get(properties[i]) == null) {
+          File f = new File(basePath + File.separator + paths[i]);
+          InputStream is = new FileInputStream(f);
+          byte[] bytes = new byte[(int) f.length()];
+          int offset = 0;
+          int numRead = 0;
+          while (offset < bytes.length
+              && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
+            offset += numRead;
+          }
+          Image image = OBProvider.getInstance().get(Image.class);
+          image.setBindaryData(bytes);
+          image.setName("Image");
+          getLog().info("Inserting image with property: " + properties[i]);
+          OBDal.getInstance().save(image);
+          OBDal.getInstance().get(SystemInformation.class, "0").set(properties[i], image);
+          OBDal.getInstance().flush();
+        } else {
+          getLog().info(
+              "Image of property " + properties[i]
+                  + " wasn't inserted because it's already in the database.");
         }
-        Image image = OBProvider.getInstance().get(Image.class);
-        image.setBindaryData(bytes);
-        image.setName("Image");
-        getLog().info("Inserting image with property: " + properties[i]);
-        OBDal.getInstance().save(image);
-        OBDal.getInstance().get(SystemInformation.class, "0").set(properties[i], image);
-        OBDal.getInstance().flush();
       }
 
     } catch (Exception e) {