Author: solomax
Date: Wed Apr  4 18:52:15 2012
New Revision: 1309538

URL: http://svn.apache.org/viewvc?rev=1309538&view=rev
Log:
OPENMEETINGS-111 commons-cli is added, usage is added, bash script improved, 
restore added (not tested)

Modified:
    incubator/openmeetings/trunk/singlewebapp/.classpath
    incubator/openmeetings/trunk/singlewebapp/WebContent/red5/admin.sh
    incubator/openmeetings/trunk/singlewebapp/build.xml
    incubator/openmeetings/trunk/singlewebapp/ivy.xml
    
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/Admin.java
    
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java

Modified: incubator/openmeetings/trunk/singlewebapp/.classpath
URL: 
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/.classpath?rev=1309538&r1=1309537&r2=1309538&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/.classpath (original)
+++ incubator/openmeetings/trunk/singlewebapp/.classpath Wed Apr  4 18:52:15 
2012
@@ -132,5 +132,6 @@
        <classpathentry kind="lib" 
path="build/lib/dtd-generator/trang-jar-20091111.jar"/>
        <classpathentry kind="lib" 
path="build/lib/om/axis2-kernel-jar-1.7.0-SNAPSHOT.jar"/>
        <classpathentry kind="lib" 
path="build/lib/om/axiom-api-bundle-1.2.13-SNAPSHOT.jar"/>
+       <classpathentry kind="lib" 
path="build/red5/dist/commons-cli-jar-1.2.jar"/>
        <classpathentry kind="output" path="build/classes/eclipse"/>
 </classpath>

Modified: incubator/openmeetings/trunk/singlewebapp/WebContent/red5/admin.sh
URL: 
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/WebContent/red5/admin.sh?rev=1309538&r1=1309537&r2=1309538&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/WebContent/red5/admin.sh 
(original)
+++ incubator/openmeetings/trunk/singlewebapp/WebContent/red5/admin.sh Wed Apr  
4 18:52:15 2012
@@ -1,6 +1,7 @@
 #!/bin/bash
+export RED5DIR=$(cd $(dirname "$0"); pwd) 
 
-export 
CLASSPATH=./*:conf:lib/*:webapps/openmeetings/WEB-INF/lib/*:webapps/openmeetings/WEB-INF:webapps/openmeetings/WEB-INF/classes
+export 
CLASSPATH=./*:conf:lib/*:$RED5DIR/webapps/openmeetings/WEB-INF/lib/*:$RED5DIR/webapps/openmeetings/WEB-INF:$RED5DIR/webapps/openmeetings/WEB-INF/classes
 
-java -cp $CLASSPATH org.openmeetings.app.Admin $*
+java -cp "$CLASSPATH" "-Dred5.home=$RED5DIR" org.openmeetings.app.Admin $*
 

Modified: incubator/openmeetings/trunk/singlewebapp/build.xml
URL: 
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/build.xml?rev=1309538&r1=1309537&r2=1309538&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/build.xml (original)
+++ incubator/openmeetings/trunk/singlewebapp/build.xml Wed Apr  4 18:52:15 2012
@@ -399,7 +399,7 @@
 
        <target name="compile" depends="compile.only, prepare" />
 
-       <target name="compile.only" depends="clean.classes, 
-retrieve-mainlibs,-retrieve-om,-retrieve-dtd-generator,-retrieve-junit,resources">
+       <target name="compile.only" depends="clean.classes, 
-retrieve-mainlibs,-retrieve-om,-retrieve-dtd-generator,-retrieve-junit, 
-retrieve-cmdadmin, resources">
                <echo message="Compile main to ${main.out.dir}"/>
                <javac debug="on" debuglevel="lines,vars,source" 
destdir="${main.out.dir}">
                        <src path="${main.src.dir}" />
@@ -668,10 +668,11 @@
        <target name="-availability-check" unless="red5.installed" 
description="Check which libraries need to be retrieved" 
depends="prepare.mkdir">
                <available classpathref="compile.classpath" 
classname="javax.persistence.spi.PersistenceProvider" 
property="mainlib.installed"/>
                <available classpathref="compile.classpath" 
classname="org.apache.axis2.Version" property="om.installed"/>
-               <available classpathref="anakia.classpath" 
classname="org.apache.oro.text.GlobCompiler" property="anakia.installed"/>
                <available classpathref="compile.classpath" 
classname="org.junit.Test" property="junit.installed"/>
-               <available classpathref="rat.classpath" 
classname="org.apache.rat.Report" property="rat.installed"/>
                <available classpathref="compile.classpath" 
classname="com.thaiopensource.relaxng.translate.Driver" 
property="dtd-generator.installed"/>
+               <available classpathref="compile.classpath" 
classname="org.apache.commons.cli.CommandLine" property="cmdadmin.installed"/>
+               <available classpathref="anakia.classpath" 
classname="org.apache.oro.text.GlobCompiler" property="anakia.installed"/>
+               <available classpathref="rat.classpath" 
classname="org.apache.rat.Report" property="rat.installed"/>
                <available classpathref="svntask.classpath" 
classname="org.tmatesoft.svn.core.SVNCommitInfo" property="svntask.installed"/>
                <available file="${laszlo.home}/WEB-INF/lib" type="dir" 
property="laszlo.installed"/>
                <available file="${red5.lib}/red5.sh" type="file" 
property="red5.installed"/>
@@ -817,6 +818,13 @@
                        <param name="ivy.lib.location" value="${laszlo.home}"/>
                </antcall>
        </target>
+       <!-- Check for Command line admin depandencies -->
+       <target name="-retrieve-cmdadmin" unless="cmdadmin.installed" 
description="Retrieves the libraries if needed" depends="-availability-check">
+               <antcall target="-retrieve" inheritAll="true" 
inheritRefs="true">
+                       <param name="ivy.conf.name" value="cmdadmin"/>
+                       <param name="ivy.lib.location" value="${red5.lib}"/>
+               </antcall>
+       </target>
        
        <!-- Clean targets -->
        <!-- Remove classes directory for clean build -->
@@ -848,6 +856,7 @@
                <antcall target="-retrieve-dtd-generator" inheritAll="true" 
inheritRefs="true"/>
                <antcall target="-retrieve-tools.jar" inheritAll="true" 
inheritRefs="true"/>
                <antcall target="-retrieve-openlaszlo" inheritAll="true" 
inheritRefs="true"/>
+               <antcall target="-retrieve-cmdadmin" inheritAll="true" 
inheritRefs="true"/>
                <echo message="db.provider == ${db.provider}"/>
                <copy file="src/META-INF/${db.provider}_persistence.xml" 
tofile="src/META-INF/persistence.xml" overwrite="true"/>
        </target>

Modified: incubator/openmeetings/trunk/singlewebapp/ivy.xml
URL: 
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/ivy.xml?rev=1309538&r1=1309537&r2=1309538&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/ivy.xml (original)
+++ incubator/openmeetings/trunk/singlewebapp/ivy.xml Wed Apr  4 18:52:15 2012
@@ -25,7 +25,8 @@
                <conf name="openmeetings.axis2" extends="openmeetings.ext" 
description="Axis required libraries with dependencies" />
                <conf name="anakia" description="Openmeetings required 
libraries" />
                <conf name="junit" description="Unit testing dependencies" />
-               <conf name="rat" description="Apache Rat dependencies" />
+               <conf name="cmdadmin" description="Command Line Admin 
dependencies" />
+               <conf name="rat" extends="cmdadmin" description="Apache Rat 
dependencies" />
                <conf name="dtd" description="Dtd-generator dependencies" />
                <conf name="svntask" description="Svn task dependencies" />
                <conf name="openlaszlo" description="Openlaszlo dependencies" />
@@ -255,9 +256,6 @@
                <dependency org="org.apache.rat" name="apache-rat-tasks" 
rev="0.8" conf="rat->*" transitive="false">
                        <include type="jar" />
                </dependency>
-               <dependency org="commons-cli" name="commons-cli" rev="1.2" 
conf="rat->*" transitive="false">
-                       <include type="jar" />
-               </dependency>
                <!--  END OF RAT -->
                
                <!--  START OF DTD -->
@@ -285,6 +283,11 @@
                </dependency>
                <!--  END OF openlaszlo -->
                
+               <!--  START OF Command Line Admin -->
+               <dependency org="commons-cli" name="commons-cli" rev="1.2" 
conf="cmdadmin->*" transitive="false">
+                       <include type="jar" />
+               </dependency>
+               <!--  END OF Command Line Admin -->
        </dependencies>
 </ivy-module>
 

Modified: 
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/Admin.java
URL: 
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/Admin.java?rev=1309538&r1=1309537&r2=1309538&view=diff
==============================================================================
--- 
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/Admin.java 
(original)
+++ 
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/Admin.java 
Wed Apr  4 18:52:15 2012
@@ -1,23 +1,66 @@
 package org.openmeetings.app;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.Parser;
+import org.apache.commons.cli.PosixParser;
 import org.openmeetings.servlet.outputhandler.BackupExport;
+import org.openmeetings.servlet.outputhandler.BackupImportController;
 import org.red5.logging.Red5LoggerFactory;
 import org.slf4j.Logger;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 public class Admin {
        private static final Logger log = 
Red5LoggerFactory.getLogger(Admin.class);
+       private SimpleDateFormat sdf = new 
SimpleDateFormat("yyyy-MM-dd_hhmmss");
        private boolean verbose = false;
+       private Options opts = buildOptions();
 
+       @SuppressWarnings("static-access")
+       private Options buildOptions() {
+               Options options = new Options();
+               OptionGroup group = new OptionGroup()
+                       
.addOption(OptionBuilder.withLongOpt("install").withDescription("Fill DB table, 
and make OM usable").create('i'))
+                       
.addOption(OptionBuilder.withLongOpt("backup").withDescription("Backups 
OM").create('b'))
+                       
.addOption(OptionBuilder.withLongOpt("restore").withDescription("Restores 
OM").create('r'))
+                       
.addOption(OptionBuilder.withLongOpt("help").withDescription("print this 
message").create('h'));
+               group.setRequired(true); 
+               options.addOptionGroup(group);
+               
options.addOption(OptionBuilder.withLongOpt("verbose").withDescription("verbose 
error messages").create('v'));
+               
options.addOption(OptionBuilder.withLongOpt("file").hasArg().withDescription("file
 used for backup/restore").create('f'));
+               
options.addOption(OptionBuilder.withLongOpt("exclude-files").withDescription("should
 backup exclude files [default: include]").create());
+               
+               return options;
+       }
+       
        private enum Command {
                install
                , backup
                , restore
+               , usage
+       }
+       
+       private void usage() {
+               new HelpFormatter().printHelp("admin [-h|-i|-b|-r] [options]", 
opts);
        }
        
        private void handleError(String msg, Exception e) {
+               handleError(msg, e, false);
+       }
+       
+       private void handleError(String msg, Exception e, boolean printUsage) {
+               if (printUsage) {
+                       usage();
+               }
                if (verbose) {
                        log.error(msg, e);
                } else {
@@ -26,56 +69,86 @@ public class Admin {
                System.exit(1);
        }
        
-       private String getFile(String[] args) {
-               String result = null;
-               for (int i = 0; i < args.length; ++i) {
-                       String a = args[i];
-                       if ("-file".equals(a)) {
-                               result = args[i + 1];
-                               break;
-                       }
-               }
-               return result;
-       }
-       
-       private void process(String[] args) {
-               String red5Home = "webapps/openmeetings/";
-               for (String a : args) {
-                       if ("-v".equals(a)) {
-                               verbose = true;
-                               break;
-                       }
-               }
+       private ClassPathXmlApplicationContext getApplicationContext() {
                ClassPathXmlApplicationContext applicationContext = null;
                try {
                        applicationContext = new 
ClassPathXmlApplicationContext("openmeetings-applicationContext.xml");
                } catch (Exception e) {
                        handleError("Unable to obtain application context", e);
                }
-
-               Command cmd = null;
+               return applicationContext;
+       }
+       
+       private void process(String[] args) {
+               File omHome = new File(System.getProperty("red5.home"), 
"webapps/openmeetings");
+               
+               Parser parser = new PosixParser();
+               CommandLine cmdl = null;
                try {
-                       cmd = Command.valueOf(args[0]);
-               } catch (Exception e) {
-                       handleError("Failed to get command ", e);
+                       cmdl = parser.parse(opts, args);
+               } catch (ParseException e) {
+                       System.out.println(e.getMessage());
+                       usage();
+                       System.exit(1);
                }
+               verbose = cmdl.hasOption('v');
+
+               Command cmd = Command.usage;
+               if (cmdl.hasOption('i')) {
+                       cmd = Command.install;
+               } else if (cmdl.hasOption('b')) {
+                       cmd = Command.backup;
+               } else if (cmdl.hasOption('r')) {
+                       cmd = Command.restore;
+               }
+
+               ClassPathXmlApplicationContext applicationContext = null;
+               switch(cmd) {
+                       case install:
+                       case backup:
+                       case restore:
+                               applicationContext = getApplicationContext();
+                       default:
+                               //noop
+               };
+               String file = cmdl.getOptionValue('f', "");
                switch(cmd) {
                        case install:
                                break;
                        case backup:
                                try {
-                                       //FIXME !!!! cleanup
-                                       //FIXME hardcoded paths
-                                       BackupExport export = 
(BackupExport)applicationContext.getBean("backupExport");
-                                       String backup_dir = red5Home + 
"uploadtemp/" + System.currentTimeMillis() + "/";
-                                       new File(backup_dir).mkdirs();
-                                       export.performExport(getFile(args), 
backup_dir, true, red5Home);
-                                       export.deleteDirectory(new 
File(backup_dir));
+                                       if (!cmdl.hasOption('f')) {
+                                               file = "backup_" + 
sdf.format(new Date()) + ".zip";
+                                               System.out.println("File name 
was not specified, '" + file + "' will be used");
+                                       }
+                                       boolean includeFiles = 
Boolean.getBoolean(cmdl.getOptionValue("exclude-files", "true"));
+                                       BackupExport export = 
applicationContext.getBean(BackupExport.class);
+                                       File backup_dir = new File(omHome, 
"uploadtemp/" + System.currentTimeMillis());
+                                       backup_dir.mkdirs();
+                                       export.performExport(file, 
backup_dir.getAbsolutePath(), includeFiles, omHome.getAbsolutePath());
+                                       export.deleteDirectory(backup_dir);
+                                       backup_dir.delete();
                                } catch (Exception e) {
                                        handleError("Backup failed", e);
                                }
                                break;
                        case restore:
+                               try {
+                                       File backup = new File(file);
+                                       if (!cmdl.hasOption('f') || 
!backup.exists() || !backup.isFile()) {
+                                               System.out.println("File should 
be specified, and point the the existent zip file");
+                                               usage();
+                                               System.exit(1);
+                                       }
+                                       BackupImportController importCtrl = 
applicationContext.getBean(BackupImportController.class);
+                                       importCtrl.performImport(new 
FileInputStream(backup), omHome.getAbsolutePath(), backup.getAbsolutePath());
+                               } catch (Exception e) {
+                                       handleError("Restore failed", e);
+                               }
+                               break;
+                       case usage:
+                       default:
+                               usage();
                                break;
                }
                

Modified: 
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java
URL: 
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java?rev=1309538&r1=1309537&r2=1309538&view=diff
==============================================================================
--- 
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java
 (original)
+++ 
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java
 Wed Apr  4 18:52:15 2012
@@ -151,6 +151,283 @@ public class BackupImportController exte
                USERS, ORGANISATIONS, APPOINTMENTS, ROOMS, MESSAGEFOLDERS, 
USERCONTACTS, FILEEXPLORERITEMS
        };
 
+       public void performImport(InputStream is, String current_dir, String 
completeName) throws Exception {
+               ZipInputStream zipinputstream = new ZipInputStream(is);
+               byte[] buf = new byte[1024];
+
+               ZipEntry zipentry = zipinputstream.getNextEntry();
+
+               while (zipentry != null) {
+                       // for each entry to be extracted
+                       String entryName = completeName + File.separatorChar
+                                       + zipentry.getName();
+                       entryName = entryName.replace('/', File.separatorChar);
+                       entryName = entryName.replace('\\', File.separatorChar);
+
+                       // log.debug("entryname " + entryName);
+
+                       // zipentry.get
+
+                       int n;
+                       FileOutputStream fileoutputstream;
+                       File newFile = new File(entryName);
+
+                       if (zipentry.isDirectory()) {
+                               if (!newFile.mkdir()) {
+                                       break;
+                               }
+                               zipentry = zipinputstream.getNextEntry();
+                               continue;
+                       }
+
+                       File fentryName = new File(entryName);
+
+                       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();
+
+                               }
+
+                       }
+
+                       fileoutputstream = new FileOutputStream(entryName);
+
+                       while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
+                               fileoutputstream.write(buf, 0, n);
+                       }
+
+                       fileoutputstream.close();
+                       zipinputstream.closeEntry();
+                       zipentry = zipinputstream.getNextEntry();
+
+               }// while
+
+               zipinputstream.close();
+
+               /*
+                * ##################### Import Organizations
+                */
+               String orgListXML = completeName + File.separatorChar
+                               + "organizations.xml";
+               File orgFile = new File(orgListXML);
+               if (!orgFile.exists()) {
+                       throw new Exception("organizations.xml missing");
+               }
+               this.importOrganizsations(orgFile);
+
+               log.info("Organizations import complete, starting user import");
+
+               /*
+                * ##################### Import Users
+                */
+               String userListXML = completeName + File.separatorChar
+                               + "users.xml";
+               File userFile = new File(userListXML);
+               if (!userFile.exists()) {
+                       throw new Exception("users.xml missing");
+               }
+               this.importUsers(userFile);
+
+               log.info("Users import complete, starting room import");
+
+               /*
+                * ##################### Import Rooms
+                */
+               String roomListXML = completeName + File.separatorChar
+                               + "rooms.xml";
+               File roomFile = new File(roomListXML);
+               if (!roomFile.exists()) {
+                       throw new Exception("rooms.xml missing");
+               }
+               this.importRooms(roomFile);
+
+               log.info("Room import complete, starting room organizations 
import");
+
+               /*
+                * ##################### Import Room Organisations
+                */
+               String orgRoomListXML = completeName + File.separatorChar
+                               + "rooms_organisation.xml";
+               File orgRoomListFile = new File(orgRoomListXML);
+               if (!orgRoomListFile.exists()) {
+                       throw new Exception("rooms_organisation.xml missing");
+               }
+               this.importOrgRooms(orgRoomListFile);
+
+               log.info("Room organizations import complete, starting 
appointement import");
+
+               /*
+                * ##################### Import Appointements
+                */
+               String appointementListXML = completeName
+                               + File.separatorChar + "appointements.xml";
+               File appointementListFile = new File(appointementListXML);
+               if (!appointementListFile.exists()) {
+                       throw new Exception("appointements.xml missing");
+               }
+               this.importAppointements(appointementListFile);
+
+               log.info("Appointement import complete, starting meeting 
members import");
+
+               /*
+                * ##################### Import MeetingMembers
+                * 
+                * Reminder Invitations will be NOT send!
+                */
+               String meetingmembersListXML = completeName
+                               + File.separatorChar + "meetingmembers.xml";
+               File meetingmembersListFile = new File(
+                               meetingmembersListXML);
+               if (!meetingmembersListFile.exists()) {
+                       throw new Exception("meetingmembersListFile missing");
+               }
+               this.importMeetingmembers(meetingmembersListFile);
+
+               log.info("Meeting members import complete, starting ldap config 
import");
+
+               /*
+                * ##################### Import LDAP Configs
+                */
+               String ldapConfigListXML = completeName
+                               + File.separatorChar + "ldapconfigs.xml";
+               File ldapConfigListFile = new File(ldapConfigListXML);
+               if (!ldapConfigListFile.exists()) {
+                       log.debug("meetingmembersListFile missing");
+                       // throw new Exception
+                       // ("meetingmembersListFile missing");
+               } else {
+                       this.importLdapConfig(ldapConfigListFile);
+               }
+
+               log.info("Ldap config import complete, starting recordings 
import");
+
+               /*
+                * ##################### Import Recordings
+                */
+               String flvRecordingsListXML = completeName
+                               + File.separatorChar + "flvRecordings.xml";
+               File flvRecordingsListFile = new File(flvRecordingsListXML);
+               if (!flvRecordingsListFile.exists()) {
+                       log.debug("flvRecordingsListFile missing");
+                       // throw new Exception
+                       // ("meetingmembersListFile missing");
+               } else {
+                       this.importFlvRecordings(flvRecordingsListFile);
+               }
+
+               log.info("FLVrecording import complete, starting private 
message folder import");
+
+               /*
+                * ##################### Import Private Message Folders
+                */
+               String privateMessageFoldersXML = completeName
+                               + File.separatorChar + 
"privateMessageFolder.xml";
+               File privateMessageFoldersFile = new File(
+                               privateMessageFoldersXML);
+               if (!privateMessageFoldersFile.exists()) {
+                       log.debug("privateMessageFoldersFile missing");
+                       // throw new Exception
+                       // ("meetingmembersListFile missing");
+               } else {
+                       
this.importPrivateMessageFolders(privateMessageFoldersFile);
+               }
+
+               log.info("Private message folder import complete, starting 
private message import");
+
+               /*
+                * ##################### Import Private Messages
+                */
+               String privateMessagesXML = completeName
+                               + File.separatorChar + "privateMessages.xml";
+               File privateMessagesFile = new File(privateMessagesXML);
+               if (!privateMessagesFile.exists()) {
+                       log.debug("privateMessagesFile missing");
+                       // throw new Exception
+                       // ("meetingmembersListFile missing");
+               } else {
+                       this.importPrivateMessages(privateMessagesFile);
+               }
+
+               log.info("Private message import complete, starting usercontact 
import");
+
+               /*
+                * ##################### Import User Contacts
+                */
+               String userContactsXML = completeName + File.separatorChar
+                               + "userContacts.xml";
+               File userContactsFile = new File(userContactsXML);
+               if (!userContactsFile.exists()) {
+                       log.debug("userContactsFile missing");
+                       // throw new Exception
+                       // ("meetingmembersListFile missing");
+               } else {
+                       this.importUserContacts(userContactsFile);
+               }
+
+               log.info("Usercontact import complete, starting file explorer 
item import");
+
+               /*
+                * ##################### Import File-Explorer Items
+                */
+               String fileExplorerListXML = completeName
+                               + File.separatorChar + "fileExplorerItems.xml";
+               File fileExplorerListFile = new File(fileExplorerListXML);
+               if (!fileExplorerListFile.exists()) {
+                       log.debug("fileExplorerListFile missing");
+                       // throw new Exception
+                       // ("meetingmembersListFile missing");
+               } else {
+                       this.importFileExplorerItems(fileExplorerListFile);
+               }
+
+               log.info("File explorer item import complete, starting file 
poll import");
+
+               /*
+                * ##################### Import File-Explorer Items
+                */
+               String roomPollListXML = completeName + File.separatorChar
+                               + "roompolls.xml";
+               File roomPollListFile = new File(roomPollListXML);
+               if (!roomPollListFile.exists()) {
+                       log.debug("roomPollListFile missing");
+               } else {
+                       this.importRoomPolls(roomPollListFile);
+               }
+
+               log.info("Poll import complete, starting copy of files and 
folders");
+
+               /*
+                * ##################### Import real files and folders
+                */
+               importFolders(current_dir, completeName);
+
+               log.info("File explorer item import complete, clearing temp 
files");
+       }
+       
     @RequestMapping(value = "/backup.upload", method = RequestMethod.POST)
        public void service(HttpServletRequest request,
                        HttpServletResponse httpServletResponse)
@@ -197,283 +474,8 @@ public class BackupImportController exte
                        f.mkdir();
 
                        log.debug("##### WRITE FILE TO: " + completeName);
-
-                       ZipInputStream zipinputstream = new ZipInputStream(is);
-                       byte[] buf = new byte[1024];
-
-                       ZipEntry zipentry = zipinputstream.getNextEntry();
-
-                       while (zipentry != null) {
-                               // for each entry to be extracted
-                               String entryName = completeName + 
File.separatorChar
-                                               + zipentry.getName();
-                               entryName = entryName.replace('/', 
File.separatorChar);
-                               entryName = entryName.replace('\\', 
File.separatorChar);
-
-                               // log.debug("entryname " + entryName);
-
-                               // zipentry.get
-
-                               int n;
-                               FileOutputStream fileoutputstream;
-                               File newFile = new File(entryName);
-
-                               if (zipentry.isDirectory()) {
-                                       if (!newFile.mkdir()) {
-                                               break;
-                                       }
-                                       zipentry = 
zipinputstream.getNextEntry();
-                                       continue;
-                               }
-
-                               File fentryName = new File(entryName);
-
-                               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();
-
-                                       }
-
-                               }
-
-                               fileoutputstream = new 
FileOutputStream(entryName);
-
-                               while ((n = zipinputstream.read(buf, 0, 1024)) 
> -1) {
-                                       fileoutputstream.write(buf, 0, n);
-                               }
-
-                               fileoutputstream.close();
-                               zipinputstream.closeEntry();
-                               zipentry = zipinputstream.getNextEntry();
-
-                       }// while
-
-                       zipinputstream.close();
-
-                       /*
-                        * ##################### Import Organizations
-                        */
-                       String orgListXML = completeName + File.separatorChar
-                                       + "organizations.xml";
-                       File orgFile = new File(orgListXML);
-                       if (!orgFile.exists()) {
-                               throw new Exception("organizations.xml 
missing");
-                       }
-                       this.importOrganizsations(orgFile);
-
-                       log.info("Organizations import complete, starting user 
import");
-
-                       /*
-                        * ##################### Import Users
-                        */
-                       String userListXML = completeName + File.separatorChar
-                                       + "users.xml";
-                       File userFile = new File(userListXML);
-                       if (!userFile.exists()) {
-                               throw new Exception("users.xml missing");
-                       }
-                       this.importUsers(userFile);
-
-                       log.info("Users import complete, starting room import");
-
-                       /*
-                        * ##################### Import Rooms
-                        */
-                       String roomListXML = completeName + File.separatorChar
-                                       + "rooms.xml";
-                       File roomFile = new File(roomListXML);
-                       if (!roomFile.exists()) {
-                               throw new Exception("rooms.xml missing");
-                       }
-                       this.importRooms(roomFile);
-
-                       log.info("Room import complete, starting room 
organizations import");
-
-                       /*
-                        * ##################### Import Room Organisations
-                        */
-                       String orgRoomListXML = completeName + 
File.separatorChar
-                                       + "rooms_organisation.xml";
-                       File orgRoomListFile = new File(orgRoomListXML);
-                       if (!orgRoomListFile.exists()) {
-                               throw new Exception("rooms_organisation.xml 
missing");
-                       }
-                       this.importOrgRooms(orgRoomListFile);
-
-                       log.info("Room organizations import complete, starting 
appointement import");
-
-                       /*
-                        * ##################### Import Appointements
-                        */
-                       String appointementListXML = completeName
-                                       + File.separatorChar + 
"appointements.xml";
-                       File appointementListFile = new 
File(appointementListXML);
-                       if (!appointementListFile.exists()) {
-                               throw new Exception("appointements.xml 
missing");
-                       }
-                       this.importAppointements(appointementListFile);
-
-                       log.info("Appointement import complete, starting 
meeting members import");
-
-                       /*
-                        * ##################### Import MeetingMembers
-                        * 
-                        * Reminder Invitations will be NOT send!
-                        */
-                       String meetingmembersListXML = completeName
-                                       + File.separatorChar + 
"meetingmembers.xml";
-                       File meetingmembersListFile = new File(
-                                       meetingmembersListXML);
-                       if (!meetingmembersListFile.exists()) {
-                               throw new Exception("meetingmembersListFile 
missing");
-                       }
-                       this.importMeetingmembers(meetingmembersListFile);
-
-                       log.info("Meeting members import complete, starting 
ldap config import");
-
-                       /*
-                        * ##################### Import LDAP Configs
-                        */
-                       String ldapConfigListXML = completeName
-                                       + File.separatorChar + 
"ldapconfigs.xml";
-                       File ldapConfigListFile = new File(ldapConfigListXML);
-                       if (!ldapConfigListFile.exists()) {
-                               log.debug("meetingmembersListFile missing");
-                               // throw new Exception
-                               // ("meetingmembersListFile missing");
-                       } else {
-                               this.importLdapConfig(ldapConfigListFile);
-                       }
-
-                       log.info("Ldap config import complete, starting 
recordings import");
-
-                       /*
-                        * ##################### Import Recordings
-                        */
-                       String flvRecordingsListXML = completeName
-                                       + File.separatorChar + 
"flvRecordings.xml";
-                       File flvRecordingsListFile = new 
File(flvRecordingsListXML);
-                       if (!flvRecordingsListFile.exists()) {
-                               log.debug("flvRecordingsListFile missing");
-                               // throw new Exception
-                               // ("meetingmembersListFile missing");
-                       } else {
-                               this.importFlvRecordings(flvRecordingsListFile);
-                       }
-
-                       log.info("FLVrecording import complete, starting 
private message folder import");
-
-                       /*
-                        * ##################### Import Private Message Folders
-                        */
-                       String privateMessageFoldersXML = completeName
-                                       + File.separatorChar + 
"privateMessageFolder.xml";
-                       File privateMessageFoldersFile = new File(
-                                       privateMessageFoldersXML);
-                       if (!privateMessageFoldersFile.exists()) {
-                               log.debug("privateMessageFoldersFile missing");
-                               // throw new Exception
-                               // ("meetingmembersListFile missing");
-                       } else {
-                               
this.importPrivateMessageFolders(privateMessageFoldersFile);
-                       }
-
-                       log.info("Private message folder import complete, 
starting private message import");
-
-                       /*
-                        * ##################### Import Private Messages
-                        */
-                       String privateMessagesXML = completeName
-                                       + File.separatorChar + 
"privateMessages.xml";
-                       File privateMessagesFile = new File(privateMessagesXML);
-                       if (!privateMessagesFile.exists()) {
-                               log.debug("privateMessagesFile missing");
-                               // throw new Exception
-                               // ("meetingmembersListFile missing");
-                       } else {
-                               this.importPrivateMessages(privateMessagesFile);
-                       }
-
-                       log.info("Private message import complete, starting 
usercontact import");
-
-                       /*
-                        * ##################### Import User Contacts
-                        */
-                       String userContactsXML = completeName + 
File.separatorChar
-                                       + "userContacts.xml";
-                       File userContactsFile = new File(userContactsXML);
-                       if (!userContactsFile.exists()) {
-                               log.debug("userContactsFile missing");
-                               // throw new Exception
-                               // ("meetingmembersListFile missing");
-                       } else {
-                               this.importUserContacts(userContactsFile);
-                       }
-
-                       log.info("Usercontact import complete, starting file 
explorer item import");
-
-                       /*
-                        * ##################### Import File-Explorer Items
-                        */
-                       String fileExplorerListXML = completeName
-                                       + File.separatorChar + 
"fileExplorerItems.xml";
-                       File fileExplorerListFile = new 
File(fileExplorerListXML);
-                       if (!fileExplorerListFile.exists()) {
-                               log.debug("fileExplorerListFile missing");
-                               // throw new Exception
-                               // ("meetingmembersListFile missing");
-                       } else {
-                               
this.importFileExplorerItems(fileExplorerListFile);
-                       }
-
-                       log.info("File explorer item import complete, starting 
file poll import");
-
-                       /*
-                        * ##################### Import File-Explorer Items
-                        */
-                       String roomPollListXML = completeName + 
File.separatorChar
-                                       + "roompolls.xml";
-                       File roomPollListFile = new File(roomPollListXML);
-                       if (!roomPollListFile.exists()) {
-                               log.debug("roomPollListFile missing");
-                       } else {
-                               this.importRoomPolls(roomPollListFile);
-                       }
-
-                       log.info("Poll import complete, starting copy of files 
and folders");
-
-                       /*
-                        * ##################### Import real files and folders
-                        */
-                       importFolders(current_dir, completeName);
-
-                       log.info("File explorer item import complete, clearing 
temp files");
-
-                       this.deleteDirectory(f);
+                       performImport(is, current_dir, completeName);
+                       deleteDirectory(f);
 
                        LinkedHashMap<String, Object> hs = new 
LinkedHashMap<String, Object>();
                        hs.put("user", usersDao.getUser(info.userId));


Reply via email to