]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-308, CSPACE-309, CSPACE-585, CSPACE-582, CSPACE-615 Account Service is
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Tue, 24 Nov 2009 21:02:00 +0000 (21:02 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Tue, 24 Nov 2009 21:02:00 +0000 (21:02 +0000)
functional. Service consumer could create, get, update and delete an
account. index operation also works.
Running mvn -Pddl in account/client generates account.sql using
hibernate tool with the help of Jpa annotations.
JpaStorage is functional as well. Added a property named entity-name
to service context to indicate Jpa entity for data base operations.
NOTE!!!! Before running tests, a one time execution of 'ant jpa' is
required from services/common. Also requires deploy at trunk level as
cspace datasource configuration has changed.
tests: mvn test passes (requires deploy (trunk) and jpa (common))

_M   services/authentication/jaxb
M    services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java
M    services/JaxRsServiceProvider/src/main/webapp/WEB-INF/jboss-web.xml
M    services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml
M    services/JaxRsServiceProvider/pom.xml
A    services/common/lib
A    services/common/lib/jpa-upgrade
AM   services/common/lib/jpa-upgrade/ejb3-persistence-1.0.2.GA.jar
AM   services/common/lib/jpa-upgrade/hibernate-entitymanager-3.4.0.GA.jar
AM   services/common/lib/jpa-upgrade/hibernate-annotations-3.4.0.GA.jar
A    services/common/lib/README.txt
M    services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java
M    services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java
M    services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java
M    services/common/build.xml
M    services/pom.xml
M    services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java
M    services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java
A  + services/account/service/src/main/resources/META-INF
M    services/account/service/src/main/resources/META-INF/persistence.xml
D    services/account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java
D    services/account/jaxb/src/test/resources/META-INF
D    services/account/jaxb/src/test/resources/hibernate.cfg.xml
D    services/account/jaxb/src/main/resources/META-INF
M    services/account/jaxb/src/main/resources/accounts_common.xsd
D    services/account/jaxb/src/main/resources/db/mysql/account.sql
M    services/account/jaxb/pom.xml
D    services/account/3rdparty
M    services/account/pom.xml
M    services/account/build.xml
A  + services/account/client/src/test/java/org/collectionspace/services/client/test/AccountTest.java
M    services/account/client/src/test/java/org/collectionspace/services/client/test/AccountServiceTest.java
A  + services/account/client/src/test/resources/META-INF
A  + services/account/client/src/test/resources/hibernate.cfg.xml
A    services/account/client/src/main/resources/db
A    services/account/client/src/main/resources/db/mysql
A    services/account/client/src/main/resources/db/mysql/account.sql
M    services/account/client/pom.xml
M    src/main/resources/config/cspace-ds.xml

30 files changed:
services/JaxRsServiceProvider/pom.xml
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java
services/JaxRsServiceProvider/src/main/webapp/WEB-INF/jboss-web.xml
services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml
services/account/3rdparty/build.xml [deleted file]
services/account/3rdparty/pom.xml [deleted file]
services/account/build.xml
services/account/client/pom.xml
services/account/client/src/main/resources/db/mysql/account.sql [new file with mode: 0644]
services/account/client/src/test/java/org/collectionspace/services/client/test/AccountServiceTest.java
services/account/client/src/test/java/org/collectionspace/services/client/test/AccountTest.java [moved from services/account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java with 92% similarity]
services/account/client/src/test/resources/META-INF/persistence.xml [moved from services/account/jaxb/src/test/resources/META-INF/persistence.xml with 100% similarity]
services/account/client/src/test/resources/hibernate.cfg.xml [moved from services/account/jaxb/src/test/resources/hibernate.cfg.xml with 100% similarity]
services/account/jaxb/pom.xml
services/account/jaxb/src/main/resources/accounts_common.xsd
services/account/jaxb/src/main/resources/db/mysql/account.sql [deleted file]
services/account/pom.xml
services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java
services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java
services/account/service/src/main/resources/META-INF/persistence.xml [moved from services/account/jaxb/src/main/resources/META-INF/persistence.xml with 95% similarity]
services/common/build.xml
services/common/lib/README.txt [new file with mode: 0644]
services/common/lib/jpa-upgrade/ejb3-persistence-1.0.2.GA.jar [new file with mode: 0644]
services/common/lib/jpa-upgrade/hibernate-annotations-3.4.0.GA.jar [new file with mode: 0644]
services/common/lib/jpa-upgrade/hibernate-entitymanager-3.4.0.GA.jar [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java
services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java
services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java
services/pom.xml
src/main/resources/config/cspace-ds.xml

index 4c57e39c6d023549f144470bd5fba0a37fe1a307..c57d1261a50094418ad1a6b0b2f329000499390d 100644 (file)
             <artifactId>org.collectionspace.services.common</artifactId>\r
             <version>1.0</version>\r
         </dependency>\r
-        <!--dependency>\r
+        <dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
             <artifactId>org.collectionspace.services.account.service</artifactId>\r
             <version>1.0</version>\r
-        </dependency-->\r
+        </dependency>\r
         <dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
             <artifactId>org.collectionspace.services.collectionobject.service</artifactId>\r
index 406b69d94de2f954c031d46c9a6b28bab15a35f8..c7196a3dd403fc4cf517b5390a473b53bdf4cbf0 100644 (file)
@@ -1,6 +1,6 @@
 package org.collectionspace.services.jaxrs;
 
-//import org.collectionspace.services.account.AccountResource;
+import org.collectionspace.services.account.AccountResource;
 import org.collectionspace.services.collectionobject.CollectionObjectResource;
 import org.collectionspace.services.id.IDResource;
 import org.collectionspace.services.intake.IntakeResource;
@@ -22,7 +22,7 @@ public class CollectionSpaceJaxRsApplication extends Application {
     private Set<Class<?>> empty = new HashSet<Class<?>>();
 
     public CollectionSpaceJaxRsApplication() {
-//        singletons.add(new AccountResource());
+        singletons.add(new AccountResource());
         singletons.add(new CollectionObjectResource());
         singletons.add(new IDResource());
         singletons.add(new IntakeResource());
index 10a4024eb789d4adda9a8e6a46ea66bf3215d4fa..2dddc9661e80596bb81e405602e32cb7552cf3c7 100644 (file)
@@ -3,11 +3,11 @@
   <!-- All secure web resources will use this security domain -->\r
     <security-domain>java:/jaas/cspace</security-domain>\r
     <context-root>/cspace-services</context-root>\r
-    <resource-ref>\r
+    <!--resource-ref>\r
         <description>DB Connection</description>\r
         <res-ref-name>jdbc/cspaceds</res-ref-name>\r
         <res-type>javax.sql.DataSource</res-type>\r
         <jndi-name>java:/cspaceds</jndi-name>\r
         <res-auth>Container</res-auth>\r
-    </resource-ref>\r
+    </resource-ref-->\r
 </jboss-web>\r
index 62d9b25b989d07ca6fdf771dd69ca24302ca24e8..5660b37af46bf14dd9781431420a4a25ed0535ac 100644 (file)
         <realm-name>CollectionSpace realm</realm-name>
     </login-config>
  END AUTH -->
-    <resource-ref>
+    <!--resource-ref>
         <description>DB Connection</description>
         <res-ref-name>jdbc/cspaceds</res-ref-name>
         <res-type>javax.sql.DataSource</res-type>
         <res-auth>Container</res-auth>
-    </resource-ref>
+    </resource-ref-->
 </web-app>
diff --git a/services/account/3rdparty/build.xml b/services/account/3rdparty/build.xml
deleted file mode 100644 (file)
index c0a1b94..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-\r
-<project name="account.3rdparty" default="package" basedir=".">\r
-    <description>\r
-        account service 3rd party\r
-    </description>\r
-  <!-- set global properties for this build -->\r
-    <property name="services.trunk" value="../../.."/>\r
-    <property file="${services.trunk}/build.properties" />\r
-    <property name="mvn.opts" value="" />\r
-    <property name="src" location="src"/>\r
-    <property name="build" location="build"/>\r
-\r
-    <condition property="osfamily-unix">\r
-        <os family="unix" />\r
-    </condition>\r
-    <condition property="osfamily-windows">\r
-        <os family="windows" />\r
-    </condition>\r
-\r
-    <target name="init" >\r
-    <!-- Create the time stamp -->\r
-        <tstamp/>\r
-\r
-    </target>\r
-\r
-    <target name="package" depends="package-unix,package-windows"\r
-  description="Package CollectionSpace Services" />\r
-    <target name="package-unix" if="osfamily-unix">\r
-        <exec executable="mvn" failonerror="true">\r
-            <arg value="package" />\r
-            <arg value="-Dmaven.test.skip=true" />\r
-            <arg value="-f" />\r
-            <arg value="${basedir}/pom.xml" />\r
-            <arg value="-N" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-    <target name="package-windows" if="osfamily-windows">\r
-        <exec executable="cmd" failonerror="true">\r
-            <arg value="/c" />\r
-            <arg value="mvn.bat" />\r
-            <arg value="package" />\r
-            <arg value="-Dmaven.test.skip=true" />\r
-            <arg value="-f" />\r
-            <arg value="${basedir}/pom.xml" />\r
-            <arg value="-N" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-\r
-    <target name="install" depends="package,install-unix,install-windows"\r
-  description="Install" />\r
-    <target name="install-unix" if="osfamily-unix">\r
-        <exec executable="mvn" failonerror="true">\r
-            <arg value="install" />\r
-            <arg value="-Dmaven.test.skip=true" />\r
-            <arg value="-f" />\r
-            <arg value="${basedir}/pom.xml" />\r
-            <arg value="-N" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-    <target name="install-windows" if="osfamily-windows">\r
-        <exec executable="cmd" failonerror="true">\r
-            <arg value="/c" />\r
-            <arg value="mvn.bat" />\r
-            <arg value="install" />\r
-            <arg value="-Dmaven.test.skip=true" />\r
-            <arg value="-f" />\r
-            <arg value="${basedir}/pom.xml" />\r
-            <arg value="-N" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-    \r
-    <target name="clean" depends="clean-unix,clean-windows"\r
-  description="Delete target directories" >\r
-        <delete dir="${build}"/>\r
-    </target>\r
-    <target name="clean-unix" if="osfamily-unix">\r
-        <exec executable="mvn" failonerror="true">\r
-            <arg value="clean" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-    <target name="clean-windows" if="osfamily-windows">\r
-        <exec executable="cmd" failonerror="true">\r
-            <arg value="/c" />\r
-            <arg value="mvn.bat" />\r
-            <arg value="clean" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-\r
-    <target name="test" depends="test-unix,test-windows" description="Run tests" />\r
-    <target name="test-unix" if="osfamily-unix">\r
-        <exec executable="mvn" failonerror="true">\r
-            <arg value="test" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-    <target name="test-windows" if="osfamily-windows">\r
-        <exec executable="cmd" failonerror="true">\r
-            <arg value="/c" />\r
-            <arg value="mvn.bat" />\r
-            <arg value="test" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-\r
-    <target name="deploy" depends="install"\r
-    description="deploy account in ${jboss.server.nuxeo}">\r
-        <ant antfile="nuxeo-platform-cs-account/build.xml" target="deploy" inheritall="false"/>\r
-    </target>\r
-\r
-    <target name="undeploy"\r
-    description="undeploy account from ${jboss.server.nuxeo}">\r
-        <ant antfile="nuxeo-platform-cs-account/build.xml" target="undeploy" inheritall="false"/>\r
-    </target>\r
-\r
-    <target name="dist"\r
-    description="generate distribution for account" depends="package">\r
-        <ant antfile="nuxeo-platform-cs-account/build.xml" target="dist" inheritall="false"/>\r
-    </target>\r
-\r
-</project>\r
diff --git a/services/account/3rdparty/pom.xml b/services/account/3rdparty/pom.xml
deleted file mode 100644 (file)
index a4a7a16..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-\r
-<project xmlns="http://maven.apache.org/POM/4.0.0"\r
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
-\r
-    <parent>\r
-        <groupId>org.collectionspace.services</groupId>\r
-        <artifactId>org.collectionspace.services.account</artifactId>\r
-        <version>1.0</version>\r
-    </parent>\r
-\r
-    <modelVersion>4.0.0</modelVersion>\r
-    <groupId>org.collectionspace.services</groupId>\r
-    <version>1.0</version>\r
-    <artifactId>org.collectionspace.services.account.3rdparty</artifactId>\r
-    <packaging>pom</packaging>\r
-    <name>services.account.3rdparty</name>\r
-    <description>\r
-    3rd party build for account service\r
-    </description>\r
-\r
-    <modules>\r
-\r
-    </modules>\r
-\r
-</project>\r
index 8219b198010ee548bb1b352669cd11d6d997ac44..445894e2f47afa8b4ae0193c7d8096ac186d06c8 100644 (file)
@@ -1,5 +1,5 @@
 \r
-<project name="collectionobject" default="package" basedir=".">\r
+<project name="account" default="package" basedir=".">\r
     <description>\r
         collectionobject service\r
     </description>\r
index c350fe47790d72c50e204cc9fc2e9380bda42c68..eb2b3786e87d8383bbfd0a5ba3ca14f97f9a73b4 100644 (file)
     <artifactId>org.collectionspace.services.account.client</artifactId>\r
     <version>1.0</version>\r
     <name>services.account.client</name>\r
-    \r
+    <properties>\r
+        <sql.file>account.sql</sql.file>\r
+        <sql.dir>${basedir}/src/main/resources/db/mysql</sql.dir>\r
+    </properties>\r
     <dependencies>\r
         <!-- keep slf4j dependencies on the top -->\r
         <dependency>\r
             <artifactId>commons-httpclient</artifactId>\r
             <version>3.1</version>\r
         </dependency>\r
+\r
+\r
+        <dependency>\r
+            <groupId>mysql</groupId>\r
+            <artifactId>mysql-connector-java</artifactId>\r
+        </dependency>\r
     </dependencies>\r
     \r
     <build>\r
             </plugin>\r
         </plugins>\r
     </build>\r
+    <profiles>\r
+        <profile>\r
+            <!-- use profile as this task is not needed for every build and test -->\r
+            <id>ddl</id>\r
+            <build>\r
+                <plugins>\r
+                    <plugin>\r
+                        <groupId>org.codehaus.mojo</groupId>\r
+                        <artifactId>hibernate3-maven-plugin</artifactId>\r
+                        <version>2.2</version>\r
+                        <executions>\r
+                            <execution>\r
+                                <goals>\r
+                                    <goal>hbm2ddl</goal>\r
+                                </goals>\r
+                            </execution>\r
+                        </executions>\r
+                        <configuration>\r
+                            <components>\r
+                                <component>\r
+                                    <name>hbm2ddl</name>\r
+                                </component>\r
+                            </components>\r
+                            <componentProperties>\r
+                                <outputfilename>${sql.file}</outputfilename>\r
+                                <implementation>jpaconfiguration</implementation>\r
+                                <drop>true</drop>\r
+                                <create>true</create>\r
+                                <export>true</export>\r
+                                <jdk5>true</jdk5>\r
+                                <ejb3>false</ejb3>\r
+                                <persistenceunit>org.collectionspace.services.account</persistenceunit>\r
+                            </componentProperties>\r
+                        </configuration>\r
+                        <dependencies>\r
+                            <dependency>\r
+                                <groupId>mysql</groupId>\r
+                                <artifactId>mysql-connector-java</artifactId>\r
+                                <version>5.0.5</version>\r
+                            </dependency>\r
+                        </dependencies>\r
+                    </plugin>\r
+                    <plugin>\r
+                        <artifactId>maven-antrun-plugin</artifactId>\r
+                        <executions>\r
+                            <execution>\r
+                                <configuration>\r
+                                    <tasks>\r
+                                        <copy file="${basedir}/target/hibernate3/sql/${sql.file}" tofile="${sql.dir}/${sql.file}"/>\r
+                                    </tasks>\r
+                                </configuration>\r
+                                <goals>\r
+                                    <goal>run</goal>\r
+                                </goals>\r
+                            </execution>\r
+                        </executions>\r
+                    </plugin>\r
+\r
+                </plugins>\r
+            </build>\r
+        </profile>\r
+    </profiles>\r
 </project>\r
 \r
diff --git a/services/account/client/src/main/resources/db/mysql/account.sql b/services/account/client/src/main/resources/db/mysql/account.sql
new file mode 100644 (file)
index 0000000..4ad2914
--- /dev/null
@@ -0,0 +1,2 @@
+drop table if exists accounts_common;
+create table accounts_common (csid varchar(255) not null, anchor_name varchar(128) not null, email longtext not null, first_name longtext not null, last_name longtext not null, mi varchar(1), mobile varchar(15), phone varchar(15), primary key (csid));
index 881d9343734ff1b33d8828ceda9e87257f4a8846..f009e76e1f8d9a2e2babf37325fb86f6d0793dab 100644 (file)
@@ -31,7 +31,6 @@ import org.collectionspace.services.account.AccountsCommon;
 import org.collectionspace.services.account.AccountsCommonList;
 import org.jboss.resteasy.client.ClientResponse;
 
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
@@ -76,7 +75,7 @@ public class AccountServiceTest extends AbstractServiceTest {
 
         // Submit the request to the service and store the response.
         AccountsCommon account =
-                createAccountInstance("sanjay", "hello");
+                createAccountInstance("barney", "dino", "barney", "hello", "barney@dinoland.com");
         ClientResponse<Response> res = client.create(account);
         int statusCode = res.getStatus();
 
@@ -207,7 +206,7 @@ public class AccountServiceTest extends AbstractServiceTest {
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
 
         // Optionally output additional data about list members for debugging.
-        boolean iterateThroughList = false;
+        boolean iterateThroughList = true;
         if (iterateThroughList && logger.isDebugEnabled()) {
             List<AccountsCommonList.AccountListItem> items =
                     list.getAccountListItem();
@@ -234,7 +233,7 @@ public class AccountServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
-    dependsOnMethods = {"read"})
+    dependsOnMethods = {"read", "readNonExistent"})
     public void update(String testName) throws Exception {
 
         // Perform setup.
@@ -250,10 +249,8 @@ public class AccountServiceTest extends AbstractServiceTest {
         if (logger.isDebugEnabled()) {
             logger.debug("got object to update with ID: " + knownResourceId);
         }
-        MultipartInput input = (MultipartInput) res.getEntity();
         AccountsCommon toUpdateAccount =
-                (AccountsCommon) extractPart(input,
-                client.getCommonPartName(), AccountsCommon.class);
+                (AccountsCommon) res.getEntity();
         Assert.assertNotNull(toUpdateAccount);
 
         // Update the content of this resource.
@@ -277,11 +274,11 @@ public class AccountServiceTest extends AbstractServiceTest {
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
 
 
-        AccountsCommon updatedAccount = (AccountsCommon)res.getEntity();
+        AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
         Assert.assertNotNull(updatedAccount);
 
         Assert.assertEquals(updatedAccount.getEmail(),
-                toUpdateAccount.getPhone(),
+                toUpdateAccount.getEmail(),
                 "Data in updated object did not match submitted data.");
 
     }
@@ -303,7 +300,7 @@ public class AccountServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
-    dependsOnMethods = {"update", "testSubmitRequest"})
+    dependsOnMethods = {"update", "readNonExistent", "testSubmitRequest"})
     public void updateNonExistent(String testName) throws Exception {
 
         // Perform setup.
@@ -314,7 +311,7 @@ public class AccountServiceTest extends AbstractServiceTest {
         // Note: The ID used in this 'create' call may be arbitrary.
         // The only relevant ID may be the one used in updateAccount(), below.
         AccountsCommon account =
-                createAccountInstance("dalal", "junk");
+                createAccountInstance("simba", "mufasa", "simba", "tiger", "simba@lionking.com");
         ClientResponse<AccountsCommon> res =
                 client.update(NON_EXISTENT_ID, account);
         int statusCode = res.getStatus();
@@ -335,7 +332,7 @@ public class AccountServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
-    dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
+    dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "updateNonExistent"})
     public void delete(String testName) throws Exception {
 
         // Perform setup.
@@ -409,15 +406,17 @@ public class AccountServiceTest extends AbstractServiceTest {
     // ---------------------------------------------------------------
     // Utility methods used by tests above
     // ---------------------------------------------------------------
-    private AccountsCommon createAccountInstance(String anchorName,
-            String passwd) {
+    private AccountsCommon createAccountInstance(String firstName, String lastName, String anchorName,
+            String passwd, String email) {
 
         AccountsCommon account = new AccountsCommon();
+        account.setFirstName(firstName);
+        account.setLastName(lastName);
         account.setAnchorName(anchorName);
         account.setUserName(anchorName);
         byte[] b64passwd = Base64.encodeBase64(passwd.getBytes());
         account.setPassword(b64passwd);
-
+        account.setEmail(email);
         if (logger.isDebugEnabled()) {
             logger.debug("to be created, account common");
             logger.debug(objectAsXmlString(account,
@@ -426,5 +425,4 @@ public class AccountServiceTest extends AbstractServiceTest {
         return account;
 
     }
-
 }
similarity index 92%
rename from services/account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java
rename to services/account/client/src/test/java/org/collectionspace/services/client/test/AccountTest.java
index 31ddfaa0523cd83ada59730c2a3e495033408f1a..e6b77b9f96d3cd881ae7a0931e3be418f197f497 100644 (file)
@@ -2,7 +2,7 @@
  * To change this template, choose Tools | Templates
  * and open the template in the editor.
  */
-package org.collectionspace.services.account.test;
+package org.collectionspace.services.client.test;
 
 import java.lang.reflect.Method;
 import java.util.List;
@@ -56,10 +56,10 @@ public class AccountTest {
     @Test(dataProvider = "testName", dataProviderClass = AccountTest.class)
     public void create(String testName) throws Exception {
         AccountsCommon account = new AccountsCommon();
-        account.setAnchorName("sanjay");
-        account.setFirstName("Sanjay");
-        account.setLastName("Dalal");
-        account.setEmail("sanjay.dalal@berkeley.edu");
+        account.setAnchorName("john");
+        account.setFirstName("John");
+        account.setLastName("Doe");
+        account.setEmail("john.doe@berkeley.edu");
         id = UUID.randomUUID().toString();
         account.setCsid(id);
         em.getTransaction().begin();
@@ -77,7 +77,7 @@ public class AccountTest {
     @Test(dataProvider = "testName", dataProviderClass = AccountTest.class,
     dependsOnMethods = {"create"})
     public void read(String testName) throws Exception {
-        AccountsCommon account = findAccount("sanjay");
+        AccountsCommon account = findAccount("john");
         Assert.assertNotNull(account);
         if (logger.isDebugEnabled()) {
             logger.debug("read account " +
@@ -97,14 +97,14 @@ public class AccountTest {
     dependsOnMethods = {"read"})
     public void update(String testName) throws Exception {
         Query q = em.createQuery("update org.collectionspace.services.account.AccountsCommon set email= :email where csid=:csid");
-        q.setParameter("email", "sanjay@berkeley.edu");
+        q.setParameter("email", "john@berkeley.edu");
         q.setParameter("csid", id);
         em.getTransaction().begin();
         int no = q.executeUpdate();
         // Commit the transaction
         em.getTransaction().commit();
         Assert.assertEquals(no, 1);
-        AccountsCommon account = findAccount("sanjay");
+        AccountsCommon account = findAccount("john");
         if (logger.isDebugEnabled()) {
             logger.debug("updated account " +
                     " first name=" + account.getFirstName() +
index 77362573494e9d35324205f7215a03f04d8b9e91..62cf46e986a3f8ff2a04b70d60c631cc71c9e70b 100644 (file)
     <artifactId>org.collectionspace.services.account.jaxb</artifactId>
     <version>1.0</version>
     <name>services.account.jaxb</name>
-    <properties>
-        <sql.file>account.sql</sql.file>
-        <sql.dir>src/main/resources/db/mysql</sql.dir>
-    </properties>
     <dependencies>
                 <!-- keep slf4j dependencies on the top -->
         <dependency>
@@ -87,6 +83,7 @@
                     <extension>true</extension>
                     <jdk5>true</jdk5>
                     <ejb3>false</ejb3>
+                    <persistenceUnitName>garbage</persistenceUnitName>
                 </configuration>
             </plugin>
             <plugin>
                     <target>1.6</target>
                 </configuration>
             </plugin>
-
         </plugins>
     </build>
-    <profiles>
-        <profile>
-            <!-- use profile as this task is not needed for every build and test -->
-            <id>ddl</id>
-            <build>
-                <plugins>
-                    <plugin>
-                        <groupId>org.codehaus.mojo</groupId>
-                        <artifactId>hibernate3-maven-plugin</artifactId>
-                        <version>2.2</version>
-                        <executions>
-                            <execution>
-                            
-                                <phase>process-test-resources</phase>
-                                <goals>
-                                    <goal>hbm2ddl</goal>
-                                </goals>
-                            </execution>
-                        </executions>
-                        <configuration>
-                            <components>
-                                <component>
-                                    <name>hbm2ddl</name>
-                                </component>
-                            </components>
-                            <componentProperties>
-                                <outputfilename>${sql.file}</outputfilename>
-                                <implementation>jpaconfiguration</implementation>
-                                <drop>true</drop>
-                                <create>true</create>
-                                <export>true</export>
-                                <jdk5>true</jdk5>
-                                <ejb3>false</ejb3>
-                                <persistenceunit>org.collectionspace.services.account</persistenceunit>
-                            </componentProperties>
-                        </configuration>
-                        <dependencies>
-                            <dependency>
-                                <groupId>mysql</groupId>
-                                <artifactId>mysql-connector-java</artifactId>
-                                <version>5.0.5</version>
-                            </dependency>
-                        </dependencies>
-                    </plugin>
-                    <plugin>
-                        <artifactId>maven-antrun-plugin</artifactId>
-                        <executions>
-                            <execution>
-                                <phase>process-test-classes</phase>
-                                <configuration>
-                                    <tasks>
-                                        <copy file="target/hibernate3/sql/${sql.file}" tofile="${sql.dir}/${sql.file}"/>
-                                    </tasks>
-                                </configuration>
-                                <goals>
-                                    <goal>run</goal>
-                                </goals>
-                            </execution>
-                        </executions>
-                    </plugin>
 
-                </plugins>
-            </build>
-        </profile>
-    </profiles>
 </project>
 
index 8d40271382e5a67d9fffa25f72a99cc4d27ffc0d..8eca84f96f07928d895271586c3a25b20485c895 100644 (file)
     <!-- convention: <servicename>-common  -->
     <xs:element name="accounts_common">
         <xs:complexType>
+            <xs:annotation>
+                <xs:appinfo>
+                    <hj:entity>
+                        <orm:table name="accounts_common"/>
+                    </hj:entity>
+                </xs:appinfo>
+            </xs:annotation>
             <xs:sequence>
-                <xs:element name="anchorName" type="xs:string" minOccurs="1" maxOccurs="1" />
-                <xs:element name="firstName" type="xs:string" minOccurs="1" maxOccurs="1" />
-                <xs:element name="lastName" type="xs:string" minOccurs="1" maxOccurs="1" />
-                <xs:element name="mi" type="xs:string"/>
-                <xs:element name="email" type="xs:string" minOccurs="1" maxOccurs="1" />
-                <xs:element name="phone" type="xs:string"/>
-
+                <xs:element name="anchorName" type="xs:string" minOccurs="1" maxOccurs="1">
+                    <xs:annotation>
+                        <xs:appinfo>
+                            <hj:basic>
+                                <orm:column name="anchor_name" length="128" nullable="false"/>
+                            </hj:basic>
+                        </xs:appinfo>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="firstName" type="xs:string" minOccurs="1" maxOccurs="1">
+                    <xs:annotation>
+                        <xs:appinfo>
+                            <hj:basic>
+                                <orm:column name="first_name" length="256" nullable="false"/>
+                            </hj:basic>
+                        </xs:appinfo>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="lastName" type="xs:string" minOccurs="1" maxOccurs="1">
+                    <xs:annotation>
+                        <xs:appinfo>
+                            <hj:basic>
+                                <orm:column name="last_name" length="256" nullable="false"/>
+                            </hj:basic>
+                        </xs:appinfo>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="mi" type="xs:string">
+                    <xs:annotation>
+                        <xs:appinfo>
+                            <hj:basic>
+                                <orm:column name="mi" length="1" nullable="true"/>
+                            </hj:basic>
+                        </xs:appinfo>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="email" type="xs:string" minOccurs="1" maxOccurs="1">
+                    <xs:annotation>
+                        <xs:appinfo>
+                            <hj:basic>
+                                <orm:column name="email" length="512" nullable="false"/>
+                            </hj:basic>
+                        </xs:appinfo>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="phone" type="xs:string">
+                    <xs:annotation>
+                        <xs:appinfo>
+                            <hj:basic>
+                                <orm:column name="phone" length="15" nullable="true"/>
+                            </hj:basic>
+                        </xs:appinfo>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="mobile" type="xs:string">
+                    <xs:annotation>
+                        <xs:appinfo>
+                            <hj:basic>
+                                <orm:column name="mobile" length="15" nullable="true"/>
+                            </hj:basic>
+                        </xs:appinfo>
+                    </xs:annotation>
+                </xs:element>
                 <!-- optional username for default identity provider -->
-                <xs:element name="userName" type="xs:string" minOccurs="0" maxOccurs="1" />
+                <xs:element name="userName" type="xs:string" minOccurs="0" maxOccurs="1">
+                    <xs:annotation>
+                        <xs:appinfo>
+                            <hj:ignored/>
+                        </xs:appinfo>
+                    </xs:annotation>
+                </xs:element>
                 <!-- optional base64 encoded password for default identity provider -->
-                <xs:element name="password" type="xs:base64Binary" minOccurs="0" maxOccurs="1" />
+                <xs:element name="password" type="xs:base64Binary" minOccurs="0" maxOccurs="1">
+                    <xs:annotation>
+                        <xs:appinfo>
+                            <hj:ignored/>
+                        </xs:appinfo>
+                    </xs:annotation>
+                </xs:element>
             </xs:sequence>
             <xs:attribute name="csid" type="xs:string">
                 <xs:annotation>
                     <xs:appinfo>
-                        <hj:id />
+                        <hj:id>
+                            <orm:column name="csid" nullable="false"/>
+                        </hj:id>
                     </xs:appinfo>
                 </xs:annotation>
             </xs:attribute>
 
     <xs:element name="accounts-common-list">
         <xs:complexType>
+            <xs:annotation>
+                <xs:appinfo>
+                    <hj:ignored/>
+                </xs:appinfo>
+            </xs:annotation>
             <xs:sequence>
                 <xs:element name="account-list-item" maxOccurs="unbounded">
                     <xs:complexType>
+                        <xs:annotation>
+                            <xs:appinfo>
+                                <hj:ignored/>
+                            </xs:appinfo>
+                        </xs:annotation>
                         <xs:sequence>
                             <xs:element name="anchorName" type="xs:string" minOccurs="1"/>
                             <xs:element name="firstName" type="xs:string" minOccurs="1" />
diff --git a/services/account/jaxb/src/main/resources/db/mysql/account.sql b/services/account/jaxb/src/main/resources/db/mysql/account.sql
deleted file mode 100644 (file)
index e69de29..0000000
index b739055ce1f3d75f82fd19fce5a3fc2ccb53f6cc..15ce11de54639a5ec4ca98e990d3242f66c67d9d 100644 (file)
@@ -15,7 +15,6 @@
     <modules>\r
         <module>jaxb</module>\r
         <module>service</module>\r
-        <module>3rdparty</module>\r
         <module>client</module>\r
     </modules>\r
 \r
index 933f1b606549b7bfaaac89e77d114380e2b067b8..e44155e693cf7a1d7f9a2dcd0ed6588675757b1f 100644 (file)
@@ -69,7 +69,8 @@ public class AccountResource
     private <T> ServiceContext createServiceContext(T obj) {
         ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
         ctx.setInput(obj);
-        ctx.setDocumentType("org.collectionspace.services.account"); //persistence unit
+        ctx.setDocumentType(AccountsCommon.class.getPackage().getName()); //persistence unit
+        ctx.setProperty("entity-name", AccountsCommon.class.getName());
         return ctx;
     }
 
@@ -127,7 +128,7 @@ public class AccountResource
             ServiceContext ctx = createServiceContext((AccountsCommon) null);
             DocumentHandler handler = createDocumentHandler(ctx);
             getStorageClient(ctx).get(ctx, csid, handler);
-            result = (AccountsCommon) ctx.getOutput();
+            result = (AccountsCommon)ctx.getOutput();
         } catch (DocumentNotFoundException dnfe) {
             if (logger.isDebugEnabled()) {
                 logger.debug("getAccount", dnfe);
@@ -164,7 +165,7 @@ public class AccountResource
             DocumentFilter myFilter = new DocumentFilter();
             handler.setDocumentFilter(myFilter);
             getStorageClient(ctx).getFiltered(ctx, handler);
-            accountList = null;
+            accountList = (AccountsCommonList)handler.getCommonPartList();
         } catch (Exception e) {
             if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception in getAccountList", e);
@@ -196,7 +197,7 @@ public class AccountResource
             ServiceContext ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getStorageClient(ctx).update(ctx, csid, handler);
-            result = (AccountsCommon) ctx.getOutput();
+            result = (AccountsCommon)ctx.getOutput();
         } catch (DocumentNotFoundException dnfe) {
             if (logger.isDebugEnabled()) {
                 logger.debug("caugth exception in updateAccount", dnfe);
index 5e4a677f5d409ecfb65e34c294e7e0462f6bad32..a42b50bbb8968d4b5e9159ec33415a356326a533 100644 (file)
  */
 package org.collectionspace.services.account.storage;
 
+import java.util.List;
 import java.util.UUID;
 import org.collectionspace.services.account.AccountsCommon;
 import org.collectionspace.services.account.AccountsCommonList;
+import org.collectionspace.services.account.AccountsCommonList.AccountListItem;
 import org.collectionspace.services.common.document.AbstractDocumentHandler;
 import org.collectionspace.services.common.document.DocumentWrapper;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 
 /**
  *
  * @author 
  */
 public class AccountDocumentHandler
-        extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList, AccountsCommon, AccountsCommonList> {
+        extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList, AccountsCommon, List> {
 
     private AccountsCommon account;
     private AccountsCommonList accountList;
@@ -48,22 +51,27 @@ public class AccountDocumentHandler
 
     @Override
     public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
+        getServiceContext().setOutput(getCommonPart());
     }
 
     @Override
     public void handleGet(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
-        setCommonPart(wrapDoc.getWrappedObject());
+        setCommonPart(extractCommonPart(wrapDoc));
+        getServiceContext().setOutput(getCommonPart());
     }
 
     @Override
-    public void handleGetAll(DocumentWrapper<AccountsCommonList> wrapDoc) throws Exception {
-        setCommonPartList(wrapDoc.getWrappedObject());
+    public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
+        AccountsCommonList accList = extractCommonPartList(wrapDoc);
+        setCommonPartList(accList);
+        getServiceContext().setOutput(getCommonPartList());
     }
 
     @Override
-    public AccountsCommon extractCommonPart(DocumentWrapper<AccountsCommon> wrapDoc)
+    public AccountsCommon extractCommonPart(
+            DocumentWrapper<AccountsCommon> wrapDoc)
             throws Exception {
-        throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
+        return wrapDoc.getWrappedObject();
     }
 
     @Override
@@ -73,9 +81,26 @@ public class AccountDocumentHandler
     }
 
     @Override
-    public AccountsCommonList extractCommonPartList(DocumentWrapper<AccountsCommonList> wrapDoc)
+    public AccountsCommonList extractCommonPartList(
+            DocumentWrapper<List> wrapDoc)
             throws Exception {
-        return wrapDoc.getWrappedObject();
+
+        AccountsCommonList accList = new AccountsCommonList();
+        List<AccountsCommonList.AccountListItem> list = accList.getAccountListItem();
+
+        for (Object obj : wrapDoc.getWrappedObject()) {
+            AccountsCommon account = (AccountsCommon) obj;
+            AccountListItem accListItem = new AccountListItem();
+            accListItem.setAnchorName(account.getAnchorName());
+            accListItem.setEmail(account.getEmail());
+            accListItem.setFirstName(account.getFirstName());
+            accListItem.setLastName(account.getLastName());
+            String id = account.getCsid();
+            accListItem.setUri(getServiceContextPath() + id);
+            accListItem.setCsid(id);
+            list.add(accListItem);
+        }
+        return accList;
     }
 
     @Override
@@ -99,7 +124,8 @@ public class AccountDocumentHandler
     }
 
     @Override
-    public String getQProperty(String prop) {
+    public String getQProperty(
+            String prop) {
         return null;
     }
 }
similarity index 95%
rename from services/account/jaxb/src/main/resources/META-INF/persistence.xml
rename to services/account/service/src/main/resources/META-INF/persistence.xml
index 74090142f6a9e1e56c1b7b80fb4a33f2ca595fc4..de4e3b2b169f0abd7f936732371c3765d6b768bb 100644 (file)
@@ -3,7 +3,7 @@
 http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <persistence-unit name="org.collectionspace.services.account">
         <provider>org.hibernate.ejb.HibernatePersistence</provider>
-        <jta-data-source>cspaceds</jta-data-source>
+        <non-jta-data-source>CSpaceDS</non-jta-data-source>
         <class>org.collectionspace.services.account.AccountsCommon</class>
         <class>org.collectionspace.services.account.AccountsCommonList</class>
         <class>org.collectionspace.services.account.AccountsCommonList$AccountListItem</class>
index c162d1199253269021fa425ae46b6f8be6fe2f7e..c689430ee3f63c0376277ae9994c7911a3785ed5 100644 (file)
         </exec>
     </target>
 
+    <target name="jpa"
+    description="one time upgrade jpa binaries in ${jboss.server.cspace}">
+        <move todir="${jboss.server.cspace}/jpa-upgrade/lib">
+            <filelist dir="${jboss.server.cspace}/lib">
+                <file name="hibernate-annotations.jar"/>
+                <file name="hibernate-entitymanager.jar"/>
+                <file name="ejb3-persistence.jar"/>
+            </filelist>
+        </move>
+        <copy todir="${jboss.server.cspace}/lib">
+            <fileset dir="${basedir}/lib/jpa-upgrade"/>
+        </copy>
+    </target>
+
     <target name="deploy" depends="install"
     description="deploy common elements in ${jboss.server.cspace}">
         <copy todir="${jboss.server.cspace}/cspace/config/services">
diff --git a/services/common/lib/README.txt b/services/common/lib/README.txt
new file mode 100644 (file)
index 0000000..6df5927
--- /dev/null
@@ -0,0 +1,6 @@
+This lib directory contains binaries required to run the common layer
+in JBoss container. Corresponding binaries (if present) in JBoss domain are
+either upgraded/replaced with a one-time execution task.
+
+For jpa upgrade in mercury 0.4, the task is 'ant jpa' executed at
+service/common level.
diff --git a/services/common/lib/jpa-upgrade/ejb3-persistence-1.0.2.GA.jar b/services/common/lib/jpa-upgrade/ejb3-persistence-1.0.2.GA.jar
new file mode 100644 (file)
index 0000000..32c2266
Binary files /dev/null and b/services/common/lib/jpa-upgrade/ejb3-persistence-1.0.2.GA.jar differ
diff --git a/services/common/lib/jpa-upgrade/hibernate-annotations-3.4.0.GA.jar b/services/common/lib/jpa-upgrade/hibernate-annotations-3.4.0.GA.jar
new file mode 100644 (file)
index 0000000..24b1583
Binary files /dev/null and b/services/common/lib/jpa-upgrade/hibernate-annotations-3.4.0.GA.jar differ
diff --git a/services/common/lib/jpa-upgrade/hibernate-entitymanager-3.4.0.GA.jar b/services/common/lib/jpa-upgrade/hibernate-entitymanager-3.4.0.GA.jar
new file mode 100644 (file)
index 0000000..662eab1
Binary files /dev/null and b/services/common/lib/jpa-upgrade/hibernate-entitymanager-3.4.0.GA.jar differ
index 48fd89583a8b40bbd7f31386e77a74c9a90afca7..47885dc9c1f3cf4afe75fc6e53ad3e1b25579a93 100644 (file)
@@ -46,33 +46,33 @@ public abstract class AbstractServiceContext<IT, OT>
         implements ServiceContext<IT, OT> {
 
     final Logger logger = LoggerFactory.getLogger(AbstractServiceContext.class);
+    Map<String, Object> properties = new HashMap<String, Object>();
     Map<String, ObjectPartType> objectPartMap = new HashMap<String, ObjectPartType>();
     private ServiceBindingType serviceBinding;
     private TenantBindingType tenantBinding;
-    
-    private String overrideDocumentType = null; 
-    
+    private String overrideDocumentType = null;
+
     public AbstractServiceContext(String serviceName) {
         TenantBindingConfigReader tReader =
                 ServiceMain.getInstance().getTenantBindingConfigReader();
         //TODO: get tenant binding from security context (Subject.g
         String tenantId = "1"; //hardcoded for movingimages.us
         tenantBinding = tReader.getTenantBinding(tenantId);
-        if(tenantBinding == null){
+        if (tenantBinding == null) {
             String msg = "No tenant binding found while processing request for " +
                     serviceName;
             logger.error(msg);
             throw new IllegalStateException(msg);
         }
         serviceBinding = tReader.getServiceBinding(tenantId, serviceName);
-        if(serviceBinding == null){
+        if (serviceBinding == null) {
             String msg = "No service binding found while processing request for " +
                     serviceName + " for tenant id=" + getTenantId() +
                     " name=" + getTenantName();
             logger.error(msg);
             throw new IllegalStateException(msg);
         }
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("tenantId=" + tenantId +
                     " service binding=" + serviceBinding.getName());
         }
@@ -97,14 +97,14 @@ public abstract class AbstractServiceContext<IT, OT>
 
     @Override
     public Map<String, ObjectPartType> getPartsMetadata() {
-        if(objectPartMap.size() != 0){
+        if (objectPartMap.size() != 0) {
             return objectPartMap;
         }
         ServiceBindingType serviceBinding = getServiceBinding();
         List<ServiceObjectType> objectTypes = serviceBinding.getObject();
-        for(ServiceObjectType objectType : objectTypes){
+        for (ServiceObjectType objectType : objectTypes) {
             List<ObjectPartType> objectPartTypes = objectType.getPart();
-            for(ObjectPartType objectPartType : objectPartTypes){
+            for (ObjectPartType objectPartType : objectPartTypes) {
                 objectPartMap.put(objectPartType.getLabel(), objectPartType);
             }
         }
@@ -152,19 +152,18 @@ public abstract class AbstractServiceContext<IT, OT>
     @Override
     public String getServiceName() {
         return serviceBinding.getName();
-    } 
-    
+    }
+
     @Override
     public String getDocumentType() {
-       // If they have not overridden the setting, use the type of the service
-       // object.
-       return(overrideDocumentType!=null)?overrideDocumentType:
-               serviceBinding.getObject().get(0).getName();
+        // If they have not overridden the setting, use the type of the service
+        // object.
+        return (overrideDocumentType != null) ? overrideDocumentType : serviceBinding.getObject().get(0).getName();
     }
 
     @Override
     public void setDocumentType(String docType) {
-       overrideDocumentType = docType;
+        overrideDocumentType = docType;
     }
 
     @Override
@@ -189,15 +188,38 @@ public abstract class AbstractServiceContext<IT, OT>
     @Override
     public abstract void setOutput(OT output);
 
+    @Override
+    public Map<String, Object> getProperties() {
+        return properties;
+    }
+
+    @Override
+    public void setProperties(Map<String, Object> props) {
+        properties.putAll(props);
+    }
+
+    public Object getProperty(String name) {
+        return properties.get(name);
+    }
+
+    public void setProperty(String name, Object o) {
+        properties.put(name, o);
+    }
+
     @Override
     public String toString() {
-        return "AbstractServiceContext [" +
-                "service name=" + serviceBinding.getName() + " " +
-                "service version=" + serviceBinding.getVersion() + " " +
-                "tenant id=" + tenantBinding.getId() + " " +
-                "tenant name=" + tenantBinding.getName() + " " +
-                tenantBinding.getDisplayName() + " " +
-                "tenant repository domain=" + tenantBinding.getRepositoryDomain() + " " +
-                "]";
+        StringBuilder msg = new StringBuilder();
+        msg.append("AbstractServiceContext [");
+        msg.append("service name=" + serviceBinding.getName() + " ");
+        msg.append("service version=" + serviceBinding.getVersion() + " ");
+        msg.append("tenant id=" + tenantBinding.getId() + " ");
+        msg.append("tenant name=" + tenantBinding.getName() + " ");
+        msg.append(tenantBinding.getDisplayName() + " ");
+        msg.append("tenant repository domain=" + tenantBinding.getRepositoryDomain());
+        for(Map.Entry<String, Object> entry : properties.entrySet()) {
+            msg.append("property name=" + entry.getKey() + " value=" + entry.getValue().toString());
+        }
+        msg.append("]");
+        return msg.toString();
     }
 }
index c3723c06d8ef924aecfa1740ed926e23bf657cc9..b3e8e3adcd50c1d7e61fcffe26641de8e64c1b04 100644 (file)
@@ -23,7 +23,9 @@
  */
 package org.collectionspace.services.common.context;
 
+import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.service.ObjectPartType;
 import org.collectionspace.services.common.service.ServiceBindingType;
@@ -167,6 +169,31 @@ public interface ServiceContext<IT, OT> {
      * @return label
      */
     public String getCommonPartLabel(String schemaName);
+    
+    /**
+     * getProperties retruns user-defined properties associated with this context
+     * @return
+     */
+    public Map<String, Object> getProperties();
+
+
+    /**
+     * setProperties sets user-defined properties to this context
+     * @param props
+     */
+    public void setProperties(Map<String, Object> props);
+
+
+    /**
+     * getProperty returns specified user-defined property
+     */
+    public Object getProperty(String name);
+
+    /**
+     * setProperty sets user-defined property with given name
+     */
+    public void setProperty(String name, Object o);
+
 }
 
 
index b5e6cb244cd08b91c629182c701357ff852466d0..4a8ef9f5152e17dbd99cfed2da1ddfdbab7a1ba5 100644 (file)
@@ -21,6 +21,7 @@ import java.lang.reflect.Method;
 import java.util.List;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.NoResultException;
 import javax.persistence.Persistence;
 import javax.persistence.Query;
 import org.collectionspace.services.common.context.ServiceContext;
@@ -69,18 +70,18 @@ public class JpaStorageClient implements StorageClient {
         EntityManager em = null;
         try {
             handler.prepare(Action.CREATE);
-            Object po = handler.getCommonPart();
-            DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(po);
+            Object entity = handler.getCommonPart();
+            DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(entity);
             handler.handle(Action.CREATE, wrapDoc);
             emf = getEntityManagerFactory(docType);
             em = emf.createEntityManager();
             em.getTransaction().begin();
-            em.persist(po);
+            em.persist(entity);
             em.getTransaction().commit();
             handler.complete(Action.CREATE, wrapDoc);
-            return getCsid(po);
+            return getCsid(entity);
         } catch (Exception e) {
-            if (em != null) {
+            if (em != null && em.getTransaction().isActive()) {
                 em.getTransaction().rollback();
             }
             if (logger.isDebugEnabled()) {
@@ -116,8 +117,9 @@ public class JpaStorageClient implements StorageClient {
         EntityManager em = null;
         try {
             handler.prepare(Action.GET);
-            StringBuilder queryStr = new StringBuilder("SELECT * FROM ");
-            queryStr.append(docType);
+            StringBuilder queryStr = new StringBuilder("SELECT a FROM ");
+            queryStr.append(getEntityName(ctx));
+            queryStr.append(" a");
             queryStr.append(" WHERE csid = :csid");
             //TODO: add tenant id
             String where = docFilter.getWhereClause();
@@ -134,10 +136,21 @@ public class JpaStorageClient implements StorageClient {
             if ((docFilter.getOffset() > 0) || (docFilter.getPageSize() > 0)) {
             } else {
             }
-            //require transaction for get?
-            em.getTransaction().begin();
-            Object o = q.getSingleResult();
-            em.getTransaction().commit();
+            Object o = null;
+
+            try {
+                //require transaction for get?
+                em.getTransaction().begin();
+                o = q.getSingleResult();
+                em.getTransaction().commit();
+            } catch (NoResultException nre) {
+                if (em != null && em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                String msg = "could not find entity with id=" + id;
+                logger.error(msg, nre);
+                throw new DocumentNotFoundException(msg, nre);
+            }
             DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(o);
             handler.handle(Action.GET, wrapDoc);
             handler.complete(Action.GET, wrapDoc);
@@ -193,8 +206,9 @@ public class JpaStorageClient implements StorageClient {
         try {
             handler.prepare(Action.GET_ALL);
 
-            StringBuilder queryStr = new StringBuilder("SELECT * FROM ");
-            queryStr.append(docType);
+            StringBuilder queryStr = new StringBuilder("SELECT a FROM ");
+            queryStr.append(getEntityName(ctx));
+            queryStr.append(" a");
             //TODO: add tenant id
             String where = docFilter.getWhereClause();
             if ((null != where) && (where.length() > 0)) {
@@ -246,14 +260,23 @@ public class JpaStorageClient implements StorageClient {
         EntityManager em = null;
         try {
             handler.prepare(Action.UPDATE);
-            Object po = handler.getCommonPart();
-            setCsid(po, id);
-            DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(po);
+            Object entity = handler.getCommonPart();
+            setCsid(entity, id);
+            DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(entity);
             handler.handle(Action.UPDATE, wrapDoc);
             emf = getEntityManagerFactory(docType);
             em = emf.createEntityManager();
             em.getTransaction().begin();
-            em.merge(po);
+            Object entityFound = em.find(entity.getClass(), id);
+            if(entityFound == null) {
+                if (em != null && em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                String msg = "could not find entity with id=" + id;
+                logger.error(msg);
+                throw new DocumentNotFoundException(msg);
+            }
+            em.merge(entity);
             em.getTransaction().commit();
             handler.complete(Action.UPDATE, wrapDoc);
         } catch (DocumentException de) {
@@ -264,6 +287,9 @@ public class JpaStorageClient implements StorageClient {
             }
             throw new DocumentException(e);
         } finally {
+            if (emf != null) {
+                releaseEntityManagerFactory(emf);
+            }
         }
     }
 
@@ -275,11 +301,12 @@ public class JpaStorageClient implements StorageClient {
      * @throws DocumentException
      */
     @Override
-    public void delete(ServiceContext ctx, String id) throws DocumentNotFoundException,
+    public void delete(ServiceContext ctx, String id)
+            throws DocumentNotFoundException,
             DocumentException {
 
         if (logger.isDebugEnabled()) {
-            logger.debug("deleting document with id=" + id);
+            logger.debug("deleting entity with id=" + id);
         }
         String docType = ctx.getDocumentType();
         if (docType == null) {
@@ -290,7 +317,7 @@ public class JpaStorageClient implements StorageClient {
         EntityManager em = null;
         try {
             StringBuilder deleteStr = new StringBuilder("DELETE FROM ");
-            deleteStr.append(docType);
+            deleteStr.append(getEntityName(ctx));
             deleteStr.append(" WHERE csid = :csid");
             //TODO: add tenant id
 
@@ -299,23 +326,26 @@ public class JpaStorageClient implements StorageClient {
             Query q = em.createQuery(deleteStr.toString());
             q.setParameter("csid", id);
             //TODO: add tenant id
+            int rcount = 0;
             em.getTransaction().begin();
-            int rcount = q.executeUpdate();
-            em.getTransaction().commit();
+            rcount = q.executeUpdate();
             if (rcount != 1) {
-                throw new DocumentException("failed to delete " + docType +
-                        " csid=" + id);
+                if (em != null && em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                String msg = "could not find entity with id=" + id;
+                logger.error(msg);
+                throw new DocumentNotFoundException(msg);
             }
+            em.getTransaction().commit();
+
         } catch (DocumentException de) {
-            if (em != null) {
-                em.getTransaction().rollback();
-            }
             throw de;
         } catch (Exception e) {
             if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception ", e);
             }
-            if (em != null) {
+            if (em != null && em.getTransaction().isActive()) {
                 em.getTransaction().rollback();
             }
             throw new DocumentException(e);
@@ -326,7 +356,8 @@ public class JpaStorageClient implements StorageClient {
         }
     }
 
-    private EntityManagerFactory getEntityManagerFactory(String persistenceUnit) {
+    private EntityManagerFactory getEntityManagerFactory(
+            String persistenceUnit) {
         return Persistence.createEntityManagerFactory(persistenceUnit);
 
     }
@@ -335,21 +366,24 @@ public class JpaStorageClient implements StorageClient {
         if (emf != null) {
             emf.close();
         }
+
     }
 
     private String getCsid(Object o) throws Exception {
         Class c = o.getClass();
         Method m = c.getMethod("getCsid");
         if (m == null) {
-            String msg = "Could not find csid in object of class=" + o.getClass().getCanonicalName();
+            String msg = "Could not find csid in entity of class=" + o.getClass().getCanonicalName();
             logger.error(msg);
             throw new IllegalArgumentException(msg);
         }
+
         Object r = m.invoke(o);
         if (logger.isDebugEnabled()) {
-            logger.debug("getCsid returned csid=" + r.toString() +
+            logger.debug("getCsid returned csid=" + r +
                     " for " + c.getName());
         }
+
         return (String) r;
     }
 
@@ -365,19 +399,32 @@ public class JpaStorageClient implements StorageClient {
                 //no need to set
                 return;
             }
+
         }
         //set csid
         Class c = o.getClass();
-        Method m = c.getMethod("setCsid");
+        Method m = c.getMethod("setCsid", java.lang.String.class);
         if (m == null) {
-            String msg = "Could not find csid in object of class=" + o.getClass().getCanonicalName();
+            String msg = "Could not find csid in entity of class=" + o.getClass().getCanonicalName();
             logger.error(msg);
             throw new IllegalArgumentException(msg);
         }
+
         Object r = m.invoke(o, csid);
         if (logger.isDebugEnabled()) {
-            logger.debug("setCsid returned csid=" + r.toString() +
+            logger.debug("completed setCsid " +
                     " for " + c.getName());
         }
+
+    }
+
+    private String getEntityName(ServiceContext ctx) {
+        Object o = ctx.getProperty("entity-name");
+        if (o == null) {
+            throw new IllegalArgumentException("property entity-name missing in context " +
+                    ctx.toString());
+        }
+
+        return (String) o;
     }
-}
\ No newline at end of file
+}
index 9f0c53a19340b253b195f646e2aa1806756badcc..a77fb66e500a9ee52ca99749b911963fb80a77de 100644 (file)
@@ -16,7 +16,7 @@
         <!-- add modules below in the order based on dependencies -->
         <module>common</module>
         <module>authentication</module>
-        <!--module>account</module-->
+        <module>account</module>
         <module>relation</module>
         <!--module>query</module-->
         <module>acquisition</module>
index 8aab83beee3a3272c15cb4821c88d590d06c7c48..d38540337d8117e699c2982be0f9188f2fb4f641 100644 (file)
@@ -8,6 +8,7 @@ http://www.mysql.com/downloads/api-jdbc-stable.html
 <datasources>
   <local-tx-datasource>
     <jndi-name>CspaceDS</jndi-name>
+    <use-java-context>false</use-java-context>
     <connection-url>jdbc:mysql://localhost:3306/cspace</connection-url>
     <driver-class>com.mysql.jdbc.Driver</driver-class>
     <user-name>test</user-name>