]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6329: Preliminary work toward writing per-repo Nuxeo config files. Entirely...
authorAron Roberts <aron@socrates.berkeley.edu>
Sat, 1 Mar 2014 01:42:13 +0000 (17:42 -0800)
committerAron Roberts <aron@socrates.berkeley.edu>
Sat, 1 Mar 2014 01:42:13 +0000 (17:42 -0800)
3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/proto-repo-config.xml [new file with mode: 0644]
services/common-api/src/main/java/org/collectionspace/services/common/api/JEEServerDeployment.java
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
services/common/src/main/java/org/collectionspace/services/common/XmlTools.java

diff --git a/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/proto-repo-config.xml b/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/proto-repo-config.xml
new file mode 100644 (file)
index 0000000..88fca73
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<component name="config:default-repository">
+    <extension target="org.nuxeo.ecm.core.repository.RepositoryService"
+                   point="repository">
+        <repository name="default"
+                            factory="org.nuxeo.ecm.core.storage.sql.ra.PoolingRepositoryFactory">
+            <repository name="default">
+                <pool minPoolSize="0" maxPoolSize="20"
+                                      blockingTimeoutMillis="100" idleTimeoutMinutes="10" />
+                <clustering enabled="false" delay="1000" />
+                <binaryStore path="" />
+                <!-- The transactional datasource for Nuxeo -->
+                <xa-datasource>@XA_DATASOURCE@</xa-datasource>                         
+                <property name="URL">@DB_URL@</property>
+                <property name="ServerName">@DB_SERVER_HOSTNAME@</property>                            
+                <property name="DatabaseName">nuxeo</property>
+                <property name="User">@NUXEO_USER@</property>
+                <property name="Password">@NUXEO_PW@</property>
+            </repository>
+        </repository>
+    </extension>
+
+    <extension target="org.nuxeo.ecm.core.api.repository.RepositoryManager"
+                   point="repositories">
+        <documentation>The default repository</documentation>
+        <repository name="default" label="Default Repository" />
+    </extension>
+</component>
index fc6108180a80a61c766280ab73638627e3bd2e3e..a66a24464a3417001036e268634c23c5aabcfe8d 100644 (file)
@@ -12,6 +12,9 @@ public interface JEEServerDeployment {
        
        public final static String NUXEO_CLIENT_DIR = "nuxeo-client";
        public final static String NUXEO_SERVER_DIR = "nuxeo-server";
+       public final static String NUXEO_CONFIG_DIR = "config";
+       public final static String NUXEO_SERVER_CONFIG_DIR = NUXEO_SERVER_DIR + File.separator + NUXEO_CONFIG_DIR;
+        public final static String NUXEO_PROTOTYPE_CONFIG_FILENAME = "proto-repo-config.xml";
        public final static String NUXEO_PLUGINS_DIR = "plugins";
        public final static String NUXEO_SERVER_PLUGINS_DIR = NUXEO_SERVER_DIR + File.separator + NUXEO_PLUGINS_DIR;
 }
index cd0ec5bd63c76cb6ed2b3f8ae5700bf94d7e884f..d46bb65630c25a07d5c5231f9bd3c2eb8d4f70ab 100644 (file)
@@ -6,8 +6,6 @@ package org.collectionspace.services.common;
 import java.io.File;\r
 import java.io.FileInputStream;\r
 import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.sql.Connection;\r
 import java.sql.PreparedStatement;\r
@@ -22,6 +20,7 @@ import javax.sql.DataSource;
 \r
 import org.collectionspace.authentication.AuthN;\r
 \r
+import org.collectionspace.services.common.api.JEEServerDeployment;\r
 import org.collectionspace.services.common.authorization_mgt.AuthorizationCommon;\r
 import org.collectionspace.services.common.config.ConfigReader;\r
 import org.collectionspace.services.common.config.ConfigUtils;\r
@@ -43,7 +42,7 @@ import org.collectionspace.services.nuxeo.client.java.NuxeoConnectorEmbedded;
 import org.collectionspace.services.nuxeo.client.java.TenantRepository;\r
 import org.jboss.resteasy.spi.ResteasyProviderFactory;\r
 \r
-import org.apache.tomcat.dbcp.dbcp.BasicDataSource;\r
+import org.dom4j.Document;\r
 \r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
@@ -71,7 +70,7 @@ public class ServiceMain {
     \r
     private static final String SERVER_HOME_PROPERTY = "catalina.home";\r
        private static final boolean USE_APP_GENERATED_CONFIG = true;\r
-    \r
+        \r
     private ServiceMain() {\r
        //empty\r
     }\r
@@ -156,6 +155,42 @@ public class ServiceMain {
         readConfig();\r
        setDataSources();\r
         propagateConfiguredProperties();\r
+        \r
+        // Ensure that Nuxeo config files exist for each repository\r
+        // specified in tenant bindings\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
+            // FIXME: Handle this error appropriately here.\r
+        }\r
+        logger.warn("Can read prototype Nuxeo config file.");\r
+        Document prototypeDoc = XmlTools.fileToXMLDocument(prototypeNuxeoConfigFile);\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 (repositoryNameList != null && repositoryNameList.isEmpty() == false) {\r
+                Document repoDoc = null;\r
+               for (String repositoryName : repositoryNameList) {\r
+                    logger.warn("Repository name=" + repositoryName);\r
+                    repoDoc = (Document) prototypeDoc.clone();\r
+                    logger.warn("Before attribute edits=\n" + repoDoc.asXML());\r
+                    // FIXME: Set up constants and/or methods for XPath expressions, element and attribute names\r
+                    repoDoc = XmlTools.setAttributeValue(repoDoc, "/component/extension[@point='repository']/repository", "name", repositoryName);\r
+                    logger.warn("After first attribute edit=\n" + repoDoc.asXML());\r
+                    repoDoc = XmlTools.setAttributeValue(repoDoc, "/component/extension[@point='repository']/repository/repository", "name", repositoryName);\r
+                    logger.warn("After second attribute edit=\n" + repoDoc.asXML());\r
+                    repoDoc = XmlTools.setAttributeValue(repoDoc, "/component/extension[@point='repositories']/repository", "name", repositoryName);\r
+                    logger.warn("After third attribute edit=\n" + repoDoc.asXML());\r
+                    // FIXME: Edit additional element and/or attribute values.\r
+                    // FIXME: Emit serialized XML and write it to an appropriately named file\r
+                    // in the Nuxeo server config directory.\r
+                    repoDoc = null;\r
+                }\r
+            }\r
+        }\r
         //\r
         // Start up and initialize our embedded Nuxeo server instance\r
         //\r
@@ -368,6 +403,14 @@ public class ServiceMain {
         return serverRootDir;\r
     }\r
     \r
+    public String getNuxeoConfigDir() {\r
+        return getServerRootDir() + JEEServerDeployment.NUXEO_SERVER_CONFIG_DIR;\r
+    }\r
+    \r
+    public String getNuxeoProtoConfigFilename() {\r
+        return JEEServerDeployment.NUXEO_PROTOTYPE_CONFIG_FILENAME;\r
+    }\r
+    \r
     /**\r
      * @return the server resources path\r
      */\r
index 6a344e80ffc4a6d65318aa3d333f46bdc6e8c59e..b51e672c117ab03f50090fa61912a1a11734c8b4 100644 (file)
@@ -1,15 +1,18 @@
 package org.collectionspace.services.common;
 
+import java.io.File;
+import java.io.StringWriter;
 import org.collectionspace.services.common.api.Tools;
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
 import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.Node;
 import org.dom4j.io.HTMLWriter;
 import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
 import org.dom4j.io.XMLWriter;
 
-import java.io.StringWriter;
-
 public class XmlTools {
 
 
@@ -85,7 +88,7 @@ public class XmlTools {
     }
 
     /**
-     * Returns an XML document, when provided with a String
+     * Returns a dom4j XML document, when provided with a String
      * representation of that XML document.
      * @param   xmlStr  A String representation of an XML document.
      * @return  A dom4j XML document.
@@ -100,6 +103,49 @@ public class XmlTools {
         }
         return doc;
     }
+    
+    /**
+     * Returns a dom4j XML document, when provided with a file
+     * containing a well-formed XML document.
+     * @param   file  A file containing a well-formed XML document.
+     * @return  A dom4j XML document.
+     */
+    public static Document fileToXMLDocument(File file) throws Exception {
+        Document doc = null;
+        try {
+            SAXReader reader = new SAXReader();
+            doc = reader.read(file);
+        } catch (DocumentException e) {
+            throw e;
+        }
+        return doc;
+    }
+    
+    /**
+     * Sets the value of a specified attribute in a dom4j XML document.
+     * @param   doc  A dom4j XML document.
+     * @param   xpathExpr  An XPath expression intended to match a single element
+     * in the XML document, in the default namespace.
+     * @param   attributeName  An attribute name.
+     * @param   attributeValue  The value that the attribute should contain.
+     * @return  The document with the specified attribute of the matched element, if
+     * any, set to the provided value. If the attribute doesn't already exist,
+     * it will be created and assigned the provided value.  If the provided
+     * value is null, the attribute, if any, will be removed.
+     */
+    public static Document setAttributeValue(Document doc, String xpathExpr,
+            String attributeName, String attributeValue) {
+        if (Tools.isBlank(xpathExpr) || Tools.isBlank(attributeName)) {
+            return doc;
+        }
+        Node node = doc.selectSingleNode(xpathExpr);
+        if ((node == null) || (node.getNodeType() != Node.ELEMENT_NODE)) {
+            return doc;
+        }
+        Element element = (Element) node;
+        element.addAttribute(attributeName, attributeValue);
+        return doc;
+    }
 
     public static String prettyPrint(String xml) throws Exception {
         Document doc = textToXMLDocument(xml);