]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-173, CSPACE-325 more refactoring. Pushed down all the handleXXX methods. Added...
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Fri, 24 Jul 2009 23:34:29 +0000 (23:34 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Fri, 24 Jul 2009 23:34:29 +0000 (23:34 +0000)
services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectRepresenationHandler.java
services/common/src/main/java/org/collectionspace/services/common/repository/DocumentHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/rest/RepresentationHandler.java

index f9d778bd7f8cb0cd43c0eb53386fba121b3863b5..ff4ed014e88c299edbc1be9dca34524bad25b9a1 100644 (file)
@@ -50,6 +50,8 @@ public class CollectionObjectServiceTest {
     public void updateCollectionObject() {
         ClientResponse<CollectionObject> res = collectionObjectClient.getCollectionObject(updateId);
         verbose("getCollectionObject: status = " + res.getStatus());
+        Assert.assertEquals(res.getStatus(), Response.Status.OK.getStatusCode());
+        
         CollectionObject collectionObject = res.getEntity();
         verbose("Got CollectionObject to update with ID: " + updateId,
                 collectionObject, CollectionObject.class);
@@ -61,6 +63,8 @@ public class CollectionObjectServiceTest {
         // make call to update service
         res = collectionObjectClient.updateCollectionObject(updateId, collectionObject);
         verbose("updateCollectionObject: status = " + res.getStatus());
+        Assert.assertEquals(res.getStatus(), Response.Status.OK.getStatusCode());
+
         // check the response
         CollectionObject updatedCollectionObject = res.getEntity();
         Assert.assertEquals(updatedCollectionObject.getObjectName(), collectionObject.getObjectName());
@@ -82,6 +86,7 @@ public class CollectionObjectServiceTest {
         ClientResponse<CollectionObjectList> res = collectionObjectClient.getCollectionObjectList();
         CollectionObjectList coList = res.getEntity();
         verbose("getCollectionObjectList: status = " + res.getStatus());
+        Assert.assertEquals(res.getStatus(), Response.Status.OK.getStatusCode());
 
         List<CollectionObjectList.CollectionObjectListItem> coItemList = coList.getCollectionObjectListItem();
         int i = 0;
index 25daff72bca3d57d639e539c09b7d7d2ef142211..0b7505a51d8ed0d397032d5179754ee6dfdfeead 100644 (file)
@@ -46,7 +46,7 @@ public class CollectionObjectResource {
 
     @POST
     public Response createCollectionObject(
-            CollectionObject co) {
+            CollectionObject collectionObject) {
 
         String csid = null;
         try{
@@ -54,11 +54,11 @@ public class CollectionObjectResource {
             RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
             CollectionObjectHandlerFactory handlerFactory = CollectionObjectHandlerFactory.getInstance();
             DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
-            handler.setCommonObject(co);
+            handler.setCommonObject(collectionObject);
             csid = client.create(CO_SERVICE_NAME, CollectionObjectConstants.CO_NUXEO_DOCTYPE, handler);
-            co.setCsid(csid);
+            collectionObject.setCsid(csid);
             if(logger.isDebugEnabled()){
-                verbose("createCollectionObject: ", co);
+                verbose("createCollectionObject: ", collectionObject);
             }
             UriBuilder path = UriBuilder.fromResource(CollectionObjectResource.class);
             path.path("" + csid);
@@ -69,7 +69,7 @@ public class CollectionObjectResource {
                 logger.debug("Caught exception in createCollectionObject", e);
             }
             Response response = Response.status(
-                    Response.Status.INTERNAL_SERVER_ERROR).entity("Crate failed").type("text/plain").build();
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
             throw new WebApplicationException(response);
         }
     }
@@ -88,14 +88,14 @@ public class CollectionObjectResource {
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
-        CollectionObject co = null;
+        CollectionObject collectionObject = null;
         try{
             RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
             RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
             CollectionObjectHandlerFactory handlerFactory = CollectionObjectHandlerFactory.getInstance();
             DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
             client.get(csid, handler);
-            co = (CollectionObject) handler.getCommonObject();
+            collectionObject = (CollectionObject) handler.getCommonObject();
         }catch(DocumentNotFoundException dnfe){
             if(logger.isDebugEnabled()){
                 logger.debug("getCollectionObject", dnfe);
@@ -113,37 +113,37 @@ public class CollectionObjectResource {
             throw new WebApplicationException(response);
         }
 
-        if(co == null){
+        if(collectionObject == null){
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Get failed, the requested CollectionObject CSID:" + csid + ": was not found.").type(
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
         if(logger.isDebugEnabled()){
-            verbose("getCollectionObject: ", co);
+            verbose("getCollectionObject: ", collectionObject);
         }
-        return co;
+        return collectionObject;
     }
 
     @GET
     public CollectionObjectList getCollectionObjectList(@Context UriInfo ui) {
-        CollectionObjectList coList = new CollectionObjectList();
+        CollectionObjectList collectionObjectList = new CollectionObjectList();
         try{
             RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
             RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
             CollectionObjectHandlerFactory handlerFactory = CollectionObjectHandlerFactory.getInstance();
             DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
             client.getAll(CO_SERVICE_NAME, handler);
-            coList = (CollectionObjectList) handler.getCommonObjectList();
+            collectionObjectList = (CollectionObjectList) handler.getCommonObjectList();
         }catch(Exception e){
             if(logger.isDebugEnabled()){
                 logger.debug("Caught exception in getCollectionObjectList", e);
             }
             Response response = Response.status(
-                    Response.Status.INTERNAL_SERVER_ERROR).entity("index failed").type("text/plain").build();
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
             throw new WebApplicationException(response);
         }
-        return coList;
+        return collectionObjectList;
     }
 
     @PUT
@@ -222,7 +222,7 @@ public class CollectionObjectResource {
 
     }
 
-    private void verbose(String msg, CollectionObject co) {
+    private void verbose(String msg, CollectionObject collectionObject) {
         try{
             verbose(msg);
             JAXBContext jc = JAXBContext.newInstance(
@@ -230,7 +230,7 @@ public class CollectionObjectResource {
 
             Marshaller m = jc.createMarshaller();
             m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
-            m.marshal(co, System.out);
+            m.marshal(collectionObject, System.out);
         }catch(Exception e){
             e.printStackTrace();
         }
index 80d6314086e88280d57b4f9929758d17f9cdf541..263c36afc4405d3dadcdba6a2b6c1396f6af0450 100644 (file)
@@ -62,78 +62,6 @@ public class CollectionObjectDocumentModelHandler
         //no specific action needed
     }
 
-    @Override
-    public void handle(Action action, DocumentWrapper wrapDoc) throws Exception {
-        switch(action){
-            case CREATE:
-                handleCreate(wrapDoc);
-                break;
-            case UPDATE:
-                handleUpdate(wrapDoc);
-                break;
-            case GET:
-                handleGet(wrapDoc);
-                break;
-            case GET_ALL:
-                handleGetAll(wrapDoc);
-                break;
-        }
-    }
-
-    /**
-     * handleCreate processes create operation response
-     * @param wrapDoc
-     * @throws Exception
-     */
-    public void handleCreate(DocumentWrapper wrapDoc) throws Exception {
-        CollectionObject co = getCommonObject();
-        if(co == null){
-            String msg = "Error creating document: Missing input data";
-            logger.error(msg);
-            throw new IllegalStateException(msg);
-        }
-        //FIXME set other parts as well
-        fillCommonObject(co, wrapDoc);
-    }
-
-    /**
-     * handleUpdate processes update operation response
-     * @param wrapDoc
-     * @throws Exception
-     */
-    public void handleUpdate(DocumentWrapper wrapDoc) throws Exception {
-        CollectionObject co = getCommonObject();
-        if(co == null){
-            String msg = "Error updating document: Missing input data";
-            logger.error(msg);
-            throw new IllegalStateException(msg);
-        }
-        //FIXME set other parts as well
-        fillCommonObject(co, wrapDoc);
-    }
-
-    /**
-     * handleGet processes get operation response
-     * @param wrapDoc
-     * @throws Exception
-     */
-    public void handleGet(DocumentWrapper wrapDoc) throws Exception {
-        CollectionObject co = extractCommonObject(wrapDoc);
-        setCommonObject(co);
-
-        //FIXME retrive other parts as well
-    }
-
-    /**
-     * handleGetAll processes index operation response
-     * @param wrapDoc
-     * @throws Exception
-     */
-    public void handleGetAll(DocumentWrapper wrapDoc) throws Exception {
-        CollectionObjectList coList = extractCommonObjectList(wrapDoc);
-        //FIXME, this is unncessarily called on each call from client
-        setCommonObjectList(coList);
-    }
 
     /**
      * getCommonObject get associated CollectionObject
index dd58dfcf2ac387855b42f9ad42079049cfb345c7..db1e31fea0d4348a3a3caabf8ef4e05232c667b9 100644 (file)
@@ -30,12 +30,10 @@ import org.collectionspace.services.CollectionObjectJAXBSchema;
 import org.collectionspace.services.collectionobject.CollectionObject;
 import org.collectionspace.services.collectionobject.CollectionObjectList;
 import org.collectionspace.services.collectionobject.CollectionObjectList.CollectionObjectListItem;
-import org.collectionspace.services.collectionobject.CollectionObjectService;
 import org.collectionspace.services.common.repository.DocumentWrapper;
 import org.collectionspace.services.nuxeo.client.rest.RepresentationHandler;
 import org.dom4j.Document;
 import org.dom4j.Element;
-import org.nuxeo.ecm.core.api.DocumentModel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -70,78 +68,6 @@ public class CollectionObjectRepresenationHandler
         }
     }
 
-    @Override
-    public void handle(Action action, DocumentWrapper wrapDoc)
-            throws Exception {
-        switch(action){
-            case CREATE:
-                handleCreate(wrapDoc);
-                break;
-            case UPDATE:
-                handleUpdate(wrapDoc);
-                break;
-            case GET:
-                handleGet(wrapDoc);
-                break;
-            case GET_ALL:
-                handleGetAll(wrapDoc);
-                break;
-        }
-    }
-
-    /**
-     * handleCreate processes create operation response
-     * @param wrapDoc
-     * @throws Exception
-     */
-    public void handleCreate(DocumentWrapper wrapDoc) throws Exception {
-        CollectionObject co = getCommonObject();
-        if(co == null){
-            String msg = "Error creating document: Missing input data";
-            logger.error(msg);
-            throw new IllegalStateException(msg);
-        }
-        //FIXME set other parts as well
-        fillCommonObject(co, wrapDoc);
-    }
-
-    /**
-     * handleUpdate processes update operation response
-     * @param wrapDoc
-     * @throws Exception
-     */
-    public void handleUpdate(DocumentWrapper wrapDoc) throws Exception {
-        CollectionObject co = getCommonObject();
-        if(co == null){
-            String msg = "Error updating document: Missing input data";
-            logger.error(msg);
-            throw new IllegalStateException(msg);
-        }
-        //FIXME set other parts as well
-        fillCommonObject(co, wrapDoc);
-    }
-
-    /**
-     * handleGet processes get operation response
-     * @param wrapDoc
-     * @throws Exception
-     */
-    public void handleGet(DocumentWrapper wrapDoc) throws Exception {
-        CollectionObject co = extractCommonObject(wrapDoc);
-        setCommonObject(co);
-        //FIXME retrive other parts as well
-    }
-
-    /**
-     * handleGetAll processes index operation response
-     * @param wrapDoc
-     * @throws Exception
-     */
-    public void handleGetAll(DocumentWrapper wrapDoc) throws Exception {
-        CollectionObjectList coList = extractCommonObjectList(wrapDoc);
-        setCommonObjectList(coList);
-    }
-
     private void prepare() {
         Map<String, String> queryParams = getQueryParams();
         CollectionObject co = getCommonObject();
index 1d92db6c1da702a2de5b3c961370c22502413880..3dc2b7fbb6a30f370f163729348a3a97f5cf08af 100644 (file)
@@ -60,6 +60,34 @@ public interface DocumentHandler<T, TL> {
      */
     public void handle(Action action, DocumentWrapper docWrap) throws Exception;
 
+        /**
+     * handleCreate processes create operation response
+     * @param wrapDoc
+     * @throws Exception
+     */
+    public void handleCreate(DocumentWrapper wrapDoc) throws Exception;
+
+    /**
+     * handleUpdate processes update operation response
+     * @param wrapDoc
+     * @throws Exception
+     */
+    public void handleUpdate(DocumentWrapper wrapDoc) throws Exception;
+
+    /**
+     * handleGet processes get operation response
+     * @param wrapDoc
+     * @throws Exception
+     */
+    public void handleGet(DocumentWrapper wrapDoc) throws Exception;
+
+    /**
+     * handleGetAll processes index operation response
+     * @param wrapDoc
+     * @throws Exception
+     */
+    public void handleGetAll(DocumentWrapper wrapDoc) throws Exception;
+    
     /**
      * extractCommonObject extracts common part of a CS document from given Nuxeo document.
      * @param docWrap nuxeo document
index ada2139e39f477a56d5912aba0fd6ad6ee85dd07..9738000c8f29d8240c1b99b63ac4164f1203c3fc 100644 (file)
@@ -33,6 +33,8 @@ import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.dom4j.Document;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * DocumentModelHandler is a base abstract Nuxeo document handler
@@ -44,6 +46,7 @@ import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
 public abstract class DocumentModelHandler<T, TL>
         implements DocumentHandler<T, TL> {
 
+    private final Logger logger = LoggerFactory.getLogger(DocumentModelHandler.class);
     private Map<String, Object> properties = new HashMap<String, Object>();
     private RepositoryInstance repositorySession;
 
@@ -51,7 +54,56 @@ public abstract class DocumentModelHandler<T, TL>
     public abstract void prepare(Action action) throws Exception;
 
     @Override
-    public abstract void handle(Action action, DocumentWrapper wrap) throws Exception;
+    public void handle(Action action, DocumentWrapper wrapDoc) throws Exception {
+        switch(action){
+            case CREATE:
+                handleCreate(wrapDoc);
+                break;
+            case UPDATE:
+                handleUpdate(wrapDoc);
+                break;
+            case GET:
+                handleGet(wrapDoc);
+                break;
+            case GET_ALL:
+                handleGetAll(wrapDoc);
+                break;
+        }
+    }
+
+    @Override
+    public void handleCreate(DocumentWrapper wrapDoc) throws Exception {
+        if(getCommonObject() == null){
+            String msg = "Error creating document: Missing input data";
+            logger.error(msg);
+            throw new IllegalStateException(msg);
+        }
+        //FIXME set other parts as well
+        fillCommonObject(getCommonObject(), wrapDoc);
+    }
+
+    @Override
+    public void handleUpdate(DocumentWrapper wrapDoc) throws Exception {
+        if(getCommonObject() == null){
+            String msg = "Error updating document: Missing input data";
+            logger.error(msg);
+            throw new IllegalStateException(msg);
+        }
+        //FIXME set other parts as well
+        fillCommonObject(getCommonObject(), wrapDoc);
+    }
+
+    @Override
+    public void handleGet(DocumentWrapper wrapDoc) throws Exception {
+        setCommonObject(extractCommonObject(wrapDoc));
+
+        //FIXME retrive other parts as well
+    }
+
+    @Override
+    public void handleGetAll(DocumentWrapper wrapDoc) throws Exception {
+        setCommonObjectList(extractCommonObjectList(wrapDoc));
+    }
 
     /**
      * getRepositorySession returns Nuxeo Repository Session
index 91828ea18844f835bec150e38be95ae35b2c666a..f2d4b0ce6d1563e80a1db69cf93be697cfca42bc 100644 (file)
@@ -33,6 +33,8 @@ import java.util.List;
 import java.util.Map;
 import org.collectionspace.services.nuxeo.client.*;
 import org.dom4j.Document;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * RepresentationHandler is a base abstract Nuxeo document handler
@@ -44,6 +46,7 @@ import org.dom4j.Document;
 public abstract class RepresentationHandler<T, TL>
         implements DocumentHandler<T, TL> {
 
+    private final Logger logger = LoggerFactory.getLogger(RepresentationHandler.class);
     private Map<String, Object> properties = new HashMap<String, Object>();
     private List<String> pathParams = new ArrayList<String>();
     private Map<String, String> queryParams = new HashMap<String, String>();
@@ -54,7 +57,56 @@ public abstract class RepresentationHandler<T, TL>
     public abstract void prepare(Action action) throws Exception;
 
     @Override
-    public abstract void handle(Action action, DocumentWrapper wrapDoc) throws Exception;
+    public void handle(Action action, DocumentWrapper wrapDoc) throws Exception {
+        switch(action){
+            case CREATE:
+                handleCreate(wrapDoc);
+                break;
+            case UPDATE:
+                handleUpdate(wrapDoc);
+                break;
+            case GET:
+                handleGet(wrapDoc);
+                break;
+            case GET_ALL:
+                handleGetAll(wrapDoc);
+                break;
+        }
+    }
+
+    @Override
+    public void handleCreate(DocumentWrapper wrapDoc) throws Exception {
+        if(getCommonObject() == null){
+            String msg = "Error creating document: Missing input data";
+            logger.error(msg);
+            throw new IllegalStateException(msg);
+        }
+        //FIXME set other parts as well
+        fillCommonObject(getCommonObject(), wrapDoc);
+    }
+
+    @Override
+    public void handleUpdate(DocumentWrapper wrapDoc) throws Exception {
+        if(getCommonObject() == null){
+            String msg = "Error updating document: Missing input data";
+            logger.error(msg);
+            throw new IllegalStateException(msg);
+        }
+        //FIXME set other parts as well
+        fillCommonObject(getCommonObject(), wrapDoc);
+    }
+
+    @Override
+    public void handleGet(DocumentWrapper wrapDoc) throws Exception {
+        setCommonObject(extractCommonObject(wrapDoc));
+
+        //FIXME retrive other parts as well
+    }
+
+    @Override
+    public void handleGetAll(DocumentWrapper wrapDoc) throws Exception {
+        setCommonObjectList(extractCommonObjectList(wrapDoc));
+    }
 
     @Override
     public abstract T extractCommonObject(DocumentWrapper wrapDoc) throws Exception;