Commits

Juan Carlos Picado Herrera  committed 28a903f

Improved home directory management, now is not mandatory set the indexes folder.

  • Participants
  • Parent commits c1e338c

Comments (0)

Files changed (7)

File enme-business/src/main/java/org/encuestame/business/setup/ApplicationStartup.java

     /**
      * Constructor.
      */
-    public ApplicationStartup() {
-    }
+    public ApplicationStartup() {}
 
     /**
      * Check if app started.
     public void startProcess() throws EnMeStartupException {
         // check if root directory exist
         try {
-            if (!DirectorySetupOperations.isHomeDirectoryValid()) {
-                throw new EnMeStartupException("home folder is missing");
-            }
             DirectorySetupOperations.validateInternalStructureDirectory(true);
             DirectorySetupOperations.createConfileFile();
             // if email notification is enabled.
-            if (EnMePlaceHolderConfigurer.getBooleanProperty(
-                    "setup.email.notification").booleanValue()) {
+            if (EnMePlaceHolderConfigurer.getBooleanProperty("setup.email.notification").booleanValue()) {
                 final StringBuilder startupMessage = new StringBuilder();
                 startupMessage.append("startup date [");
                 startupMessage.append(DateUtil.getCurrentFormatedDate());

File enme-core/src/main/java/org/encuestame/core/config/EnMePlaceHolderConfigurer.java

         //get form system property enviroment out file path.
         final String enviromentPropertyFile = System.getProperty(overwriteJvmParam);
         File customEncuestameFile;
-        if(enviromentPropertyFile != null && enviromentPropertyFile.length() > 0) {
+        if (enviromentPropertyFile != null && enviromentPropertyFile.length() > 0) {
             customEncuestameFile = new File(enviromentPropertyFile);
             // make sure the file exists, then try and load it
             if(customEncuestameFile != null && customEncuestameFile.exists()) {
         super.processProperties(beanFactory, props);
         propertiesMap = new HashMap<String, String>();
         for (Object key : props.keySet()) {
-            String keyStr = key.toString();
-            log.debug("Property--->"+keyStr+ " value="+props.getProperty(keyStr));
-            propertiesMap.put(
-                    keyStr,
-                    parseStringValue(props.getProperty(keyStr), props,
-                            new HashSet()));
+            final String keyStr = key.toString();
+            String valueStr = props.getProperty(keyStr);
+            // resolve possible properties embebed the values
+            if (valueStr.contains("${")) {
+                int start = valueStr.indexOf("${");
+                int end = valueStr.indexOf("}");
+                String keyToSearch = valueStr.substring(start + 2, end);
+                String valueToGet = props.getProperty(keyToSearch);
+                valueStr = valueStr.replace("${" +  keyToSearch+ "}", valueToGet);
+            }
+            log.debug("Property--->"+keyStr+ " value="+valueStr);
+            propertiesMap.put(keyStr,parseStringValue(valueStr, props,new HashSet()));
         }
         //TODO: xml configuration file should be outside this context.
         try {
             EnMePlaceHolderConfigurer.configurationManager = new XMLConfigurationFileSupport();
         } catch (ConfigurationException e) {
-            // TODO Auto-generated catch block
+            log.error(e.getMessage());
             e.printStackTrace();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
+            log.error(e.getMessage());
             e.printStackTrace();
         }
     }

File enme-core/src/main/java/org/encuestame/core/service/DirectorySetupOperations.java

      * @return if the directoy exist or not.
      * @throws EnmeFailOperation exception if exist issues on create directory.
      */
-    public static boolean isHomeDirectoryValid() throws EnmeFailOperation {
-        final File rootDir = new File(DirectorySetupOperations.getHomeDirectory());
+    public static boolean isHomeDirectoryValid() {
+        final String directory = DirectorySetupOperations.getHomeDirectory();
+        if (directory == null) {
+            return false;
+        }
+        final File rootDir = new File(directory);
         log.debug("EnMe: Home directory: " + rootDir);
         return rootDir.exists();
     }
      * @return real path of home directory.
      * @throws EnmeFailOperation
      */
-    public static String getHomeDirectory() throws EnmeFailOperation {
+    public static String getHomeDirectory() {
         String root = EnMePlaceHolderConfigurer.getProperty("encuestame.home");
+        boolean system_home = EnMePlaceHolderConfigurer.getBooleanProperty("encuestame.system.home");
         log.debug("getRootDirectory "+root);
-        if (root == null) {
-            throw new EnmeFailOperation("home directory not found");
+        if (root == null && system_home) {
+            root = System.getProperty("catalina.base");
+            log.debug("catalina home " + root);
+            root = (root == null ? (root + "/encuestame-store") : null);
+            log.debug("catalina home complete: " + root);
         }
-
-        if (!root.endsWith("/")) {
-            root = root + "/";
+        if (root == null) {
+          return null;
+        } else {
+            if (!root.endsWith("/")) {
+                root = root + "/";
+            }
+            log.debug("getRootFolder:{" + root);
+           return root;
         }
-        log.debug("getRootFolder:{" + root);
-        return root;
     }
 
     /**

File enme-core/src/main/resources/org/encuestame/core/config/encuestame-config.properties

 # Directory settings
 #-----------------------------------------------------------------------------
 # use real path on this directory
-encuestame.home = ${user.home}/encuestame-store/
-encuestame.home.hibernate.search.store.path = ${user.home}/encuestame-store/indexes/domain/
-
+## eg: ${user.home}/encuestame-store
+encuestame.home =
+## ${user.home}/encuestame-store/indexes/domain/
+encuestame.home.hibernate.search.store.path = ${encuestame.home}/indexes/domain/
+## if is enable get the catalina home by defualt if the home is missing
+encuestame.system.home = false
 #-----------------------------------------------------------------------------
 # Mail settings
 #-----------------------------------------------------------------------------

File enme-mvc/src/main/java/org/encuestame/mvc/listener/EnMeContext.java

 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
+import javax.servlet.ServletException;
 
 import org.apache.log4j.Logger;
 import org.encuestame.business.setup.StartupProcess;
+import org.encuestame.core.service.DirectorySetupOperations;
+import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeStartupException;
+import org.encuestame.persistence.exception.EnmeFailOperation;
 import org.springframework.web.context.ContextLoaderListener;
 import org.springframework.web.context.WebApplicationContext;
 import org.springframework.web.context.support.WebApplicationContextUtils;
     public void contextInitialized(final ServletContextEvent sce) {
         EnMeContext.servletContext = sce.getServletContext();
         super.contextInitialized(sce);
-        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
-        final StartupProcess startup = (StartupProcess) ctx.getBean("applicationStartup");
-        try {
-           startup.startProcess();
-        } catch (EnMeStartupException e) {
-           //e.printStackTrace();
-           log.fatal("EnMe: Error on stat encuestame context "+e.getMessage());
-           throw new IllegalStateException("EnMe: Error on stat encuestame context : "+e.getMessage());
+        boolean existHomeDirectory = DirectorySetupOperations.isHomeDirectoryValid();
+        if (!existHomeDirectory) {
+            log.fatal("**********************************************");
+            log.fatal("*    		 ENCUESTAME HOME IS MISSING");
+            log.fatal("*    		 Troubles ?? Visit the wiki a get your answer.");
+            log.fatal("*  http://www.encuestame.org/wiki/display/DOC/Troubleshooting+Guides");
+            log.fatal("**********************************************");
+            throw new IllegalStateException("home not valid, please set a home property in the configuration file");
+        } else {
+            WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
+            final StartupProcess startup = (StartupProcess) ctx.getBean("applicationStartup");
+            try {
+               startup.startProcess();
+               log.info("**********************************************");
+               log.info("*     ENCUESTAME IS RUNNING SUCCESSFULLY      *");
+               log.info("*        http://www.encuestame.org           *");
+               log.info("**********************************************");
+            } catch (Exception e) {
+               log.fatal("EnMe: Error on start encuestame context: "+e.getMessage());
+               this.closeWebApplicationContext(servletContext);
+               throw new IllegalStateException("EnMe: Error on stat encuestame context : "+e.getMessage());
+            }
         }
-        log.info("**********************************************");
-        log.info("*     ENCUESTAME IS RUNNING SUCCESSFULLY      *");
-        log.info("*        http://www.encuestame.org           *");
-        log.info("**********************************************");
     }
 
     @Override

File enme-persistence/enme-model/src/main/java/org/encuestame/persistence/exception/EnmeFailOperation.java

 
 /**
  * EnMe Fail Operation.
+ *
  * @author Morales, Diana Paola paolaATencuestame.org
  * @since December 8, 2010
- * @version $Id:$
  */
-public class EnmeFailOperation extends EnMeExpcetion{
+public class EnmeFailOperation extends EnMeExpcetion {
     /**
      * Serial.
      */
-       private static final long serialVersionUID = -120650589333637899L;
+    private static final long serialVersionUID = -120650589333637899L;
 
-       public EnmeFailOperation() {
-        // TODO Auto-generated constructor stub
-           super();
-        }
+    public EnmeFailOperation() {
+        super();
+    }
 
-       public EnmeFailOperation(String message, Throwable cause) {
-           super(message, cause);
-           // TODO Auto-generated constructor stub
-       }
+    public EnmeFailOperation(String message, Throwable cause) {
+        super(message, cause);
+    }
 
-       public EnmeFailOperation(String message) {
-           super(message);
-       }
-
-       public EnmeFailOperation(Throwable cause) {
-           super(cause);
-       }
-   }
+    public EnmeFailOperation(String message) {
+        super(message);
+    }
 
+    public EnmeFailOperation(Throwable cause) {
+        super(cause);
+    }
+}

File enme-war/enme-spring/src/main/webapp/WEB-INF/spring/encuestame-hibernate-context.xml

 
     <import resource="encuestame-encrypt-context.xml" />
 
-    <!-- Ehcache Configuration 
+    <!-- Ehcache Configuration
 
     <ehcache:annotation-driven />