*/\r
public interface AuthorityItemJAXBSchema {\r
\r
- final static String IN_AUTHORITY = "inAuthority";\r
+ final static String IN_AUTHORITY = "inAuthority"; // REM - Is this a CSID? Or a refname? Either?\r
final static String REF_NAME = "refName";\r
final static String ORDER = "order";\r
final static String SHORT_IDENTIFIER = "shortIdentifier";\r
protected String buildAuthorityRefNameBase(
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String shortIdentifier) {
- RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
+ RefName.Authority authority = RefName.Authority.buildAuthority(ctx.getTenantName(),
ctx.getServiceName(), shortIdentifier, null);
return authority.toString();
}
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.RefName.Authority;
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.common.context.MultipartServiceContext;
import org.collectionspace.services.common.context.ServiceContext;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* AuthorityDocumentModelHandler
public abstract class AuthorityDocumentModelHandler<AuthCommon>
extends DocHandlerBase<AuthCommon> {
+ private final Logger logger = LoggerFactory.getLogger(AuthorityDocumentModelHandler.class);
private String authorityCommonSchemaName;
public AuthorityDocumentModelHandler(String authorityCommonSchemaName) {
*/
protected void updateRefnameForAuthority(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception {
DocumentModel docModel = wrapDoc.getWrappedObject();
- String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
- String displayName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
- MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
- RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
- ctx.getServiceName(),
- shortIdentifier,
- displayName);
+ RefName.Authority authority = (Authority) getRefName(getServiceContext(), docModel);
String refName = authority.toString();
docModel.setProperty(schemaName, AuthorityJAXBSchema.REF_NAME, refName);
}
-
+
+ @Override
+ public RefName.RefNameInterface getRefName(ServiceContext ctx,
+ DocumentModel docModel) {
+ RefName.RefNameInterface refname = null;
+
+ try {
+ String shortIdentifier = (String) docModel.getProperty(authorityCommonSchemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
+ String displayName = (String) docModel.getProperty(authorityCommonSchemaName, AuthorityJAXBSchema.DISPLAY_NAME);
+ RefName.Authority authority = RefName.Authority.buildAuthority(ctx.getTenantName(),
+ ctx.getServiceName(),
+ shortIdentifier,
+ displayName);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+
+ return refname;
+ }
+
+ @Override
+ protected String getRefnameDisplayName(DocumentWrapper<DocumentModel> docWrapper) {
+ String result = null;
+
+ DocumentModel docModel = docWrapper.getWrappedObject();
+ ServiceContext ctx = this.getServiceContext();
+ RefName.Authority refname = (RefName.Authority)getRefName(ctx, docModel);
+ result = refname.getDisplayName();
+
+ return result;
+ }
+
public String getShortIdentifier(String authCSID, String schemaName) throws Exception {
String shortIdentifier = null;
RepositoryInstance repoSession = null;
import org.collectionspace.services.common.document.DocumentException;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentWrapper;
+import org.collectionspace.services.common.document.DocumentWrapperImpl;
import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
this.authorityItemCommonSchemaName = authorityItemCommonSchemaName;
}
+ @Override
+ protected String getRefnameDisplayName(DocumentWrapper<DocumentModel> docWrapper) {
+ String result = null;
+
+ DocumentModel docModel = docWrapper.getWrappedObject();
+ ServiceContext ctx = this.getServiceContext();
+ RefName.AuthorityItem refname = (RefName.AuthorityItem)getRefName(ctx, docModel);
+ result = refname.getDisplayName();
+
+ return result;
+ }
+
+ /*
+ * Before calling this method, be sure that the 'this.handleCreate()' was called and was successful.
+ * (non-Javadoc)
+ * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getRefName(org.collectionspace.services.common.context.ServiceContext, org.nuxeo.ecm.core.api.DocumentModel)
+ */
+ @Override
+ public RefName.RefNameInterface getRefName(ServiceContext ctx,
+ DocumentModel docModel) {
+ RefName.RefNameInterface refname = null;
+
+ try {
+ String shortIdentifier = (String) docModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
+ if (Tools.isEmpty(shortIdentifier)) {
+ throw new Exception("The shortIdentifier for this authority term was empty or not set.");
+ }
+
+ String displayName = getPrimaryDisplayName(docModel, authorityItemCommonSchemaName,
+ getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+ if (Tools.isEmpty(displayName)) {
+ throw new Exception("The displayName for this authority term was empty or not set.");
+ }
+
+ String authorityRefBaseName = getAuthorityRefNameBase();
+ if (Tools.isEmpty(authorityRefBaseName)) {
+ throw new Exception("Could not create the refName for this authority term, because the refName for its authority parent was empty.");
+ }
+
+ RefName.Authority parentsRefName = RefName.Authority.parse(authorityRefBaseName);
+ refname = RefName.buildAuthorityItem(parentsRefName, shortIdentifier, displayName);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+
+ return refname;
+ }
+
public void setInAuthority(String inAuthority) {
this.inAuthority = inAuthority;
}
String schemaName,
String authorityRefBaseName) throws Exception {
DocumentModel docModel = wrapDoc.getWrappedObject();
- String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
- String displayName = getPrimaryDisplayName(docModel, authorityItemCommonSchemaName,
- getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
-
- if (Tools.isEmpty(authorityRefBaseName)) {
- throw new Exception("Could not create the refName for this authority term, because the refName for its authority parent was empty.");
- }
-
- RefName.Authority authority = RefName.Authority.parse(authorityRefBaseName);
- String refName = RefName.buildAuthorityItem(authority, shortIdentifier, displayName).toString();
- docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refName);
+ RefName.RefNameInterface refname = getRefName(this.getServiceContext(), docModel);
+ String refNameStr = refname.toString();
+ docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr);
}
/**
public static final String URN_PREFIX = "urn:cspace:";\r
public static final String URN_NAME_PREFIX = "urn:cspace:name";\r
public static final String REFNAME = "refName";\r
+ \r
+ public static interface RefNameInterface {\r
+ public String toString();\r
+ }\r
\r
- public static class Authority {\r
+ public static class Authority implements RefNameInterface {\r
\r
public String tenantName = "";\r
public String resource = "";\r
return authority;\r
}\r
\r
+ public String getDisplayName() {\r
+ return this.getDisplayName();\r
+ }\r
+ \r
public String getShortIdentifier() {\r
return this.shortIdentifier;\r
}\r
}\r
}\r
\r
- public static class AuthorityItem {\r
+ public static class AuthorityItem implements RefNameInterface {\r
\r
public Authority inAuthority;\r
public String shortIdentifier = "";\r
return authorityItem;\r
}\r
\r
+ public String getDisplayName() {\r
+ return this.displayName;\r
+ }\r
+ \r
public String getParentShortIdentifier() {\r
return this.inAuthority.shortIdentifier;\r
}\r
}\r
}\r
\r
- public static AuthorityItem buildAuthorityItem(String tenantName, String serviceName, String authorityShortIdentifier,\r
- String itemShortIdentifier, String itemDisplayName) {\r
- Authority authority = Authority.buildAuthority(tenantName, serviceName, authorityShortIdentifier, "");\r
- return buildAuthorityItem(authority, itemShortIdentifier, itemDisplayName);\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
+ return buildAuthorityItem(authority, itemShortID, itemDisplayName);\r
}\r
\r
public static AuthorityItem buildAuthorityItem(String authorityRefName, String itemShortID, String itemDisplayName) {\r
return item;\r
}\r
\r
- public static AuthorityItem buildAuthorityItem(Authority authority, String itemShortIdentifier, String itemDisplayName) {\r
+ public static AuthorityItem buildAuthorityItem(Authority authority, String itemShortID, String itemDisplayName) {\r
AuthorityItem item = new AuthorityItem();\r
item.inAuthority = authority;\r
- item.shortIdentifier = itemShortIdentifier;\r
+ item.shortIdentifier = itemShortID;\r
item.displayName = itemDisplayName;\r
return item;\r
}\r
<service:documentHandler xmlns:service="http://collectionspace.org/services/config/service">org.collectionspace.services.collectionobject.nuxeo.CollectionObjectDocumentModelHandler</service:documentHandler>
<service:DocHandlerParams xmlns:service="http://collectionspace.org/services/config/service">
<service:params>
+ <service:SupportsHierarchy>false</service:SupportsHierarchy>
+ <service:RefnameDisplayNameField>
+ <service:ListResultField>
+ <service:element>objectNumber</service:element>
+ <service:xpath>objectNumber</service:xpath>
+ </service:ListResultField>
+ </service:RefnameDisplayNameField>
<service:ListResultsFields>
<service:ListResultField>
<service:element>objectNumber</service:element>
<service:DocHandlerParams xmlns:service="http://collectionspace.org/services/config/service">
<service:params>
<service:SupportsHierarchy>true</service:SupportsHierarchy>
+ <service:RefnameDisplayNameField>
+ <service:ListResultField>
+ <service:element>order</service:element>
+ <service:xpath>order</service:xpath>
+ </service:ListResultField>
+ </service:RefnameDisplayNameField>
<service:ListResultsFields>
<!-- Omit the standard AuthorityItem fields (they are handled by the code) -->
<service:ListResultField>
import java.util.Map;
import java.util.StringTokenizer;
+
+import org.collectionspace.services.common.api.RefName;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.query.QueryContext;
// Empty constructor
}
+ abstract protected String getRefnameDisplayName(DocumentWrapper<WT> docWrapper);
+
+ /*
+ * Should return a reference name for the wrapper object
+ */
+ abstract public RefName.RefNameInterface getRefName(DocumentWrapper<WT> docWrapper, String tenantName, String serviceName);
+
/* (non-Javadoc)
* @see org.collectionspace.services.common.document.DocumentHandler#getServiceContext()
*/
\r
import java.util.List;\r
\r
+import org.collectionspace.services.common.api.RefName;\r
import org.collectionspace.services.common.document.AbstractDocumentHandlerImpl;\r
import org.collectionspace.services.common.document.DocumentFilter;\r
import org.collectionspace.services.common.document.DocumentWrapper;\r
public abstract class JpaDocumentHandler<T, TL, WT, WLT>\r
extends AbstractDocumentHandlerImpl<T, TL, WT, WLT>{\r
\r
+ @Override\r
+ protected String getRefnameDisplayName(DocumentWrapper<WT> wrapDoc) {\r
+ return ""; // Empty string since we don't yet support this feature in JPA documents\r
+ }\r
+ \r
+ @Override\r
+ public RefName.RefNameInterface getRefName(DocumentWrapper<WT> docWrapper, String tenantName, String serviceName) {\r
+ //\r
+ // Not implemented\r
+ //\r
+ return null;\r
+ }\r
+ \r
/**\r
* Extract paging info.\r
*\r
return result;\r
}\r
\r
- protected static String getUpdatedAtAsString(DocumentModel docModel) throws Exception {\r
+ public static String getUpdatedAtAsString(DocumentModel docModel) throws Exception {\r
GregorianCalendar cal = (GregorianCalendar)\r
docModel.getProperty(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,\r
CollectionSpaceClient.COLLECTIONSPACE_CORE_UPDATED_AT);\r
\r
AbstractServiceContextImpl sc = (AbstractServiceContextImpl)getServiceContext();\r
MultivaluedMap<String, String> queryParams = getServiceContext().getQueryParams();\r
- markRtSbj = queryParams.getFirst(IQueryManager.MARK_RELATED_TO_CSID_AS_SUBJECT);\r
+ markRtSbj = queryParams.getFirst(IQueryManager.MARK_RELATED_TO_CSID_AS_SUBJECT); // REM - We need to document what this query param is for -i.e., what's its purpose?\r
if(markRtSbj!=null && markRtSbj.isEmpty())\r
markRtSbj = null;\r
\r
if (schema == null || schema.trim().isEmpty()) {\r
schema = commonSchema;\r
}\r
- Object value = getListResultValue(docModel, schema, field);\r
- if (value != null && value instanceof String) {\r
- String strValue = (String) value;\r
- if (strValue.trim().isEmpty() == true) {\r
- value = null;\r
- }\r
- }\r
+ Object value = getStringValue(docModel, schema, field);\r
if (value != null) {\r
item.put(field.getElement(), value);\r
}\r
import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentWrapper;
+import org.collectionspace.services.common.document.DocumentWrapperImpl;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.collectionspace.services.common.query.QueryContext;
import org.collectionspace.services.common.repository.RepositoryClient;
abstract public AuthorityRefList getAuthorityRefs(String csid,
List<AuthRefConfigInfo> authRefsInfo) throws PropertyException;
+ /*
+ * Subclasses should override this method if they need to customize their refname generation
+ */
+ public RefName.RefNameInterface getRefName(ServiceContext ctx,
+ DocumentModel docModel) {
+ return getRefName(new DocumentWrapperImpl<DocumentModel>(docModel), ctx.getTenantName(), ctx.getServiceName());
+ }
+
+ @Override
+ public RefName.RefNameInterface getRefName(DocumentWrapper<DocumentModel> docWrapper,
+ String tenantName, String serviceName) {
+ DocumentModel docModel = docWrapper.getWrappedObject();
+ String csid = docModel.getName();
+ String refnameDisplayName = this.getRefnameDisplayName(docWrapper);
+ RefName.RefNameInterface refname = RefName.Authority.buildAuthority(tenantName, serviceName,
+ csid, refnameDisplayName);
+ return refname;
+ }
+
private void handleCoreValues(DocumentWrapper<DocumentModel> docWrapper,
Action action) throws ClientException {
DocumentModel documentModel = docWrapper.getWrappedObject();
String now = GregorianCalendarDateTimeUtils.timestampUTC();
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = getServiceContext();
String userId = ctx.getUserId();
- if(action==Action.CREATE) {
+ if (action == Action.CREATE) {
//
// Add the tenant ID value to the new entity
//
//
// Add the resource's refname
//
- String csid = documentModel.getName();
- String refname = RefName.Authority.buildAuthority(ctx.getTenantName(), ctx.getServiceName(),
- csid, "" /*authorityDisplayName*/).toString();
+ String refname = getRefName(ctx, documentModel).toString();
documentModel.setProperty(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
CollectionSpaceClient.COLLECTIONSPACE_CORE_REFNAME, refname);
//
+ sb.getName());
}
+ @Override
+ protected String getRefnameDisplayName(DocumentWrapper<DocumentModel> docWrapper) {
+ return getRefnameDisplayName(docWrapper.getWrappedObject());
+ }
+
+ private String getRefnameDisplayName(DocumentModel docModel) {
+ String result = null;
+
+ DocHandlerParams.Params params = null;
+ try {
+ params = getDocHandlerParams();
+ ListResultField field = params.getRefnameDisplayNameField();
+
+ String schema = field.getSchema();
+ if (schema == null || schema.trim().isEmpty()) {
+ schema = getServiceContext().getCommonPartLabel();
+ }
+
+ result = getStringValue(docModel, schema, field);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ if (logger.isWarnEnabled()) {
+ logger.warn(String.format("Call failed to getRefnameDisplayName() for class %s", this.getClass().getName()));
+ }
+ }
+
+ return result;
+ }
+
@Override
public boolean supportsHierarchy() {
boolean result = false;
return result;
}
-
+ protected String getStringValue(DocumentModel docModel,
+ String schema, ListResultField field) {
+ String result = null;
+
+ Object value = getListResultValue(docModel, schema, field);
+ if (value != null && value instanceof String) {
+ String strValue = (String) value;
+ if (strValue.trim().isEmpty() == false) {
+ result = strValue;
+ }
+ }
+
+ return result;
+ }
+
protected void removeFromList(List<RelationsCommonList.RelationListItem> list, RelationsCommonList.RelationListItem item) {
list.remove(item);
}
<xs:complexType>
<xs:sequence>
<xs:element name="SchemaName" type="xs:string" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="RefnameDisplayNameField" type="ListResultField" minOccurs="0" maxOccurs="1"/> <!-- Should rename 'ListResultField' to a more generic name -->
<xs:element name="SupportsHierarchy" type="xs:boolean" minOccurs="0" maxOccurs="1" default="false"/>
<xs:element name="DublinCoreTitle" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="SummaryFields" type="xs:string" minOccurs="0" maxOccurs="1"/>