]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-332: Majority of this task is now finished. Need to qualify with more testing...
authorRichard Millet <richard.millet@berkeley.edu>
Sat, 8 Aug 2009 07:00:16 +0000 (07:00 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Sat, 8 Aug 2009 07:00:16 +0000 (07:00 +0000)
19 files changed:
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectConstants.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/relation/RelationsManager.java
services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationUtilsNuxeoImpl.java
services/common/src/main/java/org/collectionspace/services/common/repository/DocumentHandler.java
services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/rest/RepositoryRESTClient.java
services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java
services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeConstants.java
services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java
services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeRepresenationHandler.java
services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java [new file with mode: 0644]
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationNuxeoConstants.java
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationServiceNuxeoImpl.java

index 0b7505a51d8ed0d397032d5179754ee6dfdfeead..cff244d51ba0959df432b5ad9dba83aa9fc0a4da 100644 (file)
@@ -55,7 +55,7 @@ public class CollectionObjectResource {
             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);
index 9911f424496dc9f8bdc765127872152daaf38675..b93c269751ee93f04b0b4d4b9bb46c1dc3736625 100644 (file)
@@ -29,8 +29,8 @@ package org.collectionspace.services.collectionobject.nuxeo;
  */
 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";
     
 }
index 263c36afc4405d3dadcdba6a2b6c1396f6af0450..4e593f19d042016e7e456e3d85ce273fba63fbc2 100644 (file)
@@ -25,6 +25,8 @@ package org.collectionspace.services.collectionobject.nuxeo;
 
 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;
@@ -132,7 +134,7 @@ public class CollectionObjectDocumentModelHandler
         //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){
@@ -205,6 +207,10 @@ public class CollectionObjectDocumentModelHandler
     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
@@ -212,7 +218,7 @@ public class CollectionObjectDocumentModelHandler
      * @return
      */
     private String getQProperty(String prop) {
-        return CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME + ":" + prop;
+        return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop;
     }
 }
 
index db1e31fea0d4348a3a3caabf8ef4e05232c667b9..44dd741a3e9a04b8d1c8c0a2b9504f6f5764af35 100644 (file)
@@ -26,12 +26,15 @@ package org.collectionspace.services.collectionobject.nuxeo;
 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;
@@ -73,42 +76,42 @@ public class CollectionObjectRepresenationHandler
         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());
         }
     }
@@ -135,7 +138,7 @@ public class CollectionObjectRepresenationHandler
                 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());
@@ -232,6 +235,10 @@ public class CollectionObjectRepresenationHandler
     public void setCommonObjectList(CollectionObjectList obj) {
         this.collectionObjectList = obj;
     }
+    
+    public String getDocumentType() {
+       return CollectionObjectConstants.NUXEO_DOCTYPE;
+    }
 
     /**
      * getQProperty converts the given property to qualified schema property
@@ -239,7 +246,7 @@ public class CollectionObjectRepresenationHandler
      * @return
      */
     private String getQProperty(String prop) {
-        return CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME + ":" + prop;
+        return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop;
     }
 }
 
index 95e1cfde8a1ceb420b514489d013b9c0e268fb69..0a944c9c256479385024fa1a2e116aac169a102d 100644 (file)
@@ -38,15 +38,6 @@ import org.dom4j.Document;
 \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
@@ -54,15 +45,13 @@ public class RelationsManager {
        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
@@ -70,7 +59,7 @@ public class RelationsManager {
        }\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
@@ -87,18 +76,14 @@ public class RelationsManager {
        }\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
@@ -125,6 +110,13 @@ public class RelationsManager {
                                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
index 115994d9a7fadcab2ea01f27c9a4aa218048571a..eb963480f3c8e404330977e665e9fa43252f1bda 100644 (file)
@@ -29,6 +29,7 @@ package org.collectionspace.services.common.relation.nuxeo;
 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
@@ -37,7 +38,9 @@ import org.collectionspace.services.common.relation.RelationListItemJAXBSchema;
 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
@@ -66,6 +69,8 @@ public class RelationUtilsNuxeoImpl implements RelationUtils {
        \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
@@ -128,6 +133,44 @@ public class RelationUtilsNuxeoImpl implements RelationUtils {
                }\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
@@ -364,7 +407,10 @@ public class RelationUtilsNuxeoImpl implements RelationUtils {
                \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
@@ -419,6 +465,16 @@ public class RelationUtilsNuxeoImpl implements RelationUtils {
                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
@@ -435,12 +491,12 @@ public class RelationUtilsNuxeoImpl implements RelationUtils {
        }\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
@@ -465,6 +521,15 @@ public class RelationUtilsNuxeoImpl implements RelationUtils {
                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
@@ -504,6 +569,18 @@ public class RelationUtilsNuxeoImpl implements RelationUtils {
                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
@@ -534,6 +611,14 @@ public class RelationUtilsNuxeoImpl implements RelationUtils {
                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
index 3dc2b7fbb6a30f370f163729348a3a97f5cf08af..f3f3e251226646fc2565190ebf592e003fa5c826 100644 (file)
@@ -153,6 +153,13 @@ public interface DocumentHandler<T, TL> {
      * @throws DocumentException
      */
     public Document getDocument(DocumentWrapper docWrap) throws DocumentException;
+    
+    /**
+     * Gets the document type.
+     * 
+     * @return the document type
+     */
+    public String getDocumentType();
 
     /**
      * getProperties
index a5a7e8335e45e0fc63b77c6de7d1af5f6769d981..167261501a3672a6665ea804b1611b092d7e0219 100644 (file)
@@ -47,7 +47,7 @@ public interface RepositoryClient {
      * @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
index 9738000c8f29d8240c1b99b63ac4164f1203c3fc..3bb10b3955aecf129e8e6983eea1d487315112b3 100644 (file)
@@ -150,7 +150,13 @@ public abstract class DocumentModelHandler<T, TL>
         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
      */
index 3831c45658d57be452c3195c5bab294e7671b516..330661c0763a212cafacc5bcde6cdbf76494e9ce 100644 (file)
@@ -36,275 +36,316 @@ import org.slf4j.Logger;
 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
+               }
+       }
 }
index ec755214a6ced46b0c6f5cac4b8acb3ef00619db..9a762fd1d92a6b5f6fe0471c3f85657f19ca3a83 100644 (file)
@@ -78,11 +78,11 @@ public class RepositoryRESTClient implements RepositoryClient {
     }
 
     @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){
@@ -106,9 +106,9 @@ public class RepositoryRESTClient implements RepositoryClient {
                 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());
             }
index 028f7f5da9c83e4acaa070a816bf30f8470bacde..d7189ccd8ce8c5ba88e05d055d845400b2ff86cf 100644 (file)
@@ -78,7 +78,7 @@ public class IntakeResource {
             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);
index 306f7a8e899956d56a5796e21b659df25dda7ad9..0c9d3cf66b2f9a757afc2fe2d3f6a6a2c08d6482 100644 (file)
@@ -29,7 +29,7 @@ package org.collectionspace.services.intake.nuxeo;
  */
 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";
 }
index ae87f96845ba215382b5681942f9e9fb17b8337e..0d0c55355ee9105edd082f15d7201769a02cdad4 100644 (file)
@@ -25,12 +25,15 @@ package org.collectionspace.services.intake.nuxeo;
 
 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;
@@ -144,7 +147,7 @@ public class IntakeDocumentModelHandler
         //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){
@@ -229,13 +232,20 @@ public class IntakeDocumentModelHandler
         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;
     }
 }
 
index 720022cfe6a616e283b5fad3cf537bcea7a7c631..1723126f6b52b588cbe14126cb1e90d893d90be3 100644 (file)
@@ -72,52 +72,52 @@ public class IntakeRepresenationHandler
         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());
         }
     }
@@ -144,7 +144,7 @@ public class IntakeRepresenationHandler
                 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());
@@ -248,13 +248,20 @@ public class IntakeRepresenationHandler
         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;
     }
 }
 
diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java
new file mode 100644 (file)
index 0000000..f77645f
--- /dev/null
@@ -0,0 +1,243 @@
+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);
+    }
+}
index d88983c0c2ab917a8ec40eb6c1b1c6b61838cec1..0bb0abe5998d1c9ca7c09495b64ec94c38ec05bb 100644 (file)
@@ -26,13 +26,14 @@ package org.collectionspace.services.relation.nuxeo;
 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;
@@ -103,17 +104,18 @@ public class RelationDocumentModelHandler
     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
@@ -130,17 +132,17 @@ public class RelationDocumentModelHandler
             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 {
index e67a951e0de5f3828e80a02e16616afcbd76d5f0..cc974846fa991c50d626aa42dadf468c728d727e 100644 (file)
@@ -1,4 +1,7 @@
 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
index e3c6127b8d89aa69476d5a62f836b49dd078756f..85273c21148e2f0a39b94e2487789651a1093dd4 100644 (file)
@@ -68,8 +68,7 @@ import org.nuxeo.ecm.core.api.DocumentRef;
 \r
 \r
 /**\r
- * @author remillet\r
- * \r
+ * The Class RelationServiceNuxeoImpl.\r
  */\r
 public class RelationServiceNuxeoImpl extends\r
                CollectionSpaceServiceNuxeoImpl implements RelationService {\r
@@ -77,15 +76,8 @@ public class RelationServiceNuxeoImpl extends
        // 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
@@ -108,15 +100,8 @@ public class RelationServiceNuxeoImpl extends
                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
@@ -145,13 +130,8 @@ public class RelationServiceNuxeoImpl extends
                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
@@ -215,15 +195,8 @@ public class RelationServiceNuxeoImpl extends
                }\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
@@ -254,16 +227,8 @@ public class RelationServiceNuxeoImpl extends
                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