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);
// 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());
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;
@POST
public Response createCollectionObject(
- CollectionObject co) {
+ CollectionObject collectionObject) {
String csid = null;
try{
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);
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);
}
}
"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);
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
}
- private void verbose(String msg, CollectionObject co) {
+ private void verbose(String msg, CollectionObject collectionObject) {
try{
verbose(msg);
JAXBContext jc = JAXBContext.newInstance(
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();
}
//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
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;
}
}
- @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();
*/
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
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
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;
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
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
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>();
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;