[Yanel-commits] rev 22830 - in public/yanel/trunk/src: core/java/org/wyona/yanel/core/map resources/importsite/src/java/org/wyona/yanel/impl/resources test/junit/org/wyona/yanel/core/map

josias at wyona.com josias at wyona.com
Wed Feb 21 16:03:26 CET 2007


Author: josias
Date: 2007-02-21 16:03:24 +0100 (Wed, 21 Feb 2007)
New Revision: 22830

Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java
   public/yanel/trunk/src/resources/importsite/src/java/org/wyona/yanel/impl/resources/ImportSiteResource.java
   public/yanel/trunk/src/test/junit/org/wyona/yanel/core/map/RealmConfigurationTest.java
Log:
copy new realm to the directory the user entered in the form and create directory if it doesn't exist yet, see bug #4991

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java	2007-02-21 14:53:46 UTC (rev 22829)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/RealmConfiguration.java	2007-02-21 15:03:24 UTC (rev 22830)
@@ -307,10 +307,12 @@
      * @param destRealmID
      * @param destRealmName
      * @param destMountPoint
+     * @param destDir directory where the new realm will be created (if null, the realm
+     *                will be created in the same directory as the src realm).
      * @throws Exception
      */
     public void copyRealm(String srcRealmID, String destRealmID, String destRealmName, 
-            String destMountPoint) throws Exception {
+            String destMountPoint, File destDir) throws Exception {
         if (getRealm(destRealmID) != null) {
             log.warn("Cannot add realm: " + destRealmID + " (realm with this ID exists already)");
             return; // TODO: throw Exception
@@ -336,7 +338,17 @@
         }
         
         // copy realm directory:
-        File destRootDir = new File(srcRootDir.getParentFile(), destRealmID);
+        File destRootDir;
+        if (destDir != null) {
+            if (!destDir.exists() || !destDir.isDirectory()) {
+            	if (!new File(destDir.getAbsolutePath()).mkdirs()) {
+            		throw new Exception("cannot create directory: " + destDir);
+                }
+            }
+            destRootDir = new File(destDir, destRealmID);
+        } else {
+            destRootDir = new File(srcRootDir.getParentFile(), destRealmID);
+        }
         log.debug("copying realm " + srcRootDir + " to " + destRootDir);
         byte[] buffer = new byte[8192];
         String[] filter = { ".svn", ".cvs" };

Modified: public/yanel/trunk/src/resources/importsite/src/java/org/wyona/yanel/impl/resources/ImportSiteResource.java
===================================================================
--- public/yanel/trunk/src/resources/importsite/src/java/org/wyona/yanel/impl/resources/ImportSiteResource.java	2007-02-21 14:53:46 UTC (rev 22829)
+++ public/yanel/trunk/src/resources/importsite/src/java/org/wyona/yanel/impl/resources/ImportSiteResource.java	2007-02-21 15:03:24 UTC (rev 22830)
@@ -153,7 +153,8 @@
                     getYanel().getRealmConfiguration().copyRealm("from-scratch-realm-template", 
                             parameters.get("realmid").toString(), 
                             parameters.get("realmname").toString(),
-                            "/" + parameters.get("realmid").toString() + "/");
+                            "/" + parameters.get("realmid").toString() + "/", 
+                            new File(parameters.get("fs-location").toString()));
                     transformer.setParameter("submitted", "true");
                 }
                 

Modified: public/yanel/trunk/src/test/junit/org/wyona/yanel/core/map/RealmConfigurationTest.java
===================================================================
--- public/yanel/trunk/src/test/junit/org/wyona/yanel/core/map/RealmConfigurationTest.java	2007-02-21 14:53:46 UTC (rev 22829)
+++ public/yanel/trunk/src/test/junit/org/wyona/yanel/core/map/RealmConfigurationTest.java	2007-02-21 15:03:24 UTC (rev 22830)
@@ -15,6 +15,8 @@
  */
 package org.wyona.yanel.core.map;
 
+import java.io.File;
+
 import org.wyona.yanel.junit.AbstractYanelTest;
 
 /**
@@ -34,7 +36,7 @@
      * Tests
      */
     public void testCopyRealm() throws Exception {
-        this.realmConfig.copyRealm("from-scratch-realm-template", "test-copy-realm", "Test Realm (created by a Testcase)", "/test/test-copy-realm/");
+        this.realmConfig.copyRealm("from-scratch-realm-template", "test-copy-realm", "Test Realm (created by a Testcase)", "/test/test-copy-realm/", null);
         assertNotNull(this.realmConfig.getRealm("test-copy-realm"));
     }
 




More information about the Yanel-commits mailing list