protected String buildAuthorityRefNameBase(
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String shortIdentifier) {
RefName.Authority authority = RefName.Authority.buildAuthority(ctx.getTenantName(),
- ctx.getServiceName(), shortIdentifier, null);
+ ctx.getServiceName(),
+ null, // Only use shortId form!!!
+ shortIdentifier, null);
return authority.toString();
}
String displayName = (String) docModel.getProperty(authorityCommonSchemaName, AuthorityJAXBSchema.DISPLAY_NAME);
RefName.Authority authority = RefName.Authority.buildAuthority(ctx.getTenantName(),
ctx.getServiceName(),
+ null, // Only use shortId form!!!
shortIdentifier,
displayName);
refname = authority;
\r
public String tenantName = "";\r
public String resource = "";\r
- public String shortIdentifier = "";\r
+ public String csid = null;\r
+ public String shortIdentifier = null;\r
public String displayName = "";\r
\r
public static Authority parse(String urn) {\r
return this.shortIdentifier;\r
}\r
\r
+ public String getCSID() {\r
+ return this.csid;\r
+ }\r
+\r
public boolean equals(Object other) {\r
if (other == null) {\r
return false;\r
Authority ao = (Authority) other;\r
return (this.tenantName.equals(ao.tenantName)\r
&& this.resource.equals(ao.resource)\r
- && this.shortIdentifier.equals(ao.shortIdentifier));\r
+ && ((this.shortIdentifier != null &&\r
+ this.shortIdentifier.equals(ao.shortIdentifier))\r
+ || (this.csid != null && this.csid.equals(ao.csid))));\r
} else {\r
return false;\r
}\r
}\r
\r
public String getRelativeUri() {\r
- return "/" + resource + "/" + URN_NAME_PREFIX + "(" + shortIdentifier + ")";\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("/");\r
+ sb.append(resource);\r
+ sb.append("/");\r
+ if(csid!=null) {\r
+ sb.append(csid);\r
+ } else if(shortIdentifier!= null) {\r
+ sb.append(URN_NAME_PREFIX);\r
+ sb.append("(");\r
+ sb.append(shortIdentifier);\r
+ sb.append(")");\r
+ } else {\r
+ throw new NullPointerException("Authority has neither CSID nor shortID!");\r
+ }\r
+ return sb.toString();\r
}\r
\r
public String toString() {\r
String displaySuffix = (displayName != null && (!displayName.isEmpty())) ? '\'' + displayName + '\'' : "";\r
- return URN_PREFIX + tenantName + ':' + resource + ":" + "name" + "(" + shortIdentifier + ")" + displaySuffix;\r
+ //return URN_PREFIX + tenantName + ':' + resource + ":" + "name" + "(" + shortIdentifier + ")" + displaySuffix;\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append(URN_PREFIX);\r
+ sb.append(tenantName);\r
+ sb.append(RefNameUtils.SEPARATOR);\r
+ sb.append(resource);\r
+ sb.append(RefNameUtils.SEPARATOR);\r
+ if(csid!=null) {\r
+ sb.append(RefNameUtils.ID_SPECIFIER);\r
+ sb.append("(");\r
+ sb.append(csid);\r
+ sb.append(")");\r
+ } else if(shortIdentifier!= null) {\r
+ sb.append(RefNameUtils.NAME_SPECIFIER);\r
+ sb.append("(");\r
+ sb.append(shortIdentifier);\r
+ sb.append(")");\r
+ } else {\r
+ throw new NullPointerException("Authority has neither CSID nor shortID!");\r
+ }\r
+ sb.append(displaySuffix);\r
+ return sb.toString();\r
}\r
\r
- public static Authority buildAuthority(String tenantName, String serviceName, String authorityShortIdentifier, String authorityDisplayName) {\r
+ public static Authority buildAuthority(\r
+ String tenantName, \r
+ String serviceName, \r
+ String csid, \r
+ String authorityShortIdentifier, \r
+ String authorityDisplayName) {\r
Authority authority = new Authority();\r
authority.tenantName = tenantName;\r
authority.resource = serviceName;\r
if (Tools.notEmpty(authority.resource)) {\r
authority.resource = authority.resource.toLowerCase();\r
}\r
+ authority.csid = csid;\r
authority.shortIdentifier = authorityShortIdentifier;\r
authority.displayName = authorityDisplayName;\r
return authority;\r
\r
public static AuthorityItem buildAuthorityItem(String tenantName, String serviceName, String authorityShortID,\r
String itemShortID, String itemDisplayName) {\r
- Authority authority = Authority.buildAuthority(tenantName, serviceName, authorityShortID, "");\r
+ Authority authority = Authority.buildAuthority(tenantName, serviceName, null, authorityShortID, "");\r
return buildAuthorityItem(authority, itemShortID, itemDisplayName);\r
}\r
\r
if (authorityInfo.name != null\r
&& !authorityInfo.name.trim().isEmpty()) {\r
authority.shortIdentifier = authorityInfo.name;\r
- } else {\r
- authority.shortIdentifier = authorityInfo.csid;\r
+ }\r
+ if (authorityInfo.csid != null\r
+ && !authorityInfo.csid.trim().isEmpty()) {\r
+ authority.csid = authorityInfo.csid;\r
}\r
if (includeDisplayName) {\r
authority.displayName = authorityInfo.displayName;\r
public static final int URN_PREFIX_LEN = 11;
public static final String URN_NAME_PREFIX = "urn:cspace:name(";
public static final int URN_NAME_PREFIX_LEN = 16;
+ public static final String NAME_SPECIFIER = "name";
+ public static final String ID_SPECIFIER = "id";
+
// FIXME Should not be hard-coded
private static final String ITEMS_REGEX = "item|person|organization";
// In a list of tokens, these are indices for each part
if(idTokens.length<INSTANCE_TOKENS_MIN) {
throw new IllegalArgumentException("Missing/malformed identifier");
}
- if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].equals("name")) {
+ if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].equals(NAME_SPECIFIER)) {
this.name = idTokens[INSTANCE_SPEC_TOKEN];
this.csid = null;
- } else if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].startsWith("id")) {
+ } else if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].startsWith(ID_SPECIFIER)) {
this.csid = idTokens[INSTANCE_SPEC_TOKEN];
this.name = null;
} else {
- throw new IllegalArgumentException("Identifier type must be 'name' or 'id'");
+ throw new IllegalArgumentException("Identifier type must be '"
+ +NAME_SPECIFIER+"' or '"+ID_SPECIFIER+"'");
}
// displayName is always in quotes, so must have at least 3 chars
this.displayName =
if(idTokens.length<INSTANCE_TOKENS_MIN) {
throw new IllegalArgumentException("Missing/malformed identifier");
}
- if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].equals("name")) {
+ if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].equals(NAME_SPECIFIER)) {
this.name = idTokens[INSTANCE_SPEC_TOKEN];
this.csid = null;
- } else if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].startsWith("id")) {
+ } else if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].startsWith(ID_SPECIFIER)) {
this.csid = idTokens[INSTANCE_SPEC_TOKEN];
this.name = null;
} else {
import org.collectionspace.services.common.document.DocumentFilter;\r
import org.collectionspace.services.common.document.DocumentHandler;\r
import org.collectionspace.services.common.document.DocumentNotFoundException;\r
+import org.collectionspace.services.common.document.DocumentWrapper;\r
import org.collectionspace.services.common.query.QueryManager;\r
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;\r
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthRefConfigInfo;\r
import org.collectionspace.services.config.service.ServiceBindingType;\r
import org.collectionspace.services.jaxb.AbstractCommonList;\r
import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;\r
+import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;\r
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
import org.jboss.resteasy.util.HttpResponseCodes;\r
import org.nuxeo.ecm.core.api.DocumentModel;\r
*/\r
public static DocumentModel getDocModelForRefName(RepositoryInstance repoSession, String refName, ResourceMap resourceMap) \r
throws Exception, DocumentNotFoundException {\r
- // TODO - we need to generalize the idea of a refName to more than Authorities and Items. \r
RefName.AuthorityItem item = RefName.AuthorityItem.parse(refName);\r
- if(item == null) {\r
- return null;\r
+ if(item != null) {\r
+ ResourceBase resource = resourceMap.get(item.inAuthority.resource);\r
+ return resource.getDocModelForAuthorityItem(repoSession, item);\r
}\r
- ResourceBase resource = resourceMap.get(item.inAuthority.resource);\r
- return resource.getDocModelForAuthorityItem(repoSession, item);\r
+ RefName.Authority authority = RefName.Authority.parse(refName);\r
+ // Handle case of objects refNames, which must be csid based.\r
+ if(authority != null && !Tools.isEmpty(authority.csid)) {\r
+ ResourceBase resource = resourceMap.get(authority.resource);\r
+ // Ensure we have the right context.\r
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = \r
+ resource.createServiceContext(authority.resource);\r
+ // HACK - this really must be moved to the doc handler, not here. No Nuxeo specific stuff here!\r
+ DocumentModel docModel = NuxeoUtils.getDocFromCsid(ctx, repoSession, authority.csid);\r
+ return docModel;\r
+ }\r
+ return null;\r
}\r
\r
// THis is ugly, but prevents us parsing the refName twice. Once we make refName a little more\r
String csid = docWrapper.getWrappedObject().getName();
String refnameDisplayName = getRefnameDisplayName(docWrapper);
RefName.RefNameInterface refname = RefName.Authority.buildAuthority(tenantName, serviceName,
- csid, refnameDisplayName);
+ csid, null, refnameDisplayName);
return refname;
}
}
}
if(docModel==null) {
- throw new DocumentNotFoundException("Relation.getSubjectOrObjectDocModel could not find doc with CSID: "
+ throw new DocumentNotFoundException("RelationDMH.getSubjectOrObjectDocModel could not find doc with CSID: "
+csid+" and/or refName: "+refName );
}
return docModel;
properties.put((fSubject?RelationJAXBSchema.SUBJECT_URI:RelationJAXBSchema.OBJECT_URI),
uri);
+ /*
String common_schema = getCommonSchemaNameForDocType(doctype);
if(common_schema!=null) {
properties.put((fSubject?RelationJAXBSchema.SUBJECT_REFNAME:RelationJAXBSchema.OBJECT_REFNAME),
refname);
}
+ */
+ String refname = (String)
+ subjectOrObjectDocModel.getProperty(
+ CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
+ CollectionSpaceClient.COLLECTIONSPACE_CORE_REFNAME);
+ properties.put((fSubject?
+ RelationJAXBSchema.SUBJECT_REFNAME
+ :RelationJAXBSchema.OBJECT_REFNAME),
+ refname);
} catch (ClientException ce) {
throw new RuntimeException(
"populateSubjectOrObjectValues: Problem fetching field " + ce.getLocalizedMessage());
}
}
+ /*
private String getCommonSchemaNameForDocType(String docType) {
String common_schema = null;
if(docType!=null) {
}
return common_schema;
}
+ */
}