From: Sanjay Dalal Date: Fri, 24 Jul 2009 23:34:29 +0000 (+0000) Subject: CSPACE-173, CSPACE-325 more refactoring. Pushed down all the handleXXX methods. Added... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=5a012c8e18d957ab3d7f72645ff5c25cf2720618;p=tmp%2Fjakarta-migration.git CSPACE-173, CSPACE-325 more refactoring. Pushed down all the handleXXX methods. Added assertions for status codes in the test client. --- diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java index f9d778bd7..ff4ed014e 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java @@ -50,6 +50,8 @@ public class CollectionObjectServiceTest { public void updateCollectionObject() { ClientResponse 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 res = collectionObjectClient.getCollectionObjectList(); CollectionObjectList coList = res.getEntity(); verbose("getCollectionObjectList: status = " + res.getStatus()); + Assert.assertEquals(res.getStatus(), Response.Status.OK.getStatusCode()); List coItemList = coList.getCollectionObjectListItem(); int i = 0; diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java index 25daff72b..0b7505a51 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java @@ -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(); } diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java index 80d631408..263c36afc 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java @@ -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 diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectRepresenationHandler.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectRepresenationHandler.java index dd58dfcf2..db1e31fea 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectRepresenationHandler.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectRepresenationHandler.java @@ -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 queryParams = getQueryParams(); CollectionObject co = getCommonObject(); diff --git a/services/common/src/main/java/org/collectionspace/services/common/repository/DocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/repository/DocumentHandler.java index 1d92db6c1..3dc2b7fbb 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/repository/DocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/repository/DocumentHandler.java @@ -60,6 +60,34 @@ public interface DocumentHandler { */ 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 diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index ada2139e3..9738000c8 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -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 implements DocumentHandler { + private final Logger logger = LoggerFactory.getLogger(DocumentModelHandler.class); private Map properties = new HashMap(); private RepositoryInstance repositorySession; @@ -51,7 +54,56 @@ public abstract class DocumentModelHandler 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 diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/rest/RepresentationHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/rest/RepresentationHandler.java index 91828ea18..f2d4b0ce6 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/rest/RepresentationHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/rest/RepresentationHandler.java @@ -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 implements DocumentHandler { + private final Logger logger = LoggerFactory.getLogger(RepresentationHandler.class); private Map properties = new HashMap(); private List pathParams = new ArrayList(); private Map queryParams = new HashMap(); @@ -54,7 +57,56 @@ public abstract class RepresentationHandler 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;