--- /dev/null
+<?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>
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;
}
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
\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
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
\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
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
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
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 {
}
/**
- * 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.
}
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);