You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2012/04/25 12:35:09 UTC

svn commit: r1330188 - in /incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings: app/installation/ImportInitvalues.java cli/Admin.java servlet/outputhandler/Install.java utils/ImportHelper.java

Author: solomax
Date: Wed Apr 25 10:35:08 2012
New Revision: 1330188

URL: http://svn.apache.org/viewvc?rev=1330188&view=rev
Log:
OPENMEETINGS-111 tz issues was fixed; options to install OM from backup provided is added.

Modified:
    incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
    incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
    incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
    incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java

Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java?rev=1330188&r1=1330187&r2=1330188&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java Wed Apr 25 10:35:08 2012
@@ -768,8 +768,7 @@ public class ImportInitvalues {
 		List<OmTimeZone> omTimeZones = new LinkedList<OmTimeZone>();
 
 		SAXReader reader = new SAXReader();
-		Document document = reader.read(filePath
-				+ ImportInitvalues.nameOfTimeZoneFile);
+		Document document = reader.read(new File(filePath, ImportInitvalues.nameOfTimeZoneFile));
 
 		Element root = document.getRootElement();
 
@@ -960,8 +959,7 @@ public class ImportInitvalues {
 	}
 	// ------------------------------------------------------------------------------
 
-	public void loadAll(String filePath, InstallationConfig cfg, String username,
-			String userpass, String useremail, String groupame, String timeZone) throws Exception {
+	public void loadSystem(String filePath, InstallationConfig cfg) throws Exception {
 		loadMainMenu();
 		loadErrorMappingsFromXML(filePath);
 		loadInitLanguages(filePath);
@@ -974,7 +972,12 @@ public class ImportInitvalues {
 		loadPollTypes();
 
 		loadConfiguration(cfg);
+	}
+	
+	public void loadAll(String filePath, InstallationConfig cfg, String username,
+			String userpass, String useremail, String groupame, String timeZone) throws Exception {
 		
+		loadSystem(filePath, cfg);
 		loadInitUserAndOrganisation(username,
 				userpass, useremail, groupame, timeZone, cfg.defaultLangId);
 		

Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java?rev=1330188&r1=1330187&r2=1330188&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java Wed Apr 25 10:35:08 2012
@@ -9,6 +9,7 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Date;
 import java.util.Enumeration;
+import java.util.Map;
 import java.util.Set;
 
 import javax.mail.internet.AddressException;
@@ -27,15 +28,14 @@ import org.apache.commons.cli.Parser;
 import org.apache.commons.cli.PosixParser;
 import org.apache.openjpa.jdbc.meta.MappingTool;
 import org.openmeetings.app.OpenmeetingsVariables;
-import org.openmeetings.app.data.basic.dao.OmTimeZoneDaoImpl;
 import org.openmeetings.app.data.file.FileUtils;
 import org.openmeetings.app.documents.InstallationDocumentHandler;
 import org.openmeetings.app.installation.ImportInitvalues;
 import org.openmeetings.app.installation.InstallationConfig;
-import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
 import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
 import org.openmeetings.servlet.outputhandler.BackupExport;
 import org.openmeetings.servlet.outputhandler.BackupImportController;
+import org.openmeetings.utils.ImportHelper;
 import org.openmeetings.utils.OMContextListener;
 import org.openmeetings.utils.mail.MailUtil;
 import org.openmeetings.utils.math.CalendarPatterns;
@@ -49,6 +49,8 @@ public class Admin {
 	private boolean verbose = false;
 	private InstallationConfig cfg = null;
 	private Options opts = null;
+	private CommandLine cmdl = null;
+	File omHome = null;
 
 	private Admin() {
 		cfg = new InstallationConfig();
@@ -69,12 +71,12 @@ public class Admin {
 		options.addOption(new OmOption(null, "v", "verbose", false, "verbose error messages"));
 		//backup/restore
 		options.addOption(new OmOption("b", null, "exclude-files", false, "should backup exclude files [default: include]", true));
-		options.addOption(new OmOption("b,r", "file", null, true, "file used for backup/restore", "b"));
+		options.addOption(new OmOption("b,r,i", "file", null, true, "file used for backup/restore/install", "b"));
 		//install
-		options.addOption(new OmOption("i", "user", null, true, "Login name of the default user, minimum " + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters"));
-		options.addOption(new OmOption("i", "email", null, true, "Email of the default user"));
-		options.addOption(new OmOption("i", "group", null, true, "The name of the default user group"));
-		options.addOption(new OmOption("i", "tz", null, true, "Default server time zone, and time zone for the selected user [for ex: 'GMT+10', '-2', 'Chicago']"));
+		options.addOption(new OmOption("i", "user", null, true, "Login name of the default user, minimum " + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (mutually exclusive with 'file')"));
+		options.addOption(new OmOption("i", "email", null, true, "Email of the default user (mutually exclusive with 'file')"));
+		options.addOption(new OmOption("i", "group", null, true, "The name of the default user group (mutually exclusive with 'file')"));
+		options.addOption(new OmOption("i", "tz", null, true, "Default server time zone, and time zone for the selected user (mutually exclusive with 'file')"));
 		options.addOption(new OmOption("i", null, "password", true, "Password of the default user, minimum " + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (will be prompted if not set)", true));
 		options.addOption(new OmOption("i", null, "system-email-address", true, "System e-mail address [default: " + cfg.mailReferer + "]", true));
 		options.addOption(new OmOption("i", null, "smtp-server", true, "SMTP server for outgoing e-mails [default: " + cfg.smtpServer + "]", true));
@@ -242,11 +244,10 @@ public class Admin {
 	private void process(String[] args) {
 		String ctxName = System.getProperty("context", "openmeetings");
 		File home = new File(System.getenv("RED5_HOME"));
-		File omHome = new File(new File(home, "webapps"), ctxName);
+		omHome = new File(new File(home, "webapps"), ctxName);
 		File omUploadTemp = new File(omHome, OpenmeetingsVariables.UPLOAD_TEMP_DIR);
 		
 		Parser parser = new PosixParser();
-		CommandLine cmdl = null;
 		try {
 			cmdl = parser.parse(opts, args);
 		} catch (ParseException e) {
@@ -271,9 +272,10 @@ public class Admin {
 		switch(cmd) {
 			case install:
 				try {
-					String login = cmdl.getOptionValue("user");
-					String email = cmdl.getOptionValue("email");
-					String group = cmdl.getOptionValue("group");
+					if (cmdl.hasOption("file") && (cmdl.hasOption("user") || cmdl.hasOption("email") || cmdl.hasOption("group"))) {
+						System.out.println("Please specify even 'file' option or 'admin user'.");
+						System.exit(1);
+					}
 					//TODO commented for now, since not in use boolean force = cmdl.hasOption("force");
 					if (cmdl.hasOption("skip-default-rooms")) {
 						cfg.createDefaultRooms = "0";
@@ -299,33 +301,7 @@ public class Admin {
 					if (cmdl.hasOption("email-use-tls")) {
 						cfg.mailUseTls = "1";
 					}
-					if (login == null || login.length() < InstallationConfig.USER_LOGIN_MINIMUM_LENGTH) {
-						System.out.println("User login was not provided, or too short, should be at least " + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " character long.");
-						System.exit(1);
-					}
-					
-					try {
-						if (!MailUtil.matches(email)) {
-						    throw new AddressException("Invalid address");
-						}
-						new InternetAddress(email, true);
-					} catch (AddressException ae) {
-						System.out.println("Please provide non-empty valid email: '" + email + "' is not valid.");
-						System.exit(1);
-					}
-					if (group == null || login.length() < 1) {
-						System.out.println("User group was not provided, or too short, should be at least 1 character long.");
-						System.exit(1);
-					}
-					String pass = cmdl.getOptionValue("password");
-					if (pass == null || pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH) {
-						System.out.print("Please enter password:");
-						pass = new BufferedReader(new InputStreamReader(System.in)).readLine();
-						if (pass == null || pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH) {
-							System.out.println("Password was not provided, or too short, should be at least " + InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH + " character long.");
-							System.exit(1);
-						}
-					}
+					String langPath = new File(omHome, ImportInitvalues.languageFolderName).getAbsolutePath(); //FIXME need to be moved to helper
 					ConnectionProperties connectionProperties = new ConnectionProperties();
 					if (cmdl.hasOption("db-type") || cmdl.hasOption("db-host") || cmdl.hasOption("db-port") || cmdl.hasOption("db-name") || cmdl.hasOption("db-user") || cmdl.hasOption("db-pass")) {
 						String dbType = cmdl.getOptionValue("db-type", "derby");
@@ -342,30 +318,18 @@ public class Admin {
 								, connectionProperties
 								);
 					}
-					
-					if(cmdl.hasOption("drop")) {	
-						String[] mappingToolArgs = {"-sa", "drop", "-p", omHome.getPath() + "/WEB-INF/classes/META-INF/persistence.xml",
-								"-connectionDriverName", connectionProperties.getDriverName(), "-connectionURL", connectionProperties.getConnectionURL(),
-								"-connectionUserName", connectionProperties.getConnectionLogin(), "-connectionPassword", connectionProperties.getConnectionPass()};
-						MappingTool.main(mappingToolArgs);
-					}
-
 					ClassPathXmlApplicationContext ctx = getApplicationContext(ctxName);
-					OmTimeZoneDaoImpl tzDao =  ctx.getBean(OmTimeZoneDaoImpl.class);
-					String tz = null;
-					if (cmdl.hasOption("tz")) {
-						tz = cmdl.getOptionValue("tz");
-						tz = tzDao.getOmTimeZone(tz) == null ? null : tz;
-					}
-					if (tz == null) {
-						System.out.println("Please enter timezone, Possible timezones are:");
-						for (OmTimeZone omTz : tzDao.getOmTimeZones()) {
-							System.out.println(omTz.getJname());
-						}
-						System.exit(1);
-					}
 					ImportInitvalues importInit = ctx.getBean(ImportInitvalues.class);
-					importInit.loadAll(new File(omHome, ImportInitvalues.languageFolderName).getAbsolutePath(), cfg, login, pass, email, group, tz);
+					if (cmdl.hasOption("file")) {
+						File backup = checkRestoreFile(file);
+						dropDB(connectionProperties);
+						importInit.loadSystem(langPath, cfg); 
+						restoreOm(ctxName, backup);
+					} else {
+						AdminUserDetails admin = checkAdminDetails(importInit, langPath);
+						dropDB(connectionProperties);
+						importInit.loadAll(langPath, cfg, admin.login, admin.pass, admin.email, admin.group, admin.tz);
+					}					
 					
 					File installerFile = new File(new File(home, ScopeApplicationAdapter.configDirName), InstallationDocumentHandler.installFileName);
 					InstallationDocumentHandler.getInstance().createDocument(installerFile.getAbsolutePath(), 1);
@@ -392,19 +356,7 @@ public class Admin {
 				}
 				break;
 			case restore:
-				try {
-					File backup = new File(file);
-					if (!cmdl.hasOption("file") || !backup.exists() || !backup.isFile()) {
-						System.out.println("File should be specified, and point the existent zip file");
-						usage();
-						System.exit(1);
-					}
-					
-					BackupImportController importCtrl = getApplicationContext(ctxName).getBean(BackupImportController.class);
-					importCtrl.performImport(new FileInputStream(backup), omHome.getAbsolutePath());
-				} catch (Exception e) {
-					handleError("Restore failed", e);
-				}
+				restoreOm(ctxName, checkRestoreFile(file));
 				break;
 			case files:
 				try {
@@ -451,6 +403,95 @@ public class Admin {
 		System.exit(0);
 	}
 	
+	private class AdminUserDetails {
+		String login = null;
+		String email = null;
+		String group = null;
+		String pass = null;
+		String tz = null;
+	}
+	
+	private AdminUserDetails checkAdminDetails(ImportInitvalues importInit, String langPath) throws Exception {
+		AdminUserDetails admin = new AdminUserDetails();
+		admin.login = cmdl.getOptionValue("user");
+		admin.email = cmdl.getOptionValue("email");
+		admin.group = cmdl.getOptionValue("group");
+		if (admin.login == null || admin.login.length() < InstallationConfig.USER_LOGIN_MINIMUM_LENGTH) {
+			System.out.println("User login was not provided, or too short, should be at least " + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " character long.");
+			System.exit(1);
+		}
+		
+		try {
+			if (!MailUtil.matches(admin.email)) {
+			    throw new AddressException("Invalid address");
+			}
+			new InternetAddress(admin.email, true);
+		} catch (AddressException ae) {
+			System.out.println("Please provide non-empty valid email: '" + admin.email + "' is not valid.");
+			System.exit(1);
+		}
+		if (admin.group == null || admin.group.length() < 1) {
+			System.out.println("User group was not provided, or too short, should be at least 1 character long: " + admin.group);
+			System.exit(1);
+		}
+		admin.pass = cmdl.getOptionValue("password");
+		if (checkPassword(admin.pass)) {
+			System.out.print("Please enter password:");
+			admin.pass = new BufferedReader(new InputStreamReader(System.in)).readLine();
+			if (checkPassword(admin.pass)) {
+				System.out.println("Password was not provided, or too short, should be at least " + InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH + " character long.");
+				System.exit(1);
+			}
+		}
+		Map<String, String> tzMap = ImportHelper.getAllTimeZones(importInit.getTimeZones(langPath));
+		admin.tz = null;
+		if (cmdl.hasOption("tz")) {
+			admin.tz = cmdl.getOptionValue("tz");
+			admin.tz = tzMap.containsKey(admin.tz) ? admin.tz : null;
+		}
+		if (admin.tz == null) {
+			System.out.println("Please enter timezone, Possible timezones are:");
+			for (String tzJname : tzMap.keySet()) {
+				System.out.println(tzJname);
+			}
+			System.exit(1);
+		}
+		return admin;
+	}
+	
+	private boolean checkPassword(String pass) {
+		return (pass == null || pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH);
+	}
+	
+	private void dropDB(ConnectionProperties props) throws Exception {
+		if(cmdl.hasOption("drop")) {	
+			String[] mappingToolArgs = {"-sa", "drop", "-p", omHome.getAbsolutePath() + "/WEB-INF/classes/META-INF/persistence.xml",
+					"-connectionDriverName", props.getDriverName(), "-connectionURL", props.getConnectionURL(),
+					"-connectionUserName", props.getConnectionLogin(), "-connectionPassword", props.getConnectionPass()};
+			MappingTool.main(mappingToolArgs);
+		}
+	}
+	
+	private File checkRestoreFile(String file) {
+		File backup = new File(file);
+		if (!cmdl.hasOption("file") || !backup.exists() || !backup.isFile()) {
+			System.out.println("File should be specified, and point the existent zip file");
+			usage();
+			System.exit(1);
+		}
+		
+		return backup;
+	}
+	
+	private void restoreOm(String ctxName, File backup) {
+		try {
+			BackupImportController importCtrl = getApplicationContext(ctxName).getBean(BackupImportController.class);
+			importCtrl.performImport(new FileInputStream(backup), omHome.getAbsolutePath());
+		} catch (Exception e) {
+			handleError("Restore failed", e);
+		}
+	}
+	
 	public static void main(String[] args) {
 		new Admin().process(args);
 	}

Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java?rev=1330188&r1=1330187&r2=1330188&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java Wed Apr 25 10:35:08 2012
@@ -38,6 +38,7 @@ import org.openmeetings.app.installation
 import org.openmeetings.app.installation.InstallationConfig;
 import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
 import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
+import org.openmeetings.utils.ImportHelper;
 import org.red5.logging.Red5LoggerFactory;
 import org.slf4j.Logger;
 import org.springframework.context.ApplicationContext;
@@ -117,22 +118,14 @@ public class Install extends VelocityVie
 		allFonts.put("Verdana", "Verdana");
 		allFonts.put("Arial", "Arial");
 
-		LinkedHashMap<String, String> allTimeZones = new LinkedHashMap<String, String>();
 		List<OmTimeZone> omTimeZoneList = getImportInitvalues()
 				.getTimeZones(filePath);
-		log.debug("omTimeZoneList :: " + omTimeZoneList.size());
-		for (OmTimeZone omTimeZone : omTimeZoneList) {
-			String labelName = omTimeZone.getJname() + " ("
-					+ omTimeZone.getLabel() + ")";
-			log.debug("labelName :: " + labelName);
-			allTimeZones.put(omTimeZone.getJname(), labelName);
-		}
 
 		Template tpl = super.getTemplate("install_step1_"
 				+ lang + ".vm");
 		ctx.put("allLanguages", allLanguages);
 		ctx.put("allFonts", allFonts);
-		ctx.put("allTimeZones", allTimeZones);
+		ctx.put("allTimeZones", ImportHelper.getAllTimeZones(omTimeZoneList));
 		StringWriter writer = new StringWriter();
 		tpl.merge(ctx, writer);
 

Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java?rev=1330188&r1=1330187&r2=1330188&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java Wed Apr 25 10:35:08 2012
@@ -18,9 +18,13 @@
  */
 package org.openmeetings.utils;
 
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
 import org.openmeetings.app.OpenmeetingsVariables;
 import org.openmeetings.app.data.basic.Configurationmanagement;
-import org.openmeetings.app.persistence.beans.basic.Configuration;
+import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
 import org.red5.logging.Red5LoggerFactory;
 import org.slf4j.Logger;
 
@@ -31,22 +35,27 @@ public class ImportHelper {
 
 	public static final int getMaxUploadSize(
 			Configurationmanagement cfgManagement) {
-		return getMaxUploadSize(cfgManagement, 3L);
-	}
-
-	public static final int getMaxUploadSize(
-			Configurationmanagement cfgManagement, Long userLevel) {
-		Configuration cfg = cfgManagement.getConfKey(userLevel,
-				"DEFAULT_MAX_UPLOAD_SIZE");
 		int result = DEFAULT_MAX_UPLOAD_SIZE;
-		if (cfg != null) {
-			String val = cfg.getConf_value();
-			try {
-				result = (int) Math.min(Long.parseLong(val), Integer.MAX_VALUE);
-			} catch (Exception e) {
-				log.error("Invalid value saved for maxUploadSize: " + val, e);
-			}
+		String maxSize = cfgManagement.getConfValue("DEFAULT_MAX_UPLOAD_SIZE", String.class, "" + result);
+		try {
+			result = (int) Math.min(Long.parseLong(maxSize), Integer.MAX_VALUE);
+		} catch (Exception e) {
+			log.error("Invalid value saved for maxUploadSize: " + maxSize, e);
+		}
+		return result;
+	}
+	
+	public static Map<String, String> getAllTimeZones(List<OmTimeZone> tzList) {
+		Map<String, String> result = new LinkedHashMap<String, String>();
+		
+		log.debug("omTimeZoneList :: " + tzList.size());
+		for (OmTimeZone omTimeZone : tzList) {
+			String labelName = omTimeZone.getJname() + " ("
+					+ omTimeZone.getLabel() + ")";
+			log.debug("labelName :: " + labelName);
+			result.put(omTimeZone.getJname(), labelName);
 		}
+		
 		return result;
 	}
 }



Re: svn commit: r1330188 - in /incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings: app/installation/ImportInitvalues.java cli/Admin.java servlet/outputhandler/Install.java utils/ImportHelper.java

Posted by Maxim Solodovnik <so...@gmail.com>.
fixed

On Thu, Apr 26, 2012 at 14:29, seba.wagner@gmail.com
<se...@gmail.com>wrote:

> Yes I agree, a longer description would be extremely helpful.
>
> I think after you have fixed that I will have to look at the
> configuration value in our config table, that has to change to use the
> "ical" attribute instead of "jname" too.
>
> Sebastian
>
> 2012/4/26 Maxim Solodovnik <so...@gmail.com>:
> > Hello Sebastian,
> >
> > jname was selected since our API (OmTimeZoneDaoImpl) can only get
> timezone
> > by ID or jname.
> > Additionally while adding initial admin user we need to have jname
> > (Usermanagement.addUser:1060  requires jName_timezone).
> >
> > In fact there are no duplicate output in admin:
> > Etc/GMT+1
> > Etc/GMT+1 (North Africa)
> >
> > so user should enter "Etc/GMT+1" or "Etc/GMT+1 (North Africa)".
> >
> > I can change admin to expect timezone as iCal, but in such case we need
> to
> > agree what will be the form of user hint.
> >
> > I mean:
> > I leave in Russia/Novosibirsk, I know my timezone is Novosibirsk (GMT+7).
> > Currently I can see my timezone in the available timezone list
> (Etc/GMT+7 )
> > but if available timezone list will be "Asia/Jakarta" it might confusing.
> >
> > I guess timezone hint should looks like follows
> >
> > Please enter
> > "Asia/Jakarta"                 for Novosibirsk, Indochina Time, Thailand,
> > Vietnam, Jakarta (Etc/GMT+7)
> > "Australia/Queensland"  for Russia (Zabaykalsky Krai), Papua New Guinea,
> > Australia (Queensland) Etc/GMT+10
> > ........................................
> >
> > what do you think?
> >
> > On Wed, Apr 25, 2012 at 19:13, seba.wagner@gmail.com <
> seba.wagner@gmail.com>
> > wrote:
> >>
> >> Hi Maxim,
> >>
> >> I don't think this will work.
> >> I thought you would use the field "ical" for matching the given
> >> timezone to the user input?
> >>
> >> I was not able to use the CLI installer to accept any of my input,
> >> neither "Berlin", nor "Europe/Berlin".
> >> What should be the input that I have to give
> >>
> >> Also as error / options you list then all available timezone name's as
> >> options. There are two times the name GMT+1, so how should the user
> >> understand what is the different between GMT+1 and GMT+1 ?
> >>
> >>
> >> Sebastian
> >>
> >>
> >> 2012/4/25  <so...@apache.org>:
> >> > Author: solomax
> >> > Date: Wed Apr 25 10:35:08 2012
> >> > New Revision: 1330188
> >> >
> >> > URL: http://svn.apache.org/viewvc?rev=1330188&view=rev
> >> > Log:
> >> > OPENMEETINGS-111 tz issues was fixed; options to install OM from
> backup
> >> > provided is added.
> >> >
> >> > Modified:
> >> >
> >> >
>  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
> >> >
> >> >
>  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
> >> >
> >> >
>  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
> >> >
> >> >
>  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
> >> >
> >> > Modified:
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
> >> > URL:
> >> >
> http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> >> >
> >> >
> ==============================================================================
> >> > ---
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
> >> > (original)
> >> > +++
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
> >> > Wed Apr 25 10:35:08 2012
> >> > @@ -768,8 +768,7 @@ public class ImportInitvalues {
> >> >                List<OmTimeZone> omTimeZones = new
> >> > LinkedList<OmTimeZone>();
> >> >
> >> >                SAXReader reader = new SAXReader();
> >> > -               Document document = reader.read(filePath
> >> > -                               +
> ImportInitvalues.nameOfTimeZoneFile);
> >> > +               Document document = reader.read(new File(filePath,
> >> > ImportInitvalues.nameOfTimeZoneFile));
> >> >
> >> >                Element root = document.getRootElement();
> >> >
> >> > @@ -960,8 +959,7 @@ public class ImportInitvalues {
> >> >        }
> >> >        //
> >> >
> ------------------------------------------------------------------------------
> >> >
> >> > -       public void loadAll(String filePath, InstallationConfig cfg,
> >> > String username,
> >> > -                       String userpass, String useremail, String
> >> > groupame, String timeZone) throws Exception {
> >> > +       public void loadSystem(String filePath, InstallationConfig
> cfg)
> >> > throws Exception {
> >> >                loadMainMenu();
> >> >                loadErrorMappingsFromXML(filePath);
> >> >                loadInitLanguages(filePath);
> >> > @@ -974,7 +972,12 @@ public class ImportInitvalues {
> >> >                loadPollTypes();
> >> >
> >> >                loadConfiguration(cfg);
> >> > +       }
> >> > +
> >> > +       public void loadAll(String filePath, InstallationConfig cfg,
> >> > String username,
> >> > +                       String userpass, String useremail, String
> >> > groupame, String timeZone) throws Exception {
> >> >
> >> > +               loadSystem(filePath, cfg);
> >> >                loadInitUserAndOrganisation(username,
> >> >                                userpass, useremail, groupame,
> timeZone,
> >> > cfg.defaultLangId);
> >> >
> >> >
> >> > Modified:
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
> >> > URL:
> >> >
> http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> >> >
> >> >
> ==============================================================================
> >> > ---
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
> >> > (original)
> >> > +++
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
> >> > Wed Apr 25 10:35:08 2012
> >> > @@ -9,6 +9,7 @@ import java.net.MalformedURLException;
> >> >  import java.net.URL;
> >> >  import java.util.Date;
> >> >  import java.util.Enumeration;
> >> > +import java.util.Map;
> >> >  import java.util.Set;
> >> >
> >> >  import javax.mail.internet.AddressException;
> >> > @@ -27,15 +28,14 @@ import org.apache.commons.cli.Parser;
> >> >  import org.apache.commons.cli.PosixParser;
> >> >  import org.apache.openjpa.jdbc.meta.MappingTool;
> >> >  import org.openmeetings.app.OpenmeetingsVariables;
> >> > -import org.openmeetings.app.data.basic.dao.OmTimeZoneDaoImpl;
> >> >  import org.openmeetings.app.data.file.FileUtils;
> >> >  import org.openmeetings.app.documents.InstallationDocumentHandler;
> >> >  import org.openmeetings.app.installation.ImportInitvalues;
> >> >  import org.openmeetings.app.installation.InstallationConfig;
> >> > -import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
> >> >  import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
> >> >  import org.openmeetings.servlet.outputhandler.BackupExport;
> >> >  import org.openmeetings.servlet.outputhandler.BackupImportController;
> >> > +import org.openmeetings.utils.ImportHelper;
> >> >  import org.openmeetings.utils.OMContextListener;
> >> >  import org.openmeetings.utils.mail.MailUtil;
> >> >  import org.openmeetings.utils.math.CalendarPatterns;
> >> > @@ -49,6 +49,8 @@ public class Admin {
> >> >        private boolean verbose = false;
> >> >        private InstallationConfig cfg = null;
> >> >        private Options opts = null;
> >> > +       private CommandLine cmdl = null;
> >> > +       File omHome = null;
> >> >
> >> >        private Admin() {
> >> >                cfg = new InstallationConfig();
> >> > @@ -69,12 +71,12 @@ public class Admin {
> >> >                options.addOption(new OmOption(null, "v", "verbose",
> >> > false, "verbose error messages"));
> >> >                //backup/restore
> >> >                options.addOption(new OmOption("b", null,
> >> > "exclude-files", false, "should backup exclude files [default:
> include]",
> >> > true));
> >> > -               options.addOption(new OmOption("b,r", "file", null,
> >> > true, "file used for backup/restore", "b"));
> >> > +               options.addOption(new OmOption("b,r,i", "file", null,
> >> > true, "file used for backup/restore/install", "b"));
> >> >                //install
> >> > -               options.addOption(new OmOption("i", "user", null,
> true,
> >> > "Login name of the default user, minimum " +
> >> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters"));
> >> > -               options.addOption(new OmOption("i", "email", null,
> true,
> >> > "Email of the default user"));
> >> > -               options.addOption(new OmOption("i", "group", null,
> true,
> >> > "The name of the default user group"));
> >> > -               options.addOption(new OmOption("i", "tz", null, true,
> >> > "Default server time zone, and time zone for the selected user [for
> ex:
> >> > 'GMT+10', '-2', 'Chicago']"));
> >> > +               options.addOption(new OmOption("i", "user", null,
> true,
> >> > "Login name of the default user, minimum " +
> >> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (mutually
> >> > exclusive with 'file')"));
> >> > +               options.addOption(new OmOption("i", "email", null,
> true,
> >> > "Email of the default user (mutually exclusive with 'file')"));
> >> > +               options.addOption(new OmOption("i", "group", null,
> true,
> >> > "The name of the default user group (mutually exclusive with
> 'file')"));
> >> > +               options.addOption(new OmOption("i", "tz", null, true,
> >> > "Default server time zone, and time zone for the selected user
> (mutually
> >> > exclusive with 'file')"));
> >> >                options.addOption(new OmOption("i", null, "password",
> >> > true, "Password of the default user, minimum " +
> >> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (will be
> >> > prompted if not set)", true));
> >> >                options.addOption(new OmOption("i", null,
> >> > "system-email-address", true, "System e-mail address [default: " +
> >> > cfg.mailReferer + "]", true));
> >> >                options.addOption(new OmOption("i", null,
> "smtp-server",
> >> > true, "SMTP server for outgoing e-mails [default: " + cfg.smtpServer
> + "]",
> >> > true));
> >> > @@ -242,11 +244,10 @@ public class Admin {
> >> >        private void process(String[] args) {
> >> >                String ctxName = System.getProperty("context",
> >> > "openmeetings");
> >> >                File home = new File(System.getenv("RED5_HOME"));
> >> > -               File omHome = new File(new File(home, "webapps"),
> >> > ctxName);
> >> > +               omHome = new File(new File(home, "webapps"), ctxName);
> >> >                File omUploadTemp = new File(omHome,
> >> > OpenmeetingsVariables.UPLOAD_TEMP_DIR);
> >> >
> >> >                Parser parser = new PosixParser();
> >> > -               CommandLine cmdl = null;
> >> >                try {
> >> >                        cmdl = parser.parse(opts, args);
> >> >                } catch (ParseException e) {
> >> > @@ -271,9 +272,10 @@ public class Admin {
> >> >                switch(cmd) {
> >> >                        case install:
> >> >                                try {
> >> > -                                       String login =
> >> > cmdl.getOptionValue("user");
> >> > -                                       String email =
> >> > cmdl.getOptionValue("email");
> >> > -                                       String group =
> >> > cmdl.getOptionValue("group");
> >> > +                                       if (cmdl.hasOption("file") &&
> >> > (cmdl.hasOption("user") || cmdl.hasOption("email") ||
> >> > cmdl.hasOption("group"))) {
> >> > +
> >> > System.out.println("Please specify even 'file' option or 'admin
> user'.");
> >> > +                                               System.exit(1);
> >> > +                                       }
> >> >                                        //TODO commented for now, since
> >> > not in use boolean force = cmdl.hasOption("force");
> >> >                                        if
> >> > (cmdl.hasOption("skip-default-rooms")) {
> >> >                                                cfg.createDefaultRooms
> =
> >> > "0";
> >> > @@ -299,33 +301,7 @@ public class Admin {
> >> >                                        if
> >> > (cmdl.hasOption("email-use-tls")) {
> >> >                                                cfg.mailUseTls = "1";
> >> >                                        }
> >> > -                                       if (login == null ||
> >> > login.length() < InstallationConfig.USER_LOGIN_MINIMUM_LENGTH) {
> >> > -
> System.out.println("User
> >> > login was not provided, or too short, should be at least " +
> >> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " character long.");
> >> > -                                               System.exit(1);
> >> > -                                       }
> >> > -
> >> > -                                       try {
> >> > -                                               if
> >> > (!MailUtil.matches(email)) {
> >> > -                                                   throw new
> >> > AddressException("Invalid address");
> >> > -                                               }
> >> > -                                               new
> >> > InternetAddress(email, true);
> >> > -                                       } catch (AddressException ae)
> {
> >> > -
> >> > System.out.println("Please provide non-empty valid email: '" + email
> + "' is
> >> > not valid.");
> >> > -                                               System.exit(1);
> >> > -                                       }
> >> > -                                       if (group == null ||
> >> > login.length() < 1) {
> >> > -
> System.out.println("User
> >> > group was not provided, or too short, should be at least 1 character
> >> > long.");
> >> > -                                               System.exit(1);
> >> > -                                       }
> >> > -                                       String pass =
> >> > cmdl.getOptionValue("password");
> >> > -                                       if (pass == null ||
> >> > pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH) {
> >> > -
> System.out.print("Please
> >> > enter password:");
> >> > -                                               pass = new
> >> > BufferedReader(new InputStreamReader(System.in)).readLine();
> >> > -                                               if (pass == null ||
> >> > pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH) {
> >> > -
> >> > System.out.println("Password was not provided, or too short, should
> be at
> >> > least " + InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH + "
> character
> >> > long.");
> >> > -
> System.exit(1);
> >> > -                                               }
> >> > -                                       }
> >> > +                                       String langPath = new
> >> > File(omHome, ImportInitvalues.languageFolderName).getAbsolutePath();
> //FIXME
> >> > need to be moved to helper
> >> >                                        ConnectionProperties
> >> > connectionProperties = new ConnectionProperties();
> >> >                                        if (cmdl.hasOption("db-type")
> ||
> >> > cmdl.hasOption("db-host") || cmdl.hasOption("db-port") ||
> >> > cmdl.hasOption("db-name") || cmdl.hasOption("db-user") ||
> >> > cmdl.hasOption("db-pass")) {
> >> >                                                String dbType =
> >> > cmdl.getOptionValue("db-type", "derby");
> >> > @@ -342,30 +318,18 @@ public class Admin {
> >> >                                                                ,
> >> > connectionProperties
> >> >                                                                );
> >> >                                        }
> >> > -
> >> > -                                       if(cmdl.hasOption("drop")) {
> >> > -                                               String[]
> mappingToolArgs
> >> > = {"-sa", "drop", "-p", omHome.getPath() +
> >> > "/WEB-INF/classes/META-INF/persistence.xml",
> >> > -
> >> > "-connectionDriverName", connectionProperties.getDriverName(),
> >> > "-connectionURL", connectionProperties.getConnectionURL(),
> >> > -
> >> > "-connectionUserName", connectionProperties.getConnectionLogin(),
> >> > "-connectionPassword", connectionProperties.getConnectionPass()};
> >> > -
> >> > MappingTool.main(mappingToolArgs);
> >> > -                                       }
> >> > -
> >> >                                        ClassPathXmlApplicationContext
> >> > ctx = getApplicationContext(ctxName);
> >> > -                                       OmTimeZoneDaoImpl tzDao =
> >> >  ctx.getBean(OmTimeZoneDaoImpl.class);
> >> > -                                       String tz = null;
> >> > -                                       if (cmdl.hasOption("tz")) {
> >> > -                                               tz =
> >> > cmdl.getOptionValue("tz");
> >> > -                                               tz =
> >> > tzDao.getOmTimeZone(tz) == null ? null : tz;
> >> > -                                       }
> >> > -                                       if (tz == null) {
> >> > -
> >> > System.out.println("Please enter timezone, Possible timezones are:");
> >> > -                                               for (OmTimeZone omTz :
> >> > tzDao.getOmTimeZones()) {
> >> > -
> >> > System.out.println(omTz.getJname());
> >> > -                                               }
> >> > -                                               System.exit(1);
> >> > -                                       }
> >> >                                        ImportInitvalues importInit =
> >> > ctx.getBean(ImportInitvalues.class);
> >> > -                                       importInit.loadAll(new
> >> > File(omHome, ImportInitvalues.languageFolderName).getAbsolutePath(),
> cfg,
> >> > login, pass, email, group, tz);
> >> > +                                       if (cmdl.hasOption("file")) {
> >> > +                                               File backup =
> >> > checkRestoreFile(file);
> >> > +
> >> > dropDB(connectionProperties);
> >> > +
> >> > importInit.loadSystem(langPath, cfg);
> >> > +                                               restoreOm(ctxName,
> >> > backup);
> >> > +                                       } else {
> >> > +                                               AdminUserDetails
> admin =
> >> > checkAdminDetails(importInit, langPath);
> >> > +
> >> > dropDB(connectionProperties);
> >> > +
> >> > importInit.loadAll(langPath, cfg, admin.login, admin.pass,
> admin.email,
> >> > admin.group, admin.tz);
> >> > +                                       }
> >> >
> >> >                                        File installerFile = new
> File(new
> >> > File(home, ScopeApplicationAdapter.configDirName),
> >> > InstallationDocumentHandler.installFileName);
> >> >
> >> >
>  InstallationDocumentHandler.getInstance().createDocument(installerFile.getAbsolutePath(),
> >> > 1);
> >> > @@ -392,19 +356,7 @@ public class Admin {
> >> >                                }
> >> >                                break;
> >> >                        case restore:
> >> > -                               try {
> >> > -                                       File backup = new File(file);
> >> > -                                       if (!cmdl.hasOption("file") ||
> >> > !backup.exists() || !backup.isFile()) {
> >> > -
> System.out.println("File
> >> > should be specified, and point the existent zip file");
> >> > -                                               usage();
> >> > -                                               System.exit(1);
> >> > -                                       }
> >> > -
> >> > -                                       BackupImportController
> >> > importCtrl =
> >> > getApplicationContext(ctxName).getBean(BackupImportController.class);
> >> > -                                       importCtrl.performImport(new
> >> > FileInputStream(backup), omHome.getAbsolutePath());
> >> > -                               } catch (Exception e) {
> >> > -                                       handleError("Restore failed",
> >> > e);
> >> > -                               }
> >> > +                               restoreOm(ctxName,
> >> > checkRestoreFile(file));
> >> >                                break;
> >> >                        case files:
> >> >                                try {
> >> > @@ -451,6 +403,95 @@ public class Admin {
> >> >                System.exit(0);
> >> >        }
> >> >
> >> > +       private class AdminUserDetails {
> >> > +               String login = null;
> >> > +               String email = null;
> >> > +               String group = null;
> >> > +               String pass = null;
> >> > +               String tz = null;
> >> > +       }
> >> > +
> >> > +       private AdminUserDetails checkAdminDetails(ImportInitvalues
> >> > importInit, String langPath) throws Exception {
> >> > +               AdminUserDetails admin = new AdminUserDetails();
> >> > +               admin.login = cmdl.getOptionValue("user");
> >> > +               admin.email = cmdl.getOptionValue("email");
> >> > +               admin.group = cmdl.getOptionValue("group");
> >> > +               if (admin.login == null || admin.login.length() <
> >> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH) {
> >> > +                       System.out.println("User login was not
> provided,
> >> > or too short, should be at least " +
> >> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " character long.");
> >> > +                       System.exit(1);
> >> > +               }
> >> > +
> >> > +               try {
> >> > +                       if (!MailUtil.matches(admin.email)) {
> >> > +                           throw new AddressException("Invalid
> >> > address");
> >> > +                       }
> >> > +                       new InternetAddress(admin.email, true);
> >> > +               } catch (AddressException ae) {
> >> > +                       System.out.println("Please provide non-empty
> >> > valid email: '" + admin.email + "' is not valid.");
> >> > +                       System.exit(1);
> >> > +               }
> >> > +               if (admin.group == null || admin.group.length() < 1) {
> >> > +                       System.out.println("User group was not
> provided,
> >> > or too short, should be at least 1 character long: " + admin.group);
> >> > +                       System.exit(1);
> >> > +               }
> >> > +               admin.pass = cmdl.getOptionValue("password");
> >> > +               if (checkPassword(admin.pass)) {
> >> > +                       System.out.print("Please enter password:");
> >> > +                       admin.pass = new BufferedReader(new
> >> > InputStreamReader(System.in)).readLine();
> >> > +                       if (checkPassword(admin.pass)) {
> >> > +                               System.out.println("Password was not
> >> > provided, or too short, should be at least " +
> >> > InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH + " character long.");
> >> > +                               System.exit(1);
> >> > +                       }
> >> > +               }
> >> > +               Map<String, String> tzMap =
> >> > ImportHelper.getAllTimeZones(importInit.getTimeZones(langPath));
> >> > +               admin.tz = null;
> >> > +               if (cmdl.hasOption("tz")) {
> >> > +                       admin.tz = cmdl.getOptionValue("tz");
> >> > +                       admin.tz = tzMap.containsKey(admin.tz) ?
> >> > admin.tz : null;
> >> > +               }
> >> > +               if (admin.tz == null) {
> >> > +                       System.out.println("Please enter timezone,
> >> > Possible timezones are:");
> >> > +                       for (String tzJname : tzMap.keySet()) {
> >> > +                               System.out.println(tzJname);
> >> > +                       }
> >> > +                       System.exit(1);
> >> > +               }
> >> > +               return admin;
> >> > +       }
> >> > +
> >> > +       private boolean checkPassword(String pass) {
> >> > +               return (pass == null || pass.length() <
> >> > InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH);
> >> > +       }
> >> > +
> >> > +       private void dropDB(ConnectionProperties props) throws
> Exception
> >> > {
> >> > +               if(cmdl.hasOption("drop")) {
> >> > +                       String[] mappingToolArgs = {"-sa", "drop",
> "-p",
> >> > omHome.getAbsolutePath() +
> "/WEB-INF/classes/META-INF/persistence.xml",
> >> > +                                       "-connectionDriverName",
> >> > props.getDriverName(), "-connectionURL", props.getConnectionURL(),
> >> > +                                       "-connectionUserName",
> >> > props.getConnectionLogin(), "-connectionPassword",
> >> > props.getConnectionPass()};
> >> > +                       MappingTool.main(mappingToolArgs);
> >> > +               }
> >> > +       }
> >> > +
> >> > +       private File checkRestoreFile(String file) {
> >> > +               File backup = new File(file);
> >> > +               if (!cmdl.hasOption("file") || !backup.exists() ||
> >> > !backup.isFile()) {
> >> > +                       System.out.println("File should be specified,
> >> > and point the existent zip file");
> >> > +                       usage();
> >> > +                       System.exit(1);
> >> > +               }
> >> > +
> >> > +               return backup;
> >> > +       }
> >> > +
> >> > +       private void restoreOm(String ctxName, File backup) {
> >> > +               try {
> >> > +                       BackupImportController importCtrl =
> >> > getApplicationContext(ctxName).getBean(BackupImportController.class);
> >> > +                       importCtrl.performImport(new
> >> > FileInputStream(backup), omHome.getAbsolutePath());
> >> > +               } catch (Exception e) {
> >> > +                       handleError("Restore failed", e);
> >> > +               }
> >> > +       }
> >> > +
> >> >        public static void main(String[] args) {
> >> >                new Admin().process(args);
> >> >        }
> >> >
> >> > Modified:
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
> >> > URL:
> >> >
> http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> >> >
> >> >
> ==============================================================================
> >> > ---
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
> >> > (original)
> >> > +++
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
> >> > Wed Apr 25 10:35:08 2012
> >> > @@ -38,6 +38,7 @@ import org.openmeetings.app.installation
> >> >  import org.openmeetings.app.installation.InstallationConfig;
> >> >  import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
> >> >  import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
> >> > +import org.openmeetings.utils.ImportHelper;
> >> >  import org.red5.logging.Red5LoggerFactory;
> >> >  import org.slf4j.Logger;
> >> >  import org.springframework.context.ApplicationContext;
> >> > @@ -117,22 +118,14 @@ public class Install extends VelocityVie
> >> >                allFonts.put("Verdana", "Verdana");
> >> >                allFonts.put("Arial", "Arial");
> >> >
> >> > -               LinkedHashMap<String, String> allTimeZones = new
> >> > LinkedHashMap<String, String>();
> >> >                List<OmTimeZone> omTimeZoneList = getImportInitvalues()
> >> >                                .getTimeZones(filePath);
> >> > -               log.debug("omTimeZoneList :: " +
> omTimeZoneList.size());
> >> > -               for (OmTimeZone omTimeZone : omTimeZoneList) {
> >> > -                       String labelName = omTimeZone.getJname() + "
> ("
> >> > -                                       + omTimeZone.getLabel() + ")";
> >> > -                       log.debug("labelName :: " + labelName);
> >> > -                       allTimeZones.put(omTimeZone.getJname(),
> >> > labelName);
> >> > -               }
> >> >
> >> >                Template tpl = super.getTemplate("install_step1_"
> >> >                                + lang + ".vm");
> >> >                ctx.put("allLanguages", allLanguages);
> >> >                ctx.put("allFonts", allFonts);
> >> > -               ctx.put("allTimeZones", allTimeZones);
> >> > +               ctx.put("allTimeZones",
> >> > ImportHelper.getAllTimeZones(omTimeZoneList));
> >> >                StringWriter writer = new StringWriter();
> >> >                tpl.merge(ctx, writer);
> >> >
> >> >
> >> > Modified:
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
> >> > URL:
> >> >
> http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> >> >
> >> >
> ==============================================================================
> >> > ---
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
> >> > (original)
> >> > +++
> >> >
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
> >> > Wed Apr 25 10:35:08 2012
> >> > @@ -18,9 +18,13 @@
> >> >  */
> >> >  package org.openmeetings.utils;
> >> >
> >> > +import java.util.LinkedHashMap;
> >> > +import java.util.List;
> >> > +import java.util.Map;
> >> > +
> >> >  import org.openmeetings.app.OpenmeetingsVariables;
> >> >  import org.openmeetings.app.data.basic.Configurationmanagement;
> >> > -import org.openmeetings.app.persistence.beans.basic.Configuration;
> >> > +import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
> >> >  import org.red5.logging.Red5LoggerFactory;
> >> >  import org.slf4j.Logger;
> >> >
> >> > @@ -31,22 +35,27 @@ public class ImportHelper {
> >> >
> >> >        public static final int getMaxUploadSize(
> >> >                        Configurationmanagement cfgManagement) {
> >> > -               return getMaxUploadSize(cfgManagement, 3L);
> >> > -       }
> >> > -
> >> > -       public static final int getMaxUploadSize(
> >> > -                       Configurationmanagement cfgManagement, Long
> >> > userLevel) {
> >> > -               Configuration cfg =
> cfgManagement.getConfKey(userLevel,
> >> > -                               "DEFAULT_MAX_UPLOAD_SIZE");
> >> >                int result = DEFAULT_MAX_UPLOAD_SIZE;
> >> > -               if (cfg != null) {
> >> > -                       String val = cfg.getConf_value();
> >> > -                       try {
> >> > -                               result = (int)
> >> > Math.min(Long.parseLong(val), Integer.MAX_VALUE);
> >> > -                       } catch (Exception e) {
> >> > -                               log.error("Invalid value saved for
> >> > maxUploadSize: " + val, e);
> >> > -                       }
> >> > +               String maxSize =
> >> > cfgManagement.getConfValue("DEFAULT_MAX_UPLOAD_SIZE", String.class,
> "" +
> >> > result);
> >> > +               try {
> >> > +                       result = (int)
> Math.min(Long.parseLong(maxSize),
> >> > Integer.MAX_VALUE);
> >> > +               } catch (Exception e) {
> >> > +                       log.error("Invalid value saved for
> >> > maxUploadSize: " + maxSize, e);
> >> > +               }
> >> > +               return result;
> >> > +       }
> >> > +
> >> > +       public static Map<String, String>
> >> > getAllTimeZones(List<OmTimeZone> tzList) {
> >> > +               Map<String, String> result = new LinkedHashMap<String,
> >> > String>();
> >> > +
> >> > +               log.debug("omTimeZoneList :: " + tzList.size());
> >> > +               for (OmTimeZone omTimeZone : tzList) {
> >> > +                       String labelName = omTimeZone.getJname() + "
> ("
> >> > +                                       + omTimeZone.getLabel() + ")";
> >> > +                       log.debug("labelName :: " + labelName);
> >> > +                       result.put(omTimeZone.getJname(), labelName);
> >> >                }
> >> > +
> >> >                return result;
> >> >        }
> >> >  }
> >> >
> >> >
> >>
> >>
> >>
> >> --
> >> Sebastian Wagner
> >> https://twitter.com/#!/dead_lock
> >> http://www.openmeetings.de
> >> http://www.webbase-design.de
> >> http://www.wagner-sebastian.com
> >> seba.wagner@gmail.com
> >
> >
> >
> >
> > --
> > WBR
> > Maxim aka solomax
>
>
>
> --
> Sebastian Wagner
> https://twitter.com/#!/dead_lock
> http://www.openmeetings.de
> http://www.webbase-design.de
> http://www.wagner-sebastian.com
> seba.wagner@gmail.com
>



-- 
WBR
Maxim aka solomax

Re: svn commit: r1330188 - in /incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings: app/installation/ImportInitvalues.java cli/Admin.java servlet/outputhandler/Install.java utils/ImportHelper.java

Posted by "seba.wagner@gmail.com" <se...@gmail.com>.
Yes I agree, a longer description would be extremely helpful.

I think after you have fixed that I will have to look at the
configuration value in our config table, that has to change to use the
"ical" attribute instead of "jname" too.

Sebastian

2012/4/26 Maxim Solodovnik <so...@gmail.com>:
> Hello Sebastian,
>
> jname was selected since our API (OmTimeZoneDaoImpl) can only get timezone
> by ID or jname.
> Additionally while adding initial admin user we need to have jname
> (Usermanagement.addUser:1060  requires jName_timezone).
>
> In fact there are no duplicate output in admin:
> Etc/GMT+1
> Etc/GMT+1 (North Africa)
>
> so user should enter "Etc/GMT+1" or "Etc/GMT+1 (North Africa)".
>
> I can change admin to expect timezone as iCal, but in such case we need to
> agree what will be the form of user hint.
>
> I mean:
> I leave in Russia/Novosibirsk, I know my timezone is Novosibirsk (GMT+7).
> Currently I can see my timezone in the available timezone list (Etc/GMT+7 )
> but if available timezone list will be "Asia/Jakarta" it might confusing.
>
> I guess timezone hint should looks like follows
>
> Please enter
> "Asia/Jakarta"                 for Novosibirsk, Indochina Time, Thailand,
> Vietnam, Jakarta (Etc/GMT+7)
> "Australia/Queensland"  for Russia (Zabaykalsky Krai), Papua New Guinea,
> Australia (Queensland) Etc/GMT+10
> ........................................
>
> what do you think?
>
> On Wed, Apr 25, 2012 at 19:13, seba.wagner@gmail.com <se...@gmail.com>
> wrote:
>>
>> Hi Maxim,
>>
>> I don't think this will work.
>> I thought you would use the field "ical" for matching the given
>> timezone to the user input?
>>
>> I was not able to use the CLI installer to accept any of my input,
>> neither "Berlin", nor "Europe/Berlin".
>> What should be the input that I have to give
>>
>> Also as error / options you list then all available timezone name's as
>> options. There are two times the name GMT+1, so how should the user
>> understand what is the different between GMT+1 and GMT+1 ?
>>
>>
>> Sebastian
>>
>>
>> 2012/4/25  <so...@apache.org>:
>> > Author: solomax
>> > Date: Wed Apr 25 10:35:08 2012
>> > New Revision: 1330188
>> >
>> > URL: http://svn.apache.org/viewvc?rev=1330188&view=rev
>> > Log:
>> > OPENMEETINGS-111 tz issues was fixed; options to install OM from backup
>> > provided is added.
>> >
>> > Modified:
>> >
>> >  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
>> >
>> >  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
>> >
>> >  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
>> >
>> >  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
>> >
>> > Modified:
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
>> > URL:
>> > http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java?rev=1330188&r1=1330187&r2=1330188&view=diff
>> >
>> > ==============================================================================
>> > ---
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
>> > (original)
>> > +++
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
>> > Wed Apr 25 10:35:08 2012
>> > @@ -768,8 +768,7 @@ public class ImportInitvalues {
>> >                List<OmTimeZone> omTimeZones = new
>> > LinkedList<OmTimeZone>();
>> >
>> >                SAXReader reader = new SAXReader();
>> > -               Document document = reader.read(filePath
>> > -                               + ImportInitvalues.nameOfTimeZoneFile);
>> > +               Document document = reader.read(new File(filePath,
>> > ImportInitvalues.nameOfTimeZoneFile));
>> >
>> >                Element root = document.getRootElement();
>> >
>> > @@ -960,8 +959,7 @@ public class ImportInitvalues {
>> >        }
>> >        //
>> > ------------------------------------------------------------------------------
>> >
>> > -       public void loadAll(String filePath, InstallationConfig cfg,
>> > String username,
>> > -                       String userpass, String useremail, String
>> > groupame, String timeZone) throws Exception {
>> > +       public void loadSystem(String filePath, InstallationConfig cfg)
>> > throws Exception {
>> >                loadMainMenu();
>> >                loadErrorMappingsFromXML(filePath);
>> >                loadInitLanguages(filePath);
>> > @@ -974,7 +972,12 @@ public class ImportInitvalues {
>> >                loadPollTypes();
>> >
>> >                loadConfiguration(cfg);
>> > +       }
>> > +
>> > +       public void loadAll(String filePath, InstallationConfig cfg,
>> > String username,
>> > +                       String userpass, String useremail, String
>> > groupame, String timeZone) throws Exception {
>> >
>> > +               loadSystem(filePath, cfg);
>> >                loadInitUserAndOrganisation(username,
>> >                                userpass, useremail, groupame, timeZone,
>> > cfg.defaultLangId);
>> >
>> >
>> > Modified:
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
>> > URL:
>> > http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java?rev=1330188&r1=1330187&r2=1330188&view=diff
>> >
>> > ==============================================================================
>> > ---
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
>> > (original)
>> > +++
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
>> > Wed Apr 25 10:35:08 2012
>> > @@ -9,6 +9,7 @@ import java.net.MalformedURLException;
>> >  import java.net.URL;
>> >  import java.util.Date;
>> >  import java.util.Enumeration;
>> > +import java.util.Map;
>> >  import java.util.Set;
>> >
>> >  import javax.mail.internet.AddressException;
>> > @@ -27,15 +28,14 @@ import org.apache.commons.cli.Parser;
>> >  import org.apache.commons.cli.PosixParser;
>> >  import org.apache.openjpa.jdbc.meta.MappingTool;
>> >  import org.openmeetings.app.OpenmeetingsVariables;
>> > -import org.openmeetings.app.data.basic.dao.OmTimeZoneDaoImpl;
>> >  import org.openmeetings.app.data.file.FileUtils;
>> >  import org.openmeetings.app.documents.InstallationDocumentHandler;
>> >  import org.openmeetings.app.installation.ImportInitvalues;
>> >  import org.openmeetings.app.installation.InstallationConfig;
>> > -import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
>> >  import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
>> >  import org.openmeetings.servlet.outputhandler.BackupExport;
>> >  import org.openmeetings.servlet.outputhandler.BackupImportController;
>> > +import org.openmeetings.utils.ImportHelper;
>> >  import org.openmeetings.utils.OMContextListener;
>> >  import org.openmeetings.utils.mail.MailUtil;
>> >  import org.openmeetings.utils.math.CalendarPatterns;
>> > @@ -49,6 +49,8 @@ public class Admin {
>> >        private boolean verbose = false;
>> >        private InstallationConfig cfg = null;
>> >        private Options opts = null;
>> > +       private CommandLine cmdl = null;
>> > +       File omHome = null;
>> >
>> >        private Admin() {
>> >                cfg = new InstallationConfig();
>> > @@ -69,12 +71,12 @@ public class Admin {
>> >                options.addOption(new OmOption(null, "v", "verbose",
>> > false, "verbose error messages"));
>> >                //backup/restore
>> >                options.addOption(new OmOption("b", null,
>> > "exclude-files", false, "should backup exclude files [default: include]",
>> > true));
>> > -               options.addOption(new OmOption("b,r", "file", null,
>> > true, "file used for backup/restore", "b"));
>> > +               options.addOption(new OmOption("b,r,i", "file", null,
>> > true, "file used for backup/restore/install", "b"));
>> >                //install
>> > -               options.addOption(new OmOption("i", "user", null, true,
>> > "Login name of the default user, minimum " +
>> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters"));
>> > -               options.addOption(new OmOption("i", "email", null, true,
>> > "Email of the default user"));
>> > -               options.addOption(new OmOption("i", "group", null, true,
>> > "The name of the default user group"));
>> > -               options.addOption(new OmOption("i", "tz", null, true,
>> > "Default server time zone, and time zone for the selected user [for ex:
>> > 'GMT+10', '-2', 'Chicago']"));
>> > +               options.addOption(new OmOption("i", "user", null, true,
>> > "Login name of the default user, minimum " +
>> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (mutually
>> > exclusive with 'file')"));
>> > +               options.addOption(new OmOption("i", "email", null, true,
>> > "Email of the default user (mutually exclusive with 'file')"));
>> > +               options.addOption(new OmOption("i", "group", null, true,
>> > "The name of the default user group (mutually exclusive with 'file')"));
>> > +               options.addOption(new OmOption("i", "tz", null, true,
>> > "Default server time zone, and time zone for the selected user (mutually
>> > exclusive with 'file')"));
>> >                options.addOption(new OmOption("i", null, "password",
>> > true, "Password of the default user, minimum " +
>> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (will be
>> > prompted if not set)", true));
>> >                options.addOption(new OmOption("i", null,
>> > "system-email-address", true, "System e-mail address [default: " +
>> > cfg.mailReferer + "]", true));
>> >                options.addOption(new OmOption("i", null, "smtp-server",
>> > true, "SMTP server for outgoing e-mails [default: " + cfg.smtpServer + "]",
>> > true));
>> > @@ -242,11 +244,10 @@ public class Admin {
>> >        private void process(String[] args) {
>> >                String ctxName = System.getProperty("context",
>> > "openmeetings");
>> >                File home = new File(System.getenv("RED5_HOME"));
>> > -               File omHome = new File(new File(home, "webapps"),
>> > ctxName);
>> > +               omHome = new File(new File(home, "webapps"), ctxName);
>> >                File omUploadTemp = new File(omHome,
>> > OpenmeetingsVariables.UPLOAD_TEMP_DIR);
>> >
>> >                Parser parser = new PosixParser();
>> > -               CommandLine cmdl = null;
>> >                try {
>> >                        cmdl = parser.parse(opts, args);
>> >                } catch (ParseException e) {
>> > @@ -271,9 +272,10 @@ public class Admin {
>> >                switch(cmd) {
>> >                        case install:
>> >                                try {
>> > -                                       String login =
>> > cmdl.getOptionValue("user");
>> > -                                       String email =
>> > cmdl.getOptionValue("email");
>> > -                                       String group =
>> > cmdl.getOptionValue("group");
>> > +                                       if (cmdl.hasOption("file") &&
>> > (cmdl.hasOption("user") || cmdl.hasOption("email") ||
>> > cmdl.hasOption("group"))) {
>> > +
>> > System.out.println("Please specify even 'file' option or 'admin user'.");
>> > +                                               System.exit(1);
>> > +                                       }
>> >                                        //TODO commented for now, since
>> > not in use boolean force = cmdl.hasOption("force");
>> >                                        if
>> > (cmdl.hasOption("skip-default-rooms")) {
>> >                                                cfg.createDefaultRooms =
>> > "0";
>> > @@ -299,33 +301,7 @@ public class Admin {
>> >                                        if
>> > (cmdl.hasOption("email-use-tls")) {
>> >                                                cfg.mailUseTls = "1";
>> >                                        }
>> > -                                       if (login == null ||
>> > login.length() < InstallationConfig.USER_LOGIN_MINIMUM_LENGTH) {
>> > -                                               System.out.println("User
>> > login was not provided, or too short, should be at least " +
>> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " character long.");
>> > -                                               System.exit(1);
>> > -                                       }
>> > -
>> > -                                       try {
>> > -                                               if
>> > (!MailUtil.matches(email)) {
>> > -                                                   throw new
>> > AddressException("Invalid address");
>> > -                                               }
>> > -                                               new
>> > InternetAddress(email, true);
>> > -                                       } catch (AddressException ae) {
>> > -
>> > System.out.println("Please provide non-empty valid email: '" + email + "' is
>> > not valid.");
>> > -                                               System.exit(1);
>> > -                                       }
>> > -                                       if (group == null ||
>> > login.length() < 1) {
>> > -                                               System.out.println("User
>> > group was not provided, or too short, should be at least 1 character
>> > long.");
>> > -                                               System.exit(1);
>> > -                                       }
>> > -                                       String pass =
>> > cmdl.getOptionValue("password");
>> > -                                       if (pass == null ||
>> > pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH) {
>> > -                                               System.out.print("Please
>> > enter password:");
>> > -                                               pass = new
>> > BufferedReader(new InputStreamReader(System.in)).readLine();
>> > -                                               if (pass == null ||
>> > pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH) {
>> > -
>> > System.out.println("Password was not provided, or too short, should be at
>> > least " + InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH + " character
>> > long.");
>> > -                                                       System.exit(1);
>> > -                                               }
>> > -                                       }
>> > +                                       String langPath = new
>> > File(omHome, ImportInitvalues.languageFolderName).getAbsolutePath(); //FIXME
>> > need to be moved to helper
>> >                                        ConnectionProperties
>> > connectionProperties = new ConnectionProperties();
>> >                                        if (cmdl.hasOption("db-type") ||
>> > cmdl.hasOption("db-host") || cmdl.hasOption("db-port") ||
>> > cmdl.hasOption("db-name") || cmdl.hasOption("db-user") ||
>> > cmdl.hasOption("db-pass")) {
>> >                                                String dbType =
>> > cmdl.getOptionValue("db-type", "derby");
>> > @@ -342,30 +318,18 @@ public class Admin {
>> >                                                                ,
>> > connectionProperties
>> >                                                                );
>> >                                        }
>> > -
>> > -                                       if(cmdl.hasOption("drop")) {
>> > -                                               String[] mappingToolArgs
>> > = {"-sa", "drop", "-p", omHome.getPath() +
>> > "/WEB-INF/classes/META-INF/persistence.xml",
>> > -
>> > "-connectionDriverName", connectionProperties.getDriverName(),
>> > "-connectionURL", connectionProperties.getConnectionURL(),
>> > -
>> > "-connectionUserName", connectionProperties.getConnectionLogin(),
>> > "-connectionPassword", connectionProperties.getConnectionPass()};
>> > -
>> > MappingTool.main(mappingToolArgs);
>> > -                                       }
>> > -
>> >                                        ClassPathXmlApplicationContext
>> > ctx = getApplicationContext(ctxName);
>> > -                                       OmTimeZoneDaoImpl tzDao =
>> >  ctx.getBean(OmTimeZoneDaoImpl.class);
>> > -                                       String tz = null;
>> > -                                       if (cmdl.hasOption("tz")) {
>> > -                                               tz =
>> > cmdl.getOptionValue("tz");
>> > -                                               tz =
>> > tzDao.getOmTimeZone(tz) == null ? null : tz;
>> > -                                       }
>> > -                                       if (tz == null) {
>> > -
>> > System.out.println("Please enter timezone, Possible timezones are:");
>> > -                                               for (OmTimeZone omTz :
>> > tzDao.getOmTimeZones()) {
>> > -
>> > System.out.println(omTz.getJname());
>> > -                                               }
>> > -                                               System.exit(1);
>> > -                                       }
>> >                                        ImportInitvalues importInit =
>> > ctx.getBean(ImportInitvalues.class);
>> > -                                       importInit.loadAll(new
>> > File(omHome, ImportInitvalues.languageFolderName).getAbsolutePath(), cfg,
>> > login, pass, email, group, tz);
>> > +                                       if (cmdl.hasOption("file")) {
>> > +                                               File backup =
>> > checkRestoreFile(file);
>> > +
>> > dropDB(connectionProperties);
>> > +
>> > importInit.loadSystem(langPath, cfg);
>> > +                                               restoreOm(ctxName,
>> > backup);
>> > +                                       } else {
>> > +                                               AdminUserDetails admin =
>> > checkAdminDetails(importInit, langPath);
>> > +
>> > dropDB(connectionProperties);
>> > +
>> > importInit.loadAll(langPath, cfg, admin.login, admin.pass, admin.email,
>> > admin.group, admin.tz);
>> > +                                       }
>> >
>> >                                        File installerFile = new File(new
>> > File(home, ScopeApplicationAdapter.configDirName),
>> > InstallationDocumentHandler.installFileName);
>> >
>> >  InstallationDocumentHandler.getInstance().createDocument(installerFile.getAbsolutePath(),
>> > 1);
>> > @@ -392,19 +356,7 @@ public class Admin {
>> >                                }
>> >                                break;
>> >                        case restore:
>> > -                               try {
>> > -                                       File backup = new File(file);
>> > -                                       if (!cmdl.hasOption("file") ||
>> > !backup.exists() || !backup.isFile()) {
>> > -                                               System.out.println("File
>> > should be specified, and point the existent zip file");
>> > -                                               usage();
>> > -                                               System.exit(1);
>> > -                                       }
>> > -
>> > -                                       BackupImportController
>> > importCtrl =
>> > getApplicationContext(ctxName).getBean(BackupImportController.class);
>> > -                                       importCtrl.performImport(new
>> > FileInputStream(backup), omHome.getAbsolutePath());
>> > -                               } catch (Exception e) {
>> > -                                       handleError("Restore failed",
>> > e);
>> > -                               }
>> > +                               restoreOm(ctxName,
>> > checkRestoreFile(file));
>> >                                break;
>> >                        case files:
>> >                                try {
>> > @@ -451,6 +403,95 @@ public class Admin {
>> >                System.exit(0);
>> >        }
>> >
>> > +       private class AdminUserDetails {
>> > +               String login = null;
>> > +               String email = null;
>> > +               String group = null;
>> > +               String pass = null;
>> > +               String tz = null;
>> > +       }
>> > +
>> > +       private AdminUserDetails checkAdminDetails(ImportInitvalues
>> > importInit, String langPath) throws Exception {
>> > +               AdminUserDetails admin = new AdminUserDetails();
>> > +               admin.login = cmdl.getOptionValue("user");
>> > +               admin.email = cmdl.getOptionValue("email");
>> > +               admin.group = cmdl.getOptionValue("group");
>> > +               if (admin.login == null || admin.login.length() <
>> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH) {
>> > +                       System.out.println("User login was not provided,
>> > or too short, should be at least " +
>> > InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " character long.");
>> > +                       System.exit(1);
>> > +               }
>> > +
>> > +               try {
>> > +                       if (!MailUtil.matches(admin.email)) {
>> > +                           throw new AddressException("Invalid
>> > address");
>> > +                       }
>> > +                       new InternetAddress(admin.email, true);
>> > +               } catch (AddressException ae) {
>> > +                       System.out.println("Please provide non-empty
>> > valid email: '" + admin.email + "' is not valid.");
>> > +                       System.exit(1);
>> > +               }
>> > +               if (admin.group == null || admin.group.length() < 1) {
>> > +                       System.out.println("User group was not provided,
>> > or too short, should be at least 1 character long: " + admin.group);
>> > +                       System.exit(1);
>> > +               }
>> > +               admin.pass = cmdl.getOptionValue("password");
>> > +               if (checkPassword(admin.pass)) {
>> > +                       System.out.print("Please enter password:");
>> > +                       admin.pass = new BufferedReader(new
>> > InputStreamReader(System.in)).readLine();
>> > +                       if (checkPassword(admin.pass)) {
>> > +                               System.out.println("Password was not
>> > provided, or too short, should be at least " +
>> > InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH + " character long.");
>> > +                               System.exit(1);
>> > +                       }
>> > +               }
>> > +               Map<String, String> tzMap =
>> > ImportHelper.getAllTimeZones(importInit.getTimeZones(langPath));
>> > +               admin.tz = null;
>> > +               if (cmdl.hasOption("tz")) {
>> > +                       admin.tz = cmdl.getOptionValue("tz");
>> > +                       admin.tz = tzMap.containsKey(admin.tz) ?
>> > admin.tz : null;
>> > +               }
>> > +               if (admin.tz == null) {
>> > +                       System.out.println("Please enter timezone,
>> > Possible timezones are:");
>> > +                       for (String tzJname : tzMap.keySet()) {
>> > +                               System.out.println(tzJname);
>> > +                       }
>> > +                       System.exit(1);
>> > +               }
>> > +               return admin;
>> > +       }
>> > +
>> > +       private boolean checkPassword(String pass) {
>> > +               return (pass == null || pass.length() <
>> > InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH);
>> > +       }
>> > +
>> > +       private void dropDB(ConnectionProperties props) throws Exception
>> > {
>> > +               if(cmdl.hasOption("drop")) {
>> > +                       String[] mappingToolArgs = {"-sa", "drop", "-p",
>> > omHome.getAbsolutePath() + "/WEB-INF/classes/META-INF/persistence.xml",
>> > +                                       "-connectionDriverName",
>> > props.getDriverName(), "-connectionURL", props.getConnectionURL(),
>> > +                                       "-connectionUserName",
>> > props.getConnectionLogin(), "-connectionPassword",
>> > props.getConnectionPass()};
>> > +                       MappingTool.main(mappingToolArgs);
>> > +               }
>> > +       }
>> > +
>> > +       private File checkRestoreFile(String file) {
>> > +               File backup = new File(file);
>> > +               if (!cmdl.hasOption("file") || !backup.exists() ||
>> > !backup.isFile()) {
>> > +                       System.out.println("File should be specified,
>> > and point the existent zip file");
>> > +                       usage();
>> > +                       System.exit(1);
>> > +               }
>> > +
>> > +               return backup;
>> > +       }
>> > +
>> > +       private void restoreOm(String ctxName, File backup) {
>> > +               try {
>> > +                       BackupImportController importCtrl =
>> > getApplicationContext(ctxName).getBean(BackupImportController.class);
>> > +                       importCtrl.performImport(new
>> > FileInputStream(backup), omHome.getAbsolutePath());
>> > +               } catch (Exception e) {
>> > +                       handleError("Restore failed", e);
>> > +               }
>> > +       }
>> > +
>> >        public static void main(String[] args) {
>> >                new Admin().process(args);
>> >        }
>> >
>> > Modified:
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
>> > URL:
>> > http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java?rev=1330188&r1=1330187&r2=1330188&view=diff
>> >
>> > ==============================================================================
>> > ---
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
>> > (original)
>> > +++
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
>> > Wed Apr 25 10:35:08 2012
>> > @@ -38,6 +38,7 @@ import org.openmeetings.app.installation
>> >  import org.openmeetings.app.installation.InstallationConfig;
>> >  import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
>> >  import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
>> > +import org.openmeetings.utils.ImportHelper;
>> >  import org.red5.logging.Red5LoggerFactory;
>> >  import org.slf4j.Logger;
>> >  import org.springframework.context.ApplicationContext;
>> > @@ -117,22 +118,14 @@ public class Install extends VelocityVie
>> >                allFonts.put("Verdana", "Verdana");
>> >                allFonts.put("Arial", "Arial");
>> >
>> > -               LinkedHashMap<String, String> allTimeZones = new
>> > LinkedHashMap<String, String>();
>> >                List<OmTimeZone> omTimeZoneList = getImportInitvalues()
>> >                                .getTimeZones(filePath);
>> > -               log.debug("omTimeZoneList :: " + omTimeZoneList.size());
>> > -               for (OmTimeZone omTimeZone : omTimeZoneList) {
>> > -                       String labelName = omTimeZone.getJname() + " ("
>> > -                                       + omTimeZone.getLabel() + ")";
>> > -                       log.debug("labelName :: " + labelName);
>> > -                       allTimeZones.put(omTimeZone.getJname(),
>> > labelName);
>> > -               }
>> >
>> >                Template tpl = super.getTemplate("install_step1_"
>> >                                + lang + ".vm");
>> >                ctx.put("allLanguages", allLanguages);
>> >                ctx.put("allFonts", allFonts);
>> > -               ctx.put("allTimeZones", allTimeZones);
>> > +               ctx.put("allTimeZones",
>> > ImportHelper.getAllTimeZones(omTimeZoneList));
>> >                StringWriter writer = new StringWriter();
>> >                tpl.merge(ctx, writer);
>> >
>> >
>> > Modified:
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
>> > URL:
>> > http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java?rev=1330188&r1=1330187&r2=1330188&view=diff
>> >
>> > ==============================================================================
>> > ---
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
>> > (original)
>> > +++
>> > incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
>> > Wed Apr 25 10:35:08 2012
>> > @@ -18,9 +18,13 @@
>> >  */
>> >  package org.openmeetings.utils;
>> >
>> > +import java.util.LinkedHashMap;
>> > +import java.util.List;
>> > +import java.util.Map;
>> > +
>> >  import org.openmeetings.app.OpenmeetingsVariables;
>> >  import org.openmeetings.app.data.basic.Configurationmanagement;
>> > -import org.openmeetings.app.persistence.beans.basic.Configuration;
>> > +import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
>> >  import org.red5.logging.Red5LoggerFactory;
>> >  import org.slf4j.Logger;
>> >
>> > @@ -31,22 +35,27 @@ public class ImportHelper {
>> >
>> >        public static final int getMaxUploadSize(
>> >                        Configurationmanagement cfgManagement) {
>> > -               return getMaxUploadSize(cfgManagement, 3L);
>> > -       }
>> > -
>> > -       public static final int getMaxUploadSize(
>> > -                       Configurationmanagement cfgManagement, Long
>> > userLevel) {
>> > -               Configuration cfg = cfgManagement.getConfKey(userLevel,
>> > -                               "DEFAULT_MAX_UPLOAD_SIZE");
>> >                int result = DEFAULT_MAX_UPLOAD_SIZE;
>> > -               if (cfg != null) {
>> > -                       String val = cfg.getConf_value();
>> > -                       try {
>> > -                               result = (int)
>> > Math.min(Long.parseLong(val), Integer.MAX_VALUE);
>> > -                       } catch (Exception e) {
>> > -                               log.error("Invalid value saved for
>> > maxUploadSize: " + val, e);
>> > -                       }
>> > +               String maxSize =
>> > cfgManagement.getConfValue("DEFAULT_MAX_UPLOAD_SIZE", String.class, "" +
>> > result);
>> > +               try {
>> > +                       result = (int) Math.min(Long.parseLong(maxSize),
>> > Integer.MAX_VALUE);
>> > +               } catch (Exception e) {
>> > +                       log.error("Invalid value saved for
>> > maxUploadSize: " + maxSize, e);
>> > +               }
>> > +               return result;
>> > +       }
>> > +
>> > +       public static Map<String, String>
>> > getAllTimeZones(List<OmTimeZone> tzList) {
>> > +               Map<String, String> result = new LinkedHashMap<String,
>> > String>();
>> > +
>> > +               log.debug("omTimeZoneList :: " + tzList.size());
>> > +               for (OmTimeZone omTimeZone : tzList) {
>> > +                       String labelName = omTimeZone.getJname() + " ("
>> > +                                       + omTimeZone.getLabel() + ")";
>> > +                       log.debug("labelName :: " + labelName);
>> > +                       result.put(omTimeZone.getJname(), labelName);
>> >                }
>> > +
>> >                return result;
>> >        }
>> >  }
>> >
>> >
>>
>>
>>
>> --
>> Sebastian Wagner
>> https://twitter.com/#!/dead_lock
>> http://www.openmeetings.de
>> http://www.webbase-design.de
>> http://www.wagner-sebastian.com
>> seba.wagner@gmail.com
>
>
>
>
> --
> WBR
> Maxim aka solomax



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

Re: svn commit: r1330188 - in /incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings: app/installation/ImportInitvalues.java cli/Admin.java servlet/outputhandler/Install.java utils/ImportHelper.java

Posted by Maxim Solodovnik <so...@gmail.com>.
Hello Sebastian,

jname was selected since our API (OmTimeZoneDaoImpl) can only get timezone
by ID or jname.
Additionally while adding initial admin user we need to have jname
(Usermanagement.addUser:1060  requires jName_timezone).

In fact there are no duplicate output in admin:
Etc/GMT+1
Etc/GMT+1 (North Africa)

so user should enter "Etc/GMT+1" or "Etc/GMT+1 (North Africa)".

I can change admin to expect timezone as iCal, but in such case we need to
agree what will be the form of user hint.

I mean:
I leave in Russia/Novosibirsk, I know my timezone is Novosibirsk (GMT+7).
Currently I can see my timezone in the available timezone list (Etc/GMT+7 )
but if available timezone list will be "Asia/Jakarta" it might confusing.

I guess timezone hint should looks like follows

Please enter
"Asia/Jakarta"                 for Novosibirsk, Indochina Time, Thailand,
Vietnam, Jakarta (Etc/GMT+7)
"Australia/Queensland"  for Russia (Zabaykalsky Krai), Papua New Guinea,
Australia (Queensland) Etc/GMT+10
........................................

what do you think?

On Wed, Apr 25, 2012 at 19:13, seba.wagner@gmail.com
<se...@gmail.com>wrote:

> Hi Maxim,
>
> I don't think this will work.
> I thought you would use the field "ical" for matching the given
> timezone to the user input?
>
> I was not able to use the CLI installer to accept any of my input,
> neither "Berlin", nor "Europe/Berlin".
> What should be the input that I have to give
>
> Also as error / options you list then all available timezone name's as
> options. There are two times the name GMT+1, so how should the user
> understand what is the different between GMT+1 and GMT+1 ?
>
>
> Sebastian
>
>
> 2012/4/25  <so...@apache.org>:
> > Author: solomax
> > Date: Wed Apr 25 10:35:08 2012
> > New Revision: 1330188
> >
> > URL: http://svn.apache.org/viewvc?rev=1330188&view=rev
> > Log:
> > OPENMEETINGS-111 tz issues was fixed; options to install OM from backup
> provided is added.
> >
> > Modified:
> >
>  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
> >
>  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
> >
>  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
> >
>  incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
> >
> > Modified:
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
> > URL:
> http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> >
> ==============================================================================
> > ---
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
> (original)
> > +++
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
> Wed Apr 25 10:35:08 2012
> > @@ -768,8 +768,7 @@ public class ImportInitvalues {
> >                List<OmTimeZone> omTimeZones = new
> LinkedList<OmTimeZone>();
> >
> >                SAXReader reader = new SAXReader();
> > -               Document document = reader.read(filePath
> > -                               + ImportInitvalues.nameOfTimeZoneFile);
> > +               Document document = reader.read(new File(filePath,
> ImportInitvalues.nameOfTimeZoneFile));
> >
> >                Element root = document.getRootElement();
> >
> > @@ -960,8 +959,7 @@ public class ImportInitvalues {
> >        }
> >        //
> ------------------------------------------------------------------------------
> >
> > -       public void loadAll(String filePath, InstallationConfig cfg,
> String username,
> > -                       String userpass, String useremail, String
> groupame, String timeZone) throws Exception {
> > +       public void loadSystem(String filePath, InstallationConfig cfg)
> throws Exception {
> >                loadMainMenu();
> >                loadErrorMappingsFromXML(filePath);
> >                loadInitLanguages(filePath);
> > @@ -974,7 +972,12 @@ public class ImportInitvalues {
> >                loadPollTypes();
> >
> >                loadConfiguration(cfg);
> > +       }
> > +
> > +       public void loadAll(String filePath, InstallationConfig cfg,
> String username,
> > +                       String userpass, String useremail, String
> groupame, String timeZone) throws Exception {
> >
> > +               loadSystem(filePath, cfg);
> >                loadInitUserAndOrganisation(username,
> >                                userpass, useremail, groupame, timeZone,
> cfg.defaultLangId);
> >
> >
> > Modified:
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
> > URL:
> http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> >
> ==============================================================================
> > ---
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
> (original)
> > +++
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
> Wed Apr 25 10:35:08 2012
> > @@ -9,6 +9,7 @@ import java.net.MalformedURLException;
> >  import java.net.URL;
> >  import java.util.Date;
> >  import java.util.Enumeration;
> > +import java.util.Map;
> >  import java.util.Set;
> >
> >  import javax.mail.internet.AddressException;
> > @@ -27,15 +28,14 @@ import org.apache.commons.cli.Parser;
> >  import org.apache.commons.cli.PosixParser;
> >  import org.apache.openjpa.jdbc.meta.MappingTool;
> >  import org.openmeetings.app.OpenmeetingsVariables;
> > -import org.openmeetings.app.data.basic.dao.OmTimeZoneDaoImpl;
> >  import org.openmeetings.app.data.file.FileUtils;
> >  import org.openmeetings.app.documents.InstallationDocumentHandler;
> >  import org.openmeetings.app.installation.ImportInitvalues;
> >  import org.openmeetings.app.installation.InstallationConfig;
> > -import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
> >  import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
> >  import org.openmeetings.servlet.outputhandler.BackupExport;
> >  import org.openmeetings.servlet.outputhandler.BackupImportController;
> > +import org.openmeetings.utils.ImportHelper;
> >  import org.openmeetings.utils.OMContextListener;
> >  import org.openmeetings.utils.mail.MailUtil;
> >  import org.openmeetings.utils.math.CalendarPatterns;
> > @@ -49,6 +49,8 @@ public class Admin {
> >        private boolean verbose = false;
> >        private InstallationConfig cfg = null;
> >        private Options opts = null;
> > +       private CommandLine cmdl = null;
> > +       File omHome = null;
> >
> >        private Admin() {
> >                cfg = new InstallationConfig();
> > @@ -69,12 +71,12 @@ public class Admin {
> >                options.addOption(new OmOption(null, "v", "verbose",
> false, "verbose error messages"));
> >                //backup/restore
> >                options.addOption(new OmOption("b", null,
> "exclude-files", false, "should backup exclude files [default: include]",
> true));
> > -               options.addOption(new OmOption("b,r", "file", null,
> true, "file used for backup/restore", "b"));
> > +               options.addOption(new OmOption("b,r,i", "file", null,
> true, "file used for backup/restore/install", "b"));
> >                //install
> > -               options.addOption(new OmOption("i", "user", null, true,
> "Login name of the default user, minimum " +
> InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters"));
> > -               options.addOption(new OmOption("i", "email", null, true,
> "Email of the default user"));
> > -               options.addOption(new OmOption("i", "group", null, true,
> "The name of the default user group"));
> > -               options.addOption(new OmOption("i", "tz", null, true,
> "Default server time zone, and time zone for the selected user [for ex:
> 'GMT+10', '-2', 'Chicago']"));
> > +               options.addOption(new OmOption("i", "user", null, true,
> "Login name of the default user, minimum " +
> InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (mutually
> exclusive with 'file')"));
> > +               options.addOption(new OmOption("i", "email", null, true,
> "Email of the default user (mutually exclusive with 'file')"));
> > +               options.addOption(new OmOption("i", "group", null, true,
> "The name of the default user group (mutually exclusive with 'file')"));
> > +               options.addOption(new OmOption("i", "tz", null, true,
> "Default server time zone, and time zone for the selected user (mutually
> exclusive with 'file')"));
> >                options.addOption(new OmOption("i", null, "password",
> true, "Password of the default user, minimum " +
> InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (will be
> prompted if not set)", true));
> >                options.addOption(new OmOption("i", null,
> "system-email-address", true, "System e-mail address [default: " +
> cfg.mailReferer + "]", true));
> >                options.addOption(new OmOption("i", null, "smtp-server",
> true, "SMTP server for outgoing e-mails [default: " + cfg.smtpServer + "]",
> true));
> > @@ -242,11 +244,10 @@ public class Admin {
> >        private void process(String[] args) {
> >                String ctxName = System.getProperty("context",
> "openmeetings");
> >                File home = new File(System.getenv("RED5_HOME"));
> > -               File omHome = new File(new File(home, "webapps"),
> ctxName);
> > +               omHome = new File(new File(home, "webapps"), ctxName);
> >                File omUploadTemp = new File(omHome,
> OpenmeetingsVariables.UPLOAD_TEMP_DIR);
> >
> >                Parser parser = new PosixParser();
> > -               CommandLine cmdl = null;
> >                try {
> >                        cmdl = parser.parse(opts, args);
> >                } catch (ParseException e) {
> > @@ -271,9 +272,10 @@ public class Admin {
> >                switch(cmd) {
> >                        case install:
> >                                try {
> > -                                       String login =
> cmdl.getOptionValue("user");
> > -                                       String email =
> cmdl.getOptionValue("email");
> > -                                       String group =
> cmdl.getOptionValue("group");
> > +                                       if (cmdl.hasOption("file") &&
> (cmdl.hasOption("user") || cmdl.hasOption("email") ||
> cmdl.hasOption("group"))) {
> > +
> System.out.println("Please specify even 'file' option or 'admin user'.");
> > +                                               System.exit(1);
> > +                                       }
> >                                        //TODO commented for now, since
> not in use boolean force = cmdl.hasOption("force");
> >                                        if
> (cmdl.hasOption("skip-default-rooms")) {
> >                                                cfg.createDefaultRooms =
> "0";
> > @@ -299,33 +301,7 @@ public class Admin {
> >                                        if
> (cmdl.hasOption("email-use-tls")) {
> >                                                cfg.mailUseTls = "1";
> >                                        }
> > -                                       if (login == null ||
> login.length() < InstallationConfig.USER_LOGIN_MINIMUM_LENGTH) {
> > -                                               System.out.println("User
> login was not provided, or too short, should be at least " +
> InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " character long.");
> > -                                               System.exit(1);
> > -                                       }
> > -
> > -                                       try {
> > -                                               if
> (!MailUtil.matches(email)) {
> > -                                                   throw new
> AddressException("Invalid address");
> > -                                               }
> > -                                               new
> InternetAddress(email, true);
> > -                                       } catch (AddressException ae) {
> > -
> System.out.println("Please provide non-empty valid email: '" + email + "'
> is not valid.");
> > -                                               System.exit(1);
> > -                                       }
> > -                                       if (group == null ||
> login.length() < 1) {
> > -                                               System.out.println("User
> group was not provided, or too short, should be at least 1 character
> long.");
> > -                                               System.exit(1);
> > -                                       }
> > -                                       String pass =
> cmdl.getOptionValue("password");
> > -                                       if (pass == null ||
> pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH) {
> > -                                               System.out.print("Please
> enter password:");
> > -                                               pass = new
> BufferedReader(new InputStreamReader(System.in)).readLine();
> > -                                               if (pass == null ||
> pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH) {
> > -
> System.out.println("Password was not provided, or too short, should be at
> least " + InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH + " character
> long.");
> > -                                                       System.exit(1);
> > -                                               }
> > -                                       }
> > +                                       String langPath = new
> File(omHome, ImportInitvalues.languageFolderName).getAbsolutePath();
> //FIXME need to be moved to helper
> >                                        ConnectionProperties
> connectionProperties = new ConnectionProperties();
> >                                        if (cmdl.hasOption("db-type") ||
> cmdl.hasOption("db-host") || cmdl.hasOption("db-port") ||
> cmdl.hasOption("db-name") || cmdl.hasOption("db-user") ||
> cmdl.hasOption("db-pass")) {
> >                                                String dbType =
> cmdl.getOptionValue("db-type", "derby");
> > @@ -342,30 +318,18 @@ public class Admin {
> >                                                                ,
> connectionProperties
> >                                                                );
> >                                        }
> > -
> > -                                       if(cmdl.hasOption("drop")) {
> > -                                               String[] mappingToolArgs
> = {"-sa", "drop", "-p", omHome.getPath() +
> "/WEB-INF/classes/META-INF/persistence.xml",
> > -
> "-connectionDriverName", connectionProperties.getDriverName(),
> "-connectionURL", connectionProperties.getConnectionURL(),
> > -
> "-connectionUserName", connectionProperties.getConnectionLogin(),
> "-connectionPassword", connectionProperties.getConnectionPass()};
> > -
> MappingTool.main(mappingToolArgs);
> > -                                       }
> > -
> >                                        ClassPathXmlApplicationContext
> ctx = getApplicationContext(ctxName);
> > -                                       OmTimeZoneDaoImpl tzDao =
>  ctx.getBean(OmTimeZoneDaoImpl.class);
> > -                                       String tz = null;
> > -                                       if (cmdl.hasOption("tz")) {
> > -                                               tz =
> cmdl.getOptionValue("tz");
> > -                                               tz =
> tzDao.getOmTimeZone(tz) == null ? null : tz;
> > -                                       }
> > -                                       if (tz == null) {
> > -
> System.out.println("Please enter timezone, Possible timezones are:");
> > -                                               for (OmTimeZone omTz :
> tzDao.getOmTimeZones()) {
> > -
> System.out.println(omTz.getJname());
> > -                                               }
> > -                                               System.exit(1);
> > -                                       }
> >                                        ImportInitvalues importInit =
> ctx.getBean(ImportInitvalues.class);
> > -                                       importInit.loadAll(new
> File(omHome, ImportInitvalues.languageFolderName).getAbsolutePath(), cfg,
> login, pass, email, group, tz);
> > +                                       if (cmdl.hasOption("file")) {
> > +                                               File backup =
> checkRestoreFile(file);
> > +
> dropDB(connectionProperties);
> > +
> importInit.loadSystem(langPath, cfg);
> > +                                               restoreOm(ctxName,
> backup);
> > +                                       } else {
> > +                                               AdminUserDetails admin =
> checkAdminDetails(importInit, langPath);
> > +
> dropDB(connectionProperties);
> > +
> importInit.loadAll(langPath, cfg, admin.login, admin.pass, admin.email,
> admin.group, admin.tz);
> > +                                       }
> >
> >                                        File installerFile = new File(new
> File(home, ScopeApplicationAdapter.configDirName),
> InstallationDocumentHandler.installFileName);
> >
>  InstallationDocumentHandler.getInstance().createDocument(installerFile.getAbsolutePath(),
> 1);
> > @@ -392,19 +356,7 @@ public class Admin {
> >                                }
> >                                break;
> >                        case restore:
> > -                               try {
> > -                                       File backup = new File(file);
> > -                                       if (!cmdl.hasOption("file") ||
> !backup.exists() || !backup.isFile()) {
> > -                                               System.out.println("File
> should be specified, and point the existent zip file");
> > -                                               usage();
> > -                                               System.exit(1);
> > -                                       }
> > -
> > -                                       BackupImportController
> importCtrl =
> getApplicationContext(ctxName).getBean(BackupImportController.class);
> > -                                       importCtrl.performImport(new
> FileInputStream(backup), omHome.getAbsolutePath());
> > -                               } catch (Exception e) {
> > -                                       handleError("Restore failed", e);
> > -                               }
> > +                               restoreOm(ctxName,
> checkRestoreFile(file));
> >                                break;
> >                        case files:
> >                                try {
> > @@ -451,6 +403,95 @@ public class Admin {
> >                System.exit(0);
> >        }
> >
> > +       private class AdminUserDetails {
> > +               String login = null;
> > +               String email = null;
> > +               String group = null;
> > +               String pass = null;
> > +               String tz = null;
> > +       }
> > +
> > +       private AdminUserDetails checkAdminDetails(ImportInitvalues
> importInit, String langPath) throws Exception {
> > +               AdminUserDetails admin = new AdminUserDetails();
> > +               admin.login = cmdl.getOptionValue("user");
> > +               admin.email = cmdl.getOptionValue("email");
> > +               admin.group = cmdl.getOptionValue("group");
> > +               if (admin.login == null || admin.login.length() <
> InstallationConfig.USER_LOGIN_MINIMUM_LENGTH) {
> > +                       System.out.println("User login was not provided,
> or too short, should be at least " +
> InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " character long.");
> > +                       System.exit(1);
> > +               }
> > +
> > +               try {
> > +                       if (!MailUtil.matches(admin.email)) {
> > +                           throw new AddressException("Invalid
> address");
> > +                       }
> > +                       new InternetAddress(admin.email, true);
> > +               } catch (AddressException ae) {
> > +                       System.out.println("Please provide non-empty
> valid email: '" + admin.email + "' is not valid.");
> > +                       System.exit(1);
> > +               }
> > +               if (admin.group == null || admin.group.length() < 1) {
> > +                       System.out.println("User group was not provided,
> or too short, should be at least 1 character long: " + admin.group);
> > +                       System.exit(1);
> > +               }
> > +               admin.pass = cmdl.getOptionValue("password");
> > +               if (checkPassword(admin.pass)) {
> > +                       System.out.print("Please enter password:");
> > +                       admin.pass = new BufferedReader(new
> InputStreamReader(System.in)).readLine();
> > +                       if (checkPassword(admin.pass)) {
> > +                               System.out.println("Password was not
> provided, or too short, should be at least " +
> InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH + " character long.");
> > +                               System.exit(1);
> > +                       }
> > +               }
> > +               Map<String, String> tzMap =
> ImportHelper.getAllTimeZones(importInit.getTimeZones(langPath));
> > +               admin.tz = null;
> > +               if (cmdl.hasOption("tz")) {
> > +                       admin.tz = cmdl.getOptionValue("tz");
> > +                       admin.tz = tzMap.containsKey(admin.tz) ?
> admin.tz : null;
> > +               }
> > +               if (admin.tz == null) {
> > +                       System.out.println("Please enter timezone,
> Possible timezones are:");
> > +                       for (String tzJname : tzMap.keySet()) {
> > +                               System.out.println(tzJname);
> > +                       }
> > +                       System.exit(1);
> > +               }
> > +               return admin;
> > +       }
> > +
> > +       private boolean checkPassword(String pass) {
> > +               return (pass == null || pass.length() <
> InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH);
> > +       }
> > +
> > +       private void dropDB(ConnectionProperties props) throws Exception
> {
> > +               if(cmdl.hasOption("drop")) {
> > +                       String[] mappingToolArgs = {"-sa", "drop", "-p",
> omHome.getAbsolutePath() + "/WEB-INF/classes/META-INF/persistence.xml",
> > +                                       "-connectionDriverName",
> props.getDriverName(), "-connectionURL", props.getConnectionURL(),
> > +                                       "-connectionUserName",
> props.getConnectionLogin(), "-connectionPassword",
> props.getConnectionPass()};
> > +                       MappingTool.main(mappingToolArgs);
> > +               }
> > +       }
> > +
> > +       private File checkRestoreFile(String file) {
> > +               File backup = new File(file);
> > +               if (!cmdl.hasOption("file") || !backup.exists() ||
> !backup.isFile()) {
> > +                       System.out.println("File should be specified,
> and point the existent zip file");
> > +                       usage();
> > +                       System.exit(1);
> > +               }
> > +
> > +               return backup;
> > +       }
> > +
> > +       private void restoreOm(String ctxName, File backup) {
> > +               try {
> > +                       BackupImportController importCtrl =
> getApplicationContext(ctxName).getBean(BackupImportController.class);
> > +                       importCtrl.performImport(new
> FileInputStream(backup), omHome.getAbsolutePath());
> > +               } catch (Exception e) {
> > +                       handleError("Restore failed", e);
> > +               }
> > +       }
> > +
> >        public static void main(String[] args) {
> >                new Admin().process(args);
> >        }
> >
> > Modified:
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
> > URL:
> http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> >
> ==============================================================================
> > ---
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
> (original)
> > +++
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
> Wed Apr 25 10:35:08 2012
> > @@ -38,6 +38,7 @@ import org.openmeetings.app.installation
> >  import org.openmeetings.app.installation.InstallationConfig;
> >  import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
> >  import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
> > +import org.openmeetings.utils.ImportHelper;
> >  import org.red5.logging.Red5LoggerFactory;
> >  import org.slf4j.Logger;
> >  import org.springframework.context.ApplicationContext;
> > @@ -117,22 +118,14 @@ public class Install extends VelocityVie
> >                allFonts.put("Verdana", "Verdana");
> >                allFonts.put("Arial", "Arial");
> >
> > -               LinkedHashMap<String, String> allTimeZones = new
> LinkedHashMap<String, String>();
> >                List<OmTimeZone> omTimeZoneList = getImportInitvalues()
> >                                .getTimeZones(filePath);
> > -               log.debug("omTimeZoneList :: " + omTimeZoneList.size());
> > -               for (OmTimeZone omTimeZone : omTimeZoneList) {
> > -                       String labelName = omTimeZone.getJname() + " ("
> > -                                       + omTimeZone.getLabel() + ")";
> > -                       log.debug("labelName :: " + labelName);
> > -                       allTimeZones.put(omTimeZone.getJname(),
> labelName);
> > -               }
> >
> >                Template tpl = super.getTemplate("install_step1_"
> >                                + lang + ".vm");
> >                ctx.put("allLanguages", allLanguages);
> >                ctx.put("allFonts", allFonts);
> > -               ctx.put("allTimeZones", allTimeZones);
> > +               ctx.put("allTimeZones",
> ImportHelper.getAllTimeZones(omTimeZoneList));
> >                StringWriter writer = new StringWriter();
> >                tpl.merge(ctx, writer);
> >
> >
> > Modified:
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
> > URL:
> http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> >
> ==============================================================================
> > ---
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
> (original)
> > +++
> incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
> Wed Apr 25 10:35:08 2012
> > @@ -18,9 +18,13 @@
> >  */
> >  package org.openmeetings.utils;
> >
> > +import java.util.LinkedHashMap;
> > +import java.util.List;
> > +import java.util.Map;
> > +
> >  import org.openmeetings.app.OpenmeetingsVariables;
> >  import org.openmeetings.app.data.basic.Configurationmanagement;
> > -import org.openmeetings.app.persistence.beans.basic.Configuration;
> > +import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
> >  import org.red5.logging.Red5LoggerFactory;
> >  import org.slf4j.Logger;
> >
> > @@ -31,22 +35,27 @@ public class ImportHelper {
> >
> >        public static final int getMaxUploadSize(
> >                        Configurationmanagement cfgManagement) {
> > -               return getMaxUploadSize(cfgManagement, 3L);
> > -       }
> > -
> > -       public static final int getMaxUploadSize(
> > -                       Configurationmanagement cfgManagement, Long
> userLevel) {
> > -               Configuration cfg = cfgManagement.getConfKey(userLevel,
> > -                               "DEFAULT_MAX_UPLOAD_SIZE");
> >                int result = DEFAULT_MAX_UPLOAD_SIZE;
> > -               if (cfg != null) {
> > -                       String val = cfg.getConf_value();
> > -                       try {
> > -                               result = (int)
> Math.min(Long.parseLong(val), Integer.MAX_VALUE);
> > -                       } catch (Exception e) {
> > -                               log.error("Invalid value saved for
> maxUploadSize: " + val, e);
> > -                       }
> > +               String maxSize =
> cfgManagement.getConfValue("DEFAULT_MAX_UPLOAD_SIZE", String.class, "" +
> result);
> > +               try {
> > +                       result = (int) Math.min(Long.parseLong(maxSize),
> Integer.MAX_VALUE);
> > +               } catch (Exception e) {
> > +                       log.error("Invalid value saved for
> maxUploadSize: " + maxSize, e);
> > +               }
> > +               return result;
> > +       }
> > +
> > +       public static Map<String, String>
> getAllTimeZones(List<OmTimeZone> tzList) {
> > +               Map<String, String> result = new LinkedHashMap<String,
> String>();
> > +
> > +               log.debug("omTimeZoneList :: " + tzList.size());
> > +               for (OmTimeZone omTimeZone : tzList) {
> > +                       String labelName = omTimeZone.getJname() + " ("
> > +                                       + omTimeZone.getLabel() + ")";
> > +                       log.debug("labelName :: " + labelName);
> > +                       result.put(omTimeZone.getJname(), labelName);
> >                }
> > +
> >                return result;
> >        }
> >  }
> >
> >
>
>
>
> --
> Sebastian Wagner
> https://twitter.com/#!/dead_lock
> http://www.openmeetings.de
> http://www.webbase-design.de
> http://www.wagner-sebastian.com
> seba.wagner@gmail.com
>



-- 
WBR
Maxim aka solomax

Re: svn commit: r1330188 - in /incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings: app/installation/ImportInitvalues.java cli/Admin.java servlet/outputhandler/Install.java utils/ImportHelper.java

Posted by "seba.wagner@gmail.com" <se...@gmail.com>.
Hi Maxim,

I don't think this will work.
I thought you would use the field "ical" for matching the given
timezone to the user input?

I was not able to use the CLI installer to accept any of my input,
neither "Berlin", nor "Europe/Berlin".
What should be the input that I have to give

Also as error / options you list then all available timezone name's as
options. There are two times the name GMT+1, so how should the user
understand what is the different between GMT+1 and GMT+1 ?


Sebastian


2012/4/25  <so...@apache.org>:
> Author: solomax
> Date: Wed Apr 25 10:35:08 2012
> New Revision: 1330188
>
> URL: http://svn.apache.org/viewvc?rev=1330188&view=rev
> Log:
> OPENMEETINGS-111 tz issues was fixed; options to install OM from backup provided is added.
>
> Modified:
>    incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
>    incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
>    incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
>    incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
>
> Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java
> URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> ==============================================================================
> --- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java (original)
> +++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/app/installation/ImportInitvalues.java Wed Apr 25 10:35:08 2012
> @@ -768,8 +768,7 @@ public class ImportInitvalues {
>                List<OmTimeZone> omTimeZones = new LinkedList<OmTimeZone>();
>
>                SAXReader reader = new SAXReader();
> -               Document document = reader.read(filePath
> -                               + ImportInitvalues.nameOfTimeZoneFile);
> +               Document document = reader.read(new File(filePath, ImportInitvalues.nameOfTimeZoneFile));
>
>                Element root = document.getRootElement();
>
> @@ -960,8 +959,7 @@ public class ImportInitvalues {
>        }
>        // ------------------------------------------------------------------------------
>
> -       public void loadAll(String filePath, InstallationConfig cfg, String username,
> -                       String userpass, String useremail, String groupame, String timeZone) throws Exception {
> +       public void loadSystem(String filePath, InstallationConfig cfg) throws Exception {
>                loadMainMenu();
>                loadErrorMappingsFromXML(filePath);
>                loadInitLanguages(filePath);
> @@ -974,7 +972,12 @@ public class ImportInitvalues {
>                loadPollTypes();
>
>                loadConfiguration(cfg);
> +       }
> +
> +       public void loadAll(String filePath, InstallationConfig cfg, String username,
> +                       String userpass, String useremail, String groupame, String timeZone) throws Exception {
>
> +               loadSystem(filePath, cfg);
>                loadInitUserAndOrganisation(username,
>                                userpass, useremail, groupame, timeZone, cfg.defaultLangId);
>
>
> Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java
> URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> ==============================================================================
> --- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java (original)
> +++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/cli/Admin.java Wed Apr 25 10:35:08 2012
> @@ -9,6 +9,7 @@ import java.net.MalformedURLException;
>  import java.net.URL;
>  import java.util.Date;
>  import java.util.Enumeration;
> +import java.util.Map;
>  import java.util.Set;
>
>  import javax.mail.internet.AddressException;
> @@ -27,15 +28,14 @@ import org.apache.commons.cli.Parser;
>  import org.apache.commons.cli.PosixParser;
>  import org.apache.openjpa.jdbc.meta.MappingTool;
>  import org.openmeetings.app.OpenmeetingsVariables;
> -import org.openmeetings.app.data.basic.dao.OmTimeZoneDaoImpl;
>  import org.openmeetings.app.data.file.FileUtils;
>  import org.openmeetings.app.documents.InstallationDocumentHandler;
>  import org.openmeetings.app.installation.ImportInitvalues;
>  import org.openmeetings.app.installation.InstallationConfig;
> -import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
>  import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
>  import org.openmeetings.servlet.outputhandler.BackupExport;
>  import org.openmeetings.servlet.outputhandler.BackupImportController;
> +import org.openmeetings.utils.ImportHelper;
>  import org.openmeetings.utils.OMContextListener;
>  import org.openmeetings.utils.mail.MailUtil;
>  import org.openmeetings.utils.math.CalendarPatterns;
> @@ -49,6 +49,8 @@ public class Admin {
>        private boolean verbose = false;
>        private InstallationConfig cfg = null;
>        private Options opts = null;
> +       private CommandLine cmdl = null;
> +       File omHome = null;
>
>        private Admin() {
>                cfg = new InstallationConfig();
> @@ -69,12 +71,12 @@ public class Admin {
>                options.addOption(new OmOption(null, "v", "verbose", false, "verbose error messages"));
>                //backup/restore
>                options.addOption(new OmOption("b", null, "exclude-files", false, "should backup exclude files [default: include]", true));
> -               options.addOption(new OmOption("b,r", "file", null, true, "file used for backup/restore", "b"));
> +               options.addOption(new OmOption("b,r,i", "file", null, true, "file used for backup/restore/install", "b"));
>                //install
> -               options.addOption(new OmOption("i", "user", null, true, "Login name of the default user, minimum " + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters"));
> -               options.addOption(new OmOption("i", "email", null, true, "Email of the default user"));
> -               options.addOption(new OmOption("i", "group", null, true, "The name of the default user group"));
> -               options.addOption(new OmOption("i", "tz", null, true, "Default server time zone, and time zone for the selected user [for ex: 'GMT+10', '-2', 'Chicago']"));
> +               options.addOption(new OmOption("i", "user", null, true, "Login name of the default user, minimum " + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (mutually exclusive with 'file')"));
> +               options.addOption(new OmOption("i", "email", null, true, "Email of the default user (mutually exclusive with 'file')"));
> +               options.addOption(new OmOption("i", "group", null, true, "The name of the default user group (mutually exclusive with 'file')"));
> +               options.addOption(new OmOption("i", "tz", null, true, "Default server time zone, and time zone for the selected user (mutually exclusive with 'file')"));
>                options.addOption(new OmOption("i", null, "password", true, "Password of the default user, minimum " + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (will be prompted if not set)", true));
>                options.addOption(new OmOption("i", null, "system-email-address", true, "System e-mail address [default: " + cfg.mailReferer + "]", true));
>                options.addOption(new OmOption("i", null, "smtp-server", true, "SMTP server for outgoing e-mails [default: " + cfg.smtpServer + "]", true));
> @@ -242,11 +244,10 @@ public class Admin {
>        private void process(String[] args) {
>                String ctxName = System.getProperty("context", "openmeetings");
>                File home = new File(System.getenv("RED5_HOME"));
> -               File omHome = new File(new File(home, "webapps"), ctxName);
> +               omHome = new File(new File(home, "webapps"), ctxName);
>                File omUploadTemp = new File(omHome, OpenmeetingsVariables.UPLOAD_TEMP_DIR);
>
>                Parser parser = new PosixParser();
> -               CommandLine cmdl = null;
>                try {
>                        cmdl = parser.parse(opts, args);
>                } catch (ParseException e) {
> @@ -271,9 +272,10 @@ public class Admin {
>                switch(cmd) {
>                        case install:
>                                try {
> -                                       String login = cmdl.getOptionValue("user");
> -                                       String email = cmdl.getOptionValue("email");
> -                                       String group = cmdl.getOptionValue("group");
> +                                       if (cmdl.hasOption("file") && (cmdl.hasOption("user") || cmdl.hasOption("email") || cmdl.hasOption("group"))) {
> +                                               System.out.println("Please specify even 'file' option or 'admin user'.");
> +                                               System.exit(1);
> +                                       }
>                                        //TODO commented for now, since not in use boolean force = cmdl.hasOption("force");
>                                        if (cmdl.hasOption("skip-default-rooms")) {
>                                                cfg.createDefaultRooms = "0";
> @@ -299,33 +301,7 @@ public class Admin {
>                                        if (cmdl.hasOption("email-use-tls")) {
>                                                cfg.mailUseTls = "1";
>                                        }
> -                                       if (login == null || login.length() < InstallationConfig.USER_LOGIN_MINIMUM_LENGTH) {
> -                                               System.out.println("User login was not provided, or too short, should be at least " + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " character long.");
> -                                               System.exit(1);
> -                                       }
> -
> -                                       try {
> -                                               if (!MailUtil.matches(email)) {
> -                                                   throw new AddressException("Invalid address");
> -                                               }
> -                                               new InternetAddress(email, true);
> -                                       } catch (AddressException ae) {
> -                                               System.out.println("Please provide non-empty valid email: '" + email + "' is not valid.");
> -                                               System.exit(1);
> -                                       }
> -                                       if (group == null || login.length() < 1) {
> -                                               System.out.println("User group was not provided, or too short, should be at least 1 character long.");
> -                                               System.exit(1);
> -                                       }
> -                                       String pass = cmdl.getOptionValue("password");
> -                                       if (pass == null || pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH) {
> -                                               System.out.print("Please enter password:");
> -                                               pass = new BufferedReader(new InputStreamReader(System.in)).readLine();
> -                                               if (pass == null || pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH) {
> -                                                       System.out.println("Password was not provided, or too short, should be at least " + InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH + " character long.");
> -                                                       System.exit(1);
> -                                               }
> -                                       }
> +                                       String langPath = new File(omHome, ImportInitvalues.languageFolderName).getAbsolutePath(); //FIXME need to be moved to helper
>                                        ConnectionProperties connectionProperties = new ConnectionProperties();
>                                        if (cmdl.hasOption("db-type") || cmdl.hasOption("db-host") || cmdl.hasOption("db-port") || cmdl.hasOption("db-name") || cmdl.hasOption("db-user") || cmdl.hasOption("db-pass")) {
>                                                String dbType = cmdl.getOptionValue("db-type", "derby");
> @@ -342,30 +318,18 @@ public class Admin {
>                                                                , connectionProperties
>                                                                );
>                                        }
> -
> -                                       if(cmdl.hasOption("drop")) {
> -                                               String[] mappingToolArgs = {"-sa", "drop", "-p", omHome.getPath() + "/WEB-INF/classes/META-INF/persistence.xml",
> -                                                               "-connectionDriverName", connectionProperties.getDriverName(), "-connectionURL", connectionProperties.getConnectionURL(),
> -                                                               "-connectionUserName", connectionProperties.getConnectionLogin(), "-connectionPassword", connectionProperties.getConnectionPass()};
> -                                               MappingTool.main(mappingToolArgs);
> -                                       }
> -
>                                        ClassPathXmlApplicationContext ctx = getApplicationContext(ctxName);
> -                                       OmTimeZoneDaoImpl tzDao =  ctx.getBean(OmTimeZoneDaoImpl.class);
> -                                       String tz = null;
> -                                       if (cmdl.hasOption("tz")) {
> -                                               tz = cmdl.getOptionValue("tz");
> -                                               tz = tzDao.getOmTimeZone(tz) == null ? null : tz;
> -                                       }
> -                                       if (tz == null) {
> -                                               System.out.println("Please enter timezone, Possible timezones are:");
> -                                               for (OmTimeZone omTz : tzDao.getOmTimeZones()) {
> -                                                       System.out.println(omTz.getJname());
> -                                               }
> -                                               System.exit(1);
> -                                       }
>                                        ImportInitvalues importInit = ctx.getBean(ImportInitvalues.class);
> -                                       importInit.loadAll(new File(omHome, ImportInitvalues.languageFolderName).getAbsolutePath(), cfg, login, pass, email, group, tz);
> +                                       if (cmdl.hasOption("file")) {
> +                                               File backup = checkRestoreFile(file);
> +                                               dropDB(connectionProperties);
> +                                               importInit.loadSystem(langPath, cfg);
> +                                               restoreOm(ctxName, backup);
> +                                       } else {
> +                                               AdminUserDetails admin = checkAdminDetails(importInit, langPath);
> +                                               dropDB(connectionProperties);
> +                                               importInit.loadAll(langPath, cfg, admin.login, admin.pass, admin.email, admin.group, admin.tz);
> +                                       }
>
>                                        File installerFile = new File(new File(home, ScopeApplicationAdapter.configDirName), InstallationDocumentHandler.installFileName);
>                                        InstallationDocumentHandler.getInstance().createDocument(installerFile.getAbsolutePath(), 1);
> @@ -392,19 +356,7 @@ public class Admin {
>                                }
>                                break;
>                        case restore:
> -                               try {
> -                                       File backup = new File(file);
> -                                       if (!cmdl.hasOption("file") || !backup.exists() || !backup.isFile()) {
> -                                               System.out.println("File should be specified, and point the existent zip file");
> -                                               usage();
> -                                               System.exit(1);
> -                                       }
> -
> -                                       BackupImportController importCtrl = getApplicationContext(ctxName).getBean(BackupImportController.class);
> -                                       importCtrl.performImport(new FileInputStream(backup), omHome.getAbsolutePath());
> -                               } catch (Exception e) {
> -                                       handleError("Restore failed", e);
> -                               }
> +                               restoreOm(ctxName, checkRestoreFile(file));
>                                break;
>                        case files:
>                                try {
> @@ -451,6 +403,95 @@ public class Admin {
>                System.exit(0);
>        }
>
> +       private class AdminUserDetails {
> +               String login = null;
> +               String email = null;
> +               String group = null;
> +               String pass = null;
> +               String tz = null;
> +       }
> +
> +       private AdminUserDetails checkAdminDetails(ImportInitvalues importInit, String langPath) throws Exception {
> +               AdminUserDetails admin = new AdminUserDetails();
> +               admin.login = cmdl.getOptionValue("user");
> +               admin.email = cmdl.getOptionValue("email");
> +               admin.group = cmdl.getOptionValue("group");
> +               if (admin.login == null || admin.login.length() < InstallationConfig.USER_LOGIN_MINIMUM_LENGTH) {
> +                       System.out.println("User login was not provided, or too short, should be at least " + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " character long.");
> +                       System.exit(1);
> +               }
> +
> +               try {
> +                       if (!MailUtil.matches(admin.email)) {
> +                           throw new AddressException("Invalid address");
> +                       }
> +                       new InternetAddress(admin.email, true);
> +               } catch (AddressException ae) {
> +                       System.out.println("Please provide non-empty valid email: '" + admin.email + "' is not valid.");
> +                       System.exit(1);
> +               }
> +               if (admin.group == null || admin.group.length() < 1) {
> +                       System.out.println("User group was not provided, or too short, should be at least 1 character long: " + admin.group);
> +                       System.exit(1);
> +               }
> +               admin.pass = cmdl.getOptionValue("password");
> +               if (checkPassword(admin.pass)) {
> +                       System.out.print("Please enter password:");
> +                       admin.pass = new BufferedReader(new InputStreamReader(System.in)).readLine();
> +                       if (checkPassword(admin.pass)) {
> +                               System.out.println("Password was not provided, or too short, should be at least " + InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH + " character long.");
> +                               System.exit(1);
> +                       }
> +               }
> +               Map<String, String> tzMap = ImportHelper.getAllTimeZones(importInit.getTimeZones(langPath));
> +               admin.tz = null;
> +               if (cmdl.hasOption("tz")) {
> +                       admin.tz = cmdl.getOptionValue("tz");
> +                       admin.tz = tzMap.containsKey(admin.tz) ? admin.tz : null;
> +               }
> +               if (admin.tz == null) {
> +                       System.out.println("Please enter timezone, Possible timezones are:");
> +                       for (String tzJname : tzMap.keySet()) {
> +                               System.out.println(tzJname);
> +                       }
> +                       System.exit(1);
> +               }
> +               return admin;
> +       }
> +
> +       private boolean checkPassword(String pass) {
> +               return (pass == null || pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH);
> +       }
> +
> +       private void dropDB(ConnectionProperties props) throws Exception {
> +               if(cmdl.hasOption("drop")) {
> +                       String[] mappingToolArgs = {"-sa", "drop", "-p", omHome.getAbsolutePath() + "/WEB-INF/classes/META-INF/persistence.xml",
> +                                       "-connectionDriverName", props.getDriverName(), "-connectionURL", props.getConnectionURL(),
> +                                       "-connectionUserName", props.getConnectionLogin(), "-connectionPassword", props.getConnectionPass()};
> +                       MappingTool.main(mappingToolArgs);
> +               }
> +       }
> +
> +       private File checkRestoreFile(String file) {
> +               File backup = new File(file);
> +               if (!cmdl.hasOption("file") || !backup.exists() || !backup.isFile()) {
> +                       System.out.println("File should be specified, and point the existent zip file");
> +                       usage();
> +                       System.exit(1);
> +               }
> +
> +               return backup;
> +       }
> +
> +       private void restoreOm(String ctxName, File backup) {
> +               try {
> +                       BackupImportController importCtrl = getApplicationContext(ctxName).getBean(BackupImportController.class);
> +                       importCtrl.performImport(new FileInputStream(backup), omHome.getAbsolutePath());
> +               } catch (Exception e) {
> +                       handleError("Restore failed", e);
> +               }
> +       }
> +
>        public static void main(String[] args) {
>                new Admin().process(args);
>        }
>
> Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
> URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> ==============================================================================
> --- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java (original)
> +++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java Wed Apr 25 10:35:08 2012
> @@ -38,6 +38,7 @@ import org.openmeetings.app.installation
>  import org.openmeetings.app.installation.InstallationConfig;
>  import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
>  import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
> +import org.openmeetings.utils.ImportHelper;
>  import org.red5.logging.Red5LoggerFactory;
>  import org.slf4j.Logger;
>  import org.springframework.context.ApplicationContext;
> @@ -117,22 +118,14 @@ public class Install extends VelocityVie
>                allFonts.put("Verdana", "Verdana");
>                allFonts.put("Arial", "Arial");
>
> -               LinkedHashMap<String, String> allTimeZones = new LinkedHashMap<String, String>();
>                List<OmTimeZone> omTimeZoneList = getImportInitvalues()
>                                .getTimeZones(filePath);
> -               log.debug("omTimeZoneList :: " + omTimeZoneList.size());
> -               for (OmTimeZone omTimeZone : omTimeZoneList) {
> -                       String labelName = omTimeZone.getJname() + " ("
> -                                       + omTimeZone.getLabel() + ")";
> -                       log.debug("labelName :: " + labelName);
> -                       allTimeZones.put(omTimeZone.getJname(), labelName);
> -               }
>
>                Template tpl = super.getTemplate("install_step1_"
>                                + lang + ".vm");
>                ctx.put("allLanguages", allLanguages);
>                ctx.put("allFonts", allFonts);
> -               ctx.put("allTimeZones", allTimeZones);
> +               ctx.put("allTimeZones", ImportHelper.getAllTimeZones(omTimeZoneList));
>                StringWriter writer = new StringWriter();
>                tpl.merge(ctx, writer);
>
>
> Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java
> URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java?rev=1330188&r1=1330187&r2=1330188&view=diff
> ==============================================================================
> --- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java (original)
> +++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ImportHelper.java Wed Apr 25 10:35:08 2012
> @@ -18,9 +18,13 @@
>  */
>  package org.openmeetings.utils;
>
> +import java.util.LinkedHashMap;
> +import java.util.List;
> +import java.util.Map;
> +
>  import org.openmeetings.app.OpenmeetingsVariables;
>  import org.openmeetings.app.data.basic.Configurationmanagement;
> -import org.openmeetings.app.persistence.beans.basic.Configuration;
> +import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
>  import org.red5.logging.Red5LoggerFactory;
>  import org.slf4j.Logger;
>
> @@ -31,22 +35,27 @@ public class ImportHelper {
>
>        public static final int getMaxUploadSize(
>                        Configurationmanagement cfgManagement) {
> -               return getMaxUploadSize(cfgManagement, 3L);
> -       }
> -
> -       public static final int getMaxUploadSize(
> -                       Configurationmanagement cfgManagement, Long userLevel) {
> -               Configuration cfg = cfgManagement.getConfKey(userLevel,
> -                               "DEFAULT_MAX_UPLOAD_SIZE");
>                int result = DEFAULT_MAX_UPLOAD_SIZE;
> -               if (cfg != null) {
> -                       String val = cfg.getConf_value();
> -                       try {
> -                               result = (int) Math.min(Long.parseLong(val), Integer.MAX_VALUE);
> -                       } catch (Exception e) {
> -                               log.error("Invalid value saved for maxUploadSize: " + val, e);
> -                       }
> +               String maxSize = cfgManagement.getConfValue("DEFAULT_MAX_UPLOAD_SIZE", String.class, "" + result);
> +               try {
> +                       result = (int) Math.min(Long.parseLong(maxSize), Integer.MAX_VALUE);
> +               } catch (Exception e) {
> +                       log.error("Invalid value saved for maxUploadSize: " + maxSize, e);
> +               }
> +               return result;
> +       }
> +
> +       public static Map<String, String> getAllTimeZones(List<OmTimeZone> tzList) {
> +               Map<String, String> result = new LinkedHashMap<String, String>();
> +
> +               log.debug("omTimeZoneList :: " + tzList.size());
> +               for (OmTimeZone omTimeZone : tzList) {
> +                       String labelName = omTimeZone.getJname() + " ("
> +                                       + omTimeZone.getLabel() + ")";
> +                       log.debug("labelName :: " + labelName);
> +                       result.put(omTimeZone.getJname(), labelName);
>                }
> +
>                return result;
>        }
>  }
>
>



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