]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1081: Relation list should probably include relationship type
authorRichard Millet <richard.millet@berkeley.edu>
Wed, 19 May 2010 07:37:18 +0000 (07:37 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Wed, 19 May 2010 07:37:18 +0000 (07:37 +0000)
CSPACE-1846: Relation Service needs to paginate list results.
CSPACE-602: Update Relations service/manager to use Nuxeo queries instead of "get all" and filter with Java code

15 files changed:
services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java
services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java
services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java
services/common/src/main/java/org/collectionspace/services/common/relation/RelationListItemJAXBSchema.java
services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java
services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java
services/jaxb/src/main/resources/relations_common.xsd
services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java
services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java
services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java
services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java

index e5a15e67c7c4704ad8685459fa8bbe22bcbafd29..4c6d10e6030d68814aaddec37eaa9a540bfcac3b 100644 (file)
@@ -21,48 +21,62 @@ import java.util.ArrayList;
 import java.util.List;\r
 import javax.ws.rs.core.MultivaluedMap;\r
 import org.collectionspace.services.client.IClientQueryParams;\r
-import org.collectionspace.services.common.query.IQueryManager;\r
 import org.collectionspace.services.common.context.ServiceContext;\r
 \r
-//TODO: would be great to not rely on resteasy directly\r
-import org.jboss.resteasy.specimpl.MultivaluedMapImpl;\r
-\r
 /**\r
- * DocumentFilter bundles simple query filtering parameters. \r
- * It is designed to be used with filtered get and search calls to RepositoryClient.\r
- * The values are set up and stored on a DocumentHandler, and\r
- * fetched by a RepositoryClient when calling filtered get methods.\r
+ * The Class DocumentFilter.\r
  */\r
 public class DocumentFilter {\r
 \r
+    /** The Constant DEFAULT_PAGE_SIZE_INIT. */\r
     public static final int DEFAULT_PAGE_SIZE_INIT = 40;\r
+    \r
+    /** The Constant PAGE_SIZE_DEFAULT_PROPERTY. */\r
     public static final String PAGE_SIZE_DEFAULT_PROPERTY = "pageSizeDefault";\r
+    \r
+    /** The default page size. */\r
     public static int defaultPageSize = DEFAULT_PAGE_SIZE_INIT;\r
 \r
+    /** The where clause. */\r
     protected String whereClause;      // Filtering clause. Omit the "WHERE".\r
+    \r
+    /** The start page. */\r
     protected int startPage;           // Pagination offset for list results\r
+    \r
+    /** The page size. */\r
     protected int pageSize;                    // Pagination limit for list results\r
-    private boolean pageSizeDirty = false; // True if default page size explicitly set/overridden\r
-\r
+    \r
     //queryParams is not initialized as it would require a multi-valued map implementation\r
     //unless it is used from opensource lib...this variable holds ref to\r
     //implementation available in JBoss RESTeasy\r
+    /** The query params. */\r
     private MultivaluedMap<String, String> queryParams = null;\r
 \r
     /**\r
-     * ParamBinding encapsulates parameter binding for query\r
+     * The Class ParamBinding.\r
      */\r
     public static class ParamBinding {\r
 \r
+        /** The name. */\r
         private String name;\r
+        \r
+        /** The value. */\r
         private Object value;\r
 \r
-        public ParamBinding(String name, Object value) {\r
-            this.name = name;\r
-            this.value = value;\r
+        /**\r
+         * Instantiates a new param binding.\r
+         *\r
+         * @param theName the name\r
+         * @param theValue the value\r
+         */\r
+        public ParamBinding(String theName, Object theValue) {\r
+            this.name = theName;\r
+            this.value = theValue;\r
         }\r
 \r
         /**\r
+         * Gets the name.\r
+         *\r
          * @return the name\r
          */\r
         public String getName() {\r
@@ -70,13 +84,17 @@ public class DocumentFilter {
         }\r
 \r
         /**\r
-         * @param name the name to set\r
+         * Sets the name.\r
+         *\r
+         * @param theName the new name\r
          */\r
-        public void setName(String name) {\r
-            this.name = name;\r
+        public void setName(String theName) {\r
+            this.name = theName;\r
         }\r
 \r
         /**\r
+         * Gets the value.\r
+         *\r
          * @return the value\r
          */\r
         public Object getValue() {\r
@@ -84,16 +102,18 @@ public class DocumentFilter {
         }\r
 \r
         /**\r
-         * @param value the value to set\r
+         * Sets the value.\r
+         *\r
+         * @param theValue the new value\r
          */\r
-        public void setValue(Object value) {\r
-            this.value = value;\r
+        public void setValue(Object theValue) {\r
+            this.value = theValue;\r
         }\r
     }\r
 \r
     /**\r
      * Instantiates a new document filter.\r
-     * \r
+     *\r
      * @param ctx the ctx\r
      */\r
     public DocumentFilter(ServiceContext ctx) {\r
@@ -101,44 +121,52 @@ public class DocumentFilter {
                 DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY));\r
     }\r
 \r
+    /**\r
+     * Instantiates a new document filter.\r
+     */\r
     public DocumentFilter() {\r
         this("", 0, defaultPageSize);                  // Use empty string for easy concatenation\r
     }\r
 \r
-    public DocumentFilter(String whereClause, int startPage, int pageSize) {\r
-        this.whereClause = whereClause;\r
-        this.startPage = (startPage > 0) ? startPage : 0;\r
-        this.pageSize = (pageSize > 0) ? pageSize : defaultPageSize;\r
+    /**\r
+     * Instantiates a new document filter.\r
+     *\r
+     * @param theWhereClause the the where clause\r
+     * @param theStartPage the the start page\r
+     * @param thePageSize the the page size\r
+     */\r
+    public DocumentFilter(String theWhereClause, int theStartPage, int thePageSize) {\r
+        this.whereClause = theWhereClause;\r
+        this.startPage = (theStartPage > 0) ? theStartPage : 0;\r
+        this.pageSize = (thePageSize > 0) ? thePageSize : defaultPageSize;\r
     }\r
 \r
     /**\r
      * Sets the pagination.\r
-     * \r
-     * @param queryParams the query params\r
+     *\r
+     * @param theQueryParams the the query params\r
      */\r
-    public void setPagination(MultivaluedMap<String, String> queryParams) {\r
+    public void setPagination(MultivaluedMap<String, String> theQueryParams) {\r
         //\r
         // Bail if there are no params\r
         //\r
-        if (queryParams == null) {\r
+        if (theQueryParams == null) {\r
             return;\r
         }\r
-\r
         //\r
         // Set the page size\r
         //\r
         String pageSizeStr = null;\r
-        List<String> list = queryParams.get(IClientQueryParams.PAGE_SIZE_PARAM);\r
+        List<String> list = theQueryParams.get(IClientQueryParams.PAGE_SIZE_PARAM);\r
         if (list != null) {\r
             pageSizeStr = list.get(0);\r
         }\r
         setPageSize(pageSizeStr);\r
-\r
         //\r
         // Set the start page\r
         //\r
         String startPageStr = null;\r
-        list = queryParams.get(IClientQueryParams.START_PAGE_PARAM);\r
+        list = theQueryParams.get(IClientQueryParams.START_PAGE_PARAM);\r
         if (list != null) {\r
             startPageStr = list.get(0);\r
         }\r
@@ -146,100 +174,134 @@ public class DocumentFilter {
     }\r
 \r
     /**\r
-     * @return the current default page size for new DocumentFilter instances\r
+     * Gets the default page size.\r
+     *\r
+     * @return the default page size\r
      */\r
     public static int getDefaultPageSize() {\r
         return defaultPageSize;\r
     }\r
 \r
     /**\r
-     * @param defaultPageSize the working default page size for new DocumentFilter instances\r
+     * Sets the default page size.\r
+     *\r
+     * @param theDefaultPageSize the new default page size\r
      */\r
-    public static void setDefaultPageSize(int defaultPageSize) {\r
-        DocumentFilter.defaultPageSize = defaultPageSize;\r
+    public static void setDefaultPageSize(int theDefaultPageSize) {\r
+        DocumentFilter.defaultPageSize = theDefaultPageSize;\r
     }\r
 \r
     /**\r
-     * @return the WHERE filtering clause\r
+     * Gets the where clause.\r
+     *\r
+     * @return the where clause\r
      */\r
     public String getWhereClause() {\r
         return whereClause;\r
     }\r
 \r
     /**\r
-     * @param whereClause the filtering clause (do not include "WHERE")\r
+     * Sets the where clause.\r
+     *\r
+     * @param theWhereClause the new where clause\r
      */\r
-    public void setWhereClause(String whereClause) {\r
-        this.whereClause = whereClause;\r
+    public void setWhereClause(String theWhereClause) {\r
+        this.whereClause = theWhereClause;\r
     }\r
 \r
-    public void appendWhereClause(String whereClause) {\r
-        String currentClause = getWhereClause();\r
-        if (currentClause != null) {\r
-            String newClause = currentClause.concat(IQueryManager.SEARCH_TERM_SEPARATOR + whereClause);\r
-            this.setWhereClause(newClause);\r
-        }\r
+    /**\r
+     * Append where clause.\r
+     *\r
+     * @param theWhereClause the the where clause\r
+     * @param conjunction the conjunction\r
+     */\r
+    public void appendWhereClause(String theWhereClause, String conjunction) {\r
+       if (theWhereClause != null && theWhereClause.length() > 0) {\r
+               String currentClause = getWhereClause();\r
+               if (currentClause != null) {\r
+                   String newClause = currentClause.concat(conjunction + theWhereClause);\r
+                   this.setWhereClause(newClause);\r
+               } else {\r
+                       this.setWhereClause(theWhereClause);\r
+               }\r
+       }\r
     }\r
 \r
     /**\r
-     * buildWhereClause builds where clause for search query\r
-     * @param queryStrBldr query string to append with where clause\r
-     * @return parameter binding\r
+     * Builds the where for search.\r
+     *\r
+     * @param queryStrBldr the query str bldr\r
+     * @return the list\r
      */\r
     public List<ParamBinding> buildWhereForSearch(StringBuilder queryStrBldr) {\r
         return new ArrayList<ParamBinding>();\r
     }\r
 \r
     /**\r
-     * buildWhereClause builds where clause for get, update or delete\r
-     * @param queryStrBldr query string to append with where clause\r
-     * @return parameter binding\r
+     * Builds the where.\r
+     *\r
+     * @param queryStrBldr the query str bldr\r
+     * @return the list\r
      */\r
     public List<ParamBinding> buildWhere(StringBuilder queryStrBldr) {\r
         return new ArrayList<ParamBinding>();\r
     }\r
 \r
     /**\r
-     * @return the specified (0-based) page offset\r
+     * Gets the start page.\r
+     *\r
+     * @return the start page\r
      */\r
     public int getStartPage() {\r
         return startPage;\r
     }\r
 \r
     /**\r
-     * @param startPage the (0-based) page offset to use\r
+     * Sets the start page.\r
+     *\r
+     * @param theStartPage the new start page\r
      */\r
-    public void setStartPage(int startPage) {\r
-        this.startPage = startPage;\r
+    public void setStartPage(int theStartPage) {\r
+        this.startPage = theStartPage;\r
     }\r
 \r
     /**\r
-     * @return the max number of items to return for list requests\r
+     * Gets the page size.\r
+     *\r
+     * @return the page size\r
      */\r
     public int getPageSize() {\r
         return pageSize;\r
     }\r
 \r
+    /**\r
+     * Gets the page size dirty.\r
+     *\r
+     * @return the page size dirty\r
+     */\r
     public boolean getPageSizeDirty() {\r
         return this.getPageSizeDirty();\r
     }\r
 \r
     /**\r
-     * @param pageSize the max number of items to return for list requests\r
+     * Sets the page size.\r
+     *\r
+     * @param thePageSize the new page size\r
      */\r
-    public void setPageSize(int pageSize) {\r
-        this.pageSize = pageSize;\r
-        this.pageSizeDirty = true; // page size explicity set/overriden\r
+    public void setPageSize(int thePageSize) {\r
+        this.pageSize = thePageSize;\r
     }\r
 \r
     /**\r
-     * @param pageSize the max number of items to return for list requests\r
+     * Sets the page size.\r
+     *\r
+     * @param thePageSizeStr the new page size\r
      */\r
-    public void setPageSize(String pageSizeStr) {\r
-        int pageSize = this.defaultPageSize;\r
-        if (pageSizeStr != null) {\r
+    public void setPageSize(String thePageSizeStr) {\r
+        int newPageSize = DocumentFilter.defaultPageSize;\r
+        if (thePageSizeStr != null) {\r
             try {\r
-                pageSize = Integer.valueOf(pageSizeStr);\r
+               newPageSize = Integer.valueOf(thePageSizeStr);\r
             } catch (NumberFormatException e) {\r
                 //FIXME This should cause a warning in the log file and should result in the\r
                 //FIXME page size being set to the default.  We don't need to throw an exception here.\r
@@ -248,12 +310,12 @@ public class DocumentFilter {
             }\r
         }\r
 \r
-        setPageSize(pageSize);\r
+        setPageSize(newPageSize);\r
     }\r
 \r
     /**\r
      * Sets the start page.\r
-     * \r
+     *\r
      * @param startPageStr the new start page\r
      */\r
     protected void setStartPage(String startPageStr) {\r
@@ -268,18 +330,32 @@ public class DocumentFilter {
     }\r
 \r
     /**\r
-     * @return the offset computed from the startPage and the pageSize\r
+     * Gets the offset.\r
+     *\r
+     * @return the offset\r
      */\r
     public int getOffset() {\r
         return pageSize * startPage;\r
     }\r
 \r
+    /**\r
+     * Adds the query param.\r
+     *\r
+     * @param key the key\r
+     * @param value the value\r
+     */\r
     public void addQueryParam(String key, String value) {\r
         if (queryParams != null) {\r
             queryParams.add(key, value);\r
         }\r
     }\r
 \r
+    /**\r
+     * Gets the query param.\r
+     *\r
+     * @param key the key\r
+     * @return the query param\r
+     */\r
     public List<String> getQueryParam(String key) {\r
         if (queryParams != null) {\r
             return queryParams.get(key);\r
@@ -288,11 +364,21 @@ public class DocumentFilter {
         }\r
     }\r
 \r
+    /**\r
+     * Gets the query params.\r
+     *\r
+     * @return the query params\r
+     */\r
     public MultivaluedMap<String, String> getQueryParams() {\r
         return queryParams;\r
     }\r
 \r
-    public void setQueryParams(MultivaluedMap<String, String> queryParams) {\r
-        this.queryParams = queryParams;\r
+    /**\r
+     * Sets the query params.\r
+     *\r
+     * @param theQueryParams the the query params\r
+     */\r
+    public void setQueryParams(MultivaluedMap<String, String> theQueryParams) {\r
+        this.queryParams = theQueryParams;\r
     }\r
 }\r
index d77dd2b240d8dfc154f8d4912b43b2db1a65203a..3ac1e2742b4ca9609d683805edf42d560796dc81 100644 (file)
@@ -28,14 +28,14 @@ package org.collectionspace.services.common.query;
 \r
 public interface IQueryManager {\r
        \r
-       final static String SEARCH_LIKE = "LIKE";\r
+       final static String SEARCH_TERM_SEPARATOR = " ";\r
+       final static String SEARCH_LIKE = " LIKE ";\r
     final static String SEARCH_TYPE_KEYWORDS = "keywords";\r
     final static String SEARCH_TYPE_KEYWORDS_KW = "kw";\r
     final static String SEARCH_TYPE_PARTIALTERM = "pt";\r
-       final static String ECM_FULLTEXT_LIKE = "ecm:fulltext " + SEARCH_LIKE;\r
-       final static String SEARCH_QUALIFIER_AND = "AND";\r
-       final static String SEARCH_QUALIFIER_OR = "OR";\r
-       final static String SEARCH_TERM_SEPARATOR = " ";\r
+       final static String ECM_FULLTEXT_LIKE = "ecm:fulltext" + SEARCH_TERM_SEPARATOR + SEARCH_LIKE;\r
+       final static String SEARCH_QUALIFIER_AND = SEARCH_TERM_SEPARATOR + "AND" + SEARCH_TERM_SEPARATOR;\r
+       final static String SEARCH_QUALIFIER_OR = SEARCH_TERM_SEPARATOR + "OR" + SEARCH_TERM_SEPARATOR;\r
 \r
        public void execQuery(String queryString);\r
        \r
index 65a8b62f77b0f99c13774faef385d5b96c357892..726d69783d12297688c549a5b177a237d574b074 100644 (file)
@@ -40,11 +40,15 @@ public interface IRelationsManager {
 \r
     /** The Constant SUBJECT. */\r
     static public final String SUBJECT = "subjectCsid";\r
+    static public final String SUBJECT_QP = "sbj";\r
+    \r
     /** The Constant PREDICATE. */\r
     static public final String PREDICATE = "predicate";\r
+    static public final String PREDICATE_QP = "prd";\r
+    \r
     /** The Constant OBJECT. */\r
     static public final String OBJECT = "objectCsid";\r
-\r
+    static public final String OBJECT_QP = "obj";\r
 \r
     /**\r
      * Gets the relationships for the entity corresponding to the CSID=csid.\r
index db7fa908b82eec117ca6cea25e291113e4967c47..c90ed4bd3051154f0a83a4434ed19a74b548b513 100644 (file)
@@ -38,6 +38,7 @@ public interface RelationListItemJAXBSchema {
        final static String CSID = "csid";\r
        \r
        final static String SUBJECT_CSID = "subjectCsid";\r
+       final static String RELATIONSHIP_TYPE = "relationshipType";\r
        final static String OBJECT_CSID = "objectCsid";\r
        \r
        /** The Constant URI. */\r
index 762a32f154253805f3e56d7491f10bf34fd63509..ef9982447a68d1d5405efdf501895a6a4b450880 100644 (file)
@@ -31,7 +31,6 @@ public class RelationConstants {
 
     public final static String NUXEO_DOCTYPE = "Relation";
     public final static String NUXEO_SCHEMA_NAME = "relations_common";
-    public final static String NUXEO_DC_TITLE = "CollectionSpace-Relation";
     /** The Constant REL_NUXEO_SCHEMA_ROOT_ELEMENT. */
     final public static String NUXEO_SCHEMA_ROOT_ELEMENT = "relationtype";
 }
index af2cabd6c1e079c9a1515b0cd16ed03a15987f79..311fc42e6a0e91e70cf36995819f885b75d7ca50 100644 (file)
  */
 package org.collectionspace.services.common.relation.nuxeo;
 
-import java.util.Iterator;
-import java.util.List;
+import java.lang.StringBuilder;
 
-import org.collectionspace.services.common.relation.RelationListItemJAXBSchema;
+import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.common.relation.RelationJAXBSchema;
-import org.collectionspace.services.common.document.DocumentException;
-import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.common.context.ServiceContext;
 
-import org.collectionspace.services.nuxeo.util.NuxeoUtils;
-import org.collectionspace.services.relation.RelationsCommonList;
-import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
-import org.nuxeo.ecm.core.api.DocumentModel;
-import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -48,210 +39,47 @@ import org.slf4j.LoggerFactory;
  */
 public class RelationsUtils {
 
+    /** The Constant logger. */
     private static final Logger logger = LoggerFactory.getLogger(RelationsUtils.class);
 
-    public static RelationsCommonList extractCommonPartList(ServiceContext ctx, DocumentWrapper wrapDoc,
-            String serviceContextPath)
-            throws Exception {
-        DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
-
-        RelationsCommonList relList = new RelationsCommonList();
-        List<RelationsCommonList.RelationListItem> list = relList.getRelationListItem();
-
-        //FIXME: iterating over a long list of documents is not a long term
-        //strategy...need to change to more efficient iterating in future
-        Iterator<DocumentModel> iter = docList.iterator();
-        while (iter.hasNext()) {
-            DocumentModel docModel = iter.next();
-            RelationListItem relationListItem = getRelationListItem(ctx, docModel,
-                    serviceContextPath);
-            list.add(relationListItem);
-        }
-        return relList;
-    }
-
-    public static RelationListItem getRelationListItem(ServiceContext ctx, DocumentModel docModel,
-            String serviceContextPath) throws Exception {
-        RelationListItem relationListItem = new RelationListItem();
-        String id = NuxeoUtils.extractId(docModel.getPathAsString());
-        relationListItem.setCsid(id);
-        relationListItem.setSubjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
-                       RelationJAXBSchema.DOCUMENT_ID_1));
-        relationListItem.setObjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
-                       RelationJAXBSchema.DOCUMENT_ID_2));
-        
-        relationListItem.setUri(serviceContextPath + id);
-        return relationListItem;
-    }
-
-    public static void fillDublinCoreObject(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
-        // a default title for the Dublin Core schema
-        docModel.setPropertyValue("dublincore:title", RelationConstants.NUXEO_DC_TITLE);
-    }
-
-    /**
-     * Checks if is subject of relation.
-     *
-     * @param csid the csid
-     * @param documentModel the document model
-     *
-     * @return true, if is subject of relation
-     *
-     * @throws Exception 
-     */
-    private static boolean isSubjectOfRelation(String csid, DocumentModel documentModel)
-            throws Exception {
-        boolean result = false;
-        Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME, RelationJAXBSchema.DOCUMENT_ID_1);
-        if (valueObject != null && csid != null) {
-            String subjectID = (String) valueObject;
-            result = subjectID.equals(csid);
-        }
-
-        return result;
-    }
-
-    /**
-     * Checks if is object of relation.
-     *
-     * @param csid the csid
-     * @param documentModel the document model
-     *
-     * @return true, if is object of relation
-     *
-     * @throws Exception 
-     */
-    private static boolean isObjectOfRelation(String csid, DocumentModel documentModel)
-            throws Exception {
-        boolean result = false;
-
-        Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
-                RelationJAXBSchema.DOCUMENT_ID_2);
-        if (valueObject != null && csid != null) {
-            String subjectID = (String) valueObject;
-            result = subjectID.equals(csid);
-        }
-
-        return result;
-    }
-
-    /**
-     * Checks if is predicate of relation.
-     *
-     * @param predicate the predicate
-     * @param documentModel the document model
-     *
-     * @return true, if is predicate of relation
-     *
-     * @throws Exception 
-     */
-    private static boolean isPredicateOfRelation(String predicate,
-            DocumentModel documentModel) throws Exception {
-        boolean result = false;
-
-        Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
-                RelationJAXBSchema.RELATIONSHIP_TYPE);
-        if (valueObject != null && predicate != null) {
-            String relationType = (String) valueObject;
-            result = predicate.equalsIgnoreCase(relationType);
-        }
-
-        return result;
-    }
-
     /**
-     * Gets the object from subject.
-     *
-     * @param csid the csid
-     * @param documentModel the document model
+     * Builds the where clause.
      *
-     * @return the object from subject
-     *
-     * @throws Exception 
-     */
-    private static String getObjectFromSubject(String csid, DocumentModel documentModel)
-            throws Exception {
-        String result = null;
-
-        Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
-                RelationJAXBSchema.DOCUMENT_ID_1);
-        if (valueObject != null) {
-            String subjectID = (String) valueObject;
-            if (subjectID.equals(csid) == true) {
-                valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
-                        RelationJAXBSchema.DOCUMENT_ID_2);
-                if (valueObject != null) {
-                    result = (String) valueObject;
-                }
-            }
-        }
-
-        return result;
-    }
-
-    /**
-     * Checks if is query match.
-     *
-     * @param documentModel the document model
-     * @param subjectCsid the subject csid
+     * @param subject the subject
      * @param predicate the predicate
-     * @param objectCsid the object csid
-     *
-     * @return true, if is query match
-     *
-     * @throws ClientException the client exception
-     */
-    public static boolean isQueryMatch(DocumentModel documentModel,
-            String subjectCsid,
-            String predicate,
-            String objectCsid) throws DocumentException {
-        boolean result = true;
-
-        try {
-            block:
-            {
-                if (subjectCsid != null) {
-                    if (isSubjectOfRelation(subjectCsid, documentModel) == false) {
-                        result = false;
-                        break block;
-                    }
-                }
-                if (predicate != null) {
-                    if (isPredicateOfRelation(predicate, documentModel) == false) {
-                        result = false;
-                        break block;
-                    }
-                }
-                if (objectCsid != null) {
-                    if (isObjectOfRelation(objectCsid, documentModel) == false) {
-                        result = false;
-                        break block;
-                    }
-                }
-            }
-        } catch (Exception e) {
-            if (logger.isDebugEnabled() == true) {
-                e.printStackTrace();
-            }
-            throw new DocumentException(e);
-        }
-
-        return result;
-    }
-
-    /**
-     * Gets the rel url.
-     *
-     * @param repo the repo
-     * @param uuid the uuid
-     *
-     * @return the rel url
+     * @param object the object
+     * @return the string
      */
-    private static String getRelURL(String repo, String uuid) {
-        return '/' + repo + '/' + uuid;
+    public static String buildWhereClause(String subject, String predicate, String object) {
+       String result = null;
+       
+       StringBuilder stringBuilder = new StringBuilder();
+       if (subject != null) {
+               stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
+                               RelationJAXBSchema.DOCUMENT_ID_1 + " = " + "'" + subject + "'");
+       }
+       
+       if (predicate != null) {
+               if (stringBuilder.length() > 0) {
+                       stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
+               }
+               stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
+                               RelationJAXBSchema.RELATIONSHIP_TYPE + " = " + "'" + predicate + "'");
+       }
+       
+       if (object != null) {
+               if (stringBuilder.length() > 0) {
+                       stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
+               }
+               stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
+                               RelationJAXBSchema.DOCUMENT_ID_2 + " = " + "'" + object + "'");
+       }
+       
+       if (stringBuilder.length() > 0) {
+               result = stringBuilder.toString();
+       }
+       
+       return result;
     }
 }
 
index 22eaa36b97ea00b5442266e856b9cc5139f108b5..269f7cd82a1bc5c8e8f05db73a970c2004f8ef22 100644 (file)
@@ -44,9 +44,10 @@ import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.service.ObjectPartType;
 import org.collectionspace.services.common.vocabulary.RefNameUtils;
-//import org.collectionspace.services.vocabulary.VocabulariesCommonList;
+
 import org.jboss.resteasy.plugins.providers.multipart.InputPart;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.nuxeo.ecm.core.api.model.PropertyException;
@@ -59,6 +60,8 @@ import org.w3c.dom.Document;
  *
  * $LastChangedRevision: $
  * $LastChangedDate: $
+ * @param <T> 
+ * @param <TL> 
  */
 public abstract class RemoteDocumentModelHandlerImpl<T, TL>
         extends DocumentModelHandler<T, TL> {
index a87112159894084cd791ca8ddbe01831fc65680a..68a2a92fcfe6994bb1bfed6d130e3e1061c4e622 100644 (file)
@@ -33,6 +33,7 @@ import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.document.DocumentWrapperImpl;
 
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
+import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.common.repository.RepositoryClient;
 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
 
@@ -633,6 +634,10 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
             DocumentModelList docList = null;
             String query = buildNXQLQuery(queryContext);
 
+            if (logger.isDebugEnabled()) {
+                logger.debug("Executing NXQL query: " + query.toString());
+            }
+
             // If we have limit and/or offset, then pass true to get totalSize
             // in returned DocumentModelList.
             if ((queryContext.docFilter.getOffset() > 0) || (queryContext.docFilter.getPageSize() > 0)) {
@@ -642,10 +647,6 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
                 docList = repoSession.query(query);
             }
 
-            if (logger.isDebugEnabled()) {
-                logger.debug("Executed NXQL query: " + query.toString());
-            }
-
             //set repoSession to handle the document
             ((DocumentModelHandler) handler).setRepositorySession(repoSession);
             DocumentWrapper<DocumentModelList> wrapDoc = new DocumentWrapperImpl<DocumentModelList>(docList);
@@ -856,7 +857,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
         //
         // Restrict search to the current tenant ID.  Is the domain path filter (above) still needed?
         //
-        query.append("AND " + DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA + ":" +
+        query.append(IQueryManager.SEARCH_QUALIFIER_AND + DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA + ":" +
                        DocumentModelHandler.COLLECTIONSPACE_CORE_TENANTID +
                        " = " + queryContext.tenantId);
         //
@@ -866,12 +867,12 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
         if (whereClause != null && whereClause.length() > 0) {
             // Due to an apparent bug/issue in how Nuxeo translates the NXQL query string
             // into SQL, we need to parenthesize our 'where' clause
-            query.append(" AND " + "(" + whereClause + ")");
+            query.append(IQueryManager.SEARCH_QUALIFIER_AND + "(" + whereClause + ")");
         }
         //
         // Please lookup this use in Nuxeo support and document here
         //
-        query.append(" AND ecm:isProxy = 0");
+        query.append(IQueryManager.SEARCH_QUALIFIER_AND + "ecm:isProxy = 0");
     }
 
     /**
index 7c5a5f80e08d7f57c1f1a9d6487caf30bf24f4e6..e5f739d5bc3a58d729e189c091706cb968374bea 100644 (file)
         <xs:complexType>\r
             <xs:sequence>\r
                <xs:element name="csid" type="xs:string" />            \r
-                <xs:element name="documentId1" type="xs:string" minOccurs="1" maxOccurs="1"/>\r
-                <xs:element name="documentType1" type="xs:string" minOccurs="1" maxOccurs="1"/>\r
-                <xs:element name="documentId2" type="xs:string" minOccurs="1" maxOccurs="1"/>\r
-                <xs:element name="documentType2" type="xs:string" minOccurs="1" maxOccurs="1"/>\r
+                <xs:element name="documentId1" type="xs:string" minOccurs="1"/>\r
+                <xs:element name="documentType1" type="xs:string" minOccurs="1"/>\r
+                <xs:element name="documentId2" type="xs:string" minOccurs="1"/>\r
+                <xs:element name="documentType2" type="xs:string" minOccurs="1"/>\r
                 <!-- type of relationship between two entities -->\r
-                <xs:element name="relationshipType" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/>\r
+                <xs:element name="relationshipType" type="rel:RelationshipType" minOccurs="1"/>\r
             </xs:sequence>\r
         </xs:complexType>\r
     </xs:element>\r
@@ -71,6 +71,7 @@
                                     <xs:element name="uri" type="xs:anyURI" minOccurs="1"/>\r
                                     <xs:element name="csid" type="xs:string" minOccurs="1"/>\r
                                     <xs:element name="subjectCsid" type="xs:string" minOccurs="1"/>\r
+                                    <xs:element name="relationshipType" type="xs:string" minOccurs="1"/>\r
                                     <xs:element name="objectCsid" type="xs:string" minOccurs="1"/>\r
                                 </xs:sequence>\r
                             </xs:complexType>\r
index d84bbacb756173577bc4b6d98b325f6fd1c68712..a33800ad7c90e966156f3e14b68b7ca65a6ded56 100644 (file)
@@ -152,28 +152,6 @@ public class OrgAuthorityResource extends
         return contactResource.getServiceName();
     }
 
-    /*
-    public RemoteServiceContext createItemServiceContext(MultipartInput input) throws Exception {
-    RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
-    ctx.setInput(input);
-    return ctx;
-    }
-     */
-    /* (non-Javadoc)
-     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
-     */
-//    @Override
-//    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-//        DocumentHandler docHandler =ctx.getDocumentHandler();
-//        if (ctx.getInput() != null) {
-//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), OrgauthoritiesCommon.class);
-//            if (obj != null) {
-//                docHandler.setCommonPart((OrgauthoritiesCommon) obj);
-//            }
-//        }
-//        return docHandler;
-//    }
-
     /**
      * Creates the item document handler.
      * 
@@ -192,17 +170,7 @@ public class OrgAuthorityResource extends
                        ctx.getCommonPartLabel(getItemServiceName()),
                        OrganizationsCommon.class);             
         docHandler.setInAuthority(inAuthority);
-        
-        
-//        ((OrganizationDocumentModelHandler) docHandler).setInAuthority(inAuthority);
-//        if (ctx.getInput() != null) {
-//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
-//                    OrganizationsCommon.class);
-//            if (obj != null) {
-//                docHandler.setCommonPart((OrganizationsCommon) obj);
-//            }
-//        }
-
+                
         return docHandler;
     }
 
@@ -228,20 +196,6 @@ public class OrgAuthorityResource extends
         docHandler.setInAuthority(inAuthority);
         docHandler.setInItem(inItem);
        
-//        DocumentHandler docHandler = ctx.getDocumentHandler();
-//        // Set the inAuthority and inItem values, which specify the
-//        // parent authority (e.g. PersonAuthority, OrgAuthority) and the item
-//        // (e.g. Person, Organization) with which the Contact is associated.
-//        ((ContactDocumentModelHandler) docHandler).setInAuthority(inAuthority);
-//        ((ContactDocumentModelHandler) docHandler).setInItem(inItem);
-//        if (ctx.getInput() != null) {
-//            Object obj = ((MultipartServiceContext) ctx)
-//                .getInputPart(ctx.getCommonPartLabel(getContactServiceName()),
-//                ContactsCommon.class);
-//            if (obj != null) {
-//                docHandler.setCommonPart((ContactsCommon) obj);
-//            }
-//        }
         return docHandler;
     }
 
@@ -258,7 +212,6 @@ public class OrgAuthorityResource extends
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
-            //orgAuthorityObject.setCsid(csid);
             UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class);
             path.path("" + csid);
             Response response = Response.created(path.build()).build();
@@ -291,7 +244,6 @@ public class OrgAuthorityResource extends
     @GET
     @Path("urn:cspace:name({specifier})")
     public MultipartOutput getOrgAuthorityByName(@PathParam("specifier") String specifier) {
-        String idValue = null;
         if (specifier == null) {
             logger.error("getOrgAuthority: missing name!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
@@ -442,7 +394,6 @@ public class OrgAuthorityResource extends
     @GET
     @Path("{csid}")
     public MultipartOutput getOrgAuthority(@PathParam("csid") String csid) {
-        String idValue = null;
         if (csid == null) {
             logger.error("getOrgAuthority: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
@@ -620,11 +571,13 @@ public class OrgAuthorityResource extends
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
             throw new WebApplicationException(response);
         }
-
     }
 
     /*************************************************************************
      * Organization parts - this is a sub-resource of OrgAuthority
+     * @param parentcsid 
+     * @param input 
+     * @return org response
      *************************************************************************/
     @POST
     @Path("{csid}/items")
@@ -658,6 +611,7 @@ public class OrgAuthorityResource extends
 
     /**
      * Gets the organization.
+     * @param parentcsid 
      * 
      * @param csid The organization authority (parent) CSID.
      * @param itemcsid The organization item CSID.
@@ -725,9 +679,11 @@ public class OrgAuthorityResource extends
 
     /**
      * Gets the authority refs for an Organization item.
+     * @param parentcsid 
      *
      * @param csid The organization authority (parent) CSID.
      * @param itemcsid The organization item CSID.
+     * @param ui 
      *
      * @return the authority refs for the Organization item.
      */
@@ -799,7 +755,7 @@ public class OrgAuthorityResource extends
                String ptClause = "AND " + OrganizationJAXBSchema.ORGANIZATIONS_COMMON +
                        ":" + OrganizationJAXBSchema.DISPLAY_NAME +
                        " LIKE " + "'%" + partialTerm + "%'";
-               myFilter.appendWhereClause(ptClause);
+               myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
             }            
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             organizationObjectList = (OrganizationsCommonList) handler.getCommonPartList();
@@ -860,7 +816,7 @@ public class OrgAuthorityResource extends
                OrganizationJAXBSchema.DISPLAY_NAME +
                        " LIKE " +
                        "'%" + partialTerm + "%'";
-               myFilter.appendWhereClause(ptClause);
+               myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
             }            
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             personObjectList = (OrganizationsCommonList) handler.getCommonPartList();
@@ -1000,6 +956,10 @@ public class OrgAuthorityResource extends
 
     /*************************************************************************
      * Contact parts - this is a sub-resource of Organization (or "item")
+     * @param parentcsid 
+     * @param itemcsid 
+     * @param input 
+     * @return contact
      *************************************************************************/
     @POST
     @Path("{parentcsid}/items/{itemcsid}/contacts")
@@ -1064,11 +1024,12 @@ public class OrgAuthorityResource extends
             myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" +
                 ContactJAXBSchema.IN_AUTHORITY +
                 "='" + parentcsid + "'" +
-                " AND " +
+                IQueryManager.SEARCH_QUALIFIER_AND +
                 ContactJAXBSchema.CONTACTS_COMMON + ":" +
                 ContactJAXBSchema.IN_ITEM +
                 "='" + itemcsid + "'" +
-                " AND ecm:isProxy = 0");
+                IQueryManager.SEARCH_QUALIFIER_AND +
+                "ecm:isProxy = 0");
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             contactObjectList = (ContactsCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {
index c177be7295b994a33f1424e8b78e26a8225508e6..3ddc1b10b6eabbf7716728de808a81a55fa82592 100644 (file)
@@ -47,14 +47,9 @@ import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResou
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
-//import org.collectionspace.services.common.authorityref.AuthorityRefList;
-//import org.collectionspace.services.common.context.MultipartServiceContext;
-import org.collectionspace.services.common.context.MultipartServiceContextFactory;
-//import org.collectionspace.services.common.context.MultipartServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceBindingUtils;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.BadRequestException;
-//import org.collectionspace.services.common.document.DocumentException;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
@@ -62,19 +57,20 @@ import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.repository.RepositoryClient;
 import org.collectionspace.services.common.security.UnauthorizedException;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
-//import org.collectionspace.services.common.vocabulary.RefNameUtils;
 import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.contact.ContactResource;
 import org.collectionspace.services.contact.ContactsCommon;
 import org.collectionspace.services.contact.ContactsCommonList;
 import org.collectionspace.services.contact.ContactJAXBSchema;
 import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler;
-//import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
 import org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler;
+
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.jboss.resteasy.util.HttpResponseCodes;
+
 import org.nuxeo.ecm.core.api.DocumentModel;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -150,18 +146,6 @@ public class PersonAuthorityResource extends
         return contactResource.getServiceName();
     }
 
-//    @Override
-//    public DocumentHandler createDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> ctx) throws Exception {
-//        DocumentHandler docHandler = ctx.getDocumentHandler();
-//        if (ctx.getInput() != null) {
-//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), PersonauthoritiesCommon.class);
-//            if (obj != null) {
-//                docHandler.setCommonPart((PersonauthoritiesCommon) obj);
-//            }
-//        }
-//        return docHandler;
-//    }
-
     /**
  * Creates the item document handler.
  * 
@@ -202,20 +186,6 @@ public class PersonAuthorityResource extends
         docHandler.setInAuthority(inAuthority);
         docHandler.setInItem(inItem);
        
-//        DocumentHandler docHandler = ctx.getDocumentHandler();
-//        // Set the inAuthority and inItem values, which specify the
-//        // parent authority (e.g. PersonAuthority, OrgAuthority) and the item
-//        // (e.g. Person, Organization) with which the Contact is associated.
-//        ((ContactDocumentModelHandler) docHandler).setInAuthority(inAuthority);
-//        ((ContactDocumentModelHandler) docHandler).setInItem(inItem);
-//        if (ctx.getInput() != null) {
-//            Object obj = ((MultipartServiceContext) ctx)
-//                .getInputPart(ctx.getCommonPartLabel(getContactServiceName()),
-//                ContactsCommon.class);
-//            if (obj != null) {
-//                docHandler.setCommonPart((ContactsCommon) obj);
-//            }
-//        }
         return docHandler;
     }
 
@@ -265,7 +235,6 @@ public class PersonAuthorityResource extends
     @GET
     @Path("urn:cspace:name({specifier})")
     public MultipartOutput getPersonAuthorityByName(@PathParam("specifier") String specifier) {
-//REM:        String idValue = null;
         if (specifier == null) {
             logger.error("getPersonAuthority: missing name!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
@@ -337,73 +306,73 @@ public class PersonAuthorityResource extends
     @Path("{csid}/items/{itemcsid}/refObjs")
     @Produces("application/xml") //FIXME: REM do this for CSPACE-1079 in Org authority.
     public AuthorityRefDocList getReferencingObjects(
-            @PathParam("csid") String parentcsid,
-            @PathParam("itemcsid") String itemcsid,
+               @PathParam("csid") String parentcsid,
+               @PathParam("itemcsid") String itemcsid,
                @Context UriInfo ui) {
        AuthorityRefDocList authRefDocList = null;
-        if (logger.isDebugEnabled()) {
-            logger.debug("getReferencingObjects with parentcsid=" 
-                       + parentcsid + " and itemcsid=" + itemcsid);
-        }
-        if (parentcsid == null || "".equals(parentcsid)
-                || itemcsid == null || "".equals(itemcsid)) {
-            logger.error("getPerson: missing parentcsid or itemcsid!");
-            Response response = Response.status(Response.Status.BAD_REQUEST).entity(
-                    "get failed on Person with parentcsid=" 
-                       + parentcsid + " and itemcsid=" + itemcsid).type(
-                    "text/plain").build();
-            throw new WebApplicationException(response);
-        }
-    try {
-        MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-        // Note that we have to create the service context for the Items, not the main service
-        ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
-                       queryParams);
-        DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-        RepositoryClient repoClient = getRepositoryClient(ctx); 
-        DocumentFilter myFilter = handler.getDocumentFilter();
-       String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE;
-        List<String> list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);
-        if (list != null) {
-               serviceType = list.get(0);
-        }
-        DocumentWrapper<DocumentModel> docWrapper = repoClient.getDoc(ctx, itemcsid);
-        DocumentModel docModel = docWrapper.getWrappedObject();
-        String refName = (String)docModel.getPropertyValue(PersonJAXBSchema.REF_NAME);
+       if (logger.isDebugEnabled()) {
+               logger.debug("getReferencingObjects with parentcsid=" 
+                               + parentcsid + " and itemcsid=" + itemcsid);
+       }
+       if (parentcsid == null || "".equals(parentcsid)
+                       || itemcsid == null || "".equals(itemcsid)) {
+               logger.error("getPerson: missing parentcsid or itemcsid!");
+               Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                               "get failed on Person with parentcsid=" 
+                               + parentcsid + " and itemcsid=" + itemcsid).type(
+                               "text/plain").build();
+               throw new WebApplicationException(response);
+       }
+       try {
+               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+               // Note that we have to create the service context for the Items, not the main service
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+                               queryParams);
+               DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+               RepositoryClient repoClient = getRepositoryClient(ctx); 
+               DocumentFilter myFilter = handler.getDocumentFilter();
+               String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE;
+               List<String> list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);
+               if (list != null) {
+                       serviceType = list.get(0);
+               }
+               DocumentWrapper<DocumentModel> docWrapper = repoClient.getDoc(ctx, itemcsid);
+               DocumentModel docModel = docWrapper.getWrappedObject();
+               String refName = (String)docModel.getPropertyValue(PersonJAXBSchema.REF_NAME);
 
-        authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(ctx,
-                       repoClient, 
-                       serviceType,
-                       refName,
-                       myFilter.getPageSize(), myFilter.getStartPage(), true /*computeTotal*/ );
-    } catch (UnauthorizedException ue) {
-        Response response = Response.status(
-                Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
-        throw new WebApplicationException(response);
-    } catch (DocumentNotFoundException dnfe) {
-        if (logger.isDebugEnabled()) {
-            logger.debug("getReferencingObjects", dnfe);
-        }
-        Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                "GetReferencingObjects failed with parentcsid=" 
-                       + parentcsid + " and itemcsid=" + itemcsid).type(
-                "text/plain").build();
-        throw new WebApplicationException(response);
-    } catch (Exception e) {    // Includes DocumentException
-        if (logger.isDebugEnabled()) {
-            logger.debug("GetReferencingObjects", e);
-        }
-        Response response = Response.status(
-                Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
-        throw new WebApplicationException(response);
-    }
-    if (authRefDocList == null) {
-        Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                "Get failed, the requested Person CSID:" + itemcsid + ": was not found.").type(
-                "text/plain").build();
-        throw new WebApplicationException(response);
-    }
-    return authRefDocList;
+               authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(ctx,
+                               repoClient, 
+                               serviceType,
+                               refName,
+                               myFilter.getPageSize(), myFilter.getStartPage(), true /*computeTotal*/ );
+       } catch (UnauthorizedException ue) {
+               Response response = Response.status(
+                               Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
+               throw new WebApplicationException(response);
+       } catch (DocumentNotFoundException dnfe) {
+               if (logger.isDebugEnabled()) {
+                       logger.debug("getReferencingObjects", dnfe);
+               }
+               Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                               "GetReferencingObjects failed with parentcsid=" 
+                               + parentcsid + " and itemcsid=" + itemcsid).type(
+                               "text/plain").build();
+               throw new WebApplicationException(response);
+       } catch (Exception e) { // Includes DocumentException
+               if (logger.isDebugEnabled()) {
+                       logger.debug("GetReferencingObjects", e);
+               }
+               Response response = Response.status(
+                               Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+               throw new WebApplicationException(response);
+       }
+       if (authRefDocList == null) {
+               Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                               "Get failed, the requested Person CSID:" + itemcsid + ": was not found.").type(
+                               "text/plain").build();
+               throw new WebApplicationException(response);
+       }
+       return authRefDocList;
     }
 
     @GET
@@ -722,7 +691,7 @@ public class PersonAuthorityResource extends
                        PersonJAXBSchema.DISPLAY_NAME +
                        " LIKE " +
                        "'%" + partialTerm + "%'";
-               handler.getDocumentFilter().appendWhereClause(ptClause);
+               handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
             }            
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             personObjectList = (PersonsCommonList) handler.getCommonPartList();
@@ -783,7 +752,7 @@ public class PersonAuthorityResource extends
                        PersonJAXBSchema.DISPLAY_NAME +
                        " LIKE " +
                        "'%" + partialTerm + "%'";
-               handler.getDocumentFilter().appendWhereClause(ptClause);
+               handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
             }            
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             personObjectList = (PersonsCommonList) handler.getCommonPartList();
@@ -1069,8 +1038,8 @@ public class PersonAuthorityResource extends
                 .type("text/plain").build();
             throw new WebApplicationException(response);
         }
+        
         return result;
-
     }
 
     /**
index 09b34a2ecfac5a4b8fee079eb886884c14ec2f7f..8f82cc420025372fd91db42b07f752918abea7ec 100644 (file)
@@ -22,7 +22,6 @@
  */
 package org.collectionspace.services.client.test;
 
-import java.util.ArrayList;
 import java.util.List;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
@@ -40,7 +39,6 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.testng.Assert;
-import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
 import org.slf4j.Logger;
@@ -65,9 +63,6 @@ public class RelationServiceTest extends AbstractServiceTestImpl {
     /** The known resource id. */
     private String knownResourceId = null;
     
-    /** The all resource ids created. */
-    private List<String> allResourceIdsCreated = new ArrayList<String>();
-
     /* (non-Javadoc)
      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
      */
@@ -316,19 +311,6 @@ public class RelationServiceTest extends AbstractServiceTestImpl {
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
-
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
-        */
-       @Test(dataProvider = "testName")
-       /*
-        * FIXME: Until the Relation service uses NXQL queries to get results,
-        * we need to skip the pagination tests
-        */
-       @Override
-       public void readPaginatedList(String testName) throws Exception {
-               //Override and skip the pagination tests
-       }
    
     // ---------------------------------------------------------------
     // CRUD tests : READ_LIST tests
@@ -686,38 +668,6 @@ public class RelationServiceTest extends AbstractServiceTestImpl {
                 " status=" + statusCode);
         }
         Assert.assertEquals(statusCode, EXPECTED_STATUS);
-
-    }
-
-    // ---------------------------------------------------------------
-    // Cleanup of resources created during testing
-    // ---------------------------------------------------------------
-
-    /**
-     * Deletes all resources created by tests, after all tests have been run.
-     *
-     * This cleanup method will always be run, even if one or more tests fail.
-     * For this reason, it attempts to remove all resources created
-     * at any point during testing, even if some of those resources
-     * may be expected to be deleted by certain tests.
-     */
-    @AfterClass(alwaysRun=true)
-    public void cleanUp() {
-        String noTest = System.getProperty("noTestCleanup");
-       if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("Skipping Cleanup phase ...");
-            }
-            return;
-       }
-        if (logger.isDebugEnabled()) {
-            logger.debug("Cleaning up temporary resources created for testing ...");
-        }
-        RelationClient client = new RelationClient();
-        for (String resourceId : allResourceIdsCreated) {
-            // Note: Any non-success responses are ignored and not reported.
-            ClientResponse<Response> res = client.delete(resourceId);
-        }
     }
 
     // ---------------------------------------------------------------
index b57cdea49a8663bc627be3378131c2064e259a0a..175d52407ea15ce207e6ca7d511f08e6033963c9 100644 (file)
@@ -26,8 +26,6 @@
  */
 package org.collectionspace.services.relation;
 
-import java.util.Map;
-
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
@@ -43,10 +41,10 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
+import org.collectionspace.services.common.query.IQueryManager;
+import org.collectionspace.services.common.relation.nuxeo.RelationsUtils;
 import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
-//import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
-import org.collectionspace.services.common.relation.IRelationsManager;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.security.UnauthorizedException;
@@ -98,23 +96,6 @@ public class NewRelationResource extends
     public Class<RelationsCommon> getCommonPartClass() {
        return RelationsCommon.class;
     }
-       
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.common.AbstractCollectionSpaceResource#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
-        */
-//     @Override
-//     public DocumentHandler createDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> ctx)
-//                     throws Exception {
-//             DocumentHandler docHandler = ctx.getDocumentHandler();
-//             if (ctx.getInput() != null) {
-//                     Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx
-//                                     .getCommonPartLabel(), RelationsCommon.class);
-//                     if (obj != null) {
-//                             docHandler.setCommonPart((RelationsCommon) obj);
-//                     }
-//             }
-//             return docHandler;
-//     }
 
        /**
         * Creates the relation.
@@ -517,20 +498,15 @@ public class NewRelationResource extends
                RelationsCommonList relationList = new RelationsCommonList();
                try {
                        ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
-                       DocumentHandler handler = createDocumentHandler(ctx);
-                       Map<String, Object> propsFromPath = handler.getProperties();
-                       propsFromPath.put(IRelationsManager.SUBJECT, subjectCsid);
-                       propsFromPath.put(IRelationsManager.PREDICATE, predicate);
-                       propsFromPath.put(IRelationsManager.OBJECT, objectCsid);
-                       // Until we replace this with a search, "getAll()" is better then "getFiltered"
-                       getRepositoryClient(ctx).getAll(ctx, handler);
-                       relationList = (RelationsCommonList) handler.getCommonPartList();
+                       DocumentHandler handler = createDocumentHandler(ctx);                   
+                       String relationClause = RelationsUtils.buildWhereClause(subjectCsid, predicate, objectCsid);
+                       handler.getDocumentFilter().appendWhereClause(relationClause, IQueryManager.SEARCH_QUALIFIER_AND);                      
+                       getRepositoryClient(ctx).getFiltered(ctx, handler);
+                       relationList = (RelationsCommonList)handler.getCommonPartList();
                } catch (UnauthorizedException ue) {
-                       Response response = Response.status(Response.Status.UNAUTHORIZED)
-                                       .entity(
-                                                       "Get relations failed reason "
-                                                                       + ue.getErrorReason()).type("text/plain")
-                                       .build();
+                       Response response = Response.status(Response.Status.UNAUTHORIZED).entity(
+                                       "Get relations failed reason " +
+                                       ue.getErrorReason()).type("text/plain").build();
                        throw new WebApplicationException(response);
                } catch (Exception e) {
                        if (logger.isDebugEnabled()) {
@@ -541,6 +517,7 @@ public class NewRelationResource extends
                                        "Index failed").type("text/plain").build();
                        throw new WebApplicationException(response);
                }
+               
                return relationList;
        }
 }
index 9f4f631b4ec439b05b2ad9715041568cfbcb3ff1..dafee918147f57d62ab2164f25660f8b306dfcb2 100644 (file)
@@ -25,19 +25,19 @@ package org.collectionspace.services.relation.nuxeo;
 
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
-
-import org.collectionspace.services.common.relation.IRelationsManager;
+import org.collectionspace.services.common.relation.RelationJAXBSchema;
 import org.collectionspace.services.common.relation.nuxeo.RelationConstants;
-import org.collectionspace.services.common.relation.nuxeo.RelationsUtils;
-import org.collectionspace.services.common.document.DocumentHandler.Action;
+import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.relation.RelationsCommon;
 import org.collectionspace.services.relation.RelationsCommonList;
 import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
 
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
@@ -68,7 +68,7 @@ public class RelationDocumentModelHandler
 
     /**
      * getCommonObject get associated Relation
-     * @return
+     * @return relation
      */
     @Override
     public RelationsCommon getCommonPart() {
@@ -80,13 +80,13 @@ public class RelationDocumentModelHandler
      * @param relation
      */
     @Override
-    public void setCommonPart(RelationsCommon relation) {
-        this.relation = relation;
+    public void setCommonPart(RelationsCommon theRelation) {
+        this.relation = theRelation;
     }
 
     /**
      * getRelationList get associated Relation (for index/GET_ALL)
-     * @return
+     * @return relationCommonList
      */
     @Override
     public RelationsCommonList getCommonPartList() {
@@ -97,8 +97,8 @@ public class RelationDocumentModelHandler
      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
      */
     @Override
-    public void setCommonPartList(RelationsCommonList relationList) {
-        this.relationList = relationList;
+    public void setCommonPartList(RelationsCommonList theRelationList) {
+        this.relationList = theRelationList;
     }
 
     /* (non-Javadoc)
@@ -114,7 +114,7 @@ public class RelationDocumentModelHandler
      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
      */
     @Override
-    public void fillCommonPart(RelationsCommon relation, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+    public void fillCommonPart(RelationsCommon theRelation, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
         throw new UnsupportedOperationException();
     }
 
@@ -123,24 +123,14 @@ public class RelationDocumentModelHandler
      */
     @Override
     public RelationsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
-        Map propsFromResource = this.getProperties();
-        String subjectCsid = (String) propsFromResource.get(IRelationsManager.SUBJECT);
-        String predicate = (String) propsFromResource.get(IRelationsManager.PREDICATE);
-        String objectCsid = (String) propsFromResource.get(IRelationsManager.OBJECT);
-
-        //FIXME - Need to change this into a NXQL on subject, predicate, object terms.  Currently,
-        //FIXME - we're performing a post query filter which is far from ideal and not scalable.
         RelationsCommonList relList = this.extractPagingInfo(new RelationsCommonList(), wrapDoc) ;
         List<RelationsCommonList.RelationListItem> itemList = relList.getRelationListItem();
         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
         while(iter.hasNext()){
             DocumentModel docModel = iter.next();
-            if (RelationsUtils.isQueryMatch(docModel, subjectCsid,
-                    predicate, objectCsid) == true){
-                RelationListItem relListItem = RelationsUtils.getRelationListItem(getServiceContext(),
-                        docModel, getServiceContextPath());
-                itemList.add(relListItem);
-            }
+            RelationListItem relListItem = getRelationListItem(getServiceContext(),
+                    docModel, getServiceContextPath());
+            itemList.add(relListItem);
         }
         return relList;
     }
@@ -153,24 +143,43 @@ public class RelationDocumentModelHandler
     @Override
     public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
         super.fillAllParts(wrapDoc);
-        fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
     }
 
     /**
-     * Fill dublin core object.
+     * Gets the relation list item.
      *
-     * @param wrapDoc the wrap doc
+     * @param ctx the ctx
+     * @param docModel the doc model
+     * @param serviceContextPath the service context path
+     * @return the relation list item
      * @throws Exception the exception
      */
-    private void fillDublinCoreObject(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
-        DocumentModel docModel = wrapDoc.getWrappedObject();
-        //FIXME property setter should be dynamically set using schema inspection
-        //so it does not require hard coding
-        // a default title for the Dublin Core schema
-        docModel.setPropertyValue("dublincore:title", RelationConstants.NUXEO_DC_TITLE);
+    private RelationListItem getRelationListItem(ServiceContext<MultipartInput, MultipartOutput> ctx,
+               DocumentModel docModel,
+            String serviceContextPath) throws Exception {
+        RelationListItem relationListItem = new RelationListItem();
+        String id = NuxeoUtils.extractId(docModel.getPathAsString());
+        relationListItem.setCsid(id);
+        //
+        // Subject
+        //
+        relationListItem.setSubjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
+                       RelationJAXBSchema.DOCUMENT_ID_1));
+        //
+        // Predicate
+        //
+        relationListItem.setRelationshipType((String) docModel.getProperty(ctx.getCommonPartLabel(),
+                       RelationJAXBSchema.RELATIONSHIP_TYPE));
+        //
+        // Object
+        //
+        relationListItem.setObjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
+                       RelationJAXBSchema.DOCUMENT_ID_2));
+        
+        relationListItem.setUri(serviceContextPath + id);
+        return relationListItem;
     }
 
-
     /* (non-Javadoc)
      * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
      */
index 5b8a12830badffcc1cf30f1e6424d8c9e19ea0c5..a84d06b20d417d8b2ee7efc9c751442cf25ce210 100644 (file)
@@ -43,8 +43,6 @@ import org.collectionspace.services.VocabularyItemJAXBSchema;
 import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.context.MultipartServiceContext;
-import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.BadRequestException;
 import org.collectionspace.services.common.document.DocumentFilter;
@@ -121,32 +119,6 @@ public class VocabularyResource extends
     public String getItemServiceName() {
         return vocabularyItemServiceName;
     }
-
-    /*
-    public RemoteServiceContext createItemServiceContext(MultipartInput input) throws Exception {
-    RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
-    ctx.setInput(input);
-    return ctx;
-    }
-     */
-//    @Override
-//    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-//        DocumentHandler docHandler = ctx.getDocumentHandler();
-//        if (ctx.getInput() != null) {
-//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), VocabulariesCommon.class);
-//            if (obj != null) {
-//                docHandler.setCommonPart((VocabulariesCommon) obj);
-//            }
-//        }
-//        return docHandler;
-//    }
-    
-//    @Override
-//    public DocumentHandler createDocumentHandler(ServiceContext ctx)
-//             throws Exception {
-//        DocumentHandler docHandler = createDocumentHandler(ctx, VocabulariesCommon.class);
-//        return docHandler;
-//    }
     
     /**
      * Creates the item document handler.
@@ -214,7 +186,7 @@ public class VocabularyResource extends
     @GET
     @Path("{csid}")
     public MultipartOutput getVocabulary(@PathParam("csid") String csid) {
-        String idValue = null;
+//        String idValue = null;
         if (csid == null) {
             logger.error("getVocabulary: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
@@ -398,6 +370,9 @@ public class VocabularyResource extends
 
     /*************************************************************************
      * VocabularyItem parts - this is a sub-resource of Vocabulary
+     * @param parentcsid 
+     * @param input 
+     * @return vocab item response
      *************************************************************************/
     @POST
     @Path("{csid}/items")
@@ -530,12 +505,11 @@ public class VocabularyResource extends
 
             // AND vocabularyitems_common:displayName LIKE '%partialTerm%'
             if (partialTerm != null && !partialTerm.isEmpty()) {
-                String ptClause = "AND "
-                        + VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":"
+                String ptClause = VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":"
                         + VocabularyItemJAXBSchema.DISPLAY_NAME
-                        + " LIKE "
+                        + IQueryManager.SEARCH_LIKE
                         + "'%" + partialTerm + "%'";
-                myFilter.appendWhereClause(ptClause);
+                myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
             }
 
             if (logger.isDebugEnabled()) {