<artifactId>org.collectionspace.services.common</artifactId>\r
<version>1.0</version>\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
<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.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 CollectionObjectResource());
singletons.add(new IDResource());
singletons.add(new IntakeResource());
<?xml version="1.0" encoding="UTF-8"?>\r
<jboss-web>\r
<!-- 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
+ <security-domain>java:/jaas/cspace</security-domain>\r
+ <context-root>/cspace-services</context-root>\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
</jboss-web>\r
<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<!--
Document : web.xml
Created on : May 19, 2009, 1:31 PM
Description:
service layer web application
-->
-<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>CollectionSpace Services</display-name>
<realm-name>CollectionSpace realm</realm-name>
</login-config>
END AUTH -->
+ <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>
</web-app>
--- /dev/null
+/**
+ * AccountClient.java
+ *
+ * {Purpose of This Class}
+ *
+ * {Other Notes Relating to This Class (Optional)}
+ *
+ * $LastChangedBy: $
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ *
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright (C) 2009 {Contributing Institution}
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ */
+
+package org.collectionspace.services.client;
+
+import javax.ws.rs.core.Response;
+
+
+import org.collectionspace.services.account.AccountsCommon;
+import org.collectionspace.services.account.AccountsCommonList;
+import org.jboss.resteasy.client.ProxyFactory;
+import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
+import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
+
+/**
+ * A AccountClient.
+
+ * @version $Revision:$
+ */
+public class AccountClient extends BaseServiceClient {
+
+ /**
+ *
+ */
+ private AccountProxy accountProxy;
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent()
+ */
+ public String getServicePathComponent() {
+ return "accounts";
+ }
+
+ /**
+ *
+ * Default constructor for AccountClient class.
+ *
+ */
+ public AccountClient() {
+ ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
+ RegisterBuiltin.register(factory);
+ setProxy();
+ }
+
+ /**
+ * allow to reset proxy as per security needs
+ */
+ public void setProxy() {
+ if(useAuth()){
+ accountProxy = ProxyFactory.create(AccountProxy.class,
+ getBaseURL(), getHttpClient());
+ }else{
+ accountProxy = ProxyFactory.create(AccountProxy.class,
+ getBaseURL());
+ }
+ }
+
+ /**
+ * @return
+ * @see org.collectionspace.hello.client.AccountProxy#readList()
+ */
+ public ClientResponse<AccountsCommonList> readList() {
+ return accountProxy.readList();
+
+ }
+
+ /**
+ * @param csid
+ * @return
+ * @see org.collectionspace.hello.client.AccountProxy#getAccount(java.lang.String)
+ */
+ public ClientResponse<AccountsCommon> read(String csid) {
+ return accountProxy.read(csid);
+ }
+
+ /**
+ * @param account
+ * @return
+ * @see org.collectionspace.hello.client.AccountProxy#create(org.collectionspace.services.account.AccountsCommon)
+ */
+ public ClientResponse<Response> create(AccountsCommon multipart) {
+ return accountProxy.create(multipart);
+ }
+
+ /**
+ * @param csid
+ * @param account
+ * @return
+ * @see org.collectionspace.hello.client.AccountProxy#updateAccount(java.lang.Long, org.collectionspace.services.account.AccountsCommon)
+ */
+ public ClientResponse<AccountsCommon> update(String csid, AccountsCommon multipart) {
+ return accountProxy.update(csid, multipart);
+ }
+
+ /**
+ * @param csid
+ * @return
+ * @see org.collectionspace.hello.client.AccountProxy#deleteAccount(java.lang.Long)
+ */
+ public ClientResponse<Response> delete(String csid) {
+ return accountProxy.delete(csid);
+ }
+}
--- /dev/null
+/**
+ * AccountProxy.java
+ *
+ * {Purpose of This Class}
+ *
+ * {Other Notes Relating to This Class (Optional)}
+ *
+ * $LastChangedBy: $
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ *
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright (C) 2009 {Contributing Institution}
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ */
+package org.collectionspace.services.client;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+
+import org.collectionspace.services.account.AccountsCommon;
+import org.collectionspace.services.account.AccountsCommonList;
+import org.jboss.resteasy.client.ClientResponse;
+
+
+
+/**
+ * @version $Revision:$
+ */
+@Path("/accounts/")
+@Produces({"application/xml"})
+@Consumes({"application/xml"})
+public interface AccountProxy {
+
+ @GET
+ @Produces({"application/xml"})
+ ClientResponse<AccountsCommonList> readList();
+
+ //(C)reate
+ @POST
+ ClientResponse<Response> create(AccountsCommon multipart);
+
+ //(R)ead
+ @GET
+ @Path("/{csid}")
+ ClientResponse<AccountsCommon> read(@PathParam("csid") String csid);
+
+ //(U)pdate
+ @PUT
+ @Path("/{csid}")
+ ClientResponse<AccountsCommon> update(@PathParam("csid") String csid, AccountsCommon multipart);
+
+ //(D)elete
+ @DELETE
+ @Path("/{csid}")
+ ClientResponse<Response> delete(@PathParam("csid") String csid);
+}
--- /dev/null
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright © 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.collectionspace.services.client.test;
+
+import java.util.List;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.codec.binary.Base64;
+import org.collectionspace.services.client.AccountClient;
+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;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * AccountServiceTest, carries out tests against a
+ * deployed and running Account Service.
+ *
+ * $LastChangedRevision: 917 $
+ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
+ */
+public class AccountServiceTest extends AbstractServiceTest {
+
+ private final Logger logger =
+ LoggerFactory.getLogger(AccountServiceTest.class);
+ // Instance variables specific to this test.
+ private AccountClient client = new AccountClient();
+ private String knownResourceId = null;
+
+ /*
+ * This method is called only by the parent class, AbstractServiceTest
+ */
+ @Override
+ protected String getServicePathComponent() {
+ return client.getServicePathComponent();
+ }
+
+ // ---------------------------------------------------------------
+ // CRUD tests : CREATE tests
+ // ---------------------------------------------------------------
+ // Success outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class)
+ public void create(String testName) throws Exception {
+
+ // Perform setup, such as initializing the type of service request
+ // (e.g. CREATE, DELETE), its valid and expected status codes, and
+ // its associated HTTP method name (e.g. POST, DELETE).
+ setupCreate(testName);
+
+ // Submit the request to the service and store the response.
+ AccountsCommon account =
+ createAccountInstance("sanjay", "hello");
+ ClientResponse<Response> res = client.create(account);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ //
+ // Specifically:
+ // Does it fall within the set of valid status codes?
+ // Does it exactly match the expected status code?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Store the ID returned from this create operation
+ // for additional tests below.
+ knownResourceId = extractId(res);
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": knownResourceId=" + knownResourceId);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.ServiceTest#createList()
+ */
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+ dependsOnMethods = {"create"})
+ public void createList(String testName) throws Exception {
+ for (int i = 0; i < 3; i++) {
+ create(testName);
+ }
+ }
+
+ // Failure outcomes
+ // Placeholders until the three tests below can be uncommented.
+ // See Issue CSPACE-401.
+ @Override
+ public void createWithEmptyEntityBody(String testName) throws Exception {
+ }
+
+ @Override
+ public void createWithMalformedXml(String testName) throws Exception {
+ }
+
+ @Override
+ public void createWithWrongXmlSchema(String testName) throws Exception {
+ }
+
+ // ---------------------------------------------------------------
+ // CRUD tests : READ tests
+ // ---------------------------------------------------------------
+ // Success outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+ dependsOnMethods = {"create"})
+ public void read(String testName) throws Exception {
+
+ // Perform setup.
+ setupRead(testName);
+
+ // Submit the request to the service and store the response.
+ ClientResponse<AccountsCommon> res = client.read(knownResourceId);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ AccountsCommon output = (AccountsCommon) res.getEntity();
+ Assert.assertNotNull(output);
+ }
+
+ // Failure outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+ dependsOnMethods = {"read"})
+ public void readNonExistent(String testName) throws Exception {
+
+ // Perform setup.
+ setupReadNonExistent(testName);
+
+ // Submit the request to the service and store the response.
+ ClientResponse<AccountsCommon> res = client.read(NON_EXISTENT_ID);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ }
+
+ // ---------------------------------------------------------------
+ // CRUD tests : READ_LIST tests
+ // ---------------------------------------------------------------
+ // Success outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+ dependsOnMethods = {"createList", "read"})
+ public void readList(String testName) throws Exception {
+
+ // Perform setup.
+ setupReadList(testName);
+
+ // Submit the request to the service and store the response.
+ ClientResponse<AccountsCommonList> res = client.readList();
+ AccountsCommonList list = res.getEntity();
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Optionally output additional data about list members for debugging.
+ boolean iterateThroughList = false;
+ if (iterateThroughList && logger.isDebugEnabled()) {
+ List<AccountsCommonList.AccountListItem> items =
+ list.getAccountListItem();
+ int i = 0;
+
+ for (AccountsCommonList.AccountListItem item : items) {
+ logger.debug(testName + ": list-item[" + i + "] csid=" +
+ item.getCsid());
+ logger.debug(testName + ": list-item[" + i + "] anchorName=" +
+ item.getAnchorName());
+ logger.debug(testName + ": list-item[" + i + "] URI=" +
+ item.getUri());
+ i++;
+
+ }
+ }
+ }
+
+ // Failure outcomes
+ // None at present.
+ // ---------------------------------------------------------------
+ // CRUD tests : UPDATE tests
+ // ---------------------------------------------------------------
+ // Success outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+ dependsOnMethods = {"read"})
+ public void update(String testName) throws Exception {
+
+ // Perform setup.
+ setupUpdate(testName);
+
+ ClientResponse<AccountsCommon> res =
+ client.read(knownResourceId);
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": read status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+ 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);
+ Assert.assertNotNull(toUpdateAccount);
+
+ // Update the content of this resource.
+ toUpdateAccount.setEmail("updated-" + toUpdateAccount.getEmail());
+ toUpdateAccount.setPhone("updated-" + toUpdateAccount.getPhone());
+ if (logger.isDebugEnabled()) {
+ logger.debug("updated object");
+ logger.debug(objectAsXmlString(toUpdateAccount,
+ AccountsCommon.class));
+ }
+
+ // Submit the request to the service and store the response.
+ res = client.update(knownResourceId, toUpdateAccount);
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+
+ AccountsCommon updatedAccount = (AccountsCommon)res.getEntity();
+ Assert.assertNotNull(updatedAccount);
+
+ Assert.assertEquals(updatedAccount.getEmail(),
+ toUpdateAccount.getPhone(),
+ "Data in updated object did not match submitted data.");
+
+ }
+
+ // Failure outcomes
+ // Placeholders until the three tests below can be uncommented.
+ // See Issue CSPACE-401.
+ @Override
+ public void updateWithEmptyEntityBody(String testName) throws Exception {
+ }
+
+ @Override
+ public void updateWithMalformedXml(String testName) throws Exception {
+ }
+
+ @Override
+ public void updateWithWrongXmlSchema(String testName) throws Exception {
+ }
+
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+ dependsOnMethods = {"update", "testSubmitRequest"})
+ public void updateNonExistent(String testName) throws Exception {
+
+ // Perform setup.
+ setupUpdateNonExistent(testName);
+
+ // Submit the request to the service and store the response.
+ //
+ // 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");
+ ClientResponse<AccountsCommon> res =
+ client.update(NON_EXISTENT_ID, account);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ }
+
+ // ---------------------------------------------------------------
+ // CRUD tests : DELETE tests
+ // ---------------------------------------------------------------
+ // Success outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+ dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
+ public void delete(String testName) throws Exception {
+
+ // Perform setup.
+ setupDelete(testName);
+
+ // Submit the request to the service and store the response.
+ ClientResponse<Response> res = client.delete(knownResourceId);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ }
+
+ // Failure outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+ dependsOnMethods = {"delete"})
+ public void deleteNonExistent(String testName) throws Exception {
+
+ // Perform setup.
+ setupDeleteNonExistent(testName);
+
+ // Submit the request to the service and store the response.
+ ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ }
+
+ // ---------------------------------------------------------------
+ // Utility tests : tests of code used in tests above
+ // ---------------------------------------------------------------
+ /**
+ * Tests the code for manually submitting data that is used by several
+ * of the methods above.
+ */
+ @Test(dependsOnMethods = {"create", "read"})
+ public void testSubmitRequest() throws Exception {
+
+ // Expected status code: 200 OK
+ final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
+
+ // Submit the request to the service and store the response.
+ String method = ServiceRequestType.READ.httpMethodName();
+ String url = getResourceURL(knownResourceId);
+ int statusCode = submitRequest(method, url);
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug("testSubmitRequest: url=" + url +
+ " status=" + statusCode);
+ }
+ Assert.assertEquals(statusCode, EXPECTED_STATUS);
+
+ }
+
+ // ---------------------------------------------------------------
+ // Utility methods used by tests above
+ // ---------------------------------------------------------------
+ private AccountsCommon createAccountInstance(String anchorName,
+ String passwd) {
+
+ AccountsCommon account = new AccountsCommon();
+ account.setAnchorName(anchorName);
+ account.setUserName(anchorName);
+ byte[] b64passwd = Base64.encodeBase64(passwd.getBytes());
+ account.setPassword(b64passwd);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("to be created, account common");
+ logger.debug(objectAsXmlString(account,
+ AccountsCommon.class));
+ }
+ return account;
+
+ }
+
+}
<executions>
<execution>
- <phase>process-test-classes</phase>
+ <phase>process-test-resources</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<persistence version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
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">
- <non-jta-data-source>java:/CSpaceDS</non-jta-data-source>
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <jta-data-source>cspaceds</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>
<xs:element name="email" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="phone" type="xs:string"/>
+ <!-- optional username for default identity provider -->
+ <xs:element name="userName" type="xs:string" minOccurs="0" maxOccurs="1" />
+ <!-- optional base64 encoded password for default identity provider -->
+ <xs:element name="password" type="xs:base64Binary" minOccurs="0" maxOccurs="1" />
</xs:sequence>
<xs:attribute name="csid" type="xs:string">
<xs:annotation>
-alter table ACCOUNTLISTITEM drop foreign key FKBD8755BE37E86A94;
-drop table if exists ACCOUNTLISTITEM;
-drop table if exists ACCOUNTSCOMMON;
-drop table if exists ACCOUNTSCOMMONLIST;
-create table ACCOUNTLISTITEM (HJID bigint not null auto_increment, ANCHORNAME varchar(255), CSID varchar(255), EMAIL varchar(255), FIRSTNAME varchar(255), LASTNAME varchar(255), MI varchar(255), URI varchar(255), ACCOUNTLISTITEM_ACCOUNTSCOMM_0 bigint, primary key (HJID));
-create table ACCOUNTSCOMMON (CSID varchar(255) not null, ANCHORNAME varchar(255), EMAIL varchar(255), FIRSTNAME varchar(255), LASTNAME varchar(255), MI varchar(255), PHONE varchar(255), primary key (CSID));
-create table ACCOUNTSCOMMONLIST (HJID bigint not null auto_increment, primary key (HJID));
-alter table ACCOUNTLISTITEM add index FKBD8755BE37E86A94 (ACCOUNTLISTITEM_ACCOUNTSCOMM_0), add constraint FKBD8755BE37E86A94 foreign key (ACCOUNTLISTITEM_ACCOUNTSCOMM_0) references ACCOUNTSCOMMONLIST (HJID);
<artifactId>org.collectionspace.services.common</artifactId>\r
<version>1.0</version>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.authentication.jaxb</artifactId>\r
+ <version>1.0</version>\r
+ </dependency>\r
<dependency>\r
<groupId>org.collectionspace.services</groupId>\r
<artifactId>org.collectionspace.services.account.jaxb</artifactId>\r
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import org.collectionspace.services.account.storage.AccountHandlerFactory;
+import org.collectionspace.services.account.storage.AccountStorageClient;
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
+import org.collectionspace.services.common.context.MultipartServiceContext;
import org.collectionspace.services.common.context.RemoteServiceContextImpl;
import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.collectionspace.services.common.storage.StorageClient;
import org.jboss.resteasy.util.HttpResponseCodes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final private String serviceName = "accounts";
final Logger logger = LoggerFactory.getLogger(AccountResource.class);
+ final StorageClient storageClient = new AccountStorageClient();
@Override
public String getServiceName() {
private <T> ServiceContext createServiceContext(T obj) {
ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
ctx.setInput(obj);
+ ctx.setDocumentType("org.collectionspace.services.account"); //persistence unit
return ctx;
}
+ @Override
+ public StorageClient getStorageClient(ServiceContext ctx) {
+ //FIXME use ctx to identify storage client
+ return storageClient;
+ }
+
@Override
public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- throw new IllegalStateException();
+ DocumentHandler docHandler = AccountHandlerFactory.getInstance().getHandler(
+ ctx.getRepositoryClientType().toString());
+ docHandler.setServiceContext(ctx);
+ docHandler.setCommonPart(ctx.getInput());
+ return docHandler;
}
@POST
public Response createAccount(AccountsCommon input) {
try {
ServiceContext ctx = createServiceContext(input);
- String csid = "";
+ DocumentHandler handler = createDocumentHandler(ctx);
+ String csid = getStorageClient(ctx).create(ctx, handler);
UriBuilder path = UriBuilder.fromResource(AccountResource.class);
path.path("" + csid);
Response response = Response.created(path.build()).build();
}
AccountsCommon result = null;
try {
- ServiceContext ctx = createServiceContext((AccountsCommon)null);
-
+ ServiceContext ctx = createServiceContext((AccountsCommon) null);
+ DocumentHandler handler = createDocumentHandler(ctx);
+ getStorageClient(ctx).get(ctx, csid, handler);
result = (AccountsCommon) ctx.getOutput();
} catch (DocumentNotFoundException dnfe) {
if (logger.isDebugEnabled()) {
public AccountsCommonList getAccountList(@Context UriInfo ui) {
AccountsCommonList accountList = new AccountsCommonList();
try {
- ServiceContext ctx = createServiceContext((AccountsCommonList)null);
-
+ ServiceContext ctx = createServiceContext((AccountsCommonList) null);
+ DocumentHandler handler = createDocumentHandler(ctx);
+ DocumentFilter myFilter = new DocumentFilter();
+ handler.setDocumentFilter(myFilter);
+ getStorageClient(ctx).getFiltered(ctx, handler);
accountList = null;
} catch (Exception e) {
if (logger.isDebugEnabled()) {
AccountsCommon result = null;
try {
ServiceContext ctx = createServiceContext(theUpdate);
-
- result = (AccountsCommon)ctx.getOutput();
+ DocumentHandler handler = createDocumentHandler(ctx);
+ getStorageClient(ctx).update(ctx, csid, handler);
+ result = (AccountsCommon) ctx.getOutput();
} catch (DocumentNotFoundException dnfe) {
if (logger.isDebugEnabled()) {
logger.debug("caugth exception in updateAccount", dnfe);
throw new WebApplicationException(response);
}
try {
- ServiceContext ctx = createServiceContext((AccountsCommon)null);
-
+ ServiceContext ctx = createServiceContext((AccountsCommon) null);
+ getStorageClient(ctx).delete(ctx, csid);
return Response.status(HttpResponseCodes.SC_OK).build();
} catch (DocumentNotFoundException dnfe) {
if (logger.isDebugEnabled()) {
import org.collectionspace.services.common.document.AbstractDocumentHandler;
import org.collectionspace.services.common.document.DocumentWrapper;
-
/**
*
* @author
public class AccountDocumentHandler
extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList, AccountsCommon, AccountsCommonList> {
+ private AccountsCommon account;
+ private AccountsCommonList accountList;
+
@Override
public void handleCreate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
String id = UUID.randomUUID().toString();
@Override
public void handleGet(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
+ setCommonPart(wrapDoc.getWrappedObject());
}
@Override
- public void handleGetAll(DocumentWrapper< AccountsCommonList> wrapDoc) throws Exception {
+ public void handleGetAll(DocumentWrapper<AccountsCommonList> wrapDoc) throws Exception {
+ setCommonPartList(wrapDoc.getWrappedObject());
}
@Override
public AccountsCommon extractCommonPart(DocumentWrapper<AccountsCommon> wrapDoc)
throws Exception {
- return null;
+ throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
}
@Override
public void fillCommonPart(AccountsCommon obj, DocumentWrapper<AccountsCommon> wrapDoc)
throws Exception {
+ throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
}
@Override
public AccountsCommonList extractCommonPartList(DocumentWrapper<AccountsCommonList> wrapDoc)
throws Exception {
- return null;
+ return wrapDoc.getWrappedObject();
}
@Override
public AccountsCommon getCommonPart() {
- return null;
+ return account;
}
@Override
- public void setCommonPart(AccountsCommon obj) {
+ public void setCommonPart(AccountsCommon account) {
+ this.account = account;
}
@Override
public AccountsCommonList getCommonPartList() {
- return null;
+ return accountList;
}
@Override
- public void setCommonPartList(AccountsCommonList obj) {
+ public void setCommonPartList(AccountsCommonList accountList) {
+ this.accountList = accountList;
}
@Override
@Override
public DocumentHandler getHandler(String clientType) {
- if(ClientType.JAVA.toString().equals(clientType)){
- return new AccountDocumentHandler();
- }
- throw new IllegalArgumentException("Not supported client=" + clientType);
+ return new AccountDocumentHandler();
}
}
--- /dev/null
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+
+ * Copyright 2009 University of California at Berkeley
+
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+
+ * You may obtain a copy of the ECL 2.0 License at
+
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.collectionspace.services.account.storage;
+
+import org.collectionspace.services.common.storage.jpa.JpaStorageClient;
+
+/**
+ * AccountStorageClient deals with both Account and Default Identity Provider's
+ * state in persistent storage
+ * @author
+ */
+public class AccountStorageClient extends JpaStorageClient
+{
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <artifactId>org.collectionspace.services.authentication</artifactId>
+ <groupId>org.collectionspace.services</groupId>
+ <version>1.0</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.collectionspace.services</groupId>
+ <artifactId>org.collectionspace.services.authentication.jaxb</artifactId>
+ <version>1.0</version>
+ <name>services.authentication.jaxb</name>
+ <properties>
+ <sql.file>authentication.sql</sql.file>
+ <sql.dir>src/main/resources/db/mysql</sql.dir>
+ </properties>
+ <dependencies>
+ <!-- keep slf4j dependencies on the top -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jvnet.jaxb2-commons</groupId>
+ <artifactId>property-listener-injector</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jvnet.jaxb2_commons</groupId>
+ <artifactId>runtime</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>5.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.collectionspace.services</groupId>
+ <artifactId>org.collectionspace.services.client</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>collectionspace-services-authentication-jaxb</finalName>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <!-- maven-hyperjaxb3-plugin generates jaxb + jpa bindings -->
+ <groupId>org.jvnet.hyperjaxb3</groupId>
+ <artifactId>maven-hyperjaxb3-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <extension>true</extension>
+ <jdk5>true</jdk5>
+ <ejb3>false</ejb3>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence version="1.0" 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" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
+ <persistence-unit name="org.collectionspace.services.authentication">
+ <non-jta-data-source>java:comp/env/jdbc/CspaceDS</non-jta-data-source>
+ <class>org.collectionspace.services.authentication.User</class>
+ <class>org.collectionspace.services.authentication.Role</class>
+ <class>org.collectionspace.services.authentication.UserRole</class>
+ <properties>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
+ <property name="hibernate.max_fetch_depth" value="3"/>
+ <!--property name="hibernate.hbm2ddl.auto" value="create-drop"/-->
+ </properties>
+ </persistence-unit>
+</persistence>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+
+<!--
+ CollectionSpace identity provider schema (XSD)
+
+ Entity :
+ Used for:
+
+ $LastChangedRevision: 916 $
+ $LastChangedDate: 2009-11-05 16:59:20 -0800 (Thu, 05 Nov 2009) $
+-->
+
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+ xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
+ xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
+ xmlns:ns="http://collectionspace.org/servics/authentication"
+ xmlns="http://collectionspace.org/services/authentication"
+ targetNamespace="http://collectionspace.org/services/authentication"
+ version="0.1"
+ jaxb:extensionBindingPrefixes="hj orm"
+>
+
+<!--
+ Avoid XmlRootElement nightmare:
+ See http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html
+-->
+
+ <xs:element name="user">
+ <xs:complexType>
+ <xs:annotation>
+ <xs:appinfo>
+ <hj:entity>
+ <orm:table name="users"/>
+ </hj:entity>
+ </xs:appinfo>
+ </xs:annotation>
+ <xs:sequence>
+ <xs:element name="username" type="xs:string" minOccurs="1" maxOccurs="1">
+ <xs:annotation>
+ <xs:appinfo>
+ <hj:id>
+ <orm:column name="username" length="128" nullable="false"/>
+ </hj:id>
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:element>
+ <xs:element name="passwd" type="xs:string" minOccurs="1" maxOccurs="1">
+ <xs:annotation>
+ <xs:appinfo>
+ <hj:basic>
+ <orm:column name="passwd" length="128" nullable="false"/>
+ </hj:basic>
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="role">
+ <xs:complexType>
+ <xs:annotation>
+ <xs:appinfo>
+ <hj:entity>
+ <orm:table name="roles"/>
+ </hj:entity>
+ </xs:appinfo>
+ </xs:annotation>
+ <xs:sequence>
+ <xs:element name="rolename" type="xs:string" minOccurs="1" maxOccurs="1">
+ <xs:annotation>
+ <xs:appinfo>
+ <hj:id>
+ <orm:column name="rolename" length="128" nullable="false"/>
+ </hj:id>
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:element>
+ <xs:element name="rolegroup" type="xs:string" minOccurs="1" maxOccurs="1">
+ <xs:annotation>
+ <xs:appinfo>
+ <hj:basic>
+ <orm:column name="rolegroup" length="128" nullable="false"/>
+ </hj:basic>
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="user_role">
+ <xs:complexType>
+ <xs:annotation>
+ <xs:appinfo>
+ <hj:entity>
+ <orm:table name="users_roles"/>
+ </hj:entity>
+ </xs:appinfo>
+ </xs:annotation>
+ <xs:sequence>
+ <xs:element name="username" type="xs:string" minOccurs="1" maxOccurs="1">
+ <xs:annotation>
+ <xs:appinfo>
+ <hj:basic>
+ <orm:column name="username" length="128" nullable="false"/>
+ </hj:basic>
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:element>
+ <xs:element name="rolename" type="xs:string" minOccurs="1" maxOccurs="1">
+ <xs:annotation>
+ <xs:appinfo>
+ <hj:basic>
+ <orm:column name="rolename" length="128" nullable="false"/>
+ </hj:basic>
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
+
--- /dev/null
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.collectionspace.services.authentication.test;
+
+import java.lang.reflect.Method;
+import java.util.UUID;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import javax.persistence.Query;
+import org.collectionspace.services.authentication.User;
+import org.collectionspace.services.authentication.Role;
+import org.collectionspace.services.authentication.UserRole;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+
+/**
+ *
+ * @author
+ */
+public class DefaultIdentityProviderTest {
+
+ private final Logger logger = LoggerFactory.getLogger(DefaultIdentityProviderTest.class);
+ private EntityManagerFactory emf;
+ private EntityManager em;
+ private String id;
+
+ @BeforeMethod
+ public void init() {
+
+ emf = Persistence.createEntityManagerFactory("org.collectionspace.services.authentication");
+
+ em = emf.createEntityManager();
+// if (logger.isDebugEnabled()) {
+// logger.debug("created entity manager");
+// }
+ }
+
+ @AfterMethod
+ public void cleanup() {
+ if (em != null) {
+ em.close();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test(dataProvider = "testName", dataProviderClass = DefaultIdentityProviderTest.class)
+ public void create(String testName) throws Exception {
+ User user = new User();
+ user.setUsername("sanjay");
+ user.setPasswd("uiouio");
+ em.getTransaction().begin();
+ em.persist(user);
+ // Commit the transaction
+ em.getTransaction().commit();
+ if (logger.isDebugEnabled()) {
+ logger.debug("created user " +
+ " username=" + user.getUsername() +
+ " password=" + user.getPasswd());
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test(dataProvider = "testName", dataProviderClass = DefaultIdentityProviderTest.class,
+ dependsOnMethods = {"create"})
+ public void read(String testName) throws Exception {
+ User user = findUser("sanjay");
+ Assert.assertNotNull(user);
+ if (logger.isDebugEnabled()) {
+ logger.debug("read user " +
+ " username=" + user.getUsername());
+ }
+ }
+
+ private User findUser(String userName) throws Exception {
+ Query q = em.createQuery("select a from org.collectionspace.services.authentication.User a where a.username = :username");
+ q.setParameter("username", userName);
+ return (User) q.getSingleResult();
+
+ }
+
+// @SuppressWarnings("unchecked")
+// @Test(dataProvider = "testName", dataProviderClass = DefaultIdentityProviderTest.class,
+// dependsOnMethods = {"read"})
+// public void update(String testName) throws Exception {
+// Query q = em.createQuery("update org.collectionspace.services.authentication.User set email= :email where csid=:csid");
+// q.setParameter("email", "sanjay@berkeley.edu");
+// q.setParameter("csid", id);
+// em.getTransaction().begin();
+// int no = q.executeUpdate();
+// // Commit the transaction
+// em.getTransaction().commit();
+// Assert.assertEquals(no, 1);
+// Users account = findAccount("sanjay");
+// if (logger.isDebugEnabled()) {
+// logger.debug("updated account " +
+// " first name=" + account.getFirstName() +
+// " email=" + account.getEmail());
+// }
+// }
+ @SuppressWarnings("unchecked")
+ @Test(dataProvider = "testName", dataProviderClass = DefaultIdentityProviderTest.class,
+ dependsOnMethods = {"read"}) //FIXME change to update
+ public void delete(String testName) throws Exception {
+ Query q = em.createQuery("delete from org.collectionspace.services.authentication.User where username=:username");
+ q.setParameter("username", "sanjay");
+ // Begin transaction
+ em.getTransaction().begin();
+ int no = q.executeUpdate();
+ ;
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleting user " +
+ " username=" + "sanjay");
+ }
+ // Commit the transaction
+ em.getTransaction().commit();
+ Assert.assertEquals(no, 1);
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleted user " +
+ " username=" + "sanjay");
+ }
+ }
+
+ /**
+ * Returns the name of the currently running test.
+ *
+ * Note: although the return type is listed as Object[][],
+ * this method instead returns a String.
+ *
+ * @param m The currently running test method.
+ *
+ * @return The name of the currently running test method.
+ */
+ @DataProvider(name = "testName")
+ public static Object[][] testName(Method m) {
+ return new Object[][]{
+ new Object[]{m.getName()}
+ };
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<persistence version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
+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.authentication">
+ <class>org.collectionspace.services.authentication.User</class>
+ <class>org.collectionspace.services.authentication.Role</class>
+ <class>org.collectionspace.services.authentication.UserRole</class>
+ <properties>
+ <property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"/>
+
+ <!--property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
+ <property name="hibernate.max_fetch_depth" value="3"/>
+ <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
+ <property name="hibernate.connection.username" value="test"/>
+ <property name="hibernate.connection.password" value="test"/>
+ <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/cspace"/-->
+ </properties>
+ </persistence-unit>
+</persistence>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Document : hibernate.cfg.xml.xml
+ Created on : November 12, 2009, 12:02 PM
+ Author : sanjaydalal
+ Description:
+ Purpose of the document follows.
+-->
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+<hibernate-configuration>
+ <session-factory>
+ <property name="connection.url">jdbc:mysql://localhost:3306/cspace</property>
+ <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
+ <property name="connection.username">test</property>
+ <property name="connection.password">test</property>
+ <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
+ <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
+ <property name="current_session_context_class">thread</property>
+ <property name="hibernate.show_sql">true</property>
+ </session-factory>
+</hibernate-configuration>
--- /dev/null
+log4j.rootLogger=debug, stdout, R\r
+\r
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r
+\r
+# Pattern to output the caller's file name and line number.\r
+log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+log4j.appender.R=org.apache.log4j.RollingFileAppender\r
+log4j.appender.R.File=target/test-client.log\r
+\r
+log4j.appender.R.MaxFileSize=100KB\r
+# Keep one backup file\r
+log4j.appender.R.MaxBackupIndex=1\r
+\r
+log4j.appender.R.layout=org.apache.log4j.PatternLayout\r
+log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+#packages\r
+log4j.logger.org.collectionspace=DEBUG\r
+log4j.logger.org.apache=INFO\r
+log4j.logger.httpclient=INFO\r
+log4j.logger.org.jboss.resteasy=INFO\r
+log4j.logger.org.jvnet.hyperjaxb3=DEBUG\r
+log4j.logger.org.hibernate=WARN
\ No newline at end of file
</properties>\r
\r
<modules>\r
+ <module>jaxb</module>\r
<module>service</module>\r
<module>client</module>\r
</modules>\r
</service:object>
</tenant:serviceBindings>
<!-- end relation service meta-data -->
+ <!-- begin account service meta-data -->
+ <tenant:serviceBindings name="Accounts" version="0.1">
+ <service:object id="1" name="Acccount" version="0.1"
+ xmlns:service='http://collectionspace.org/services/common/service'>
+ <service:part id="0" control_group="Managed"
+ versionable="true" auditable="false"
+ label="accounts_system" updated="" order="0">
+ <service:content contentType="application/xml">
+ <service:xmlContent
+ namespaceURI="http://collectionspace.org/services/common/system"
+ schemaLocation="http://collectionspace.org/services/common/system http://collectionspace.org/services/common/system/system-response.xsd">
+ </service:xmlContent>
+ </service:content>
+ </service:part>
+ <service:part id="1" control_group="Managed"
+ versionable="true" auditable="false"
+ label="accounts_common" updated="" order="1">
+ <service:content contentType="application/xml">
+ <service:xmlContent
+ namespaceURI="http://collectionspace.org/services/account"
+ schemaLocation="http://collectionspace.org/services/account http://services.collectionspace.org/relation/accounts_common.xsd">
+ </service:xmlContent>
+ </service:content>
+ </service:part>
+ </service:object>
+ </tenant:serviceBindings>
+ <!-- end account service meta-data -->
</tenant:tenantBinding>
<!-- end movinimages.us tenant meta-data -->
</tenant:TenantBindingConfig>
public void read() throws Exception {
String configFileName = getAbsoluteFileName(CONFIG_FILE_NAME);
File configFile = new File(configFileName);
- if(!configFile.exists()){
+ if (!configFile.exists()) {
String msg = "Could not find configuration file " + configFileName;
logger.error(msg);
throw new RuntimeException(msg);
}
tenantBindingConfig = (TenantBindingConfig) parse(configFile, TenantBindingConfig.class);
- for(TenantBindingType tenantBinding : tenantBindingConfig.getTenantBinding()){
+ for (TenantBindingType tenantBinding : tenantBindingConfig.getTenantBinding()) {
tenantBindings.put(tenantBinding.getId(), tenantBinding);
readServiceBindings(tenantBinding);
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("read() added tenant id=" + tenantBinding.getId() +
" name=" + tenantBinding.getName());
}
}
private void readServiceBindings(TenantBindingType tenantBinding) throws Exception {
- for(ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()){
+ for (ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()) {
String key = getTenantQualifiedServiceName(tenantBinding.getId(),
serviceBinding.getName());
serviceBindings.put(key, serviceBinding);
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("readServiceBindings() added service " +
" name=" + key +
" workspace=" + serviceBinding.getName());
* @throws Exception
*/
public void retrieveAllWorkspaceIds() throws Exception {
- for(TenantBindingType tenantBinding : tenantBindings.values()){
+ for (TenantBindingType tenantBinding : tenantBindings.values()) {
retrieveWorkspaceIds(tenantBinding);
}
}
ServiceMain svcMain = ServiceMain.getInstance();
RepositoryClientConfigType rclientConfig = svcMain.getServicesConfigReader().getConfiguration().getRepositoryClient();
ClientType clientType = svcMain.getClientType();
- if(clientType.equals(ClientType.JAVA) &&
- rclientConfig.getName().equalsIgnoreCase("nuxeo-java")){
+ if (clientType.equals(ClientType.JAVA) &&
+ rclientConfig.getName().equalsIgnoreCase("nuxeo-java")) {
//FIXME only one repository client is recognized
workspaceIds = svcMain.getNuxeoConnector().retrieveWorkspaceIds(
tenantBinding.getRepositoryDomain());
}
//verify if workspace exists for each service in the tenant binding
- for(ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()){
+ for (ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()) {
String serviceName = serviceBinding.getName();
+ if (serviceBinding.getRepositoryClient() == null) {
+ //no repository needed for this service...skip
+ if (logger.isDebugEnabled()) {
+ logger.debug("no repository configured for service " + serviceName +
+ " skipping...");
+ }
+ continue;
+ }
RepositoryClient repositoryClient = getRepositoryClient(
serviceBinding.getRepositoryClient());
String workspaceId = null;
//workspace name is service name by convention
String workspace = serviceBinding.getName().toLowerCase();
- if(clientType.equals(ClientType.JAVA)){
+ if (clientType.equals(ClientType.JAVA)) {
workspaceId = workspaceIds.get(workspace);
- if(workspaceId == null){
+ if (workspaceId == null) {
logger.warn("failed to retrieve workspace id for " + workspace +
" trying to create a new workspace...");
workspaceId = repositoryClient.createWorkspace(
tenantBinding.getRepositoryDomain(),
serviceBinding.getName());
- if(workspaceId == null){
+ if (workspaceId == null) {
logger.warn("failed to create workspace for " + workspace);
continue;
}
}
- }else{
+ } else {
workspaceId = serviceBinding.getRepositoryWorkspaceId();
- if(workspaceId == null || "".equals(workspaceId)){
+ if (workspaceId == null || "".equals(workspaceId)) {
logger.error("could not find workspace id for " + workspace);
//FIXME: should we throw an exception here?
continue;
}
String tenantService = getTenantQualifiedServiceName(tenantBinding.getId(), serviceName);
serviceWorkspaces.put(tenantService, workspaceId);
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("retrieved workspace id=" + workspaceId +
" service=" + serviceName +
" workspace=" + workspace);
*/
package org.collectionspace.services.common.document;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.StringTokenizer;
-import org.collectionspace.services.common.context.ServiceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactory;
/**
- * JpaStorageClient is used to perform CRUD operations on documents in Nuxeo
- * repository using Remote Java APIs. It uses @see DocumentHandler as IOHandler
- * with the client.
+ * JpaStorageClient is used to perform CRUD operations on SQL storage using JPA.
+ * It uses @see DocumentHandler as IOHandler with the client.
+ * All the operations in this client are carried out under their own transactions.
+ * A call to any method would start and commit/rollback a transaction.
*
* $LastChangedRevision: $ $LastChangedDate: $
*/
<!-- add modules below in the order based on dependencies -->
<module>common</module>
<module>authentication</module>
+ <!--module>account</module-->
<module>relation</module>
<!--module>query</module-->
<module>acquisition</module>
<module>client</module>
<module>sdk</module>
<module>IntegrationTests</module>
- <!--module>account</module-->
</modules>
<repositories> </repositories>
</dependency>
</dependencies>
</dependencyManagement>
-</project>
\ No newline at end of file
+</project>