]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-245: Stubbed out initial "get next ID for a pattern" functionality in ID Service.
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 26 Jun 2009 15:57:29 +0000 (15:57 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 26 Jun 2009 15:57:29 +0000 (15:57 +0000)
services/id/service/src/main/java/org/collectionspace/services/IDResource.java
services/id/service/src/main/java/org/collectionspace/services/IDService.java
services/id/service/src/main/java/org/collectionspace/services/IDServiceNuxeoImpl.java

index dfc5be2863cb7831418371f80055edb867c377c1..82140940ba8459c9e2dcae569091682934e0731f 100644 (file)
  * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
  */
  
+ // @TODO: Add Javadoc comments.
+ // @TODO: Remove unused import statements.
+ // @TODO: Replace wildcarded import statement for
+ // org.collectionspace.services.id.* with class-specific
+ // import statements.
  package org.collectionspace.services;
 
 import java.util.Iterator;
@@ -48,26 +56,60 @@ import org.dom4j.Element;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@Path("/idpatterns") // Think long and hard about this ...
+@Path("/ids")
 @Consumes("application/xml")
 @Produces("application/xml")
 public class IDResource {
 
        final Logger logger = LoggerFactory.getLogger(IDResource.class);
 
-       // This should be a DI wired by a container like Spring, Seam, or EJB3
-       // final static CollectionObjectService service = new CollectionObjectServiceNuxeoImpl();
+       // Richard's comment in the CollectionObject Resource class, from which
+       // this class was derived: This should be a DI wired by a container like
+       // Spring, Seam, or EJB3.
+       final static IDService service = new IDServiceJdbcImpl();
 
        public IDResource() {
                // do nothing
        }
 
-  // Retrieve the next ID 
+  // Retrieve the next available ID associated with a specified pattern.
+  //
+  // @TODO: We're currently using simple integer IDs.  We'll need to
+  // handle both CSIDs, and URIs or another identifier type that we select,
+  // for uniquely identifying IDPatterns.
        @GET
-       @Path("/{csid}/ids/next")
+       @Path("/next/patterns/{id}")
+       // @TODO: Temporary during testing; to be changed to return XML
   @Produces("text/plain")
-       public String getCollectionObject(@PathParam("csid") String csid) {
-    return "foo"; // placeholder
+       public Response getNextID(@PathParam("csid") String csid) {
+       
+               Response response = null;
+               String nextId = "";
+               String msg = "";
+       
+               try {
+               
+                       nextId = service.nextID(csid);
+               
+               // @TODO: An IllegalStateException often indicates an overflow
+               // of an IDPart.  Consider whether returning a 400 Bad Request
+               // status code is warranted, or whether returning some other
+               // status would be more appropriate.
+               } catch (IllegalStateException ise) {
+                       response = Response.status(Response.Status.BAD_REQUEST)
+                               .entity(ise.getMessage()).type("text/plain").build();
+                               
+               } catch (IllegalArgumentException iae) {
+                       response = Response.status(Response.Status.BAD_REQUEST)
+                               .entity(iae.getMessage()).type("text/plain").build();
+                               
+               } catch (Exception e) {
+                       response = Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+                               .entity(e.getMessage()).type("text/plain").build();
+               }
+               
+    return response;
+    
   }
 
 /*
index 903ccd6b2b561ffdc0126391d6e065a22ab605ce..d0b9a60776f88ad4d4be7ec4a3c38fb27b29dc8d 100644 (file)
@@ -29,7 +29,33 @@ import org.collectionspace.services.id.IDServiceNuxeoImpl;
 
 public interface IDService {
 
-       public final static String ID_SCHEMA_NAME = "id"; // Note to self: Where is this used?
+       // public final static String ID_SCHEMA_NAME = "id"; // Note to self: Where is this used?
+
+       // ----------------------------------------
+       // IDs
+       // ----------------------------------------
+
+       // Create
+
+       // Read single object
+       public String nextID(String csid) throws IllegalArgumentException, IllegalStateException;
+       
+       // Read a list of objects (aka read multiple)
+       
+       // ----------------------------------------
+       // ID Patterns
+       // ----------------------------------------
+       
+       // Create
+       
+       // Read single object
+       
+       // Read a list of objects (aka read multiple)
+       
+       // Update
+       
+       // Delete (possibly not permitted - deactivate instead?)
+       
 
 /*
        // Create
index feea99c029b87c2a7b617ebd9dd3aec78b988af9..d50cde5aeaaba9aae6a8d7895bc834366edc4c56 100644 (file)
@@ -4,6 +4,8 @@
  * Implementation of Nuxeo-specific portions of the ID Service,
  * such as storing and retrieving documents from the Nuxeo repository.
  *
+ * NOTE: Placeholder class - not currently used.
+ *
  * Copyright 2009 Regents of the University of California
  *
  * Licensed under the Educational Community License (ECL), Version 2.0.
@@ -19,7 +21,7 @@
  * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
  */
  
-package org.collectionspace.services.id;
+package org.collectionspace.services;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -38,7 +40,7 @@ import org.dom4j.DocumentException;
 import org.dom4j.io.SAXReader;
 // import org.restlet.resource.Representation;
 
-public class IDServiceNuxeoImpl { // implements IDService {
+public class IDServiceNuxeoImpl {      // implements IDService {
 
   // Placeholder constructor.
   public void IDServiceNuxeoImpl() {