You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openmeetings.apache.org by "seba.wagner@gmail.com" <se...@gmail.com> on 2013/02/10 21:43:22 UTC

Re: svn commit: r1444587 - in /openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler: BackupExport.java BackupImportController.java

@Maxim: It seems to work fine for me now on the importing side.
I can't really test the export, as I have no windows machine. However,
theoretically "wrong" windows export should
 work fine to import too. We will find that out when we have the import
automatized via JUnit and integrated it into our nightly build easily.

Great work btw :)
Cheers!
Sebastian


2013/2/11 <so...@apache.org>

> Author: solomax
> Date: Sun Feb 10 19:34:47 2013
> New Revision: 1444587
>
> URL: http://svn.apache.org/r1444587
> Log:
> Import: both export and import should work as expected now (requires
> additional testing)
>
> Modified:
>
> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupExport.java
>
> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java
>
> Modified:
> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupExport.java
> URL:
> http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupExport.java?rev=1444587&r1=1444586&r2=1444587&view=diff
>
> ==============================================================================
> ---
> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupExport.java
> (original)
> +++
> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupExport.java
> Sun Feb 10 19:34:47 2013
> @@ -19,12 +19,11 @@
>  package org.apache.openmeetings.servlet.outputhandler;
>
>  import java.io.File;
> -import java.io.FileNotFoundException;
>  import java.io.FileOutputStream;
>  import java.io.IOException;
>  import java.io.OutputStream;
>  import java.io.OutputStreamWriter;
> -import java.util.ArrayList;
> +import java.net.URI;
>  import java.util.Date;
>  import java.util.List;
>  import java.util.zip.ZipEntry;
> @@ -74,8 +73,8 @@ import org.apache.openmeetings.persisten
>  import org.apache.openmeetings.persistence.beans.flvrecord.FlvRecording;
>  import org.apache.openmeetings.persistence.beans.poll.PollType;
>  import org.apache.openmeetings.persistence.beans.poll.RoomPoll;
> -import org.apache.openmeetings.persistence.beans.room.RoomType;
>  import org.apache.openmeetings.persistence.beans.room.Room;
> +import org.apache.openmeetings.persistence.beans.room.RoomType;
>  import org.apache.openmeetings.persistence.beans.user.PrivateMessage;
>  import org.apache.openmeetings.persistence.beans.user.State;
>  import org.apache.openmeetings.persistence.beans.user.User;
> @@ -383,12 +382,7 @@ public class BackupExport {
>                         FileHelper.copyRec(sourceDirRec, targetDirRec);
>                 }
>
> -               List<File> fileList = new ArrayList<File>();
> -               log.debug("---Getting references to all files in: "
> -                               + backup_dir.getCanonicalPath());
> -               getAllFiles(backup_dir, fileList);
> -               log.debug("---Creating zip file");
> -               writeZipFile(backup_dir, fileList, new
> FileOutputStream(filePath));
> +               writeZipDir(backup_dir, filePath);
>                 log.debug("---Done");
>         }
>
> @@ -524,57 +518,45 @@ public class BackupExport {
>                 }
>         }
>
> -       public void getAllFiles(File dir, List<File> fileList) throws
> IOException {
> +       private void writeZipDir(File directoryToZip, File f) throws
> IOException {
> +               FileOutputStream fos = null;
> +               ZipOutputStream zos = null;
>                 try {
> -                       File[] files = dir.listFiles();
> -                       for (File file : files) {
> -                               fileList.add(file);
> -                               if (file.isDirectory()) {
> -                                       // log.debug("directory:" +
> file.getCanonicalPath());
> -                                       getAllFiles(file, fileList);
> -                               } else {
> -                                       // log.debug("     file:" +
> file.getCanonicalPath());
> +                       fos = new FileOutputStream(f);
> +                       zos = new ZipOutputStream(fos);
> +
> +                       writeZipDir(directoryToZip.toURI(),
> directoryToZip, zos);
> +               } finally {
> +                       if (zos != null) {
> +                               try {
> +                                       zos.close();
> +                               } catch (IOException e) {
> +                                       log.debug("Enexpected error while
> closing ZipOutputStream", e);
>                                 }
>                         }
> -               } catch (IOException e) {
> -                       e.printStackTrace();
> -               }
> -       }
> -
> -       public void writeZipFile(File directoryToZip, List<File> fileList,
> -                       FileOutputStream fos) {
> -
> -               try {
> -                       ZipOutputStream zos = new ZipOutputStream(fos);
> -
> -                       for (File file : fileList) {
> -                               if (!file.isDirectory()) { // we only zip
> files, not directories
> -                                       addToZip(directoryToZip, file,
> zos);
> +                       if (fos != null) {
> +                               try {
> +                                       fos.close();
> +                               } catch (IOException e) {
> +                                       log.debug("Enexpected error while
> closing FileOutputStream", e);
>                                 }
>                         }
> -
> -                       zos.close();
> -                       fos.close();
> -               } catch (FileNotFoundException e) {
> -                       e.printStackTrace();
> -               } catch (IOException e) {
> -                       e.printStackTrace();
>                 }
>         }
> +
> +       private void writeZipDir(URI base, File dir, ZipOutputStream zos)
> throws IOException {
> +               for (File file : dir.listFiles()) {
> +                       if (file.isDirectory()) {
> +                               writeZipDir(base, file, zos);
> +                       } else {
> +                               String path =
> base.relativize(file.toURI()).toString();
> +                               log.debug("Writing '" + path + "' to zip
> file");
> +                               ZipEntry zipEntry = new ZipEntry(path);
> +                               zos.putNextEntry(zipEntry);
>
> -       public void addToZip(File directoryToZip, File file,
> ZipOutputStream zos)
> -                       throws FileNotFoundException, IOException {
> -
> -               // we want the zipEntry's path to be a relative path that
> is relative
> -               // to the directory being zipped, so chop off the rest of
> the path
> -               String zipFilePath = file.getCanonicalPath().substring(
> -                               directoryToZip.getCanonicalPath().length()
> + 1,
> -                               file.getCanonicalPath().length());
> -               log.debug("Writing '" + zipFilePath + "' to zip file");
> -               ZipEntry zipEntry = new ZipEntry(zipFilePath);
> -               zos.putNextEntry(zipEntry);
> -
> -               OmFileHelper.copyFile(file, zos);
> -               zos.closeEntry();
> +                               OmFileHelper.copyFile(file, zos);
> +                               zos.closeEntry();
> +                       }
> +               }
>         }
>  }
>
> Modified:
> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java
> URL:
> http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java?rev=1444587&r1=1444586&r2=1444587&view=diff
>
> ==============================================================================
> ---
> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java
> (original)
> +++
> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java
> Sun Feb 10 19:34:47 2013
> @@ -18,6 +18,12 @@
>   */
>  package org.apache.openmeetings.servlet.outputhandler;
>
> +import static org.apache.commons.transaction.util.FileHelper.copyRec;
> +import static
> org.apache.openmeetings.utils.OmFileHelper.getStreamsHibernateDir;
> +import static org.apache.openmeetings.utils.OmFileHelper.getUploadDir;
> +import static
> org.apache.openmeetings.utils.OmFileHelper.getUploadProfilesUserDir;
> +import static org.apache.openmeetings.utils.OmFileHelper.profilesPrefix;
> +
>  import java.io.File;
>  import java.io.FileInputStream;
>  import java.io.IOException;
> @@ -194,59 +200,26 @@ public class BackupImportController exte
>                 log.debug("##### WRITE FILE TO: " + f);
>
>                 ZipInputStream zipinputstream = new ZipInputStream(is);
> -
>                 ZipEntry zipentry = zipinputstream.getNextEntry();
> -
>                 while (zipentry != null) {
> +                       String fName = zipentry.getName();
> +                       if (File.pathSeparatorChar != '\\' &&
> fName.indexOf('\\') > -1) {
> +                               fName = fName.replace('\\', '/');
> +                       }
>                         // for each entry to be extracted
> -                       File fentryName = new File(f, zipentry.getName());
> -
> -                       if (zipentry.isDirectory()) {
> -                               if (!fentryName.mkdir()) {
> -                                       break;
> -                               }
> +                       File fentry = new File(f, fName);
> +                       File dir = fentry.isDirectory() ? fentry :
> fentry.getParentFile();
> +                       dir.mkdirs();
> +                       if (fentry.isDirectory()) {
>                                 zipentry = zipinputstream.getNextEntry();
>                                 continue;
>                         }
>
> -                       File fparent = new File(fentryName.getParent());
> -
> -                       if (!fparent.exists()) {
> -
> -                               File fparentparent = new
> File(fparent.getParent());
> -
> -                               if (!fparentparent.exists()) {
> -
> -                                       File fparentparentparent = new
> File(
> -
> fparentparent.getParent());
> -
> -                                       if (!fparentparentparent.exists())
> {
> -
> -
> fparentparentparent.mkdir();
> -                                               fparentparent.mkdir();
> -                                               fparent.mkdir();
> -
> -                                       } else {
> -
> -                                               fparentparent.mkdir();
> -                                               fparent.mkdir();
> -
> -                                       }
> -
> -                               } else {
> -
> -                                       fparent.mkdir();
> -
> -                               }
> -
> -                       }
> -
> -                       FileHelper.copy(zipinputstream, fentryName);
> +                       FileHelper.copy(zipinputstream, fentry);
>                         zipinputstream.closeEntry();
>                         zipentry = zipinputstream.getNextEntry();
>
> -               }// while
> -
> +               }
>                 zipinputstream.close();
>
>                 /*
> @@ -766,84 +739,37 @@ public class BackupImportController exte
>                 return list;
>         }
>
> -       private void importFolders(File importBaseDir)
> -                       throws IOException {
> -
> +       private Long getProfileId(File f) {
> +               String n = f.getName();
> +               if (n.indexOf(profilesPrefix) > -1) {
> +                       return
> importLongType(n.substring(profilesPrefix.length()));
> +               }
> +               return null;
> +       }
> +
> +       private void importFolders(File importBaseDir) throws IOException {
>                 // Now check the room files and import them
>                 File roomFilesFolder = new File(importBaseDir,
> "roomFiles");
>
> -               File library_dir = OmFileHelper.getUploadDir();
> +               File uploadDir = getUploadDir();
>
>                 log.debug("roomFilesFolder PATH " +
> roomFilesFolder.getCanonicalPath());
>
>                 if (roomFilesFolder.exists()) {
> -
> -                       File[] files = roomFilesFolder.listFiles();
> -                       for (File file : files) {
> +                       for (File file : roomFilesFolder.listFiles()) {
>                                 if (file.isDirectory()) {
> -
> -                                       File parentPathFile = new
> File(library_dir, file.getName());
> -
> -                                       if (!parentPathFile.exists()) {
> -                                               parentPathFile.mkdir();
> -                                       }
> -
> -                                       File[] roomOrProfileFiles =
> file.listFiles();
> -                                       for (File
> roomOrProfileFileOrFolder : roomOrProfileFiles) {
> -
> -                                               if
> (roomOrProfileFileOrFolder.isDirectory()) {
> -
> -                                                       String
> fileOrFolderName = roomOrProfileFileOrFolder
> -
> .getName();
> -                                                       int beginIndex =
> fileOrFolderName
> -
> .indexOf(OmFileHelper.profilesPrefix);
> -                                                       // Profile folder
> should be renamed if new user id
> -                                                       // is differ from
> current id.
> -                                                       if (beginIndex >
> -1) {
> -                                                               beginIndex
> = beginIndex
> -
>       + OmFileHelper.profilesPrefix
> -
>                       .length();
> -                                                               Long
> profileId = importLongType(fileOrFolderName
> -
>       .substring(beginIndex));
> -                                                               Long
> newProfileID = getNewId(profileId,
> -
>       Maps.USERS);
> -                                                               if
> (profileId != newProfileID) {
> -
> fileOrFolderName = fileOrFolderName
> -
>               .replaceFirst(
> -
>                               OmFileHelper.profilesPrefix
> -
>                                               + profileId,
> -
>                               OmFileHelper.profilesPrefix
> -
>                                               + newProfileID);
> -                                                               }
> -                                                       }
> -                                                       File
> roomDocumentFolder = new File(parentPathFile, fileOrFolderName);
> -
> -                                                       if
> (!roomDocumentFolder.exists()) {
> -
> roomDocumentFolder.mkdir();
> -
> -                                                               File[]
> roomDocumentFiles = roomOrProfileFileOrFolder
> -
>       .listFiles();
> -
> -                                                               for (File
> roomDocumentFile : roomDocumentFiles) {
> -                                                                       if
> (roomDocumentFile.isDirectory()) {
> -
>       log.error("Folder detected in Documents space! Folder " +
> roomDocumentFolder);
> -                                                                       }
> else {
> -
>       FileHelper.copy(roomDocumentFile, new File(roomDocumentFolder,
> roomDocumentFile.getName()));
> -                                                                       }
> -                                                               }
> -                                                       } else {
> -
> log.debug("Document already exists :: ",
> -
>       roomDocumentFolder);
> -                                                       }
> -                                               } else {
> -                                                       File
> roomFileOrProfileFile = new File(parentPathFile,
> roomOrProfileFileOrFolder.getName());
> -                                                       if
> (!roomFileOrProfileFile.exists()) {
> -
> FileHelper.copy(roomOrProfileFileOrFolder, roomFileOrProfileFile);
> -                                                       } else {
> -
> log.debug("File does already exist :: ", roomFileOrProfileFile);
> +                                       String fName = file.getName();
> +                                       if ("profiles".equals(fName)) {
> +                                               for (File profile :
> file.listFiles()) {
> +                                                       Long oldId =
> getProfileId(profile);
> +                                                       Long id = oldId !=
> null ? getNewId(oldId, Maps.USERS) : null;
> +                                                       if (id != null) {
> +
> copyRec(profile, getUploadProfilesUserDir(id));
>                                                         }
>                                                 }
> +                                               continue;
>                                         }
> +                                       copyRec(file, new File(uploadDir,
> fName));
>                                 }
>                         }
>                 }
> @@ -855,53 +781,56 @@ public class BackupImportController exte
>                 log.debug("sourceDirRec PATH " +
> sourceDirRec.getCanonicalPath());
>
>                 if (sourceDirRec.exists()) {
> -                       File targetDirRec =
> OmFileHelper.getStreamsHibernateDir();
> +                       File targetDirRec = getStreamsHibernateDir();
>
> -                       FileHelper.copyRec(sourceDirRec, targetDirRec);
> +                       copyRec(sourceDirRec, targetDirRec);
>                 }
>         }
>
>         private Long importLongType(String value) {
> -
>                 if (value.equals("null") || value.equals("")) {
>                         return null;
>                 }
>
>                 return Long.valueOf(value).longValue();
> -
>         }
>
>         private Long getNewId(Long oldId, Maps map) {
>                 Long newId = oldId;
>                 switch (map) {
> -               case USERS:
> -                       if (usersMap.get(oldId) != null)
> -                               newId = usersMap.get(oldId);
> -                       break;
> -               case ORGANISATIONS:
> -                       if (organisationsMap.get(oldId) != null)
> -                               newId = organisationsMap.get(oldId);
> -                       break;
> -               case APPOINTMENTS:
> -                       if (appointmentsMap.get(oldId) != null)
> -                               newId = appointmentsMap.get(oldId);
> -                       break;
> -               case ROOMS:
> -                       if (roomsMap.get(oldId) != null)
> -                               newId = roomsMap.get(oldId);
> -                       break;
> -               case MESSAGEFOLDERS:
> -                       if (messageFoldersMap.get(oldId) != null)
> -                               newId = messageFoldersMap.get(oldId);
> -                       break;
> -               case USERCONTACTS:
> -                       if (userContactsMap.get(oldId) != null)
> -                               newId = userContactsMap.get(oldId);
> -                       break;
> -               default:
> -                       break;
> +                       case USERS:
> +                               if (usersMap.containsKey(oldId)) {
> +                                       newId = usersMap.get(oldId);
> +                               }
> +                               break;
> +                       case ORGANISATIONS:
> +                               if (organisationsMap.containsKey(oldId)) {
> +                                       newId =
> organisationsMap.get(oldId);
> +                               }
> +                               break;
> +                       case APPOINTMENTS:
> +                               if (appointmentsMap.containsKey(oldId)) {
> +                                       newId = appointmentsMap.get(oldId);
> +                               }
> +                               break;
> +                       case ROOMS:
> +                               if (roomsMap.containsKey(oldId)) {
> +                                       newId = roomsMap.get(oldId);
> +                               }
> +                               break;
> +                       case MESSAGEFOLDERS:
> +                               if (messageFoldersMap.containsKey(oldId)) {
> +                                       newId =
> messageFoldersMap.get(oldId);
> +                               }
> +                               break;
> +                       case USERCONTACTS:
> +                               if (userContactsMap.containsKey(oldId)) {
> +                                       newId = userContactsMap.get(oldId);
> +                               }
> +                               break;
> +                       default:
> +                               break;
>                 }
>                 return newId;
>         }
> -
>  }
>
>
>


-- 
Sebastian Wagner
https://twitter.com/#!/dead_lock
http://www.webbase-design.de
http://www.wagner-sebastian.com
seba.wagner@gmail.com

Re: svn commit: r1444587 - in /openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler: BackupExport.java BackupImportController.java

Posted by Maxim Solodovnik <so...@gmail.com>.
I'm going to test the export right now :)
it was too late yesterday (~3 AM) :)))


On Mon, Feb 11, 2013 at 3:43 AM, seba.wagner@gmail.com <
seba.wagner@gmail.com> wrote:

> @Maxim: It seems to work fine for me now on the importing side.
> I can't really test the export, as I have no windows machine. However,
> theoretically "wrong" windows export should
>  work fine to import too. We will find that out when we have the import
> automatized via JUnit and integrated it into our nightly build easily.
>
> Great work btw :)
> Cheers!
> Sebastian
>
>
> 2013/2/11 <so...@apache.org>
>
> Author: solomax
>> Date: Sun Feb 10 19:34:47 2013
>> New Revision: 1444587
>>
>> URL: http://svn.apache.org/r1444587
>> Log:
>> Import: both export and import should work as expected now (requires
>> additional testing)
>>
>> Modified:
>>
>> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupExport.java
>>
>> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java
>>
>> Modified:
>> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupExport.java
>> URL:
>> http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupExport.java?rev=1444587&r1=1444586&r2=1444587&view=diff
>>
>> ==============================================================================
>> ---
>> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupExport.java
>> (original)
>> +++
>> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupExport.java
>> Sun Feb 10 19:34:47 2013
>> @@ -19,12 +19,11 @@
>>  package org.apache.openmeetings.servlet.outputhandler;
>>
>>  import java.io.File;
>> -import java.io.FileNotFoundException;
>>  import java.io.FileOutputStream;
>>  import java.io.IOException;
>>  import java.io.OutputStream;
>>  import java.io.OutputStreamWriter;
>> -import java.util.ArrayList;
>> +import java.net.URI;
>>  import java.util.Date;
>>  import java.util.List;
>>  import java.util.zip.ZipEntry;
>> @@ -74,8 +73,8 @@ import org.apache.openmeetings.persisten
>>  import org.apache.openmeetings.persistence.beans.flvrecord.FlvRecording;
>>  import org.apache.openmeetings.persistence.beans.poll.PollType;
>>  import org.apache.openmeetings.persistence.beans.poll.RoomPoll;
>> -import org.apache.openmeetings.persistence.beans.room.RoomType;
>>  import org.apache.openmeetings.persistence.beans.room.Room;
>> +import org.apache.openmeetings.persistence.beans.room.RoomType;
>>  import org.apache.openmeetings.persistence.beans.user.PrivateMessage;
>>  import org.apache.openmeetings.persistence.beans.user.State;
>>  import org.apache.openmeetings.persistence.beans.user.User;
>> @@ -383,12 +382,7 @@ public class BackupExport {
>>                         FileHelper.copyRec(sourceDirRec, targetDirRec);
>>                 }
>>
>> -               List<File> fileList = new ArrayList<File>();
>> -               log.debug("---Getting references to all files in: "
>> -                               + backup_dir.getCanonicalPath());
>> -               getAllFiles(backup_dir, fileList);
>> -               log.debug("---Creating zip file");
>> -               writeZipFile(backup_dir, fileList, new
>> FileOutputStream(filePath));
>> +               writeZipDir(backup_dir, filePath);
>>                 log.debug("---Done");
>>         }
>>
>> @@ -524,57 +518,45 @@ public class BackupExport {
>>                 }
>>         }
>>
>> -       public void getAllFiles(File dir, List<File> fileList) throws
>> IOException {
>> +       private void writeZipDir(File directoryToZip, File f) throws
>> IOException {
>> +               FileOutputStream fos = null;
>> +               ZipOutputStream zos = null;
>>                 try {
>> -                       File[] files = dir.listFiles();
>> -                       for (File file : files) {
>> -                               fileList.add(file);
>> -                               if (file.isDirectory()) {
>> -                                       // log.debug("directory:" +
>> file.getCanonicalPath());
>> -                                       getAllFiles(file, fileList);
>> -                               } else {
>> -                                       // log.debug("     file:" +
>> file.getCanonicalPath());
>> +                       fos = new FileOutputStream(f);
>> +                       zos = new ZipOutputStream(fos);
>> +
>> +                       writeZipDir(directoryToZip.toURI(),
>> directoryToZip, zos);
>> +               } finally {
>> +                       if (zos != null) {
>> +                               try {
>> +                                       zos.close();
>> +                               } catch (IOException e) {
>> +                                       log.debug("Enexpected error while
>> closing ZipOutputStream", e);
>>                                 }
>>                         }
>> -               } catch (IOException e) {
>> -                       e.printStackTrace();
>> -               }
>> -       }
>> -
>> -       public void writeZipFile(File directoryToZip, List<File> fileList,
>> -                       FileOutputStream fos) {
>> -
>> -               try {
>> -                       ZipOutputStream zos = new ZipOutputStream(fos);
>> -
>> -                       for (File file : fileList) {
>> -                               if (!file.isDirectory()) { // we only zip
>> files, not directories
>> -                                       addToZip(directoryToZip, file,
>> zos);
>> +                       if (fos != null) {
>> +                               try {
>> +                                       fos.close();
>> +                               } catch (IOException e) {
>> +                                       log.debug("Enexpected error while
>> closing FileOutputStream", e);
>>                                 }
>>                         }
>> -
>> -                       zos.close();
>> -                       fos.close();
>> -               } catch (FileNotFoundException e) {
>> -                       e.printStackTrace();
>> -               } catch (IOException e) {
>> -                       e.printStackTrace();
>>                 }
>>         }
>> +
>> +       private void writeZipDir(URI base, File dir, ZipOutputStream zos)
>> throws IOException {
>> +               for (File file : dir.listFiles()) {
>> +                       if (file.isDirectory()) {
>> +                               writeZipDir(base, file, zos);
>> +                       } else {
>> +                               String path =
>> base.relativize(file.toURI()).toString();
>> +                               log.debug("Writing '" + path + "' to zip
>> file");
>> +                               ZipEntry zipEntry = new ZipEntry(path);
>> +                               zos.putNextEntry(zipEntry);
>>
>> -       public void addToZip(File directoryToZip, File file,
>> ZipOutputStream zos)
>> -                       throws FileNotFoundException, IOException {
>> -
>> -               // we want the zipEntry's path to be a relative path that
>> is relative
>> -               // to the directory being zipped, so chop off the rest of
>> the path
>> -               String zipFilePath = file.getCanonicalPath().substring(
>> -
>> directoryToZip.getCanonicalPath().length() + 1,
>> -                               file.getCanonicalPath().length());
>> -               log.debug("Writing '" + zipFilePath + "' to zip file");
>> -               ZipEntry zipEntry = new ZipEntry(zipFilePath);
>> -               zos.putNextEntry(zipEntry);
>> -
>> -               OmFileHelper.copyFile(file, zos);
>> -               zos.closeEntry();
>> +                               OmFileHelper.copyFile(file, zos);
>> +                               zos.closeEntry();
>> +                       }
>> +               }
>>         }
>>  }
>>
>> Modified:
>> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java
>> URL:
>> http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java?rev=1444587&r1=1444586&r2=1444587&view=diff
>>
>> ==============================================================================
>> ---
>> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java
>> (original)
>> +++
>> openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java
>> Sun Feb 10 19:34:47 2013
>> @@ -18,6 +18,12 @@
>>   */
>>  package org.apache.openmeetings.servlet.outputhandler;
>>
>> +import static org.apache.commons.transaction.util.FileHelper.copyRec;
>> +import static
>> org.apache.openmeetings.utils.OmFileHelper.getStreamsHibernateDir;
>> +import static org.apache.openmeetings.utils.OmFileHelper.getUploadDir;
>> +import static
>> org.apache.openmeetings.utils.OmFileHelper.getUploadProfilesUserDir;
>> +import static org.apache.openmeetings.utils.OmFileHelper.profilesPrefix;
>> +
>>  import java.io.File;
>>  import java.io.FileInputStream;
>>  import java.io.IOException;
>> @@ -194,59 +200,26 @@ public class BackupImportController exte
>>                 log.debug("##### WRITE FILE TO: " + f);
>>
>>                 ZipInputStream zipinputstream = new ZipInputStream(is);
>> -
>>                 ZipEntry zipentry = zipinputstream.getNextEntry();
>> -
>>                 while (zipentry != null) {
>> +                       String fName = zipentry.getName();
>> +                       if (File.pathSeparatorChar != '\\' &&
>> fName.indexOf('\\') > -1) {
>> +                               fName = fName.replace('\\', '/');
>> +                       }
>>                         // for each entry to be extracted
>> -                       File fentryName = new File(f, zipentry.getName());
>> -
>> -                       if (zipentry.isDirectory()) {
>> -                               if (!fentryName.mkdir()) {
>> -                                       break;
>> -                               }
>> +                       File fentry = new File(f, fName);
>> +                       File dir = fentry.isDirectory() ? fentry :
>> fentry.getParentFile();
>> +                       dir.mkdirs();
>> +                       if (fentry.isDirectory()) {
>>                                 zipentry = zipinputstream.getNextEntry();
>>                                 continue;
>>                         }
>>
>> -                       File fparent = new File(fentryName.getParent());
>> -
>> -                       if (!fparent.exists()) {
>> -
>> -                               File fparentparent = new
>> File(fparent.getParent());
>> -
>> -                               if (!fparentparent.exists()) {
>> -
>> -                                       File fparentparentparent = new
>> File(
>> -
>> fparentparent.getParent());
>> -
>> -                                       if
>> (!fparentparentparent.exists()) {
>> -
>> -
>> fparentparentparent.mkdir();
>> -                                               fparentparent.mkdir();
>> -                                               fparent.mkdir();
>> -
>> -                                       } else {
>> -
>> -                                               fparentparent.mkdir();
>> -                                               fparent.mkdir();
>> -
>> -                                       }
>> -
>> -                               } else {
>> -
>> -                                       fparent.mkdir();
>> -
>> -                               }
>> -
>> -                       }
>> -
>> -                       FileHelper.copy(zipinputstream, fentryName);
>> +                       FileHelper.copy(zipinputstream, fentry);
>>                         zipinputstream.closeEntry();
>>                         zipentry = zipinputstream.getNextEntry();
>>
>> -               }// while
>> -
>> +               }
>>                 zipinputstream.close();
>>
>>                 /*
>> @@ -766,84 +739,37 @@ public class BackupImportController exte
>>                 return list;
>>         }
>>
>> -       private void importFolders(File importBaseDir)
>> -                       throws IOException {
>> -
>> +       private Long getProfileId(File f) {
>> +               String n = f.getName();
>> +               if (n.indexOf(profilesPrefix) > -1) {
>> +                       return
>> importLongType(n.substring(profilesPrefix.length()));
>> +               }
>> +               return null;
>> +       }
>> +
>> +       private void importFolders(File importBaseDir) throws IOException
>> {
>>                 // Now check the room files and import them
>>                 File roomFilesFolder = new File(importBaseDir,
>> "roomFiles");
>>
>> -               File library_dir = OmFileHelper.getUploadDir();
>> +               File uploadDir = getUploadDir();
>>
>>                 log.debug("roomFilesFolder PATH " +
>> roomFilesFolder.getCanonicalPath());
>>
>>                 if (roomFilesFolder.exists()) {
>> -
>> -                       File[] files = roomFilesFolder.listFiles();
>> -                       for (File file : files) {
>> +                       for (File file : roomFilesFolder.listFiles()) {
>>                                 if (file.isDirectory()) {
>> -
>> -                                       File parentPathFile = new
>> File(library_dir, file.getName());
>> -
>> -                                       if (!parentPathFile.exists()) {
>> -                                               parentPathFile.mkdir();
>> -                                       }
>> -
>> -                                       File[] roomOrProfileFiles =
>> file.listFiles();
>> -                                       for (File
>> roomOrProfileFileOrFolder : roomOrProfileFiles) {
>> -
>> -                                               if
>> (roomOrProfileFileOrFolder.isDirectory()) {
>> -
>> -                                                       String
>> fileOrFolderName = roomOrProfileFileOrFolder
>> -
>> .getName();
>> -                                                       int beginIndex =
>> fileOrFolderName
>> -
>> .indexOf(OmFileHelper.profilesPrefix);
>> -                                                       // Profile folder
>> should be renamed if new user id
>> -                                                       // is differ from
>> current id.
>> -                                                       if (beginIndex >
>> -1) {
>> -
>> beginIndex = beginIndex
>> -
>>       + OmFileHelper.profilesPrefix
>> -
>>                       .length();
>> -                                                               Long
>> profileId = importLongType(fileOrFolderName
>> -
>>       .substring(beginIndex));
>> -                                                               Long
>> newProfileID = getNewId(profileId,
>> -
>>       Maps.USERS);
>> -                                                               if
>> (profileId != newProfileID) {
>> -
>> fileOrFolderName = fileOrFolderName
>> -
>>               .replaceFirst(
>> -
>>                               OmFileHelper.profilesPrefix
>> -
>>                                               + profileId,
>> -
>>                               OmFileHelper.profilesPrefix
>> -
>>                                               + newProfileID);
>> -                                                               }
>> -                                                       }
>> -                                                       File
>> roomDocumentFolder = new File(parentPathFile, fileOrFolderName);
>> -
>> -                                                       if
>> (!roomDocumentFolder.exists()) {
>> -
>> roomDocumentFolder.mkdir();
>> -
>> -                                                               File[]
>> roomDocumentFiles = roomOrProfileFileOrFolder
>> -
>>       .listFiles();
>> -
>> -                                                               for (File
>> roomDocumentFile : roomDocumentFiles) {
>> -
>> if (roomDocumentFile.isDirectory()) {
>> -
>>       log.error("Folder detected in Documents space! Folder " +
>> roomDocumentFolder);
>> -                                                                       }
>> else {
>> -
>>       FileHelper.copy(roomDocumentFile, new File(roomDocumentFolder,
>> roomDocumentFile.getName()));
>> -                                                                       }
>> -                                                               }
>> -                                                       } else {
>> -
>> log.debug("Document already exists :: ",
>> -
>>       roomDocumentFolder);
>> -                                                       }
>> -                                               } else {
>> -                                                       File
>> roomFileOrProfileFile = new File(parentPathFile,
>> roomOrProfileFileOrFolder.getName());
>> -                                                       if
>> (!roomFileOrProfileFile.exists()) {
>> -
>> FileHelper.copy(roomOrProfileFileOrFolder, roomFileOrProfileFile);
>> -                                                       } else {
>> -
>> log.debug("File does already exist :: ", roomFileOrProfileFile);
>> +                                       String fName = file.getName();
>> +                                       if ("profiles".equals(fName)) {
>> +                                               for (File profile :
>> file.listFiles()) {
>> +                                                       Long oldId =
>> getProfileId(profile);
>> +                                                       Long id = oldId
>> != null ? getNewId(oldId, Maps.USERS) : null;
>> +                                                       if (id != null) {
>> +
>> copyRec(profile, getUploadProfilesUserDir(id));
>>                                                         }
>>                                                 }
>> +                                               continue;
>>                                         }
>> +                                       copyRec(file, new File(uploadDir,
>> fName));
>>                                 }
>>                         }
>>                 }
>> @@ -855,53 +781,56 @@ public class BackupImportController exte
>>                 log.debug("sourceDirRec PATH " +
>> sourceDirRec.getCanonicalPath());
>>
>>                 if (sourceDirRec.exists()) {
>> -                       File targetDirRec =
>> OmFileHelper.getStreamsHibernateDir();
>> +                       File targetDirRec = getStreamsHibernateDir();
>>
>> -                       FileHelper.copyRec(sourceDirRec, targetDirRec);
>> +                       copyRec(sourceDirRec, targetDirRec);
>>                 }
>>         }
>>
>>         private Long importLongType(String value) {
>> -
>>                 if (value.equals("null") || value.equals("")) {
>>                         return null;
>>                 }
>>
>>                 return Long.valueOf(value).longValue();
>> -
>>         }
>>
>>         private Long getNewId(Long oldId, Maps map) {
>>                 Long newId = oldId;
>>                 switch (map) {
>> -               case USERS:
>> -                       if (usersMap.get(oldId) != null)
>> -                               newId = usersMap.get(oldId);
>> -                       break;
>> -               case ORGANISATIONS:
>> -                       if (organisationsMap.get(oldId) != null)
>> -                               newId = organisationsMap.get(oldId);
>> -                       break;
>> -               case APPOINTMENTS:
>> -                       if (appointmentsMap.get(oldId) != null)
>> -                               newId = appointmentsMap.get(oldId);
>> -                       break;
>> -               case ROOMS:
>> -                       if (roomsMap.get(oldId) != null)
>> -                               newId = roomsMap.get(oldId);
>> -                       break;
>> -               case MESSAGEFOLDERS:
>> -                       if (messageFoldersMap.get(oldId) != null)
>> -                               newId = messageFoldersMap.get(oldId);
>> -                       break;
>> -               case USERCONTACTS:
>> -                       if (userContactsMap.get(oldId) != null)
>> -                               newId = userContactsMap.get(oldId);
>> -                       break;
>> -               default:
>> -                       break;
>> +                       case USERS:
>> +                               if (usersMap.containsKey(oldId)) {
>> +                                       newId = usersMap.get(oldId);
>> +                               }
>> +                               break;
>> +                       case ORGANISATIONS:
>> +                               if (organisationsMap.containsKey(oldId)) {
>> +                                       newId =
>> organisationsMap.get(oldId);
>> +                               }
>> +                               break;
>> +                       case APPOINTMENTS:
>> +                               if (appointmentsMap.containsKey(oldId)) {
>> +                                       newId =
>> appointmentsMap.get(oldId);
>> +                               }
>> +                               break;
>> +                       case ROOMS:
>> +                               if (roomsMap.containsKey(oldId)) {
>> +                                       newId = roomsMap.get(oldId);
>> +                               }
>> +                               break;
>> +                       case MESSAGEFOLDERS:
>> +                               if (messageFoldersMap.containsKey(oldId))
>> {
>> +                                       newId =
>> messageFoldersMap.get(oldId);
>> +                               }
>> +                               break;
>> +                       case USERCONTACTS:
>> +                               if (userContactsMap.containsKey(oldId)) {
>> +                                       newId =
>> userContactsMap.get(oldId);
>> +                               }
>> +                               break;
>> +                       default:
>> +                               break;
>>                 }
>>                 return newId;
>>         }
>> -
>>  }
>>
>>
>>
>
>
> --
> Sebastian Wagner
> https://twitter.com/#!/dead_lock
> http://www.webbase-design.de
> http://www.wagner-sebastian.com
> seba.wagner@gmail.com
>



-- 
WBR
Maxim aka solomax