]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-2496 Added support for richer params in IInitHandler and in initHandler block...
authorLaramie Crocker <laramie@berkeley.edu>
Wed, 5 Jan 2011 23:16:16 +0000 (23:16 +0000)
committerLaramie Crocker <laramie@berkeley.edu>
Wed, 5 Jan 2011 23:16:16 +0000 (23:16 +0000)
services/common/src/main/config/services/tenant-bindings.xml
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
services/common/src/main/java/org/collectionspace/services/common/init/AddIndices.java
services/common/src/main/java/org/collectionspace/services/common/init/IInitHandler.java
services/common/src/main/java/org/collectionspace/services/common/init/InitHandler.java
services/common/src/main/java/org/collectionspace/services/common/storage/JDBCTools.java
services/common/src/main/resources/service.xsd

index 92d2cdc76e6dd45e3ff464a0fb66d0e3ae94c509..6736d569c2a50ac36ee4f9c4aabfe13a7f6ea5cc 100644 (file)
             <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.loanin.nuxeo.LoaninValidatorHandler
             </service:validatorHandler>
+            <!--
             <service:initHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:classname>org.collectionspace.services.common.init.InitHandler</service:classname>
                 <service:fields>
                     <service:field>Foo</service:field>
                 </service:fields>
             </service:initHandler>
+            -->
+            <s:initHandler xmlns:s='http://collectionspace.org/services/common/service'>
+                <s:classname>org.collectionspace.services.common.init.InitHandler</s:classname>
+                <s:params>
+                    <s:field>
+                        <s:table>mytable</s:table>
+                        <s:col>mycol</s:col>
+                        <s:type>mytpe</s:type>
+                        <s:param>myparam, myparamB</s:param>
+                    </s:field>
+                    <s:field>
+                        <s:table>mytable2</s:table>
+                        <s:col>mycol2</s:col>
+                        <s:type>mytpe2</s:type>
+                        <s:param>myparam, myparam2B</s:param>
+                    </s:field>
+
+                    <s:property>
+                        <s:key>my key</s:key><s:value>my value</s:value>
+                    </s:property>
+                    <s:property>
+                        <s:key>my key 2</s:key><s:value>my value 2</s:value>
+                    </s:property>
+
+                </s:params>
+            </s:initHandler>
+
+            <tenant:properties>
+
+            <types:item><types:key>datePattern</types:key><types:value>MMM dd, yyyy</types:value></types:item>
+            <types:item><types:key>datePattern</types:key><types:value>dd.MM.yyyy</types:value></types:item>
+            <!-- <types:item><types:key>datePattern</types:key><types:value>dd/MM/yyyy</types:value></types:item> -->
+            <types:item><types:key>localeLanguage</types:key><types:value>en</types:value></types:item>
+            <!-- <types:item><types:key>localeLanguage</types:key><types:value>da</types:value></types:item> -->
+        </tenant:properties>
+
+
             <service:properties xmlns:service='http://collectionspace.org/services/common/service'>
                 <!-- What to use for name???
                 <types:item><types:key>objectNameProperty</types:key><types:value>objectName</types:value></types:item> -->
index fb0615c5a4b61cd662b324a14283ca763278d025..97167c197759af0234bee7af8a416afb2824e8df 100644 (file)
@@ -56,7 +56,7 @@ public class ServiceMain {
     private static final String DEFAULT_ADMIN_PASSWORD = "Administrator";\r
     private static final String DEFAULT_READER_PASSWORD = "reader";\r
     \r
-    private static String REPOSITORY_NAME = "CspaceDS";\r
+    public static String DEFAULT_REPOSITORY_NAME = "CspaceDS";\r
 \r
     private ServiceMain() {\r
     }\r
@@ -528,12 +528,19 @@ public class ServiceMain {
                 if (list!=null && list.size()>0){\r
                     org.collectionspace.services.common.service.InitHandler handlerType = list.get(0);\r
                     String initHandlerClassname = handlerType.getClassname();\r
-                    org.collectionspace.services.common.service.InitHandler.Fields ft = handlerType.getFields();\r
-                    List<String> fields = ft.getField();\r
+\r
+                    List<org.collectionspace.services.common.service.InitHandler.Params.Field>\r
+                            fields = handlerType.getParams().getField();\r
+\r
+                    List<org.collectionspace.services.common.service.InitHandler.Params.Property>\r
+                            props = handlerType.getParams().getProperty();\r
+\r
+                    //org.collectionspace.services.common.service.InitHandler.Fields ft = handlerType.getFields();\r
+                    //List<String> fields = ft.getField();\r
                     Object o = instantiate(initHandlerClassname, IInitHandler.class);\r
                     if (o != null && o instanceof IInitHandler){\r
                         IInitHandler handler = (IInitHandler)o;\r
-                        handler.onRepositoryInitialized(sbt, fields);\r
+                        handler.onRepositoryInitialized(sbt, fields, props);\r
                         //The InitHandler may be the default one,\r
                         //  or specialized classes which still implement this interface and are registered in tenant-bindings.xml.\r
                     }\r
@@ -593,7 +600,7 @@ public class ServiceMain {
     }\r
 \r
     private Connection getConnection() throws LoginException, SQLException {\r
-        return JDBCTools.getConnection(REPOSITORY_NAME);\r
+        return JDBCTools.getConnection(DEFAULT_REPOSITORY_NAME);\r
     }\r
 \r
     void retrieveAllWorkspaceIds() throws Exception {\r
index 2d4ef97d11359f7972193f6e2fefced036a53da1..b763be67122d856e103ff5e515297c1dc1ec7e6b 100755 (executable)
@@ -1,6 +1,26 @@
+/**\r
+ *  This document is a part of the source code and related artifacts\r
+ *  for CollectionSpace, an open source collections management system\r
+ *  for museums and related institutions:\r
+\r
+ *  http://www.collectionspace.org\r
+ *  http://wiki.collectionspace.org\r
+\r
+ *  Copyright 2009 University of California at Berkeley\r
+\r
+ *  Licensed under the Educational Community License (ECL), Version 2.0.\r
+ *  You may not use this file except in compliance with this License.\r
+\r
+ *  You may obtain a copy of the ECL 2.0 License at\r
+\r
+ *  https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
 package org.collectionspace.services.common.init;\r
 \r
 import org.collectionspace.services.common.service.ServiceBindingType;\r
+import org.collectionspace.services.common.service.InitHandler.Params.Field;\r
+import org.collectionspace.services.common.service.InitHandler.Params.Property;\r
+\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
@@ -16,7 +36,7 @@ public class AddIndices extends InitHandler implements IInitHandler {
 \r
     final Logger logger = LoggerFactory.getLogger(AddIndices.class);\r
 \r
-    public void onRepositoryInitialized(ServiceBindingType sbt, List<String> fields) throws Exception {\r
+    public void onRepositoryInitialized(ServiceBindingType sbt, List<org.collectionspace.services.common.service.InitHandler.Params.Field> fields, List<Property> property) throws Exception {\r
           //todo: all post-init tasks for services, or delegate to services that override.\r
           System.out.println("\r\n\r\n~~~~~~~~~~~~~ in AddIndices.onRepositoryInitialized with ServiceBindingType: "+sbt);\r
 \r
index 321006e3540dd0026cf1eac89a1a226013b9530e..b4ee4ef39456616a3561054c28ffdcd155154288 100755 (executable)
@@ -2,6 +2,8 @@ package org.collectionspace.services.common.init;
 \r
 import org.collectionspace.services.common.context.ServiceContext;\r
 import org.collectionspace.services.common.service.ServiceBindingType;\r
+import org.collectionspace.services.common.service.InitHandler.Params.Field;\r
+import org.collectionspace.services.common.service.InitHandler.Params.Property;\r
 \r
 import java.util.List;\r
 \r
@@ -11,5 +13,5 @@ import java.util.List;
  * $LastChangedDate:  $\r
  */\r
 public interface IInitHandler {\r
-   public void onRepositoryInitialized(ServiceBindingType sbt, List<String> fields) throws Exception;\r
+   public void onRepositoryInitialized(ServiceBindingType sbt, List<Field> fields, List<Property> property) throws Exception;\r
 }\r
index e6076390b4436fddd6c8b284b2f447fef939cc9e..8786c5a768d8a5d2442bda27d4f756f8a7393925 100755 (executable)
@@ -1,58 +1,64 @@
+/**\r
+ *  This document is a part of the source code and related artifacts\r
+ *  for CollectionSpace, an open source collections management system\r
+ *  for museums and related institutions:\r
+\r
+ *  http://www.collectionspace.org\r
+ *  http://wiki.collectionspace.org\r
+\r
+ *  Copyright 2009 University of California at Berkeley\r
+\r
+ *  Licensed under the Educational Community License (ECL), Version 2.0.\r
+ *  You may not use this file except in compliance with this License.\r
+\r
+ *  You may obtain a copy of the ECL 2.0 License at\r
+\r
+ *  https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
+\r
 package org.collectionspace.services.common.init;\r
 \r
+import org.collectionspace.services.common.ServiceMain;\r
 import org.collectionspace.services.common.storage.JDBCTools;\r
 import org.collectionspace.services.common.service.ServiceBindingType;\r
+import org.collectionspace.services.common.service.InitHandler.Params.Field;\r
+import org.collectionspace.services.common.service.InitHandler.Params.Property;\r
+\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
 import java.sql.*;\r
 import java.util.List;\r
 \r
-/**\r
- * User: laramie\r
- * $LastChangedRevision:  $\r
- * $LastChangedDate:  $\r
+/** Concrete class which does nothing, but subclasses may override to do\r
+ *  some action on the event onRepositoryInitialized(), such as sending JDBC\r
+ *  calls to the repository to add indices, etc.\r
+ * @author Laramie\r
  */\r
 public class InitHandler implements IInitHandler {\r
 \r
     final Logger logger = LoggerFactory.getLogger(InitHandler.class);\r
 \r
-    public void onRepositoryInitialized(ServiceBindingType sbt, List<String> fields) throws Exception {\r
+    public void onRepositoryInitialized(ServiceBindingType sbt, List<Field> fields, List<Property> properties) throws Exception {\r
         // see org.collectionspace.services.common.init.AddIndices for a real implementation example.\r
         System.out.println("\r\n\r\n~~~~~~~~~~~~~ in InitHandler.onRepositoryInitialized with ServiceBindingType: "+sbt);\r
-    }\r
+        for (Field field : fields){\r
+            System.out.println( "InitHandler.fields:"\r
+                               +"\r\n    col: "+field.getCol()\r
+                               +"   table: "+field.getTable()\r
+                               +"   type: "+field.getType()\r
+                               +"   param: "+field.getParam());\r
+        }\r
+        for (Property prop : properties){\r
+            System.out.println( "InitHandler.properties:"\r
+                               +"\r\n    key: "+prop.getKey()\r
+                               +"   value: "+prop.getValue());\r
 \r
-    public ResultSet openResultSet(String sql) throws Exception {\r
-        Connection conn = null;\r
-       Statement stmt = null;\r
-        try {\r
-               conn = JDBCTools.getConnection(JDBCTools.DEFAULT_REPOSITORY_NAME);\r
-               stmt = conn.createStatement();\r
-                       ResultSet rs = stmt.executeQuery(sql);\r
-                       stmt.close();\r
-            return rs;  //don't call rs.close() here ... Let caller close and catch any exceptions.\r
-        } catch (RuntimeException rte) {\r
-            logger.debug("Exception in createDefaultAccounts: "+rte.getLocalizedMessage());\r
-            logger.debug(rte.getStackTrace().toString());\r
-            throw rte;\r
-        } catch (SQLException sqle) {\r
-            SQLException tempException = sqle;\r
-            while (null != tempException) {       // SQLExceptions can be chained. Loop to log all.\r
-                logger.debug("SQL Exception: " + sqle.getLocalizedMessage());\r
-                tempException = tempException.getNextException();\r
-            }\r
-            logger.debug(sqle.getStackTrace().toString());\r
-            throw new RuntimeException("SQL problem in openResultSet: ", sqle);\r
-        } finally {\r
-               try {\r
-               if(conn!=null) conn.close();\r
-               if(stmt!=null) stmt.close();\r
-            } catch (SQLException sqle) {\r
-                logger.debug("SQL Exception closing statement/connection in openResultSet: "+ sqle.getLocalizedMessage());\r
-                return null;\r
-               }\r
         }\r
+    }\r
 \r
+    public ResultSet openResultSet(String sql) throws Exception {\r
+        return JDBCTools.openResultSet(sql);\r
     }\r
 \r
     public void closeResultSet(ResultSet rs) throws SQLException {\r
index 30fe5153f8cd997b58a393a90358514c96204cb4..b6921a5f0cd5aca3a34a4e12088fc52db91dc1e7 100755 (executable)
@@ -1,13 +1,36 @@
+/**\r
+ *  This document is a part of the source code and related artifacts\r
+ *  for CollectionSpace, an open source collections management system\r
+ *  for museums and related institutions:\r
+\r
+ *  http://www.collectionspace.org\r
+ *  http://wiki.collectionspace.org\r
+\r
+ *  Copyright 2009 University of California at Berkeley\r
+\r
+ *  Licensed under the Educational Community License (ECL), Version 2.0.\r
+ *  You may not use this file except in compliance with this License.\r
+\r
+ *  You may obtain a copy of the ECL 2.0 License at\r
+\r
+ *  https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
+\r
 package org.collectionspace.services.common.storage;\r
 \r
+import org.collectionspace.services.common.ServiceMain;\r
 import org.collectionspace.services.common.Tools;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
 \r
 import javax.naming.InitialContext;\r
 import javax.naming.NamingException;\r
 import javax.security.auth.login.LoginException;\r
 import javax.sql.DataSource;\r
 import java.sql.Connection;\r
+import java.sql.ResultSet;\r
 import java.sql.SQLException;\r
+import java.sql.Statement;\r
 \r
 /**\r
  * User: laramie\r
@@ -16,11 +39,12 @@ import java.sql.SQLException;
  */\r
 public class JDBCTools {\r
 \r
-    public static final String DEFAULT_REPOSITORY_NAME = "CspaceDS";\r
+    //todo: make sure this will get instantiated in the right order\r
+    final static Logger logger = LoggerFactory.getLogger(JDBCTools.class);\r
 \r
     public static Connection getConnection(String repositoryName) throws LoginException, SQLException {\r
         if (Tools.isEmpty(repositoryName)){\r
-            repositoryName = DEFAULT_REPOSITORY_NAME;\r
+            repositoryName = ServiceMain.DEFAULT_REPOSITORY_NAME;\r
         }\r
         InitialContext ctx = null;\r
         Connection conn = null;\r
@@ -46,6 +70,39 @@ public class JDBCTools {
         }\r
     }\r
 \r
+    public static ResultSet openResultSet(String sql) throws Exception {\r
+        Connection conn = null;\r
+       Statement stmt = null;\r
+        try {\r
+               conn = JDBCTools.getConnection(ServiceMain.DEFAULT_REPOSITORY_NAME);\r
+               stmt = conn.createStatement();\r
+                       ResultSet rs = stmt.executeQuery(sql);\r
+                       stmt.close();\r
+            return rs;  //don't call rs.close() here ... Let caller close and catch any exceptions.\r
+        } catch (RuntimeException rte) {\r
+            logger.debug("Exception in createDefaultAccounts: "+rte.getLocalizedMessage());\r
+            logger.debug(rte.getStackTrace().toString());\r
+            throw rte;\r
+        } catch (SQLException sqle) {\r
+            SQLException tempException = sqle;\r
+            while (null != tempException) {       // SQLExceptions can be chained. Loop to log all.\r
+                logger.debug("SQL Exception: " + sqle.getLocalizedMessage());\r
+                tempException = tempException.getNextException();\r
+            }\r
+            logger.debug(sqle.getStackTrace().toString());\r
+            throw new RuntimeException("SQL problem in openResultSet: ", sqle);\r
+        } finally {\r
+               try {\r
+               if(conn!=null) conn.close();\r
+               if(stmt!=null) stmt.close();\r
+            } catch (SQLException sqle) {\r
+                logger.debug("SQL Exception closing statement/connection in openResultSet: "+ sqle.getLocalizedMessage());\r
+                return null;\r
+               }\r
+        }\r
+\r
+    }\r
+\r
 \r
 \r
 \r
index 9ef2ccf2f89838672d054d7b33b911045caa0ede..af351db823c7c5f81318a0ff1a255f9f211fb972 100644 (file)
         </xs:sequence>
     </xs:complexType>
 
-    <xs:complexType name="initHandler">
+    <xs:complexType name="initHandlerOLD">
         <xs:sequence>
             <xs:element name="classname" type="xs:string" minOccurs="0" maxOccurs="1"/>
             <!--<xs:element name="fields" type="FieldsType" minOccurs="0" maxOccurs="1"/>-->
         </xs:sequence>
     </xs:complexType>
 
+    <xs:complexType name="initHandler">
+        <xs:sequence>
+            <xs:element name="classname" type="xs:string" minOccurs="0" maxOccurs="1"/>
+            <xs:element name="params">
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element name="field" minOccurs="0" maxOccurs="unbounded">
+                            <xs:complexType>
+                                <xs:sequence>
+                                    <xs:element name="table" type="xs:string" minOccurs="0" maxOccurs="1"/>
+                                    <xs:element name="col" type="xs:string" minOccurs="0" maxOccurs="1"/>
+                                    <xs:element name="type" type="xs:string" minOccurs="0" maxOccurs="1"/>
+                                    <xs:element name="param" type="xs:string" minOccurs="0" maxOccurs="1"/>
+                                </xs:sequence>
+                            </xs:complexType>
+                        </xs:element>
+                        <xs:element name="property" minOccurs="0" maxOccurs="unbounded">
+                            <xs:complexType>
+                                <xs:sequence>
+                                    <xs:element name="key" type="xs:string" minOccurs="1" maxOccurs="1"/>
+                                    <xs:element name="value" type="xs:string" minOccurs="1" maxOccurs="1"/>
+                                </xs:sequence>
+                            </xs:complexType>
+                        </xs:element>
+                    </xs:sequence>
+                </xs:complexType>
+           </xs:element>
+        </xs:sequence>
+    </xs:complexType>
+
     <xs:complexType name="DocHandlerParams">
         <xs:sequence>
             <xs:element name="classname" type="xs:string" minOccurs="0" maxOccurs="1"/>