From: Sanjay Dalal Date: Sat, 21 Nov 2009 00:32:42 +0000 (+0000) Subject: NOJIRA account service in testing phase. added jaxb-jpa for default security identify... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=63d5ff00e093f9479134cbc965b4e6f11977e48b;p=tmp%2Fjakarta-migration.git NOJIRA account service in testing phase. added jaxb-jpa for default security identify provider (to be used by account). checking in for safefy purposes. disabled acccount from service pom.xml. A services/authentication/jaxb A services/authentication/jaxb/src A services/authentication/jaxb/src/test A services/authentication/jaxb/src/test/java A services/authentication/jaxb/src/test/java/org A services/authentication/jaxb/src/test/java/org/collectionspace A services/authentication/jaxb/src/test/java/org/collectionspace/services A services/authentication/jaxb/src/test/java/org/collectionspace/services/authentication A services/authentication/jaxb/src/test/java/org/collectionspace/services/authentication/test A services/authentication/jaxb/src/test/java/org/collectionspace/services/authentication/test/DefaultIdentityProviderTest.java A services/authentication/jaxb/src/test/resources A services/authentication/jaxb/src/test/resources/META-INF A services/authentication/jaxb/src/test/resources/META-INF/persistence.xml A services/authentication/jaxb/src/test/resources/log4j.properties A services/authentication/jaxb/src/test/resources/hibernate.cfg.xml A services/authentication/jaxb/src/main A services/authentication/jaxb/src/main/java A services/authentication/jaxb/src/main/java/org A services/authentication/jaxb/src/main/java/org/collectionspace A services/authentication/jaxb/src/main/java/org/collectionspace/services A services/authentication/jaxb/src/main/resources A services/authentication/jaxb/src/main/resources/authentication_identity_provider.xsd A services/authentication/jaxb/src/main/resources/META-INF A services/authentication/jaxb/src/main/resources/META-INF/persistence.xml A services/authentication/jaxb/pom.xml M services/authentication/pom.xml M services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java M services/JaxRsServiceProvider/src/main/webapp/WEB-INF/jboss-web.xml M services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml M services/JaxRsServiceProvider/pom.xml M services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java M services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReader.java M services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandler.java M services/common/src/main/config/tenant-bindings.xml M services/pom.xml A services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountStorageClient.java M services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountHandlerFactory.java M services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java M services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java M services/account/service/pom.xml M services/account/jaxb/src/main/resources/META-INF/persistence.xml M services/account/jaxb/src/main/resources/accounts_common.xsd M services/account/jaxb/src/main/resources/db/mysql/account.sql M services/account/jaxb/pom.xml _M services/account/client A services/account/client/src/test/java/org/collectionspace/services/client/test/AccountServiceTest.java A services/account/client/src/test/java/org/collectionspace/services/client/AccountClient.java A services/account/client/src/test/java/org/collectionspace/services/client/AccountProxy.java --- diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index db4a04768..c57d1261a 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -22,6 +22,11 @@ org.collectionspace.services.common 1.0 + + org.collectionspace.services + org.collectionspace.services.account.service + 1.0 + org.collectionspace.services org.collectionspace.services.collectionobject.service diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java index a801ccb0e..3b1d095ae 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java @@ -1,5 +1,6 @@ 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; @@ -22,6 +23,7 @@ public class CollectionSpaceJaxRsApplication extends Application { private Set> empty = new HashSet>(); public CollectionSpaceJaxRsApplication() { + singletons.add(new AccountResource()); singletons.add(new CollectionObjectResource()); singletons.add(new IDResource()); singletons.add(new IntakeResource()); diff --git a/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/jboss-web.xml b/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/jboss-web.xml index 33a226218..10a4024eb 100644 --- a/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/jboss-web.xml +++ b/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/jboss-web.xml @@ -1,6 +1,13 @@ - java:/jaas/cspace - /cspace-services + java:/jaas/cspace + /cspace-services + + DB Connection + jdbc/cspaceds + javax.sql.DataSource + java:/cspaceds + Container + diff --git a/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml b/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml index 6d52948b7..62d9b25b9 100644 --- a/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml +++ b/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml @@ -1,4 +1,5 @@ + - CollectionSpace Services @@ -66,4 +66,10 @@ CollectionSpace realm END AUTH --> + + DB Connection + jdbc/cspaceds + javax.sql.DataSource + Container + diff --git a/services/account/client/src/test/java/org/collectionspace/services/client/AccountClient.java b/services/account/client/src/test/java/org/collectionspace/services/client/AccountClient.java new file mode 100644 index 000000000..dd06c3795 --- /dev/null +++ b/services/account/client/src/test/java/org/collectionspace/services/client/AccountClient.java @@ -0,0 +1,128 @@ +/** + * 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 readList() { + return accountProxy.readList(); + + } + + /** + * @param csid + * @return + * @see org.collectionspace.hello.client.AccountProxy#getAccount(java.lang.String) + */ + public ClientResponse read(String csid) { + return accountProxy.read(csid); + } + + /** + * @param account + * @return + * @see org.collectionspace.hello.client.AccountProxy#create(org.collectionspace.services.account.AccountsCommon) + */ + public ClientResponse 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 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 delete(String csid) { + return accountProxy.delete(csid); + } +} diff --git a/services/account/client/src/test/java/org/collectionspace/services/client/AccountProxy.java b/services/account/client/src/test/java/org/collectionspace/services/client/AccountProxy.java new file mode 100644 index 000000000..d3a98ad00 --- /dev/null +++ b/services/account/client/src/test/java/org/collectionspace/services/client/AccountProxy.java @@ -0,0 +1,76 @@ +/** + * 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 readList(); + + //(C)reate + @POST + ClientResponse create(AccountsCommon multipart); + + //(R)ead + @GET + @Path("/{csid}") + ClientResponse read(@PathParam("csid") String csid); + + //(U)pdate + @PUT + @Path("/{csid}") + ClientResponse update(@PathParam("csid") String csid, AccountsCommon multipart); + + //(D)elete + @DELETE + @Path("/{csid}") + ClientResponse delete(@PathParam("csid") String csid); +} diff --git a/services/account/client/src/test/java/org/collectionspace/services/client/test/AccountServiceTest.java b/services/account/client/src/test/java/org/collectionspace/services/client/test/AccountServiceTest.java new file mode 100644 index 000000000..881d93437 --- /dev/null +++ b/services/account/client/src/test/java/org/collectionspace/services/client/test/AccountServiceTest.java @@ -0,0 +1,430 @@ +/** + * 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 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 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 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 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 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 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 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 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 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; + + } + +} diff --git a/services/account/jaxb/pom.xml b/services/account/jaxb/pom.xml index f4e8dff2e..773625734 100644 --- a/services/account/jaxb/pom.xml +++ b/services/account/jaxb/pom.xml @@ -112,7 +112,7 @@ - process-test-classes + process-test-resources hbm2ddl diff --git a/services/account/jaxb/src/main/resources/META-INF/persistence.xml b/services/account/jaxb/src/main/resources/META-INF/persistence.xml index 70e1e5dd3..74090142f 100644 --- a/services/account/jaxb/src/main/resources/META-INF/persistence.xml +++ b/services/account/jaxb/src/main/resources/META-INF/persistence.xml @@ -2,7 +2,8 @@ - java:/CSpaceDS + org.hibernate.ejb.HibernatePersistence + cspaceds org.collectionspace.services.account.AccountsCommon org.collectionspace.services.account.AccountsCommonList org.collectionspace.services.account.AccountsCommonList$AccountListItem diff --git a/services/account/jaxb/src/main/resources/accounts_common.xsd b/services/account/jaxb/src/main/resources/accounts_common.xsd index c93750bac..8d4027138 100644 --- a/services/account/jaxb/src/main/resources/accounts_common.xsd +++ b/services/account/jaxb/src/main/resources/accounts_common.xsd @@ -40,6 +40,10 @@ + + + + diff --git a/services/account/jaxb/src/main/resources/db/mysql/account.sql b/services/account/jaxb/src/main/resources/db/mysql/account.sql index 4e9d9e6f9..e69de29bb 100644 --- a/services/account/jaxb/src/main/resources/db/mysql/account.sql +++ b/services/account/jaxb/src/main/resources/db/mysql/account.sql @@ -1,8 +0,0 @@ -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); diff --git a/services/account/service/pom.xml b/services/account/service/pom.xml index 38c3fa08a..85138a9ad 100644 --- a/services/account/service/pom.xml +++ b/services/account/service/pom.xml @@ -20,6 +20,11 @@ org.collectionspace.services.common 1.0 + + org.collectionspace.services + org.collectionspace.services.authentication.jaxb + 1.0 + org.collectionspace.services org.collectionspace.services.account.jaxb diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java b/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java index 014022c69..933f1b606 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java @@ -37,12 +37,16 @@ import javax.ws.rs.core.Response; 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; @@ -55,6 +59,7 @@ public class AccountResource final private String serviceName = "accounts"; final Logger logger = LoggerFactory.getLogger(AccountResource.class); + final StorageClient storageClient = new AccountStorageClient(); @Override public String getServiceName() { @@ -64,19 +69,31 @@ public class AccountResource private ServiceContext createServiceContext(T obj) { ServiceContext ctx = new RemoteServiceContextImpl(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(); @@ -107,8 +124,9 @@ public class AccountResource } 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()) { @@ -141,8 +159,11 @@ public class AccountResource 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()) { @@ -173,8 +194,9 @@ public class AccountResource 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); @@ -206,8 +228,8 @@ public class AccountResource 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()) { diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java index cc554b9eb..5e4a677f5 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java @@ -29,7 +29,6 @@ import org.collectionspace.services.account.AccountsCommonList; import org.collectionspace.services.common.document.AbstractDocumentHandler; import org.collectionspace.services.common.document.DocumentWrapper; - /** * * @author @@ -37,6 +36,9 @@ import org.collectionspace.services.common.document.DocumentWrapper; public class AccountDocumentHandler extends AbstractDocumentHandler { + private AccountsCommon account; + private AccountsCommonList accountList; + @Override public void handleCreate(DocumentWrapper wrapDoc) throws Exception { String id = UUID.randomUUID().toString(); @@ -50,45 +52,50 @@ public class AccountDocumentHandler @Override public void handleGet(DocumentWrapper wrapDoc) throws Exception { + setCommonPart(wrapDoc.getWrappedObject()); } @Override - public void handleGetAll(DocumentWrapper< AccountsCommonList> wrapDoc) throws Exception { + public void handleGetAll(DocumentWrapper wrapDoc) throws Exception { + setCommonPartList(wrapDoc.getWrappedObject()); } @Override public AccountsCommon extractCommonPart(DocumentWrapper wrapDoc) throws Exception { - return null; + throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler"); } @Override public void fillCommonPart(AccountsCommon obj, DocumentWrapper wrapDoc) throws Exception { + throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler"); } @Override public AccountsCommonList extractCommonPartList(DocumentWrapper 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 diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountHandlerFactory.java b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountHandlerFactory.java index c90280fad..4e76ed084 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountHandlerFactory.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountHandlerFactory.java @@ -47,9 +47,6 @@ public class AccountHandlerFactory implements DocumentHandlerFactory { @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(); } } diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountStorageClient.java b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountStorageClient.java new file mode 100644 index 000000000..cfbe19371 --- /dev/null +++ b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountStorageClient.java @@ -0,0 +1,36 @@ +/** + * 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 +{ + +} diff --git a/services/authentication/jaxb/pom.xml b/services/authentication/jaxb/pom.xml new file mode 100644 index 000000000..5510cb666 --- /dev/null +++ b/services/authentication/jaxb/pom.xml @@ -0,0 +1,104 @@ + + + + + org.collectionspace.services.authentication + org.collectionspace.services + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.authentication.jaxb + 1.0 + services.authentication.jaxb + + authentication.sql + src/main/resources/db/mysql + + + + + org.slf4j + slf4j-api + test + + + org.slf4j + slf4j-log4j12 + test + + + com.sun.xml.bind + jaxb-impl + + + org.jvnet.jaxb2-commons + property-listener-injector + + + org.jvnet.jaxb2_commons + runtime + + + + mysql + mysql-connector-java + + + + javax.persistence + persistence-api + + + org.hibernate + hibernate-entitymanager + + + org.testng + testng + 5.6 + + + org.collectionspace.services + org.collectionspace.services.client + 1.0 + + + + + collectionspace-services-authentication-jaxb + install + + + + org.jvnet.hyperjaxb3 + maven-hyperjaxb3-plugin + + + + generate + + + + + true + true + false + + + + maven-compiler-plugin + + 1.6 + 1.6 + + + + + + + + diff --git a/services/authentication/jaxb/src/main/resources/META-INF/persistence.xml b/services/authentication/jaxb/src/main/resources/META-INF/persistence.xml new file mode 100644 index 000000000..6a124e8db --- /dev/null +++ b/services/authentication/jaxb/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,14 @@ + + + + java:comp/env/jdbc/CspaceDS + org.collectionspace.services.authentication.User + org.collectionspace.services.authentication.Role + org.collectionspace.services.authentication.UserRole + + + + + + + diff --git a/services/authentication/jaxb/src/main/resources/authentication_identity_provider.xsd b/services/authentication/jaxb/src/main/resources/authentication_identity_provider.xsd new file mode 100644 index 000000000..899c0675d --- /dev/null +++ b/services/authentication/jaxb/src/main/resources/authentication_identity_provider.xsd @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/authentication/jaxb/src/test/java/org/collectionspace/services/authentication/test/DefaultIdentityProviderTest.java b/services/authentication/jaxb/src/test/java/org/collectionspace/services/authentication/test/DefaultIdentityProviderTest.java new file mode 100644 index 000000000..2e5cb37a8 --- /dev/null +++ b/services/authentication/jaxb/src/test/java/org/collectionspace/services/authentication/test/DefaultIdentityProviderTest.java @@ -0,0 +1,151 @@ +/* + * 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()} + }; + } +} diff --git a/services/authentication/jaxb/src/test/resources/META-INF/persistence.xml b/services/authentication/jaxb/src/test/resources/META-INF/persistence.xml new file mode 100644 index 000000000..a2eeadba1 --- /dev/null +++ b/services/authentication/jaxb/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,19 @@ + + + + org.collectionspace.services.authentication.User + org.collectionspace.services.authentication.Role + org.collectionspace.services.authentication.UserRole + + + + + + + diff --git a/services/authentication/jaxb/src/test/resources/hibernate.cfg.xml b/services/authentication/jaxb/src/test/resources/hibernate.cfg.xml new file mode 100644 index 000000000..c7c600995 --- /dev/null +++ b/services/authentication/jaxb/src/test/resources/hibernate.cfg.xml @@ -0,0 +1,24 @@ + + + + + + + jdbc:mysql://localhost:3306/cspace + com.mysql.jdbc.Driver + test + test + org.hibernate.dialect.MySQLDialect + org.hibernate.transaction.JDBCTransactionFactory + thread + true + + diff --git a/services/authentication/jaxb/src/test/resources/log4j.properties b/services/authentication/jaxb/src/test/resources/log4j.properties new file mode 100644 index 000000000..3aa34b3fc --- /dev/null +++ b/services/authentication/jaxb/src/test/resources/log4j.properties @@ -0,0 +1,25 @@ +log4j.rootLogger=debug, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=target/test-client.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +#packages +log4j.logger.org.collectionspace=DEBUG +log4j.logger.org.apache=INFO +log4j.logger.httpclient=INFO +log4j.logger.org.jboss.resteasy=INFO +log4j.logger.org.jvnet.hyperjaxb3=DEBUG +log4j.logger.org.hibernate=WARN \ No newline at end of file diff --git a/services/authentication/pom.xml b/services/authentication/pom.xml index e0f5348a3..8d131d494 100644 --- a/services/authentication/pom.xml +++ b/services/authentication/pom.xml @@ -16,6 +16,7 @@ + jaxb service client diff --git a/services/common/src/main/config/tenant-bindings.xml b/services/common/src/main/config/tenant-bindings.xml index e452193c7..70cf8caa9 100644 --- a/services/common/src/main/config/tenant-bindings.xml +++ b/services/common/src/main/config/tenant-bindings.xml @@ -193,6 +193,33 @@ + + + + + + + + + + + + + + + + + + diff --git a/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReader.java b/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReader.java index cd4e052b1..7e01ae27b 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReader.java +++ b/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReader.java @@ -70,16 +70,16 @@ public class TenantBindingConfigReader 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()); } @@ -87,11 +87,11 @@ public class TenantBindingConfigReader } 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()); @@ -105,7 +105,7 @@ public class TenantBindingConfigReader * @throws Exception */ public void retrieveAllWorkspaceIds() throws Exception { - for(TenantBindingType tenantBinding : tenantBindings.values()){ + for (TenantBindingType tenantBinding : tenantBindings.values()) { retrieveWorkspaceIds(tenantBinding); } } @@ -121,36 +121,44 @@ public class TenantBindingConfigReader 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; @@ -158,7 +166,7 @@ public class TenantBindingConfigReader } 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); diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandler.java index fef1b5df3..db763c958 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandler.java @@ -23,11 +23,7 @@ */ 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; diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java index 32a326728..b5e6cb244 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java @@ -37,9 +37,10 @@ import org.slf4j.Logger; 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: $ */ diff --git a/services/pom.xml b/services/pom.xml index fe51aa74d..9f0c53a19 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -16,6 +16,7 @@ common authentication + relation acquisition @@ -27,7 +28,6 @@ client sdk IntegrationTests - @@ -213,4 +213,4 @@ - \ No newline at end of file +