*
* @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
*/
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
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
// "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
}
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
+ 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: "
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: "
}
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(
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 {
// 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());
* @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
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;
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;
@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;
int nFoundInPage = 0;
int nFoundTotal = 0;
- ArrayList<RefNameServiceUtils.AuthRefInfo> foundProps
+ ArrayList<RefNameServiceUtils.AuthRefInfo> foundReferences
= new ArrayList<RefNameServiceUtils.AuthRefInfo>();
boolean releaseRepoSession = false;
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++;
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;
}
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;
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;
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,
<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>