]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6329: Move code to create or update Nuxeo repo config files out of initialize...
authorAron Roberts <aron@socrates.berkeley.edu>
Thu, 6 Mar 2014 02:17:31 +0000 (18:17 -0800)
committerAron Roberts <aron@socrates.berkeley.edu>
Thu, 6 Mar 2014 02:17:31 +0000 (18:17 -0800)
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java

index 04292ab2f85f14dda4578d9207913468392901b1..6542e2da5ae7a0d1754070ff32d7073f663a7f78 100644 (file)
@@ -162,53 +162,8 @@ public class ServiceMain {
         readConfig();\r
        setDataSources();\r
         propagateConfiguredProperties();\r
-        \r
-        // Ensure that Nuxeo repository config files exist for each repository\r
-        // specified in tenant bindings.\r
-        \r
-        // Get the prototype copy of the Nuxeo repository config file.\r
-        // This file will then be cloned, creating a separate config file\r
-        // for each repository.\r
-        File prototypeNuxeoConfigFile =\r
-                new File(getNuxeoConfigDir() + File.separator + getNuxeoProtoConfigFilename());\r
-        logger.warn("Prototype Nuxeo config file path=" + prototypeNuxeoConfigFile.getCanonicalPath());\r
-        if (! prototypeNuxeoConfigFile.canRead()) {\r
-            String msg = String.format("Could not find and/or read the prototype Nuxeo config file '%s'",\r
-                    prototypeNuxeoConfigFile.getCanonicalPath());\r
-            throw new RuntimeException(msg);\r
-        }\r
-        logger.warn("Can read prototype Nuxeo config file.");\r
-        Document prototypeConfigDoc = XmlTools.fileToXMLDocument(prototypeNuxeoConfigFile);\r
-        Document repositoryConfigDoc = null;\r
-        // FIXME: Can the variable below reasonably be made a class variable? Its value\r
-        // is used in at least one other method in this class.\r
-        Hashtable<String, TenantBindingType> tenantBindingTypeMap = tenantBindingConfigReader.getTenantBindings();\r
-        for (TenantBindingType tbt : tenantBindingTypeMap.values()) {\r
-            List<String> repositoryNameList = ConfigUtils.getRepositoryNameList(tbt);\r
-            logger.warn("Getting repository name(s) for tenant " + tbt.getName());\r
-            if (repositoryNameList == null || repositoryNameList.isEmpty() == true) {\r
-              logger.warn(String.format("Could not get repository name(s) for tenant %s", tbt.getName()));\r
-              continue;\r
-            } else {\r
-                for (String repositoryName : repositoryNameList) {\r
-                    if (Tools.isBlank(repositoryName)) {\r
-                        continue;\r
-                    }\r
-                    logger.warn(String.format("Repository name is %s", repositoryName));\r
-                    repositoryConfigDoc = (Document) prototypeConfigDoc.clone();\r
-                    // Update the newly-cloned repository config file by inserting\r
-                    // values specific to the current repo.\r
-                    repositoryConfigDoc = updateRepositoryConfigDoc(repositoryConfigDoc, repositoryName);\r
-                    logger.warn("repositoryConfigDoc=\n" + repositoryConfigDoc.asXML());\r
-                    // Write this repository config file to the Nuxeo server config directory.\r
-                    File repofile = new File(getNuxeoConfigDir() + File.separator +\r
-                            repositoryName + JEEServerDeployment.NUXEO_REPO_CONFIG_FILENAME_SUFFIX);\r
-                    logger.warn(String.format("Repository config filepath is %s", repofile.getAbsolutePath()));\r
-                    XmlTools.xmlDocumentToFile(repositoryConfigDoc, repofile);\r
-                }\r
-            }\r
-        }\r
-        \r
+        createOrUpdateNuxeoRepositoryConfigFiles();\r
+                \r
         //\r
         // Start up and initialize our embedded Nuxeo server instance\r
         //\r
@@ -801,6 +756,72 @@ public class ServiceMain {
         return uriTemplateRegistry;\r
     }\r
 \r
+   /**\r
+    * Ensure that Nuxeo repository configuration files exist for each repository\r
+    * specified in tenant bindings. Create or update these files, as needed.\r
+    */\r
+    private void createOrUpdateNuxeoRepositoryConfigFiles() throws Exception {\r
+        \r
+        // Get the prototype copy of the Nuxeo repository config file.\r
+        File prototypeNuxeoConfigFile =\r
+                new File(getNuxeoConfigDir() + File.separator + getNuxeoProtoConfigFilename());\r
+        // FIXME: Consider checking for the presence of existing configuration files,\r
+        // rather than always failing outright if the prototype file for creating\r
+        // new or updated files can't be located.\r
+        if (! prototypeNuxeoConfigFile.canRead()) {\r
+            String msg = String.format("Could not find and/or read the prototype Nuxeo config file '%s'",\r
+                    prototypeNuxeoConfigFile.getCanonicalPath());\r
+            throw new RuntimeException(msg);\r
+        }\r
+        if (logger.isTraceEnabled()) {\r
+            logger.trace("Found and can read prototype Nuxeo config file at path %s", prototypeNuxeoConfigFile.getAbsolutePath());\r
+        }\r
+        Document prototypeConfigDoc = XmlTools.fileToXMLDocument(prototypeNuxeoConfigFile);\r
+        Document repositoryConfigDoc = null;\r
+        // FIXME: Can the variable below reasonably be made a class variable? Its value\r
+        // is used in at least one other method in this class.\r
+        Hashtable<String, TenantBindingType> tenantBindingTypeMap = tenantBindingConfigReader.getTenantBindings();\r
+        for (TenantBindingType tbt : tenantBindingTypeMap.values()) {\r
+            List<String> repositoryNameList = ConfigUtils.getRepositoryNameList(tbt);\r
+            if (logger.isTraceEnabled()) {\r
+                logger.trace("Getting repository name(s) for tenant " + tbt.getName());\r
+            }\r
+            if (repositoryNameList == null || repositoryNameList.isEmpty() == true) {\r
+              logger.warn(String.format("Could not get repository name(s) for tenant %s", tbt.getName()));\r
+              continue;\r
+            } else {\r
+                for (String repositoryName : repositoryNameList) {\r
+                    if (Tools.isBlank(repositoryName)) {\r
+                        continue;\r
+                    }\r
+                    if (logger.isTraceEnabled()) {\r
+                        logger.trace(String.format("Repository name is %s", repositoryName));\r
+                    }\r
+                    // FIXME: As per above, we might check for the presence of an existing\r
+                    // config file for this repository and, if present, not fail even if\r
+                    // the code below fails to update that file on any given system startup.\r
+                    //\r
+                    // Clone the prototype copy of the Nuxeo repository config file,\r
+                    // thus creating a separate config file for the current repository.\r
+                    repositoryConfigDoc = (Document) prototypeConfigDoc.clone();\r
+                    // Update this config file by inserting values pertinent to the\r
+                    // current repository.\r
+                    repositoryConfigDoc = updateRepositoryConfigDoc(repositoryConfigDoc, repositoryName);\r
+                    if (logger.isTraceEnabled()) {\r
+                        logger.trace("Updated Nuxeo repo config file contents=\n" + repositoryConfigDoc.asXML());\r
+                    }\r
+                    // Write this config file to the Nuxeo server config directory.\r
+                    File repofile = new File(getNuxeoConfigDir() + File.separator +\r
+                            repositoryName + JEEServerDeployment.NUXEO_REPO_CONFIG_FILENAME_SUFFIX);\r
+                    if (logger.isTraceEnabled()) {\r
+                        logger.trace(String.format("Attempting to write Nuxeo repo config file to %s", repofile.getAbsolutePath()));\r
+                    }\r
+                    XmlTools.xmlDocumentToFile(repositoryConfigDoc, repofile);\r
+                }\r
+            }\r
+        }\r
+    }\r
+    \r
     private Document updateRepositoryConfigDoc(Document repoConfigDoc, String repositoryName) {\r
         // FIXME: Remove this temporary placeholder variable used only during development.\r
         final String PLACEHOLDER = "placeholder";\r
@@ -833,5 +854,4 @@ public class ServiceMain {
         return repoConfigDoc;\r
     }\r
 \r
-\r
 }\r