]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-106: Added CSID value to items in authority references list.
authorremillet <remillet@yahoo.com>
Fri, 24 Feb 2017 21:03:36 +0000 (13:03 -0800)
committerremillet <remillet@yahoo.com>
Fri, 24 Feb 2017 21:03:36 +0000 (13:03 -0800)
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.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/RemoteDocumentModelHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java
services/jaxb/src/main/resources/authorityref.xsd

index 893c4e0be253cded5e9d5aff562e4bf5d5df80e8..21240018fa7c010e202bbde0bf9c909607fe3fd0 100644 (file)
@@ -183,7 +183,7 @@ public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
      * 
      * @throws Exception the exception
      */
-    protected ServiceContext<IT, OT> createServiceContext(String serviceName) throws Exception {       
+    public ServiceContext<IT, OT> createServiceContext(String serviceName) throws Exception {          
         ServiceContext<IT, OT> ctx = createServiceContext(
                        serviceName,
                        (IT)null, // The input part
index 429b1c42fc5d8ebfe1663652ed98119dcabbf6b0..60697a9c4f0929ea2ccd0e37189de6bf6962458d 100644 (file)
@@ -644,23 +644,7 @@ public abstract class NuxeoBasedResource
      */
     public static DocumentModel getDocModelForRefName(CoreSessionInterface repoSession, String refName, ResourceMap resourceMap) 
                        throws Exception, DocumentNotFoundException {
-       RefName.AuthorityItem item = RefName.AuthorityItem.parse(refName);
-       if (item != null) {
-               NuxeoBasedResource resource = (NuxeoBasedResource) resourceMap.get(item.inAuthority.resource);
-               return resource.getDocModelForAuthorityItem(repoSession, item);
-       }
-       RefName.Authority authority = RefName.Authority.parse(refName);
-       // Handle case of objects refNames, which must be csid based.
-       if(authority != null && !Tools.isEmpty(authority.csid)) {
-               NuxeoBasedResource resource = (NuxeoBasedResource) resourceMap.get(authority.resource);
-            // Ensure we have the right context.
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = 
-                       resource.createServiceContext(authority.resource);
-            // HACK - this really must be moved to the doc handler, not here. No Nuxeo specific stuff here!
-            DocumentModel docModel = NuxeoUtils.getDocFromCsid(ctx, repoSession, authority.csid);
-            return docModel;
-       }
-       return null;
+       return NuxeoUtils.getDocModelForRefName(repoSession, refName, resourceMap);
     }
 
     // This is ugly, but prevents us parsing the refName twice. Once we make refName a little more
index aa623abc704ca030e9c344a983b96cf011fdd4d1..58a6ce1a9b67e463857fe91f4cbf9490df1f3af5 100644 (file)
@@ -980,19 +980,19 @@ public class RefNameServiceUtils {
 
     public static List<AuthRefInfo> findAuthRefPropertiesInDoc(
             DocumentModel docModel,
-            List<AuthRefConfigInfo> authRefFieldInfo,
+            List<AuthRefConfigInfo> authRefFieldInfoList,
             String refNameToMatch,
             List<AuthRefInfo> foundProps) {
-       return findAuthRefPropertiesInDoc(docModel, authRefFieldInfo, 
+       return findAuthRefPropertiesInDoc(docModel, authRefFieldInfoList
                                                                        refNameToMatch, false, foundProps);
     }
     
     public static List<AuthRefInfo> findAuthRefPropertiesInDoc(
             DocumentModel docModel,
-            List<AuthRefConfigInfo> authRefFieldInfo,
+            List<AuthRefConfigInfo> authRefFieldInfoList,
             String refNameToMatch,
             boolean matchBaseOnly,
-            List<AuthRefInfo> foundProps) {
+            List<AuthRefInfo> authRefInfoList) {
         // Assume that authRefFieldInfo is keyed by the field name (possibly mapped for UI)
         // and the values are elPaths to the field, where intervening group structures in
         // lists of complex structures are replaced with "*". Thus, valid paths include
@@ -1005,20 +1005,20 @@ public class RefNameServiceUtils {
         // "schemaname:complexlistname/*/complexfieldname/fieldname"
         // "schemaname:complexlistname/*/complexlistname/*/fieldname"
         // etc.
-        for (AuthRefConfigInfo arci : authRefFieldInfo) {
+        for (AuthRefConfigInfo arci : authRefFieldInfoList) {
             try {
                 // Get first property and work down as needed.
                 Property prop = docModel.getProperty(arci.pathEls[0]);
-                findAuthRefPropertiesInProperty(foundProps, prop, arci, 0, refNameToMatch, matchBaseOnly);
+                findAuthRefPropertiesInProperty(authRefInfoList, prop, arci, 0, refNameToMatch, matchBaseOnly);
             } catch (Exception e) {
                 logger.error("Problem fetching property: " + arci.pathEls[0]);
             }
         }
-        return foundProps;
+        return authRefInfoList;
     }
 
     private static List<AuthRefInfo> findAuthRefPropertiesInProperty(
-            List<AuthRefInfo> foundProps,
+            List<AuthRefInfo> authRefInfoList,
             Property prop,
             AuthRefConfigInfo arci,
             int pathStartIndex, // Supports recursion and we work down the path
@@ -1030,11 +1030,11 @@ public class RefNameServiceUtils {
         }
         AuthRefInfo ari = null;
         if (prop == null) {
-            return foundProps;
+            return authRefInfoList;
         }
 
         if (prop instanceof StringProperty) {    // scalar string
-            addARIifMatches(refNameToMatch, matchBaseOnly, arci, prop, foundProps); // REM - Side effect that foundProps gets changed/updated
+            addARIifMatches(refNameToMatch, matchBaseOnly, arci, prop, authRefInfoList); // REM - Side effect that foundProps gets changed/updated
         } else if (prop instanceof List) {
             List<Property> propList = (List<Property>) prop;
             // run through list. Must either be list of Strings, or Complex
@@ -1045,12 +1045,12 @@ public class RefNameServiceUtils {
                                 + arci.pathEls.toString());
                         break;
                     } else {
-                        addARIifMatches(refNameToMatch, matchBaseOnly, arci, listItemProp, foundProps);
+                        addARIifMatches(refNameToMatch, matchBaseOnly, arci, listItemProp, authRefInfoList);
                     }
                 } else if (listItemProp.isComplex()) {
                     // Just recurse to handle this. Note that since this is a list of complex, 
                     // which should look like listName/*/... we add 2 to the path start index 
-                    findAuthRefPropertiesInProperty(foundProps, listItemProp, arci,
+                    findAuthRefPropertiesInProperty(authRefInfoList, listItemProp, arci,
                             pathStartIndex + 2, refNameToMatch, matchBaseOnly);
                 } else {
                     logger.error("Configuration for authRefs does not match schema structure: "
@@ -1063,7 +1063,7 @@ public class RefNameServiceUtils {
             try {
                 Property localProp = prop.get(localPropName);
                 // Now just recurse, pushing down the path 1 step
-                findAuthRefPropertiesInProperty(foundProps, localProp, arci,
+                findAuthRefPropertiesInProperty(authRefInfoList, localProp, arci,
                         pathStartIndex, refNameToMatch, matchBaseOnly);
             } catch (PropertyNotFoundException pnfe) {
                 logger.error("Could not find property: [" + localPropName + "] in path: "
@@ -1076,10 +1076,10 @@ public class RefNameServiceUtils {
         }
 
         if (ari != null) {
-            foundProps.add(ari); //FIXME: REM - This is dead code.  'ari' is never touched after being initalized to null.  Why?
+            authRefInfoList.add(ari); //FIXME: REM - This is dead code.  'ari' is never touched after being initalized to null.  Why?
         }
 
-        return foundProps;
+        return authRefInfoList;
     }
 
     private static void addARIifMatches(
@@ -1087,7 +1087,7 @@ public class RefNameServiceUtils {
             boolean matchBaseOnly,
             AuthRefConfigInfo arci,
             Property prop,
-            List<AuthRefInfo> foundProps) {
+            List<AuthRefInfo> authRefInfoList) {
         // Need to either match a passed refName 
         // OR have no refName to match but be non-empty
         try {
@@ -1100,7 +1100,7 @@ public class RefNameServiceUtils {
                 // Found a match
                 logger.debug("Found a match on property: " + prop.getPath() + " with value: [" + value + "]");
                 AuthRefInfo ari = new AuthRefInfo(arci, prop);
-                foundProps.add(ari);
+                authRefInfoList.add(ari);
             }
         } catch (PropertyException pe) {
             logger.debug("PropertyException on: " + prop.getPath() + pe.getLocalizedMessage());
index 0f4442248510b38ea1211f8e6c7a0ed0ab153c3a..d26a52c670697d72084fe5926abae7793dcdcd2b 100644 (file)
@@ -241,7 +241,7 @@ public abstract class DocumentModelHandler<T, TL>
      * @throws PropertyException the property exception
      */
     abstract public AuthorityRefList getAuthorityRefs(String csid,
-               List<AuthRefConfigInfo> authRefsInfo) throws PropertyException, Exception;    
+               List<AuthRefConfigInfo> authRefConfigInfoList) throws PropertyException, Exception;    
 
     /*
      * Subclasses should override this method if they need to customize their refname generation
index 0ef72eafc733a27946b419d20cccd68416e29929..3d4b70687da0948f26310773a97c0ec7a5b2bdb8 100644 (file)
@@ -72,6 +72,7 @@ import org.collectionspace.services.common.api.RefNameUtils;
 import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthRefConfigInfo;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier;
 import org.collectionspace.services.config.service.DocHandlerParams;
 import org.collectionspace.services.config.service.ListResultField;
 import org.collectionspace.services.config.service.ObjectPartType;
@@ -83,6 +84,7 @@ import org.collectionspace.services.relation.RelationshipType;
 import org.dom4j.Element;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
+import org.nuxeo.ecm.core.api.DocumentNotFoundException;
 import org.nuxeo.ecm.core.api.model.PropertyException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -604,7 +606,7 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
     @Override
     public AuthorityRefList getAuthorityRefs(
             String csid,
-            List<AuthRefConfigInfo> authRefsInfo) throws PropertyException, Exception {
+            List<AuthRefConfigInfo> authRefConfigInfoList) throws PropertyException, Exception {
 
         AuthorityRefList authRefList = new AuthorityRefList();
         AbstractCommonList commonList = (AbstractCommonList) authRefList;
@@ -623,7 +625,7 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
                int nFoundInPage = 0;
                int nFoundTotal = 0;
                
-               ArrayList<RefNameServiceUtils.AuthRefInfo> foundProp
+               ArrayList<RefNameServiceUtils.AuthRefInfo> foundReference
                        = new ArrayList<RefNameServiceUtils.AuthRefInfo>();
                
                boolean releaseRepoSession = false;
@@ -633,14 +635,15 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
                if (repoSession == null) {
                        repoSession = repoClient.getRepositorySession(ctx);
                        releaseRepoSession = true;
+                       this.setRepositorySession(repoSession); // we (the doc handler) should keep track of this repository session in case we need it
                }
                
                try {
                        DocumentModel docModel = repoClient.getDoc(repoSession, ctx, csid).getWrappedObject();
-                       RefNameServiceUtils.findAuthRefPropertiesInDoc(docModel, authRefsInfo, null, foundProps);
+                       RefNameServiceUtils.findAuthRefPropertiesInDoc(docModel, authRefConfigInfoList, null, foundReferences);
                        // Slightly goofy pagination support - how many refs do we expect from one object?
-                       for(RefNameServiceUtils.AuthRefInfo ari:foundProps) {
-                               if((nFoundTotal >= iFirstToUse) && (nFoundInPage < pageSize)) {
+                       for(RefNameServiceUtils.AuthRefInfo ari:foundReferences) {
+                               if ((nFoundTotal >= iFirstToUse) && (nFoundInPage < pageSize)) {
                                        if(appendToAuthRefsList(ari, list)) {
                                                nFoundInPage++;
                                        nFoundTotal++;
@@ -691,25 +694,62 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
                                return true;
                        }
        } catch(PropertyException pe) {
-                       logger.debug("PropertyException on: "+ari.getProperty().getPath()+pe.getLocalizedMessage());
+               String msg = "PropertyException on: "+ari.getProperty().getPath()+pe.getLocalizedMessage();
+               if (logger.isDebugEnabled()) {
+                       logger.debug(msg, pe);
+               } else {
+                       logger.error(msg);
+               }
        }
        return false;
     }
 
+    /**
+     * Fill in all the values to be returned in the authrefs payload for this item.
+     * 
+     * @param authRefFieldName
+     * @param refName
+     * @return
+     */
     private AuthorityRefList.AuthorityRefItem authorityRefListItem(String authRefFieldName, String refName) {
-
+       //
+       // Find the CSID for the authority item
+       //
+       String csid = null;
+       try {
+                       DocumentModel docModel = NuxeoUtils.getDocModelForRefName(this.getRepositorySession(), refName, this.getServiceContext().getResourceMap());
+                       csid = NuxeoUtils.getCsid(docModel);
+               } catch (Exception e1) {
+                       String msg = String.format("Could not find CSID for authority reference with refname = %s.", refName);
+                       if (logger.isDebugEnabled()) {
+                               logger.debug(msg, e1);
+                       } else {
+                               logger.error(msg);
+                       }
+               }
+       
         AuthorityRefList.AuthorityRefItem ilistItem = new AuthorityRefList.AuthorityRefItem();
         try {
             RefNameUtils.AuthorityTermInfo termInfo = RefNameUtils.parseAuthorityTermInfo(refName);
+            if (Tools.isEmpty(csid) == false) {
+               ilistItem.setCsid(csid);
+            }
             ilistItem.setRefName(refName);
             ilistItem.setAuthDisplayName(termInfo.inAuthority.displayName);
             ilistItem.setItemDisplayName(termInfo.displayName);
             ilistItem.setSourceField(authRefFieldName);
             ilistItem.setUri(termInfo.getRelativeUri());
         } catch (Exception e) {
-               logger.error("Trouble parsing refName from value: "+refName+" in field: "+authRefFieldName+e.getLocalizedMessage());
                ilistItem = null;
+               String msg = String.format("Trouble parsing refName from value: %s in field: %s. Error message: %s.",
+                               refName, authRefFieldName + e.getLocalizedMessage());
+               if (logger.isDebugEnabled()) {
+                       logger.debug(msg, e);
+               } else {
+                       logger.error(msg);
+               }
         }
+        
         return ilistItem;
     }
 
index c13df907db2fc351254bc5e5b8510b23c43e9f29..c1febcbbc797cf5814153e764132025527cf53d3 100644 (file)
@@ -32,15 +32,18 @@ import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 
 import org.collectionspace.services.common.NuxeoBasedResource;
+import org.collectionspace.services.common.ResourceMap;
 import org.collectionspace.services.client.CollectionSpaceClient;
 import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.common.api.RefName;
 import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.common.context.ServiceBindingUtils;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentException;
 import org.collectionspace.services.common.document.DocumentFilter;
+import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentUtils;
 import org.collectionspace.services.common.query.QueryContext;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
@@ -55,7 +58,6 @@ import org.collectionspace.services.lifecycle.TransitionDefList;
 import org.collectionspace.services.lifecycle.TransitionList;
 import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentException;
 import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
-
 import org.dom4j.Document;
 import org.dom4j.io.SAXReader;
 import org.nuxeo.ecm.core.NXCore;
@@ -723,6 +725,28 @@ public class NuxeoUtils {
        return null;
     }
     
+    public static DocumentModel getDocModelForRefName(CoreSessionInterface repoSession, String refName, ResourceMap resourceMap)
+               throws DocumentNotFoundException, Exception {
+       RefName.AuthorityItem item = RefName.AuthorityItem.parse(refName);
+       if (item != null) {
+               NuxeoBasedResource resource = (NuxeoBasedResource) resourceMap.get(item.inAuthority.resource);
+               return resource.getDocModelForAuthorityItem(repoSession, item);
+       }
+       RefName.Authority authority = RefName.Authority.parse(refName);
+       // Handle case of objects refNames, which must be csid based.
+       if(authority != null && !Tools.isEmpty(authority.csid)) {
+               NuxeoBasedResource resource = (NuxeoBasedResource) resourceMap.get(authority.resource);
+            // Ensure we have the right context.
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = 
+                       resource.createServiceContext(authority.resource);
+            // HACK - this really must be moved to the doc handler, not here. No Nuxeo specific stuff here!
+            DocumentModel docModel = NuxeoUtils.getDocFromCsid(ctx, repoSession, authority.csid);
+            return docModel;
+       }
+       
+       return null;  // We've failed to find a matching document model
+    }    
+    
     static public DocumentModel getDocFromSpecifier(
                ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
                CoreSessionInterface repoSession,
index 2f27ea0a1e3837d1a666331158c934f38d909559..68c1d4dcd6bd64c913287e485a0a47b946b280b5 100644 (file)
                                                 <xs:element name="authority-ref-item" maxOccurs="unbounded">
                                                        <xs:complexType>
                                                                <xs:sequence>
-                                                                       <xs:element name="sourceField"     type="xs:string" minOccurs="1" />
-                                                                       <xs:element name="refName"         type="xs:string" minOccurs="1" />
-                                                                       <xs:element name="authDisplayName" type="xs:string" minOccurs="1" />
-                                                                       <xs:element name="itemDisplayName" type="xs:string" minOccurs="1" />
-                                                                       <xs:element name="uri"             type="xs:anyURI" minOccurs="1" />
+                                                                       <xs:element name="csid"                         type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="sourceField"      type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="refName"          type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="authDisplayName"  type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="itemDisplayName"  type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="uri"              type="xs:anyURI" minOccurs="1" />
                                                                </xs:sequence>
                                                        </xs:complexType>
                                                </xs:element>