From: Sanjay Dalal Date: Sat, 14 Nov 2009 00:04:19 +0000 (+0000) Subject: NOJIRA work in progress for account management. uses jaxb/jpa. still to write resource X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=bcdd53f2bb07f21df044ad9de1f0b4978eead08e;p=tmp%2Fjakarta-migration.git NOJIRA work in progress for account management. uses jaxb/jpa. still to write resource and handler. builds but is not linked to service build yet. A account A account/service A account/service/src A account/service/src/test A account/service/src/test/java A account/service/src/test/java/org A account/service/src/test/java/org/collectionspace A account/service/src/test/java/org/collectionspace/services A account/service/src/test/java/org/collectionspace/services/test A account/service/src/test/resources A account/service/src/test/resources/log4j.xml A account/service/src/main A account/service/src/main/java A account/service/src/main/java/org A account/service/src/main/java/org/collectionspace A account/service/src/main/java/org/collectionspace/services A account/service/src/main/java/org/collectionspace/services/account A account/service/src/main/java/org/collectionspace/services/account/storage A account/service/src/main/java/org/collectionspace/services/account/storage/AccountHandlerFactory.java A account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java A account/service/src/main/java/org/collectionspace/services/account/AccountResource.java A account/service/src/main/resources A account/service/pom.xml AM account/jaxb A account/jaxb/src A account/jaxb/src/test A account/jaxb/src/test/java A account/jaxb/src/test/java/org A account/jaxb/src/test/java/org/collectionspace A account/jaxb/src/test/java/org/collectionspace/services A account/jaxb/src/test/java/org/collectionspace/services/account A account/jaxb/src/test/java/org/collectionspace/services/account/test A account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java A account/jaxb/src/test/resources A account/jaxb/src/test/resources/META-INF A account/jaxb/src/test/resources/META-INF/persistence.xml A account/jaxb/src/test/resources/log4j.properties A account/jaxb/src/test/resources/hibernate.cfg.xml A account/jaxb/src/main A account/jaxb/src/main/java A account/jaxb/src/main/java/org A account/jaxb/src/main/java/org/collectionspace A account/jaxb/src/main/java/org/collectionspace/services A account/jaxb/src/main/resources A account/jaxb/src/main/resources/META-INF A account/jaxb/src/main/resources/META-INF/persistence.xml A account/jaxb/src/main/resources/accounts_common.xsd A account/jaxb/src/main/resources/db A account/jaxb/src/main/resources/db/mysql A account/jaxb/src/main/resources/org A account/jaxb/src/main/resources/org/collectionspace A account/jaxb/src/main/resources/org/collectionspace/services A account/jaxb/src/main/resources/org/collectionspace/services/account A account/jaxb/pom.xml A account/3rdparty A account/3rdparty/pom.xml A account/3rdparty/build.xml A account/pom.xml A account/build.xml A account/client A account/client/src A account/client/src/test A account/client/src/test/java A account/client/src/test/java/org A account/client/src/test/java/org/collectionspace A account/client/src/test/java/org/collectionspace/services A account/client/src/test/java/org/collectionspace/services/client A account/client/src/test/java/org/collectionspace/services/client/test A account/client/src/test/resources A account/client/src/test/resources/log4j.properties A account/client/src/main A account/client/src/main/java A account/client/src/main/java/org A account/client/src/main/java/org/collectionspace A account/client/src/main/java/org/collectionspace/services A account/client/src/main/java/org/collectionspace/services/client A account/client/src/main/resources A account/client/pom.xml --- diff --git a/services/account/3rdparty/build.xml b/services/account/3rdparty/build.xml new file mode 100644 index 000000000..c0a1b94bd --- /dev/null +++ b/services/account/3rdparty/build.xml @@ -0,0 +1,126 @@ + + + + account service 3rd party + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/account/3rdparty/pom.xml b/services/account/3rdparty/pom.xml new file mode 100644 index 000000000..a4a7a16f7 --- /dev/null +++ b/services/account/3rdparty/pom.xml @@ -0,0 +1,26 @@ + + + + + org.collectionspace.services + org.collectionspace.services.account + 1.0 + + + 4.0.0 + org.collectionspace.services + 1.0 + org.collectionspace.services.account.3rdparty + pom + services.account.3rdparty + + 3rd party build for account service + + + + + + + diff --git a/services/account/build.xml b/services/account/build.xml new file mode 100644 index 000000000..8219b1980 --- /dev/null +++ b/services/account/build.xml @@ -0,0 +1,123 @@ + + + + collectionobject service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/account/client/pom.xml b/services/account/client/pom.xml new file mode 100644 index 000000000..c350fe477 --- /dev/null +++ b/services/account/client/pom.xml @@ -0,0 +1,110 @@ + + + + + org.collectionspace.services.account + org.collectionspace.services + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.account.client + 1.0 + services.account.client + + + + + org.slf4j + slf4j-api + test + + + org.slf4j + slf4j-log4j12 + test + + + org.collectionspace.services + org.collectionspace.services.account.jaxb + 1.0 + + + org.collectionspace.services + org.collectionspace.services.client + 1.0 + + + + + + org.testng + testng + 5.6 + + + org.jboss.resteasy + resteasy-jaxrs + 1.1.GA + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.1.GA + + + org.jboss.resteasy + resteasy-multipart-provider + 1.1.GA + + + commons-httpclient + commons-httpclient + 3.1 + + + + + cspace-services-account-client + + + org.apache.maven.plugins + maven-surefire-plugin + + + + log4j.configuration + file:target/test-classes/log4j.properties + + + + + + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + + diff --git a/services/account/client/src/test/resources/log4j.properties b/services/account/client/src/test/resources/log4j.properties new file mode 100644 index 000000000..18c510350 --- /dev/null +++ b/services/account/client/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +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 diff --git a/services/account/jaxb/pom.xml b/services/account/jaxb/pom.xml new file mode 100644 index 000000000..98f96b175 --- /dev/null +++ b/services/account/jaxb/pom.xml @@ -0,0 +1,213 @@ + + + + + org.collectionspace.services.account + org.collectionspace.services + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.account.jaxb + 1.0 + services.account.jaxb + + + + + 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-account-jaxb + install + + + + org.jvnet.hyperjaxb3 + maven-hyperjaxb3-plugin + + + + generate + + + + + true + true + false + + + + maven-compiler-plugin + + 1.6 + 1.6 + + + + + + + + + ddl + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + process-classes + process-test-resources + + + + + + + + + + + + + + + + run + + + + + + org.hibernate + hibernate-tools + 3.2.3.GA + + + org.hibernate + hibernate + 3.4.0.GA + + + org.hibernate + hibernate-entitymanager + 3.4.0.GA + + + org.slf4j + slf4j-api + 1.5.2 + + + org.slf4j + slf4j-log4j12 + 1.5.2 + + + commons-logging + commons-logging + 1.1 + + + + + + + + + + diff --git a/services/account/jaxb/src/main/resources/META-INF/persistence.xml b/services/account/jaxb/src/main/resources/META-INF/persistence.xml new file mode 100644 index 000000000..70e1e5dd3 --- /dev/null +++ b/services/account/jaxb/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,16 @@ + + + + java:/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 new file mode 100644 index 000000000..fab3f5876 --- /dev/null +++ b/services/account/jaxb/src/main/resources/accounts_common.xsd @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java b/services/account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java new file mode 100644 index 000000000..4a7a08ecf --- /dev/null +++ b/services/account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java @@ -0,0 +1,151 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.collectionspace.services.account.test; + +import java.lang.reflect.Method; +import java.util.List; +import java.util.UUID; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import javax.persistence.Query; +import org.collectionspace.services.account.AccountsCommon; +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 AccountTest { + + private final Logger logger = LoggerFactory.getLogger(AccountTest.class); + private EntityManagerFactory emf; + private EntityManager em; + + @BeforeMethod + public void init() { + + emf = Persistence.createEntityManagerFactory("org.collectionspace.services.account"); + + 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 = AccountTest.class) + public void create(String testName) throws Exception { + // Begin transaction + em.getTransaction().begin(); + AccountsCommon account = new AccountsCommon(); + account.setAnchorName("sanjay"); + account.setFirstName("Sanjay"); + account.setLastName("Dalal"); + account.setEmail("sanjay.dalal@berkeley.edu"); + account.setCsid(UUID.randomUUID().toString()); + em.persist(account); + // Commit the transaction + em.getTransaction().commit(); + if (logger.isDebugEnabled()) { + logger.debug("created account " + + " first name=" + account.getFirstName() + + " email=" + account.getEmail()); + } + } + + @SuppressWarnings("unchecked") + @Test(dataProvider = "testName", dataProviderClass = AccountTest.class, + dependsOnMethods = {"create"}) + public void read(String testName) throws Exception { + AccountsCommon account = findAccount("sanjay"); + Assert.assertNotNull(account); + if (logger.isDebugEnabled()) { + logger.debug("read account " + + " first name=" + account.getFirstName()); + } + } + + private AccountsCommon findAccount(String anchorName) throws Exception { + Query q = em.createQuery("select a from org.collectionspace.services.account.AccountsCommon a where a.anchorName = :anchorname"); + q.setParameter("anchorname", anchorName); + return (AccountsCommon) q.getSingleResult(); + + } + + @SuppressWarnings("unchecked") + @Test(dataProvider = "testName", dataProviderClass = AccountTest.class, + dependsOnMethods = {"read"}) + public void update(String testName) throws Exception { + // Begin transaction + em.getTransaction().begin(); + AccountsCommon account = findAccount("sanjay"); + Assert.assertNotNull(account); + account.setEmail("sanjay@berkeley.edu"); + em.persist(account); + // Commit the transaction + em.getTransaction().commit(); + if (logger.isDebugEnabled()) { + logger.debug("updated account " + + " first name=" + account.getFirstName() + + " email=" + account.getEmail()); + } + } + + @SuppressWarnings("unchecked") + @Test(dataProvider = "testName", dataProviderClass = AccountTest.class, + dependsOnMethods = {"update"}) + public void delete(String testName) throws Exception { + // Begin transaction + em.getTransaction().begin(); + AccountsCommon account = findAccount("sanjay"); + Assert.assertNotNull(account); + if (logger.isDebugEnabled()) { + logger.debug("deleting account " + + " first name=" + account.getFirstName() + + " email=" + account.getEmail()); + } + em.remove(account); + // Commit the transaction + em.getTransaction().commit(); + if (logger.isDebugEnabled()) { + logger.debug("deleted account " + + " first name=" + account.getFirstName()); + } + } + + /** + * 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/account/jaxb/src/test/resources/META-INF/persistence.xml b/services/account/jaxb/src/test/resources/META-INF/persistence.xml new file mode 100644 index 000000000..123eef2d6 --- /dev/null +++ b/services/account/jaxb/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,19 @@ + + + + org.collectionspace.services.account.AccountsCommon + org.collectionspace.services.account.AccountsCommonList + org.collectionspace.services.account.AccountsCommonList$AccountListItem + + + + + + + diff --git a/services/account/jaxb/src/test/resources/hibernate.cfg.xml b/services/account/jaxb/src/test/resources/hibernate.cfg.xml new file mode 100644 index 000000000..c7c600995 --- /dev/null +++ b/services/account/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/account/jaxb/src/test/resources/log4j.properties b/services/account/jaxb/src/test/resources/log4j.properties new file mode 100644 index 000000000..3aa34b3fc --- /dev/null +++ b/services/account/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/account/pom.xml b/services/account/pom.xml new file mode 100644 index 000000000..b739055ce --- /dev/null +++ b/services/account/pom.xml @@ -0,0 +1,69 @@ + + + + org.collectionspace.services.main + org.collectionspace.services + 1.0 + + 4.0.0 + org.collectionspace.services + 1.0 + org.collectionspace.services.account + pom + services.account + + + jaxb + service + 3rdparty + client + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-site-plugin + + /usr/bin/unzip -o > err.txt + + + + org.apache.maven.plugins + maven-war-plugin + 2.0.1 + + WEB-INF/lib/*.jar + + + true + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + + diff --git a/services/account/service/pom.xml b/services/account/service/pom.xml new file mode 100644 index 000000000..38c3fa08a --- /dev/null +++ b/services/account/service/pom.xml @@ -0,0 +1,119 @@ + + + + + org.collectionspace.services.account + org.collectionspace.services + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.account.service + jar + 1.0 + services.account.service + + + + org.collectionspace.services + org.collectionspace.services.common + 1.0 + + + org.collectionspace.services + org.collectionspace.services.account.jaxb + 1.0 + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + + junit + junit + 4.1 + test + + + org.testng + testng + 5.6 + + + + + commons-beanutils + commons-beanutils + 1.6.1 + + + commons-logging + commons-logging + 1.1 + + + + + + javax.security + jaas + 1.0.01 + provided + + + + + + + org.jboss.resteasy + resteasy-jaxrs + 1.1.GA + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.1.GA + + + org.jboss.resteasy + resteasy-multipart-provider + 1.1.GA + + + + + + + collectionspace-services-account + + + org.codehaus.mojo + jboss-maven-plugin + + ${jboss.dir} + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + + + + + + 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 new file mode 100644 index 000000000..6665462c8 --- /dev/null +++ b/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java @@ -0,0 +1,222 @@ +/** + * 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; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.PathParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +import org.collectionspace.services.common.AbstractCollectionSpaceResource; +import org.collectionspace.services.common.context.RemoteServiceContext; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.DocumentNotFoundException; +import org.collectionspace.services.common.document.DocumentHandler; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.util.HttpResponseCodes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/accounts") +@Consumes("multipart/mixed") +@Produces("multipart/mixed") +public class AccountResource + extends AbstractCollectionSpaceResource { + + final private String serviceName = "accounts"; + final Logger logger = LoggerFactory.getLogger(AccountResource.class); + + @Override + public String getServiceName() { + return serviceName; + } + + @Override + public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception { + throw new IllegalStateException(); + } + + @POST + public Response createAccount(MultipartInput input) { + try { + RemoteServiceContext ctx = createServiceContext(input); + String csid = ""; + UriBuilder path = UriBuilder.fromResource(AccountResource.class); + path.path("" + csid); + Response response = Response.created(path.build()).build(); + return response; + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in createAccount", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + @GET + @Path("{csid}") + public MultipartOutput getAccount( + @PathParam("csid") String csid) { + if (logger.isDebugEnabled()) { + logger.debug("getAccount with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("getAccount: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Account csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + RemoteServiceContext ctx = createServiceContext(null); + + result = ctx.getOutput(); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getAccount", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Account csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getAccount", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested Account CSID:" + csid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + @GET + @Produces("application/xml") + public AccountsCommonList getAccountList(@Context UriInfo ui) { + AccountsCommonList accountList = new AccountsCommonList(); + try { + RemoteServiceContext ctx = createServiceContext(null); + + accountList = null; + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getAccountList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return accountList; + } + + @PUT + @Path("{csid}") + public MultipartOutput updateAccount( + @PathParam("csid") String csid, + MultipartInput theUpdate) { + if (logger.isDebugEnabled()) { + logger.debug("updateAccount with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("updateAccount: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on Account csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + RemoteServiceContext ctx = createServiceContext(theUpdate); + + result = ctx.getOutput(); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caugth exception in updateAccount", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on Account csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + @DELETE + @Path("{csid}") + public Response deleteAccount(@PathParam("csid") String csid) { + + if (logger.isDebugEnabled()) { + logger.debug("deleteAccount with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("deleteAccount: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on Account csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try { + ServiceContext ctx = createServiceContext(null); + + return Response.status(HttpResponseCodes.SC_OK).build(); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caught exception in deleteAccount", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed on Account csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + + } +} 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 new file mode 100644 index 000000000..d76d73473 --- /dev/null +++ b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java @@ -0,0 +1,104 @@ +/** + * 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.account.AccountsCommon; +import org.collectionspace.services.account.AccountsCommonList; +import org.collectionspace.services.common.document.AbstractDocumentHandler; +import org.collectionspace.services.common.document.DocumentWrapper; + + +/** + * + * @author + */ +public class AccountDocumentHandler + extends AbstractDocumentHandler { + + @Override + public void handleCreate(DocumentWrapper wrapDoc) throws Exception { + } + + @Override + public void handleUpdate(DocumentWrapper wrapDoc) throws Exception { + } + + @Override + public void handleGet(DocumentWrapper wrapDoc) throws Exception { + } + + @Override + public void handleGetAll(DocumentWrapper wrapDoc) throws Exception { + } + + @Override + public void extractAllParts(DocumentWrapper wrapDoc) + throws Exception { + } + + @Override + public void fillAllParts(DocumentWrapper wrapDoc) + throws Exception { + } + + @Override + public AccountsCommon extractCommonPart(DocumentWrapper wrapDoc) + throws Exception { + return null; + } + + @Override + public void fillCommonPart(AccountsCommon obj, DocumentWrapper wrapDoc) + throws Exception { + } + + @Override + public AccountsCommonList extractCommonPartList(DocumentWrapper wrapDoc) + throws Exception { + return null; + } + + @Override + public AccountsCommon getCommonPart() { + return null; + } + + @Override + public void setCommonPart(AccountsCommon obj) { + } + + @Override + public AccountsCommonList getCommonPartList() { + return null; + } + + @Override + public void setCommonPartList(AccountsCommonList obj) { + } + + @Override + public String getQProperty(String prop) { + return null; + } +} 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 new file mode 100644 index 000000000..c90280fad --- /dev/null +++ b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountHandlerFactory.java @@ -0,0 +1,55 @@ +/** + * 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.ClientType; +import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.document.DocumentHandlerFactory; + +/** + * CollectionObjectHandlerFactory creates handlers for collectionobject based + * on type of Nuxeo client used + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class AccountHandlerFactory implements DocumentHandlerFactory { + + private static final AccountHandlerFactory self = new AccountHandlerFactory(); + + private AccountHandlerFactory() { + } + + public static AccountHandlerFactory getInstance() { + return self; + } + + @Override + public DocumentHandler getHandler(String clientType) { + if(ClientType.JAVA.toString().equals(clientType)){ + return new AccountDocumentHandler(); + } + throw new IllegalArgumentException("Not supported client=" + clientType); + } +} diff --git a/services/account/service/src/test/resources/log4j.xml b/services/account/service/src/test/resources/log4j.xml new file mode 100644 index 000000000..52121cb83 --- /dev/null +++ b/services/account/service/src/test/resources/log4j.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +