CollectionObjectHandlerFactory handlerFactory = CollectionObjectHandlerFactory.getInstance();
DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
handler.setCommonObject(collectionObject);
- csid = client.create(CO_SERVICE_NAME, CollectionObjectConstants.CO_NUXEO_DOCTYPE, handler);
+ csid = client.create(CO_SERVICE_NAME, handler);
collectionObject.setCsid(csid);
if(logger.isDebugEnabled()){
verbose("createCollectionObject: ", collectionObject);
*/
public class CollectionObjectConstants {
- public final static String CO_NUXEO_DOCTYPE = "CollectionObject";
- public final static String CO_NUXEO_SCHEMA_NAME = "collectionobject";
- public final static String CO_NUXEO_DC_TITLE = "CollectionSpace-CollectionObject";
+ public final static String NUXEO_DOCTYPE = "CollectionObject";
+ public final static String NUXEO_SCHEMA_NAME = "collectionobject";
+ public final static String NUXEO_DC_TITLE = "CollectionSpace-CollectionObject";
}
import java.util.Iterator;
import java.util.List;
+
+import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectConstants;
import org.collectionspace.services.CollectionObjectJAXBSchema;
import org.collectionspace.services.collectionobject.CollectionObject;
import org.collectionspace.services.collectionobject.CollectionObjectList;
//so it does not require hard coding
// a default title for the Dublin Core schema
- docModel.setPropertyValue("dublincore:title", CollectionObjectConstants.CO_NUXEO_DC_TITLE);
+ docModel.setPropertyValue("dublincore:title", CollectionObjectConstants.NUXEO_DC_TITLE);
// CollectionObject core values
if(co.getObjectNumber() != null){
public void fillCommonObjectList(CollectionObjectList obj, DocumentWrapper wrapDoc) throws Exception {
throw new UnsupportedOperationException();
}
+
+ public String getDocumentType() {
+ return CollectionObjectConstants.NUXEO_DOCTYPE;
+ }
/**
* getQProperty converts the given property to qualified schema property
* @return
*/
private String getQProperty(String prop) {
- return CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME + ":" + prop;
+ return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop;
}
}
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+
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.common.repository.DocumentWrapper;
import org.collectionspace.services.nuxeo.client.rest.RepresentationHandler;
+import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectConstants;
+
import org.dom4j.Document;
import org.dom4j.Element;
import org.slf4j.Logger;
CollectionObject co = getCommonObject();
// todo: intelligent merge needed
if(co.getObjectNumber() != null){
- queryParams.put(CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME +
+ queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
":" + CollectionObjectJAXBSchema.OBJECT_NUMBER, co.getObjectNumber());
}
if(co.getOtherNumber() != null){
- queryParams.put(CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME +
+ queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
":" + CollectionObjectJAXBSchema.OTHER_NUMBER, co.getOtherNumber());
}
if(co.getBriefDescription() != null){
- queryParams.put(CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME +
+ queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
":" + CollectionObjectJAXBSchema.BRIEF_DESCRIPTION, co.getBriefDescription());
}
if(co.getComments() != null){
- queryParams.put(CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME +
+ queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
":" + CollectionObjectJAXBSchema.COMMENTS, co.getComments());
}
if(co.getDistFeatures() != null){
- queryParams.put(CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME +
+ queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
":" + CollectionObjectJAXBSchema.DIST_FEATURES, co.getDistFeatures());
}
if(co.getObjectName() != null){
- queryParams.put(CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME +
+ queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
":" + CollectionObjectJAXBSchema.OBJECT_NAME, co.getObjectName());
}
if(co.getResponsibleDept() != null){
- queryParams.put(CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME +
+ queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
":" + CollectionObjectJAXBSchema.RESPONSIBLE_DEPT, co.getResponsibleDept());
}
if(co.getTitle() != null){
- queryParams.put(CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME +
+ queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
":" + CollectionObjectJAXBSchema.TITLE, co.getTitle());
}
}
logger.debug("getCommonObject() populating Common Object");
}
// TODO: recognize schema thru namespace uri
- if(CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME.equals(schemaElement.attribute("name").getValue())){
+ if(CollectionObjectConstants.NUXEO_SCHEMA_NAME.equals(schemaElement.attribute("name").getValue())){
Element ele = schemaElement.element(CollectionObjectJAXBSchema.OBJECT_NUMBER);
if(ele != null){
co.setObjectNumber((String) ele.getData());
public void setCommonObjectList(CollectionObjectList obj) {
this.collectionObjectList = obj;
}
+
+ public String getDocumentType() {
+ return CollectionObjectConstants.NUXEO_DOCTYPE;
+ }
/**
* getQProperty converts the given property to qualified schema property
* @return
*/
private String getQProperty(String prop) {
- return CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME + ":" + prop;
+ return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop;
}
}
\r
/**\r
* The Class RelationsManager.\r
- * \r
- * This class loosely uses the RDF terms subject, predicate, object to describe\r
- * relationships between entity objects. For example, if a CollectionObject entity named\r
- * CO#1 is related to a Intake entity named IN#1 then the corresponding\r
- * RDF-like term would be: (Subject) CO#1 (Predicate) has-intake (Object) IN#1.\r
- * \r
- * Many of the methods below, refer to RDF-like terms such as "Subject" and "Object" and\r
- * "Predicate."\r
- * \r
*/\r
public class RelationsManager {\r
\r
static private RelationUtils relationUtils = new RelationUtilsNuxeoImpl();\r
\r
/**\r
- * Gets the ALL relationships in the system.\r
+ * Gets the relationships.\r
* \r
- * @param repoSession\r
- * the repo session\r
+ * @param repoSession the repo session\r
* \r
* @return the relationships\r
* \r
- * @throws DocumentException\r
- * the document exception\r
+ * @throws DocumentException the document exception\r
*/\r
static public List<Relation> getRelationships(Object repoSession)\r
throws DocumentException {\r
}\r
\r
/**\r
- * Gets the relationships. Null values act as wild card and match everything.\r
+ * Gets the relationships.\r
* \r
* @param repoSession the repo session\r
* @param subjectCsid the subject csid\r
}\r
\r
/**\r
- * Gets the relationships for the entity corresponding to the CSID=csid.\r
- * The csid refers to either the subject OR the object\r
+ * Gets the relationships.\r
* \r
- * @param repoSession\r
- * the repo session\r
- * @param csid\r
- * the csid\r
+ * @param repoSession the repo session\r
+ * @param csid the csid\r
* \r
* @return the relationships\r
* \r
- * @throws DocumentException\r
- * the document exception\r
+ * @throws DocumentException the document exception\r
*/\r
static public List<Relation> getRelationships(Object repoSession,\r
String csid) throws DocumentException {\r
predicate, objectCsid);\r
}\r
\r
+ /**\r
+ * Gets the q property name.\r
+ * \r
+ * @param propertyName the property name\r
+ * \r
+ * @return the q property name\r
+ */\r
static public String getQPropertyName(String propertyName) {\r
return relationUtils.getQPropertyName(propertyName);\r
}\r
import java.io.IOException;\r
import java.io.Serializable;\r
import java.util.ArrayList;\r
+import java.util.Iterator;\r
import java.util.List;\r
import java.util.Map;\r
\r
import org.collectionspace.services.common.relation.RelationUtils;\r
\r
import org.collectionspace.services.relation.Relation;\r
+import org.collectionspace.services.relation.RelationList;\r
import org.collectionspace.services.relation.RelationshipType;\r
+import org.collectionspace.services.relation.RelationList.RelationListItem;\r
import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
import org.collectionspace.services.common.repository.DocumentException;\r
\r
\r
/** The C s_ relatio n_ servic e_ name. */\r
static public String CS_RELATION_SERVICE_NAME = "relations";\r
+ \r
+ /** The C s_ empt y_ string. */\r
static public String CS_EMPTY_STRING = "";\r
\r
/** The Constant REL_NUXEO_DOCTYPE. */\r
}\r
}\r
\r
+ /**\r
+ * Fill relation list item from doc model.\r
+ * \r
+ * @param relationListItem the relation list item\r
+ * @param relDocModel the rel doc model\r
+ * \r
+ * @throws DocumentException the document exception\r
+ */\r
+ static public void fillRelationListItemFromDocModel(RelationListItem relationListItem,\r
+ DocumentModel relDocModel)\r
+ throws DocumentException {\r
+\r
+ try {\r
+ relationListItem.setUri(\r
+ relDocModel.getId());\r
+ relationListItem.setCsid(\r
+ getRelURL(CS_RELATION_SERVICE_NAME, relDocModel.getId()));\r
+ } catch (Exception e) {\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Caught exception in fillRelationListItemFromDocModel", e);\r
+ }\r
+ throw new DocumentException(e);\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Fill doc model list from relation list.\r
+ * \r
+ * @param relationList the relation list\r
+ * @param relDocModelList the rel doc model list\r
+ * \r
+ * @throws Exception the exception\r
+ */\r
+ static public void fillDocModelListFromRelationList(RelationList relationList,\r
+ DocumentModelList relDocModelList)\r
+ throws Exception {\r
+ } \r
+ \r
/**\r
* Fill doc model from relation.\r
* \r
\r
return result;\r
}\r
- \r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.common.relation.RelationUtils#getQPropertyName(java.lang.String)\r
+ */\r
public String getQPropertyName(String propertyName) {\r
return "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/" + propertyName;\r
}\r
return result;\r
}\r
\r
+ /**\r
+ * Checks if is predicate of relation.\r
+ * \r
+ * @param predicate the predicate\r
+ * @param documentModel the document model\r
+ * \r
+ * @return true, if is predicate of relation\r
+ * \r
+ * @throws ClientException the client exception\r
+ */\r
private boolean isPredicateOfRelation(String predicate,\r
DocumentModel documentModel) throws ClientException {\r
boolean result = false;\r
}\r
\r
/**\r
- * Gets the object ID from of the (Subject-Predicate-Object) relationship.\r
+ * Gets the object from subject.\r
* \r
- * @param csid the ID of the 'Subject' (Subject-Predicate-Object)\r
- * @param documentModel represents the relation entry.\r
+ * @param csid the csid\r
+ * @param documentModel the document model\r
* \r
- * @return the object csid of the relationship\r
+ * @return the object from subject\r
* \r
* @throws ClientException the client exception\r
*/\r
return result;\r
}\r
\r
+ /**\r
+ * Gets the document.\r
+ * \r
+ * @param relationList the relation list\r
+ * \r
+ * @return the document\r
+ * \r
+ * @throws DocumentException the document exception\r
+ */\r
static public Document getDocument(List<Relation> relationList)\r
throws DocumentException {\r
DOMDocumentFactory domfactory = new DOMDocumentFactory();\r
return result;\r
}\r
\r
+ /**\r
+ * Checks if is query match.\r
+ * \r
+ * @param documentModel the document model\r
+ * @param subjectCsid the subject csid\r
+ * @param predicate the predicate\r
+ * @param objectCsid the object csid\r
+ * \r
+ * @return true, if is query match\r
+ * \r
+ * @throws ClientException the client exception\r
+ */\r
private boolean isQueryMatch(DocumentModel documentModel,\r
String subjectCsid,\r
String predicate,\r
return result;\r
}\r
\r
+ /**\r
+ * Gets the rel url.\r
+ * \r
+ * @param repo the repo\r
+ * @param uuid the uuid\r
+ * \r
+ * @return the rel url\r
+ */\r
private static String getRelURL(String repo, String uuid) {\r
return '/' + repo + '/' + uuid;\r
} \r
* @throws DocumentException
*/
public Document getDocument(DocumentWrapper docWrap) throws DocumentException;
+
+ /**
+ * Gets the document type.
+ *
+ * @return the document type
+ */
+ public String getDocumentType();
/**
* getProperties
* @throws BadRequestException data input is bad
* @throws DocumentException
*/
- String create(String serviceName, String docType, DocumentHandler handler) throws BadRequestException, DocumentException;
+ String create(String serviceName, DocumentHandler handler) throws BadRequestException, DocumentException;
/**
* delete a document from the Document repository
DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
return NuxeoUtils.getDocument(getRepositorySession(), docModel);
}
-
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.common.repository.DocumentHandler#getDocumentType()
+ */
+ @Override
+ public abstract String getDocumentType();
+
/**
* @return the properties
*/
import org.slf4j.LoggerFactory;
/**
- * RepositoryJavaClient is used to perform CRUD operations on documents
- * in Nuxeo repository using Remote Java APIs. It uses @see DocumentHandler
- * as IOHandler with the client.
- *
- * $LastChangedRevision: $
- * $LastChangedDate: $
+ * RepositoryJavaClient is used to perform CRUD operations on documents in Nuxeo
+ * repository using Remote Java APIs. It uses @see DocumentHandler as IOHandler
+ * with the client.
+ *
+ * $LastChangedRevision: $ $LastChangedDate: $
*/
public class RepositoryJavaClient implements RepositoryClient {
- private final Logger logger = LoggerFactory.getLogger(RepositoryJavaClient.class);
+ private final Logger logger = LoggerFactory
+ .getLogger(RepositoryJavaClient.class);
- public RepositoryJavaClient() {
- }
+ public RepositoryJavaClient() {
+ }
- /**
- * create document in the Nuxeo repository
- * @param serviceName entity service for which document is created. this is used to find mapping
- * to a Nuxeo workspace using service-config.xml
- * @param docType of the document created
- * @param handler should be used by the caller to provide and transform the document
- * @return id in repository of the newly created document
- * @throws DocumentException
- */
- @Override
- public String create(String serviceName, String docType, DocumentHandler handler) throws BadRequestException, DocumentException {
+ /**
+ * create document in the Nuxeo repository
+ *
+ * @param serviceName
+ * entity service for which document is created. this is used to
+ * find mapping to a Nuxeo workspace using service-config.xml
+ * @param docType
+ * of the document created
+ * @param handler
+ * should be used by the caller to provide and transform the
+ * document
+ * @return id in repository of the newly created document
+ * @throws DocumentException
+ */
+ @Override
+ public String create(String serviceName,
+ DocumentHandler handler) throws BadRequestException,
+ DocumentException {
- if(serviceName == null){
- throw new IllegalArgumentException("RemoteRepositoryClient.create: serviceName is missing");
- }
- if(docType == null){
- throw new IllegalArgumentException("RemoteRepositoryClient.create: docType is missing");
- }
- if(handler == null){
- throw new IllegalArgumentException("RemoteRepositoryClient.create: handler is missing");
- }
- ServiceMain smain = ServiceMain.getInstance();
- String nuxeoWspaceId = smain.getWorkspaceId(serviceName);
- if(nuxeoWspaceId == null){
- throw new DocumentNotFoundException("Unable to find workspace for service " + serviceName +
- " check if the mapping exists in service-config.xml or " +
- " the the mapped workspace exists in the Nuxeo repository");
- }
- RepositoryInstance repoSession = null;
- try{
- handler.prepare(Action.CREATE);
- repoSession = getRepositorySession();
+ if (serviceName == null) {
+ throw new IllegalArgumentException(
+ "RemoteRepositoryClient.create: serviceName is missing");
+ }
+ if (handler.getDocumentType() == null) {
+ throw new IllegalArgumentException(
+ "RemoteRepositoryClient.create: docType is missing");
+ }
+ if (handler == null) {
+ throw new IllegalArgumentException(
+ "RemoteRepositoryClient.create: handler is missing");
+ }
+ ServiceMain smain = ServiceMain.getInstance();
+ String nuxeoWspaceId = smain.getWorkspaceId(serviceName);
+ if (nuxeoWspaceId == null) {
+ throw new DocumentNotFoundException(
+ "Unable to find workspace for service "
+ + serviceName
+ + " check if the mapping exists in service-config.xml or "
+ + " the the mapped workspace exists in the Nuxeo repository");
+ }
+ RepositoryInstance repoSession = null;
+ try {
+ handler.prepare(Action.CREATE);
+ repoSession = getRepositorySession();
- DocumentRef nuxeoWspace = new IdRef(nuxeoWspaceId);
- DocumentModel wspaceDoc = repoSession.getDocument(nuxeoWspace);
- String wspacePath = wspaceDoc.getPathAsString();
- String id = IdUtils.generateId("New " + docType);
- //create document model
- DocumentModel doc = repoSession.createDocumentModel(wspacePath, id, docType);
- ((DocumentModelHandler) handler).setRepositorySession(repoSession);
- DocumentModelWrapper wrapDoc = new DocumentModelWrapper(doc);
- handler.handle(Action.CREATE, wrapDoc);
- //create document with documentmodel
- doc = repoSession.createDocument(doc);
- repoSession.save();
- return doc.getId();
- }catch(Exception e){
- if(logger.isDebugEnabled()){
- logger.debug("Caught exception ", e);
- }
- throw new DocumentException(e);
- }finally{
- if(repoSession != null){
- releaseRepositorySession(repoSession);
- }
- }
+ DocumentRef nuxeoWspace = new IdRef(nuxeoWspaceId);
+ DocumentModel wspaceDoc = repoSession.getDocument(nuxeoWspace);
+ String wspacePath = wspaceDoc.getPathAsString();
+ String id = IdUtils.generateId("New " + handler.getDocumentType());
+ // create document model
+ DocumentModel doc = repoSession.createDocumentModel(wspacePath, id,
+ handler.getDocumentType());
+ ((DocumentModelHandler) handler).setRepositorySession(repoSession);
+ DocumentModelWrapper wrapDoc = new DocumentModelWrapper(doc);
+ handler.handle(Action.CREATE, wrapDoc);
+ // create document with documentmodel
+ doc = repoSession.createDocument(doc);
+ repoSession.save();
+ return doc.getId();
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ } finally {
+ if (repoSession != null) {
+ releaseRepositorySession(repoSession);
+ }
+ }
- }
+ }
- /**
- * get document from the Nuxeo repository
- * @param id of the document to retrieve
- * @param handler should be used by the caller to provide and transform the document
- * @throws DocumentException
- */
- @Override
- public void get(String id, DocumentHandler handler) throws DocumentNotFoundException, DocumentException {
+ /**
+ * get document from the Nuxeo repository
+ *
+ * @param id
+ * of the document to retrieve
+ * @param handler
+ * should be used by the caller to provide and transform the
+ * document
+ * @throws DocumentException
+ */
+ @Override
+ public void get(String id, DocumentHandler handler)
+ throws DocumentNotFoundException, DocumentException {
- if(handler == null){
- throw new IllegalArgumentException("RemoteRepositoryClient.get: handler is missing");
- }
- RepositoryInstance repoSession = null;
+ if (handler == null) {
+ throw new IllegalArgumentException(
+ "RemoteRepositoryClient.get: handler is missing");
+ }
+ RepositoryInstance repoSession = null;
- try{
- handler.prepare(Action.GET);
- repoSession = getRepositorySession();
- DocumentRef docRef = new IdRef(id);
- DocumentModel doc = null;
- try{
- doc = repoSession.getDocument(docRef);
- }catch(ClientException ce){
- String msg = "could not find document with id=" + id;
- logger.error(msg, ce);
- throw new DocumentNotFoundException(msg, ce);
- }
- ((DocumentModelHandler) handler).setRepositorySession(repoSession);
- DocumentModelWrapper wrapDoc = new DocumentModelWrapper(doc);
- handler.handle(Action.GET, wrapDoc);
- }catch(IllegalArgumentException iae) {
- throw iae;
- }catch(DocumentException de){
- throw de;
- }catch(Exception e){
- if(logger.isDebugEnabled()){
- logger.debug("Caught exception ", e);
- }
- throw new DocumentException(e);
- }finally{
- if(repoSession != null){
- releaseRepositorySession(repoSession);
- }
- }
- }
+ try {
+ handler.prepare(Action.GET);
+ repoSession = getRepositorySession();
+ DocumentRef docRef = new IdRef(id);
+ DocumentModel doc = null;
+ try {
+ doc = repoSession.getDocument(docRef);
+ } catch (ClientException ce) {
+ String msg = "could not find document with id=" + id;
+ logger.error(msg, ce);
+ throw new DocumentNotFoundException(msg, ce);
+ }
+ ((DocumentModelHandler) handler).setRepositorySession(repoSession);
+ DocumentModelWrapper wrapDoc = new DocumentModelWrapper(doc);
+ handler.handle(Action.GET, wrapDoc);
+ } catch (IllegalArgumentException iae) {
+ throw iae;
+ } catch (DocumentException de) {
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ } finally {
+ if (repoSession != null) {
+ releaseRepositorySession(repoSession);
+ }
+ }
+ }
- /**
- * getAll get all documents for an entity entity service from the Nuxeo repository
- * @param serviceName entity service for which documents are retrieved. this is used to find mapping
- * to a Nuxeo workspace using service-config.xml
- * @param handler should be used by the caller to provide and transform the document
- * @throws DocumentException
- */
- @Override
- public void getAll(String serviceName, DocumentHandler handler) throws DocumentNotFoundException, DocumentException {
- if(serviceName == null){
- throw new IllegalArgumentException("RemoteRepositoryClient.getAll: serviceName is missing");
- }
- if(handler == null){
- throw new IllegalArgumentException("RemoteRepositoryClient.getAll: handler is missing");
- }
- ServiceMain smain = ServiceMain.getInstance();
- String nuxeoWspaceId = smain.getWorkspaceId(serviceName);
- if(nuxeoWspaceId == null){
- throw new DocumentNotFoundException("Unable to find workspace for service " + serviceName +
- " check if the mapping exists in service-config.xml or " +
- " the the mapped workspace exists in the Nuxeo repository");
- }
- RepositoryInstance repoSession = null;
+ /**
+ * getAll get all documents for an entity entity service from the Nuxeo
+ * repository
+ *
+ * @param serviceName
+ * entity service for which documents are retrieved. this is used
+ * to find mapping to a Nuxeo workspace using service-config.xml
+ * @param handler
+ * should be used by the caller to provide and transform the
+ * document
+ * @throws DocumentException
+ */
+ @Override
+ public void getAll(String serviceName, DocumentHandler handler)
+ throws DocumentNotFoundException, DocumentException {
+ if (serviceName == null) {
+ throw new IllegalArgumentException(
+ "RemoteRepositoryClient.getAll: serviceName is missing");
+ }
+ if (handler == null) {
+ throw new IllegalArgumentException(
+ "RemoteRepositoryClient.getAll: handler is missing");
+ }
+ ServiceMain smain = ServiceMain.getInstance();
+ String nuxeoWspaceId = smain.getWorkspaceId(serviceName);
+ if (nuxeoWspaceId == null) {
+ throw new DocumentNotFoundException(
+ "Unable to find workspace for service "
+ + serviceName
+ + " check if the mapping exists in service-config.xml or "
+ + " the the mapped workspace exists in the Nuxeo repository");
+ }
+ RepositoryInstance repoSession = null;
- try{
- handler.prepare(Action.GET_ALL);
- repoSession = getRepositorySession();
- DocumentRef wsDocRef = new IdRef(nuxeoWspaceId);
- DocumentModelList docList = repoSession.getChildren(wsDocRef);
+ try {
+ handler.prepare(Action.GET_ALL);
+ repoSession = getRepositorySession();
+ DocumentRef wsDocRef = new IdRef(nuxeoWspaceId);
+ DocumentModelList docList = repoSession.getChildren(wsDocRef);
- ((DocumentModelHandler) handler).setRepositorySession(repoSession);
- DocumentModelListWrapper wrapDoc = new DocumentModelListWrapper(docList);
- handler.handle(Action.GET_ALL, wrapDoc);
-
- }catch(DocumentException de){
- throw de;
- }catch(Exception e){
- if(logger.isDebugEnabled()){
- logger.debug("Caught exception ", e);
- }
- throw new DocumentException(e);
- }finally{
- if(repoSession != null){
- releaseRepositorySession(repoSession);
- }
- }
- }
+ ((DocumentModelHandler) handler).setRepositorySession(repoSession);
+ DocumentModelListWrapper wrapDoc = new DocumentModelListWrapper(
+ docList);
+ handler.handle(Action.GET_ALL, wrapDoc);
- /**
- * update given document in the Nuxeo repository
- * @param id of the document
- * @param handler should be used by the caller to provide and transform the document
- * @throws DocumentException
- */
- @Override
- public void update(String id, DocumentHandler handler) throws BadRequestException, DocumentNotFoundException, DocumentException {
- if(id == null){
- throw new BadRequestException("RemoteRepositoryClient.update: id is missing");
- }
- if(handler == null){
- throw new IllegalArgumentException("RemoteRepositoryClient.update: handler is missing");
- }
- RepositoryInstance repoSession = null;
- try{
- handler.prepare(Action.UPDATE);
- repoSession = getRepositorySession();
- DocumentRef docRef = new IdRef(id);
- DocumentModel doc = null;
- try{
- doc = repoSession.getDocument(docRef);
- }catch(ClientException ce){
- String msg = "Could not find document to update with id=" + id;
- logger.error(msg, ce);
- throw new DocumentNotFoundException(msg, ce);
- }
- ((DocumentModelHandler) handler).setRepositorySession(repoSession);
- DocumentModelWrapper wrapDoc = new DocumentModelWrapper(doc);
- handler.handle(Action.UPDATE, wrapDoc);
- repoSession.saveDocument(doc);
- repoSession.save();
- }catch(DocumentException de){
- throw de;
- }catch(Exception e){
- if(logger.isDebugEnabled()){
- logger.debug("Caught exception ", e);
- }
- throw new DocumentException(e);
- }finally{
- if(repoSession != null){
- releaseRepositorySession(repoSession);
- }
- }
- }
+ } catch (DocumentException de) {
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ } finally {
+ if (repoSession != null) {
+ releaseRepositorySession(repoSession);
+ }
+ }
+ }
- /**
- * delete a document from the Nuxeo repository
- * @param id of the document
- * @throws DocumentException
- */
- @Override
- public void delete(String id) throws DocumentNotFoundException, DocumentException {
+ /**
+ * update given document in the Nuxeo repository
+ *
+ * @param id
+ * of the document
+ * @param handler
+ * should be used by the caller to provide and transform the
+ * document
+ * @throws DocumentException
+ */
+ @Override
+ public void update(String id, DocumentHandler handler)
+ throws BadRequestException, DocumentNotFoundException,
+ DocumentException {
+ if (id == null) {
+ throw new BadRequestException(
+ "RemoteRepositoryClient.update: id is missing");
+ }
+ if (handler == null) {
+ throw new IllegalArgumentException(
+ "RemoteRepositoryClient.update: handler is missing");
+ }
+ RepositoryInstance repoSession = null;
+ try {
+ handler.prepare(Action.UPDATE);
+ repoSession = getRepositorySession();
+ DocumentRef docRef = new IdRef(id);
+ DocumentModel doc = null;
+ try {
+ doc = repoSession.getDocument(docRef);
+ } catch (ClientException ce) {
+ String msg = "Could not find document to update with id=" + id;
+ logger.error(msg, ce);
+ throw new DocumentNotFoundException(msg, ce);
+ }
+ ((DocumentModelHandler) handler).setRepositorySession(repoSession);
+ DocumentModelWrapper wrapDoc = new DocumentModelWrapper(doc);
+ handler.handle(Action.UPDATE, wrapDoc);
+ repoSession.saveDocument(doc);
+ repoSession.save();
+ } catch (DocumentException de) {
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ } finally {
+ if (repoSession != null) {
+ releaseRepositorySession(repoSession);
+ }
+ }
+ }
- if(logger.isDebugEnabled()){
- logger.debug("deleting document with id=" + id);
- }
- RepositoryInstance repoSession = null;
- try{
- repoSession = getRepositorySession();
- DocumentRef docRef = new IdRef(id);
- try{
- repoSession.removeDocument(docRef);
- }catch(ClientException ce){
- String msg = "could not find document to delete with id=" + id;
- logger.error(msg, ce);
- throw new DocumentNotFoundException(msg, ce);
- }
- repoSession.save();
- }catch(DocumentException de){
- throw de;
- }catch(Exception e){
- if(logger.isDebugEnabled()){
- logger.debug("Caught exception ", e);
- }
- throw new DocumentException(e);
- }finally{
- if(repoSession != null){
- releaseRepositorySession(repoSession);
- }
- }
- }
+ /**
+ * delete a document from the Nuxeo repository
+ *
+ * @param id
+ * of the document
+ * @throws DocumentException
+ */
+ @Override
+ public void delete(String id) throws DocumentNotFoundException,
+ DocumentException {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleting document with id=" + id);
+ }
+ RepositoryInstance repoSession = null;
+ try {
+ repoSession = getRepositorySession();
+ DocumentRef docRef = new IdRef(id);
+ try {
+ repoSession.removeDocument(docRef);
+ } catch (ClientException ce) {
+ String msg = "could not find document to delete with id=" + id;
+ logger.error(msg, ce);
+ throw new DocumentNotFoundException(msg, ce);
+ }
+ repoSession.save();
+ } catch (DocumentException de) {
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ } finally {
+ if (repoSession != null) {
+ releaseRepositorySession(repoSession);
+ }
+ }
+ }
- private RepositoryInstance getRepositorySession() throws Exception {
- //FIXME: is it possible to reuse repository session?
- //Authentication failures happen while trying to reuse the session
- NuxeoClient client = NuxeoConnector.getInstance().getClient();
- RepositoryInstance repoSession = client.openRepository();
- if(logger.isDebugEnabled()){
- logger.debug("getRepository() repository root: " +
- repoSession.getRootDocument());
- }
- return repoSession;
- }
+ private RepositoryInstance getRepositorySession() throws Exception {
+ // FIXME: is it possible to reuse repository session?
+ // Authentication failures happen while trying to reuse the session
+ NuxeoClient client = NuxeoConnector.getInstance().getClient();
+ RepositoryInstance repoSession = client.openRepository();
+ if (logger.isDebugEnabled()) {
+ logger.debug("getRepository() repository root: "
+ + repoSession.getRootDocument());
+ }
+ return repoSession;
+ }
- private void releaseRepositorySession(RepositoryInstance repoSession) {
- try{
- NuxeoClient client = NuxeoConnector.getInstance().getClient();
- //release session
- client.releaseRepository(repoSession);
- }catch(Exception e){
- logger.error("Could not close the repository session", e);
- //no need to throw this service specific exception
- }
- }
+ private void releaseRepositorySession(RepositoryInstance repoSession) {
+ try {
+ NuxeoClient client = NuxeoConnector.getInstance().getClient();
+ // release session
+ client.releaseRepository(repoSession);
+ } catch (Exception e) {
+ logger.error("Could not close the repository session", e);
+ // no need to throw this service specific exception
+ }
+ }
}
}
@Override
- public String create(String serviceName, String docType, DocumentHandler handler) throws BadRequestException, DocumentException {
+ public String create(String serviceName, DocumentHandler handler) throws BadRequestException, DocumentException {
if(serviceName == null){
throw new IllegalArgumentException("RepositoryRESTClient.create: serviceName is missing");
}
- if(docType == null){
+ if(handler.getDocumentType() == null){
throw new IllegalArgumentException("RepositoryRESTClient.create: docType is missing");
}
if(handler == null){
pathParams.addAll(repHandler.getPathParams());
}
Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put("docType", docType);
+ queryParams.put("docType", handler.getDocumentType());
// a default title for the Dublin Core schema
- queryParams.put("dublincore:title", "CollectionSpace-" + docType);
+ queryParams.put("dublincore:title", "CollectionSpace-" + handler.getDocumentType());
if(repHandler.getQueryParams().size() > 0){
queryParams.putAll(repHandler.getQueryParams());
}
IntakeHandlerFactory handlerFactory = IntakeHandlerFactory.getInstance();
DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
handler.setCommonObject(intakeObject);
- csid = client.create(INTAKE_SERVICE_NAME, IntakeConstants.INTAKE_NUXEO_DOCTYPE, handler);
+ csid = client.create(INTAKE_SERVICE_NAME, handler);
intakeObject.setCsid(csid);
if(logger.isDebugEnabled()){
verbose("createIntake: ", intakeObject);
*/
public class IntakeConstants {
- public final static String INTAKE_NUXEO_DOCTYPE = "Intake";
- public final static String INTAKE_NUXEO_SCHEMA_NAME = "intake";
- public final static String INTAKE_NUXEO_DC_TITLE = "CollectionSpace-Intake";
+ public final static String NUXEO_DOCTYPE = "Intake";
+ public final static String NUXEO_SCHEMA_NAME = "intake";
+ public final static String NUXEO_DC_TITLE = "CollectionSpace-Intake";
}
import java.util.Iterator;
import java.util.List;
+
import org.collectionspace.services.IntakeJAXBSchema;
import org.collectionspace.services.common.repository.DocumentWrapper;
import org.collectionspace.services.intake.Intake;
import org.collectionspace.services.intake.IntakeList;
import org.collectionspace.services.intake.IntakeList.IntakeListItem;
import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
+import org.collectionspace.services.intake.nuxeo.IntakeConstants;
+
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentModelList;
import org.slf4j.Logger;
//so it does not require hard coding
// a default title for the Dublin Core schema
- docModel.setPropertyValue("dublincore:title", IntakeConstants.INTAKE_NUXEO_DC_TITLE);
+ docModel.setPropertyValue("dublincore:title", IntakeConstants.NUXEO_DC_TITLE);
// intake core values
if(intakeObject.getCurrentOwner() != null){
throw new UnsupportedOperationException();
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getDocumentType()
+ */
+ public String getDocumentType() {
+ return IntakeConstants.NUXEO_DOCTYPE;
+ }
+
/**
* getQProperty converts the given property to qualified schema property
* @param prop
* @return
*/
private String getQProperty(String prop) {
- return IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" + prop;
+ return IntakeConstants.NUXEO_SCHEMA_NAME + ":" + prop;
}
}
Map<String, String> queryParams = getQueryParams();
Intake intakeObject = getCommonObject();
if(intakeObject.getCurrentOwner() != null){
- queryParams.put(IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" +
+ queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
IntakeJAXBSchema.CURRENT_OWNER, intakeObject.getCurrentOwner());
}
if(intakeObject.getDepositor() != null){
- queryParams.put(IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" +
+ queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
IntakeJAXBSchema.DEPOSITOR, intakeObject.getDepositor());
}
if(intakeObject.getDepositorsRequirements() != null){
- queryParams.put(IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" +
+ queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS, intakeObject.getDepositorsRequirements());
}
if(intakeObject.getEntryDate() != null){
- queryParams.put(IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" +
+ queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
IntakeJAXBSchema.ENTRY_DATE, intakeObject.getEntryDate());
}
if(intakeObject.getEntryMethod() != null){
- queryParams.put(IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" +
+ queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
IntakeJAXBSchema.ENTRY_METHOD, intakeObject.getEntryMethod());
}
if(intakeObject.getEntryNote() != null){
- queryParams.put(IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" +
+ queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
IntakeJAXBSchema.ENTRY_NOTE, intakeObject.getEntryNote());
}
if(intakeObject.getEntryNumber() != null){
- queryParams.put(IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" +
+ queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
IntakeJAXBSchema.ENTRY_NUMBER, intakeObject.getEntryNumber());
}
if(intakeObject.getEntryReason() != null){
- queryParams.put(IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" +
+ queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
IntakeJAXBSchema.ENTRY_REASON, intakeObject.getEntryReason());
}
if(intakeObject.getPackingNote() != null){
- queryParams.put(IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" +
+ queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
IntakeJAXBSchema.PACKING_NOTE, intakeObject.getPackingNote());
}
if(intakeObject.getReturnDate() != null){
- queryParams.put(IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" +
+ queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
IntakeJAXBSchema.RETURN_DATE, intakeObject.getReturnDate());
}
}
logger.debug("getCommonObject() populating Common Object");
}
// TODO: recognize schema thru namespace uri
- if(IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME.equals(schemaElement.attribute("name").getValue())){
+ if(IntakeConstants.NUXEO_SCHEMA_NAME.equals(schemaElement.attribute("name").getValue())){
Element ele = schemaElement.element(IntakeJAXBSchema.CURRENT_OWNER);
if(ele != null){
intakeObj.setCurrentOwner((String) ele.getData());
this.intakeList = obj;
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getDocumentType()
+ */
+ public String getDocumentType() {
+ return IntakeConstants.NUXEO_DOCTYPE;
+ }
+
/**
* getQProperty converts the given property to qualified schema property
* @param prop
* @return
*/
private String getQProperty(String prop) {
- return IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" + prop;
+ return IntakeConstants.NUXEO_SCHEMA_NAME + ":" + prop;
}
}
--- /dev/null
+package org.collectionspace.services.relation;
+
+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 javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+import org.collectionspace.services.relation.RelationList.RelationListItem;
+
+import org.collectionspace.services.relation.nuxeo.RelationNuxeoConstants;
+import org.collectionspace.services.relation.nuxeo.RelationHandlerFactory;
+import org.collectionspace.services.common.NuxeoClientType;
+import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.repository.DocumentNotFoundException;
+import org.collectionspace.services.common.repository.DocumentHandler;
+import org.collectionspace.services.common.repository.RepositoryClient;
+import org.collectionspace.services.common.repository.RepositoryClientFactory;
+import org.jboss.resteasy.util.HttpResponseCodes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("/relations")
+@Consumes("application/xml")
+@Produces("application/xml")
+public class NewRelationResource {
+
+ public final static String SERVICE_NAME = "relations";
+ final Logger logger = LoggerFactory.getLogger(NewRelationResource.class);
+ //FIXME retrieve client type from configuration
+ final static NuxeoClientType CLIENT_TYPE = ServiceMain.getInstance().getNuxeoClientType();
+
+ public NewRelationResource() {
+ // do nothing
+ }
+
+ @POST
+ public Response createRelation(
+ Relation relation) {
+
+ String csid = null;
+ try{
+ RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
+ RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
+ RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance();
+ DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
+ handler.setCommonObject(relation);
+ csid = client.create(SERVICE_NAME, handler);
+ relation.setCsid(csid);
+ if(logger.isDebugEnabled()){
+ verbose("createRelation: ", relation);
+ }
+ UriBuilder path = UriBuilder.fromResource(RelationResource.class);
+ path.path("" + csid);
+ Response response = Response.created(path.build()).build();
+ return response;
+ }catch(Exception e){
+ if(logger.isDebugEnabled()){
+ logger.debug("Caught exception in createRelation", 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 Relation getRelation(
+ @PathParam("csid") String csid) {
+ if(logger.isDebugEnabled()){
+ verbose("getRelation with csid=" + csid);
+ }
+ if(csid == null || "".equals(csid)){
+ logger.error("getRelation: missing csid!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "get failed on Relation csid=" + csid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ Relation relation = null;
+ try{
+ RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
+ RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
+ RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance();
+ DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
+ client.get(csid, handler);
+ relation = (Relation) handler.getCommonObject();
+ }catch(DocumentNotFoundException dnfe){
+ if(logger.isDebugEnabled()){
+ logger.debug("getRelation", dnfe);
+ }
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed on Relation csid=" + csid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }catch(Exception e){
+ if(logger.isDebugEnabled()){
+ logger.debug("getRelation", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+
+ if(relation == null){
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed, the requested Relation CSID:" + csid + ": was not found.").type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if(logger.isDebugEnabled()){
+ verbose("getRelation: ", relation);
+ }
+ return relation;
+ }
+
+ @GET
+ public RelationList getRelationList(@Context UriInfo ui) {
+ RelationList relationList = new RelationList();
+ try{
+ RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
+ RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
+ RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance();
+ DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
+ client.getAll(SERVICE_NAME, handler);
+ relationList = (RelationList) handler.getCommonObjectList();
+ }catch(Exception e){
+ if(logger.isDebugEnabled()){
+ logger.debug("Caught exception in getRelationList", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return relationList;
+ }
+
+ @PUT
+ @Path("{csid}")
+ public Relation updateRelation(
+ @PathParam("csid") String csid,
+ Relation theUpdate) {
+ if(logger.isDebugEnabled()){
+ verbose("updateRelation with csid=" + csid);
+ }
+ if(csid == null || "".equals(csid)){
+ logger.error("updateRelation: missing csid!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "update failed on Relation csid=" + csid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if(logger.isDebugEnabled()){
+ verbose("updateRelation with input: ", theUpdate);
+ }
+ try{
+ RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
+ RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
+ RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance();
+ DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
+ handler.setCommonObject(theUpdate);
+ client.update(csid, handler);
+ }catch(DocumentNotFoundException dnfe){
+ if(logger.isDebugEnabled()){
+ logger.debug("caugth exception in updateRelation", dnfe);
+ }
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Update failed on Relation 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 theUpdate;
+ }
+
+ @DELETE
+ @Path("{csid}")
+ public Response deleteRelation(@PathParam("csid") String csid) {
+
+ if(logger.isDebugEnabled()){
+ verbose("deleteRelation with csid=" + csid);
+ }
+ if(csid == null || "".equals(csid)){
+ logger.error("deleteRelation: missing csid!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "delete failed on Relation csid=" + csid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ try{
+ RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
+ RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
+ client.delete(csid);
+ return Response.status(HttpResponseCodes.SC_OK).build();
+ }catch(DocumentNotFoundException dnfe){
+ if(logger.isDebugEnabled()){
+ logger.debug("caught exception in deleteRelation", dnfe);
+ }
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Delete failed on Relation 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);
+ }
+
+ }
+
+ private void verbose(String msg, Relation relation) {
+ try{
+ verbose(msg);
+ JAXBContext jc = JAXBContext.newInstance(
+ Relation.class);
+
+ Marshaller m = jc.createMarshaller();
+ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+ m.marshal(relation, System.out);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ }
+
+ private void verbose(String msg) {
+ System.out.println("RelationResource. " + msg);
+ }
+}
import java.util.Iterator;
import java.util.List;
import org.collectionspace.services.common.relation.RelationJAXBSchema;
-//import org.collectionspace.services.common.relation.nuxeo.RelationUtilsNuxeoImpl;
+import org.collectionspace.services.common.relation.nuxeo.RelationUtilsNuxeoImpl;
import org.collectionspace.services.common.relation.RelationsManager;
import org.collectionspace.services.relation.Relation;
import org.collectionspace.services.relation.RelationList;
import org.collectionspace.services.relation.RelationList.RelationListItem;
+import org.collectionspace.services.relation.nuxeo.RelationNuxeoConstants;
import org.collectionspace.services.common.repository.DocumentWrapper;
import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
import org.nuxeo.ecm.core.api.DocumentModel;
public Relation extractCommonObject(DocumentWrapper wrapDoc)
throws Exception {
DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
- Relation co = new Relation();
+ Relation theRelation = new Relation();
+
+ RelationUtilsNuxeoImpl.fillRelationFromDocModel(theRelation, docModel);
- return co;
+ return theRelation;
}
@Override
- public void fillCommonObject(Relation co, DocumentWrapper wrapDoc) throws Exception {
+ public void fillCommonObject(Relation relation, DocumentWrapper wrapDoc) throws Exception {
DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
- //FIXME property setter should be dynamically set using schema inspection
- //so it does not require hard coding
+ RelationUtilsNuxeoImpl.fillDocModelFromRelation(relation, docModel);
}
@Override
DocumentModel docModel = iter.next();
RelationListItem coListItem = new RelationListItem();
- coListItem.setCsid((String) docModel.getPropertyValue(
- getQProperty(RelationJAXBSchema.DOCUMENT_ID_1)));
+ RelationUtilsNuxeoImpl.fillRelationListItemFromDocModel(coListItem, docModel);
- //need fully qualified context for URI
- coListItem.setUri("/relations/" + docModel.getId());
- coListItem.setCsid(docModel.getId());
list.add(coListItem);
}
return coList;
}
+
+ public String getDocumentType() {
+ return RelationNuxeoConstants.NUXEO_DOCTYPE;
+ }
@Override
public void fillCommonObjectList(RelationList obj, DocumentWrapper wrapDoc) throws Exception {
package org.collectionspace.services.relation.nuxeo;\r
\r
+import org.collectionspace.services.common.relation.nuxeo.RelationUtilsNuxeoImpl;\r
+\r
public class RelationNuxeoConstants {\r
+ static String NUXEO_DOCTYPE = RelationUtilsNuxeoImpl.REL_NUXEO_DOCTYPE;\r
}
\ No newline at end of file
\r
\r
/**\r
- * @author remillet\r
- * \r
+ * The Class RelationServiceNuxeoImpl.\r
*/\r
public class RelationServiceNuxeoImpl extends\r
CollectionSpaceServiceNuxeoImpl implements RelationService {\r
// replace WORKSPACE_UID for resource workspace\r
// static String CS_RELATION_WORKSPACE_UID = "55f99358-5dbe-4462-8000-c5c3c2063919";\r
\r
- /**\r
- * Delete relation.\r
- * \r
- * @param csid the csid\r
- * \r
- * @return the document\r
- * \r
- * @throws DocumentException the document exception\r
- * @throws IOException Signals that an I/O exception has occurred.\r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.relation.RelationService#deleteRelation(java.lang.String)\r
*/\r
public Document deleteRelation(String csid) throws DocumentException {\r
Document result = null;\r
return result;\r
}\r
\r
- /**\r
- * Gets the relation.\r
- * \r
- * @param csid the csid\r
- * \r
- * @return the relation\r
- * \r
- * @throws DocumentException the document exception\r
- * @throws IOException Signals that an I/O exception has occurred.\r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.relation.RelationService#getRelation(java.lang.String)\r
*/\r
public Document getRelation(String csid)\r
throws DocumentException, IOException {\r
return result;\r
}\r
\r
- /**\r
- * Gets the relation list.\r
- * \r
- * @return the relation list\r
- * \r
- * @throws DocumentException the document exception\r
- * @throws IOException Signals that an I/O exception has occurred.\r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.relation.RelationService#getRelationList()\r
*/\r
public Document getRelationList()\r
throws DocumentException, IOException {\r
}\r
\r
// Create a new relation document\r
- /**\r
- * Post relation.\r
- * \r
- * @param co the co\r
- * \r
- * @return the document\r
- * \r
- * @throws DocumentException the document exception\r
- * @throws IOException Signals that an I/O exception has occurred.\r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.relation.RelationService#postRelation(org.collectionspace.services.relation.Relation)\r
*/\r
public Document postRelation(Relation co) throws DocumentException,\r
IOException {\r
return result;\r
}\r
\r
- /**\r
- * Put relation.\r
- * \r
- * @param csid the csid\r
- * @param theUpdate the the update\r
- * \r
- * @return the document\r
- * \r
- * @throws DocumentException the document exception\r
- * @throws IOException Signals that an I/O exception has occurred.\r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.relation.RelationService#putRelation(java.lang.String, org.collectionspace.services.relation.Relation)\r
*/\r
public Document putRelation(String csid, Relation theUpdate)\r
throws DocumentException, IOException {\r