public String shortIdentifier = "";
public String displayName = "";
- public static AuthorityItem parse(String urn) {
+ public static AuthorityItem parse(String urn) throws IllegalArgumentException {
AuthorityItem authorityItem = null;
- try {
- RefNameUtils.AuthorityTermInfo termInfo =
- RefNameUtils.parseAuthorityTermInfo(urn);
- authorityItem = authorityItemFromTermInfo(termInfo);
- } catch (IllegalArgumentException iae) {
- return null;
- }
+
+ RefNameUtils.AuthorityTermInfo termInfo = RefNameUtils.parseAuthorityTermInfo(urn);
+ authorityItem = authorityItemFromTermInfo(termInfo);
+
return authorityItem;
}
return new AuthorityInfo(refNameTokens);
}
- public static AuthorityTermInfo parseAuthorityTermInfo(String refName)
- throws IllegalArgumentException {
- if(refName==null || !refName.startsWith(URN_PREFIX))
- throw new IllegalArgumentException( "Null or invalid refName syntax");
- String[] refNameTokens = refName.substring(URN_PREFIX_LEN).split(SEPARATOR, AUTH_ITEM_REFNAME_TOKENS);
- return new AuthorityTermInfo(refNameTokens);
- }
+ public static AuthorityTermInfo parseAuthorityTermInfo(String refName) throws IllegalArgumentException {
+ if (refName == null || !refName.startsWith(URN_PREFIX)) {
+ throw new IllegalArgumentException("Null or invalid refName syntax");
+ }
+ String[] refNameTokens = refName.substring(URN_PREFIX_LEN).split(SEPARATOR, AUTH_ITEM_REFNAME_TOKENS);
+ return new AuthorityTermInfo(refNameTokens);
+ }
public static String stripAuthorityTermDisplayName(String refName)
throws IllegalArgumentException {
* for all inheriting resource classes. Just use ServiceContext.getResourceMap() to get
* the map, and pass it in.
*/
- public static DocumentModel getDocModelForRefName(CoreSessionInterface repoSession, String refName, ResourceMap resourceMap)
+ public static DocumentModel getDocModelForRefName(ServiceContext ctx, String refName, ResourceMap resourceMap)
throws Exception, DocumentNotFoundException {
- return NuxeoUtils.getDocModelForRefName(repoSession, refName, resourceMap);
+ return NuxeoUtils.getDocModelForRefName(ctx, refName, resourceMap);
}
// This is ugly, but prevents us parsing the refName twice. Once we make refName a little more
try {
QueryContext queryContext = new QueryContext(ctx, selectClause, whereClause, orderByClause);
- result = NuxeoUtils.buildNXQLQuery(ctx, queryContext);
+ result = NuxeoUtils.buildNXQLQuery(queryContext);
} catch (DocumentException de) {
throw de;
} catch (Exception x) {
+ NuxeoUtils.buildWorkflowNotDeletedWhereClause();
QueryContext queryContext = new QueryContext(ctx, whereClause);
queryContext.setDocType(IRelationsManager.DOC_TYPE);
- String query = NuxeoUtils.buildNXQLQuery(ctx, queryContext);
+ String query = NuxeoUtils.buildNXQLQuery(queryContext);
// Search for 1 relation that matches. 1 is enough to fail
// the filter
DocumentModelList docList = repoSession.query(query, null, 1, 0, false);
//
String csid = null;
try {
- DocumentModel docModel = NuxeoUtils.getDocModelForRefName(this.getRepositorySession(), refName, this.getServiceContext().getResourceMap());
+ DocumentModel docModel = NuxeoUtils.getDocModelForRefName(getServiceContext(), refName, getServiceContext().getResourceMap());
csid = NuxeoUtils.getCsid(docModel);
} catch (Exception e1) {
String msg = String.format("Could not find CSID for authority reference with refname = %s.", refName);
logger.trace("Fetching CSID for child with only refname: "+newChildRefName);
}
DocumentModel newChildDocModel =
- NuxeoBasedResource.getDocModelForRefName(this.getRepositorySession(),
+ NuxeoBasedResource.getDocModelForRefName(getServiceContext(),
newChildRefName, getServiceContext().getResourceMap());
newChildCsid = getCsid(newChildDocModel);
}
DocumentModelList docList = null;
// force limit to 1, and ignore totalSize
- String query = NuxeoUtils.buildNXQLQuery(ctx, queryContext);
+ String query = NuxeoUtils.buildNXQLQuery(queryContext);
docList = repoSession.query(query, null, 1, 0, false);
if (docList.size() != 1) {
throw new DocumentNotFoundException("No document found matching filter params: " + query);
QueryContext queryContext = new QueryContext(ctx, whereClause);
DocumentModelList docList = null;
// force limit to 1, and ignore totalSize
- String query = NuxeoUtils.buildNXQLQuery(ctx, queryContext);
+ String query = NuxeoUtils.buildNXQLQuery(queryContext);
docList = repoSession.query(query,
null, //Filter
1, //limit
docList = getFilteredCMIS(repoSession, ctx, handler, queryContext); //FIXME: REM - Need to deal with paging info in CMIS query
// NXQL query
} else {
- String query = NuxeoUtils.buildNXQLQuery(ctx, queryContext);
+ String query = NuxeoUtils.buildNXQLQuery(queryContext);
if (logger.isDebugEnabled()) {
logger.debug("Executing NXQL query: " + query.toString());
}
* @return an NXQL query
* @throws Exception if supplied values in the query are invalid.
*/
- static public final String buildNXQLQuery(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, QueryContext queryContext) throws Exception {
+ static public final String buildNXQLQuery(QueryContext queryContext) throws Exception {
StringBuilder query = new StringBuilder(queryContext.getSelectClause());
// Since we have a tenant qualification in the WHERE clause, we do not need
// tenant-specific doc types
//
// Since we're doing a query, we get back a list so we need to make sure there is only
// a single result since CSID values are supposed to be unique.
- String query = buildNXQLQuery(ctx, queryContext);
+ String query = buildNXQLQuery(queryContext);
docModelList = repoSession.query(query);
long resultSize = docModelList.totalSize();
if (resultSize == 1) {
return null;
}
- public static DocumentModel getDocModelForRefName(CoreSessionInterface repoSession, String refName, ResourceMap resourceMap)
+ /**
+ * The refname could be for an authority, an authority item/term, or a csid-form to an object or procedure record
+ * @param repoSession
+ * @param refName
+ * @param resourceMap
+ * @return
+ * @throws DocumentNotFoundException
+ * @throws Exception
+ */
+ public static DocumentModel getDocModelForRefName(ServiceContext<PoxPayloadIn,PoxPayloadOut> ctx, 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.AuthorityItem item = null;
+ CoreSessionInterface repoSession = (CoreSessionInterface)ctx.getCurrentRepositorySession();
+ //
+ // Let's see if our refname refers to an authority item/term.
+ //
+ try {
+ item = RefName.AuthorityItem.parse(refName);
+ if (item != null) {
+ NuxeoBasedResource resource = (NuxeoBasedResource) resourceMap.get(item.inAuthority.resource);
+ return resource.getDocModelForAuthorityItem(repoSession, item);
+ }
+ } catch (IllegalArgumentException e) {
+ // Ignore exception
}
- RefName.Authority authority = RefName.Authority.parse(refName);
- // Handle case of objects refNames, which must be csid based.
- if(authority != null && !Tools.isEmpty(authority.csid)) {
+
+ //
+ // If we got this far, we know the refname doesn't refer to an authority item/term, so it might refer
+ // to an authority or an object or procedure.
+ //
+ RefName.Authority authority = RefName.Authority.parse(refName); // could be an authority or an object or procedure record
+ // 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;
//
// Since we're doing a query, we get back a list so we need to make sure there is only
// a single result since CSID values are supposed to be unique.
- String query = buildNXQLQuery(ctx, queryContext);
+ String query = buildNXQLQuery(queryContext);
docModelList = repoSession.query(query);
long resultSize = docModelList.totalSize();
if (resultSize == 1) {
//
// Since we're doing a query, we get back a list so we need to make sure there is only
// a single result since CSID values are supposed to be unique.
- String query = buildNXQLQuery(ctx, queryContext);
+ String query = buildNXQLQuery(queryContext);
docModelList = repoSession.query(query);
long resultSize = docModelList.totalSize();
if (resultSize == 1) {
try {
refName = (String) relationDocModel.getProperty(commonPartLabel,
(fSubject?RelationJAXBSchema.SUBJECT_REFNAME:RelationJAXBSchema.OBJECT_REFNAME));
- docModel = NuxeoBasedResource.getDocModelForRefName(repoSession, refName, ctx.getResourceMap());
+ docModel = NuxeoBasedResource.getDocModelForRefName(ctx, refName, ctx.getResourceMap());
} catch (Exception e) {
throw new InvalidDocumentException(
"Relation record must have a CSID or refName to identify the object of the relation.", e);
return hasRefName(objectRefName);
}
+ /**
+ * Check to see if the refname is valid. It can be a refname of either an authority, an authority item, or another record type.
+ * @param refName
+ * @return
+ */
private boolean hasRefName(String refName) {
- boolean hasRefname = false;
- if (Tools.isBlank(refName)) {
- return hasRefname;
- } else {
- Authority authority = Authority.parse(refName);
- AuthorityItem authItem = AuthorityItem.parse(refName);
- if (authority != null || authItem != null) {
- hasRefname = true;
- }
- return hasRefname;
+ boolean result = false; // assume it's not a valid refname
+
+ if (Tools.isBlank(refName) == false) {
+ try {
+ Authority authority = Authority.parse(refName); // Will also parse refname to an object or procedure record
+ if (authority != null) {
+ result = true;
+ } else {
+ AuthorityItem authItem = AuthorityItem.parse(refName); // See if it is a refname to an authority item or vocabulary term
+ result = authItem != null;
+ }
+ } catch (IllegalArgumentException e) {
+ // Ignore exception
+ }
}
+ return result;
}
}
<groupId>org.collectionspace.services</groupId>
<artifactId>org.collectionspace.services.common</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.collectionspace.services</groupId>
+ <artifactId>org.collectionspace.services.authority.service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.collectionspace.services</groupId>
<artifactId>org.collectionspace.services.servicegroup.client</artifactId>
@GET
@Path("{csid}/items")
- public AbstractCommonList getItemList(
+ public AbstractCommonList getResourceItemList(
@Context UriInfo uriInfo,
@PathParam("csid") String serviceGroupName) {
UriInfoWrapper ui = new UriInfoWrapper(uriInfo);
@GET
@Path("{csid}/items/{specifier}")
- public byte[] getItem(
+ public byte[] getResourceItem(
@Context ResourceMap resourceMap,
@Context UriInfo uriInfo,
@PathParam("csid") String serviceGroupName,
DocumentFilter myFilter = new NuxeoDocumentFilter(whereClause, 0, 1);
handler.setDocumentFilter(myFilter);
- result = handler.getItemForCsid(ctx, groupsList, specifier);
+ result = handler.getResourceItemForCsid(ctx, groupsList, specifier);
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.READ_FAILED, serviceGroupName);
}
import org.collectionspace.services.nuxeo.client.java.RepositoryClientImpl;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.collectionspace.services.jaxb.AbstractCommonList;
+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.NuxeoBasedResource;
import org.collectionspace.services.common.CSWebApplicationException;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.UriTemplateFactory;
import org.collectionspace.services.common.UriTemplateRegistry;
import org.collectionspace.services.common.UriTemplateRegistryKey;
+import org.collectionspace.services.common.api.RefName;
+import org.collectionspace.services.common.api.RefNameUtils;
+import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo;
import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
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.DocumentWrapper;
import org.collectionspace.services.common.security.SecurityUtils;
import org.collectionspace.services.common.query.nuxeo.QueryManagerNuxeoImpl;
-
import org.collectionspace.services.config.service.ServiceBindingType;
import org.collectionspace.services.config.service.ServiceObjectType;
import org.collectionspace.services.servicegroup.ServicegroupsCommon;
-
+import org.collectionspace.services.common.vocabulary.AuthorityResource;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentModelList;
-
+import org.nuxeo.ecm.core.api.PropertyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
protected static final String DOC_TYPE_FIELD = "docType";
protected static final String DOC_NUMBER_FIELD = "docNumber";
protected static final String DOC_NAME_FIELD = "docName";
+
+ //
+ // Returns a service payload for an authority item
+ //
+ private PoxPayloadOut getAuthorityItem(ServiceContext ctx, String termRefName) throws Exception {
+ PoxPayloadOut result = null;
+
+ RefName.AuthorityItem item = RefName.AuthorityItem.parse(termRefName);
+ AuthorityResource authorityResource = (AuthorityResource) ctx.getResourceMap().get(item.inAuthority.resource);
+
+ AuthorityTermInfo authorityTermInfo = RefNameUtils.parseAuthorityTermInfo(termRefName);
+ String parentIdentifier = Specifier.createShortIdURNValue(authorityTermInfo.inAuthority.name);
+ String itemIdentifier = Specifier.createShortIdURNValue(authorityTermInfo.name);
+
+ result = authorityResource.getAuthorityItemWithExistingContext(ctx, parentIdentifier, itemIdentifier);
+
+ return result;
+ }
- public PoxPayloadOut getItemForCsid(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+ public PoxPayloadOut getResourceItemForCsid(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
List<String> serviceGroupNames,
String csid) throws DocumentException {
PoxPayloadOut result = null;
DocumentModelList docList = this.getDocListForGroup(ctx, serviceGroupNames, queriedServiceBindings,
repoSession, repoClient);
if (docList == null) { // found no authRef fields - nothing to process
- //return list;
+ throw new DocumentNotFoundException();
}
DocumentModel docModel = docList.get(0);
- TenantBindingConfigReaderImpl bindingReader = ServiceMain.getInstance().getTenantBindingConfigReader();
- String serviceName = ServiceBindingUtils.getServiceNameFromObjectName(bindingReader, ctx.getTenantId(),
- docModel.getDocumentType().getName());
- NuxeoBasedResource resource = (NuxeoBasedResource) ctx.getResourceMap().get(serviceName);
- result = resource.getWithParentCtx(ctx, csid);
+ //
+ // Determine if the docModel is an authority term, object, or some other procedure record.
+ //
+ String termRefName = (String) NuxeoUtils.getProperyValue(docModel, CollectionSpaceClient.COLLECTIONSPACE_CORE_REFNAME);
+ if (isAuthorityTermDocument(termRefName) == true) {
+ result = getAuthorityItem(ctx, termRefName);
+ } else {
+ TenantBindingConfigReaderImpl bindingReader = ServiceMain.getInstance().getTenantBindingConfigReader();
+ String serviceName = ServiceBindingUtils.getServiceNameFromObjectName(bindingReader, ctx.getTenantId(),
+ docModel.getDocumentType().getName());
+ NuxeoBasedResource resource = (NuxeoBasedResource) ctx.getResourceMap().get(serviceName);
+ result = resource.getWithParentCtx(ctx, csid);
+ }
} catch (DocumentException de) {
throw de;
} catch (Exception e) {
return result;
}
- private DocumentModelList getDocListForGroup(
+ private boolean isAuthorityTermDocument(String termRefName) {
+ boolean result = true;
+
+ try {
+ //String inAuthorityCsid = (String) NuxeoUtils.getProperyValue(docModel, "inAuthority"); //docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY
+ //String refName = (String) NuxeoUtils.getProperyValue(docModel, CollectionSpaceClient.COLLECTIONSPACE_CORE_REFNAME);
+ RefName.AuthorityItem item = RefName.AuthorityItem.parse(termRefName);
+ } catch (IllegalArgumentException e) {
+ result = false;
+ }
+
+ return result;
+ }
+
+ private DocumentModelList getDocListForGroup(
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
List<String> serviceGroupNames,
Map<String, ServiceBindingType> queriedServiceBindings,
docType = ServiceBindingUtils.getUnqualifiedTenantDocType(docType);
ServiceBindingType sb = queriedServiceBindings.get(docType);
if (sb == null) {
- throw new RuntimeException(
- "processDocList: No Service Binding for docType: " + docType);
+ throw new RuntimeException("processDocList: No Service Binding for docType: " + docType);
}
String csid = NuxeoUtils.getCsid(docModel);