<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
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;
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());
<!-- 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
<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>
+++ /dev/null
-\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
+++ /dev/null
-\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
\r
-<project name="collectionobject" default="package" basedir=".">\r
+<project name="account" default="package" basedir=".">\r
<description>\r
collectionobject service\r
</description>\r
<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
--- /dev/null
+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));
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;
// 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();
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();
// Success outcomes
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
- dependsOnMethods = {"read"})
+ dependsOnMethods = {"read", "readNonExistent"})
public void update(String testName) throws Exception {
// Perform setup.
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.
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.");
}
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
- dependsOnMethods = {"update", "testSubmitRequest"})
+ dependsOnMethods = {"update", "readNonExistent", "testSubmitRequest"})
public void updateNonExistent(String testName) throws Exception {
// Perform setup.
// 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();
// 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.
// ---------------------------------------------------------------
// 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,
return account;
}
-
}
* 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;
@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();
@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 " +
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() +
<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>
<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>
<!-- 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" />
<modules>\r
<module>jaxb</module>\r
<module>service</module>\r
- <module>3rdparty</module>\r
<module>client</module>\r
</modules>\r
\r
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;
}
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);
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);
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);
*/
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;
@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
}
@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
}
@Override
- public String getQProperty(String prop) {
+ public String getQProperty(
+ String prop) {
return null;
}
}
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>
</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">
--- /dev/null
+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.
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());
}
@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);
}
}
@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
@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();
}
}
*/
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;
* @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);
+
}
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;
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()) {
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();
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);
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)) {
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) {
}
throw new DocumentException(e);
} finally {
+ if (emf != null) {
+ releaseEntityManagerFactory(emf);
+ }
}
}
* @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) {
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
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);
}
}
- private EntityManagerFactory getEntityManagerFactory(String persistenceUnit) {
+ private EntityManagerFactory getEntityManagerFactory(
+ String persistenceUnit) {
return Persistence.createEntityManagerFactory(persistenceUnit);
}
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;
}
//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
+}
<!-- 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>
<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>