From: remillet Date: Fri, 24 Feb 2017 21:03:36 +0000 (-0800) Subject: DRYD-106: Added CSID value to items in authority references list. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=a0d4839e72b23e502f88e4c710b2a0024723c491;p=tmp%2Fjakarta-migration.git DRYD-106: Added CSID value to items in authority references list. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java index 893c4e0be..21240018f 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java @@ -183,7 +183,7 @@ public abstract class AbstractCollectionSpaceResourceImpl * * @throws Exception the exception */ - protected ServiceContext createServiceContext(String serviceName) throws Exception { + public ServiceContext createServiceContext(String serviceName) throws Exception { ServiceContext ctx = createServiceContext( serviceName, (IT)null, // The input part diff --git a/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java b/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java index 429b1c42f..60697a9c4 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java +++ b/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java @@ -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 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 diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java index aa623abc7..58a6ce1a9 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java @@ -980,19 +980,19 @@ public class RefNameServiceUtils { public static List findAuthRefPropertiesInDoc( DocumentModel docModel, - List authRefFieldInfo, + List authRefFieldInfoList, String refNameToMatch, List foundProps) { - return findAuthRefPropertiesInDoc(docModel, authRefFieldInfo, + return findAuthRefPropertiesInDoc(docModel, authRefFieldInfoList, refNameToMatch, false, foundProps); } public static List findAuthRefPropertiesInDoc( DocumentModel docModel, - List authRefFieldInfo, + List authRefFieldInfoList, String refNameToMatch, boolean matchBaseOnly, - List foundProps) { + List 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 findAuthRefPropertiesInProperty( - List foundProps, + List 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 propList = (List) 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 foundProps) { + List 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()); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index 0f4442248..d26a52c67 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -241,7 +241,7 @@ public abstract class DocumentModelHandler * @throws PropertyException the property exception */ abstract public AuthorityRefList getAuthorityRefs(String csid, - List authRefsInfo) throws PropertyException, Exception; + List authRefConfigInfoList) throws PropertyException, Exception; /* * Subclasses should override this method if they need to customize their refname generation diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 0ef72eafc..3d4b70687 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -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 @Override public AuthorityRefList getAuthorityRefs( String csid, - List authRefsInfo) throws PropertyException, Exception { + List authRefConfigInfoList) throws PropertyException, Exception { AuthorityRefList authRefList = new AuthorityRefList(); AbstractCommonList commonList = (AbstractCommonList) authRefList; @@ -623,7 +625,7 @@ public abstract class RemoteDocumentModelHandlerImpl int nFoundInPage = 0; int nFoundTotal = 0; - ArrayList foundProps + ArrayList foundReferences = new ArrayList(); boolean releaseRepoSession = false; @@ -633,14 +635,15 @@ public abstract class RemoteDocumentModelHandlerImpl 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 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; } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java index c13df907d..c1febcbbc 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java @@ -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 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 ctx, CoreSessionInterface repoSession, diff --git a/services/jaxb/src/main/resources/authorityref.xsd b/services/jaxb/src/main/resources/authorityref.xsd index 2f27ea0a1..68c1d4dcd 100644 --- a/services/jaxb/src/main/resources/authorityref.xsd +++ b/services/jaxb/src/main/resources/authorityref.xsd @@ -41,11 +41,12 @@ - - - - - + + + + + +