]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5024 Added support in services to search across all vocabs of a given authorit...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Thu, 19 Apr 2012 20:04:53 +0000 (13:04 -0700)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Thu, 19 Apr 2012 20:04:53 +0000 (13:04 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java

index bf47c2dae4fd1ea035cd591d4471210e92484a0e..4e4e6dce9fd0fdd456fcf12aebf88c4da1f93429 100644 (file)
@@ -124,6 +124,8 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     final static String URN_PREFIX_ID = "id(";
     final static int URN_ID_PREFIX_LEN = URN_PREFIX_LEN + URN_PREFIX_ID.length();
     final static String FETCH_SHORT_ID = "_fetch_";
+       final static String PARENT_WILDCARD = "_ALL_";
+       
     final Logger logger = LoggerFactory.getLogger(AuthorityResource.class);
 
     public enum SpecifierForm {
@@ -661,12 +663,15 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             // Note that docType defaults to the ServiceName, so we're fine with that.
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
 
-            String parentcsid = lookupParentCSID(specifier, "getAuthorityItemList", "LIST", queryParams);
+            String parentcsid = PARENT_WILDCARD.equals(specifier)?null:
+                                               lookupParentCSID(specifier, "getAuthorityItemList", "LIST", queryParams);
 
             ctx = createServiceContext(getItemServiceName(), queryParams);
+
+            // For the wildcard case, parentcsid is null, but docHandler will deal with this.
             // We omit the parentShortId, only needed when doing a create...
-            DocumentHandler handler = createItemDocumentHandler(ctx,
-                    parentcsid, null);
+            DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null);
+            
             DocumentFilter myFilter = handler.getDocumentFilter();
             // Need to make the default sort order for authority items
             // be on the displayName field
@@ -674,11 +679,14 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             if (sortBy == null || sortBy.isEmpty()) {
                 myFilter.setOrderByClause(qualifiedDisplayNameField);
             }
-            
-            myFilter.appendWhereClause(authorityItemCommonSchemaName + ":"
-                    + AuthorityItemJAXBSchema.IN_AUTHORITY + "="
-                    + "'" + parentcsid + "'",
-                    IQueryManager.SEARCH_QUALIFIER_AND);
+
+            // If we are not wildcarding the parent, add a restriction
+            if(parentcsid!=null) {
+                   myFilter.appendWhereClause(authorityItemCommonSchemaName + ":"
+                           + AuthorityItemJAXBSchema.IN_AUTHORITY + "="
+                           + "'" + parentcsid + "'",
+                           IQueryManager.SEARCH_QUALIFIER_AND);
+            }
 
             if (Tools.notBlank(termStatus)) {
                // Start with the qualified termStatus field
index f251ee25a5fff85edffeebb9a117f39091aadb4a..e439c38b3f774223e48183c9ccaec6f92100c61b 100644 (file)
@@ -58,6 +58,7 @@ import org.collectionspace.services.relation.RelationsCommon;
 import org.collectionspace.services.relation.RelationsCommonList;
 import org.collectionspace.services.relation.RelationsDocListItem;
 import org.collectionspace.services.relation.RelationshipType;
+import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.model.PropertyException;
 import org.nuxeo.ecm.core.api.model.PropertyNotFoundException;
@@ -93,8 +94,8 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     /**
      * inVocabulary is the parent Authority for this context
      */
-    protected String inAuthority;
-    protected String authorityRefNameBase;
+    protected String inAuthority = null;
+    protected String authorityRefNameBase = null;
     // Used to determine when the displayName changes as part of the update.
     protected String oldDisplayNameOnUpdate = null;
     protected String oldRefNameOnUpdate = null;
@@ -104,10 +105,6 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         this.authorityItemCommonSchemaName = authorityItemCommonSchemaName;
     }
 
-    public String getInAuthority() {
-        return inAuthority;
-    }
-
     public void setInAuthority(String inAuthority) {
         this.inAuthority = inAuthority;
     }
@@ -121,10 +118,18 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     public String getUri(DocumentModel docModel) {
         // Laramie20110510 CSPACE-3932
         String authorityServicePath = getAuthorityServicePath();
+        if(inAuthority==null) {        // Only happens on queries to wildcarded authorities
+               try {
+                       inAuthority = (String) docModel.getProperty(authorityItemCommonSchemaName,
+                       AuthorityItemJAXBSchema.IN_AUTHORITY);
+               } catch (ClientException pe) {
+                       throw new RuntimeException("Could not get parent specifier for item!");
+               }
+        }
         return "/" + authorityServicePath + '/' + inAuthority + '/' + AuthorityClient.ITEMS + '/' + getCsid(docModel);
     }
 
-    public String getAuthorityRefNameBase() {
+    protected String getAuthorityRefNameBase() {
         return this.authorityRefNameBase;
     }
 
@@ -346,6 +351,9 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
      * @throws Exception the exception
      */
     private void handleInAuthority(DocumentModel docModel) throws Exception {
+        if(inAuthority==null) {        // Only happens on queries to wildcarded authorities
+               throw new IllegalStateException("Trying to Create an object with no inAuthority value!");
+        }
         docModel.setProperty(authorityItemCommonSchemaName,
                 AuthorityItemJAXBSchema.IN_AUTHORITY, inAuthority);
     }