2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 package org.collectionspace.services.common.vocabulary.nuxeo;
28 import org.collectionspace.services.common.api.RefName;
29 import org.collectionspace.services.common.api.Tools;
30 import org.collectionspace.services.common.context.MultipartServiceContext;
31 import org.collectionspace.services.common.document.DocumentWrapper;
32 import org.collectionspace.services.common.service.ObjectPartType;
33 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
35 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
36 import org.nuxeo.ecm.core.api.ClientException;
37 import org.nuxeo.ecm.core.api.DocumentModel;
40 * AuthorityDocumentModelHandler
42 * $LastChangedRevision: $
45 public abstract class AuthorityDocumentModelHandler<AuthCommon>
46 extends DocHandlerBase<AuthCommon> {
48 private String authorityCommonSchemaName;
50 public AuthorityDocumentModelHandler(String authorityCommonSchemaName) {
51 this.authorityCommonSchemaName = authorityCommonSchemaName;
55 * Non standard injection of CSID into common part, since caller may access through
56 * shortId, and not know the CSID.
57 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
60 protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
62 Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
64 // Add the CSID to the common part
65 if (partMeta.getLabel().equalsIgnoreCase(authorityCommonSchemaName)) {
66 String csid = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
67 unQObjectProperties.put("csid", csid);
70 return unQObjectProperties;
74 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
75 super.handleCreate(wrapDoc);
77 // Uncomment once debugged and App layer is read to integrate
78 // Experimenting with this uncommented now ...
79 handleDisplayNameAsShortIdentifier(wrapDoc.getWrappedObject(), authorityCommonSchemaName);
80 updateRefnameForAuthority(wrapDoc, authorityCommonSchemaName);//CSPACE-3178
83 private void handleDisplayNameAsShortIdentifier(DocumentModel docModel, String schemaName) throws Exception {
84 String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
85 String displayName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
86 String shortDisplayName = "";
87 if (Tools.isEmpty(shortIdentifier)) {
88 String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(displayName, shortDisplayName);
89 docModel.setProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier);
93 protected void updateRefnameForAuthority(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception {
94 DocumentModel docModel = wrapDoc.getWrappedObject();
95 String suppliedRefName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.REF_NAME);
97 // Temporarily accept client-supplied refName values, rather than always generating such values,
98 // Remove the surrounding 'if' statement when clients should no longer supply refName values.
99 if (suppliedRefName == null || suppliedRefName.isEmpty()) {
100 String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
101 String displayName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
102 MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
103 RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
104 ctx.getServiceName(),
107 String refName = authority.toString();
108 docModel.setProperty(schemaName, AuthorityJAXBSchema.REF_NAME, refName);
112 public String getShortIdentifier(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) {
113 DocumentModel docModel = wrapDoc.getWrappedObject();
114 String shortIdentifier = null;
116 shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
117 } catch (ClientException ce) {
118 throw new RuntimeException("AuthorityDocHandler Internal Error: cannot get shortId!", ce);
120 return shortIdentifier;
124 * Filters out selected values supplied in an update request.
126 * @param objectProps the properties filtered out from the update payload
127 * @param partMeta metadata for the object to fill
130 public void filterReadOnlyPropertiesForPart(
131 Map<String, Object> objectProps, ObjectPartType partMeta) {
132 super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
133 String commonPartLabel = getServiceContext().getCommonPartLabel();
134 if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) {
135 objectProps.remove(AuthorityJAXBSchema.CSID);
136 objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
137 // Enable when clients should no longer supply refName values
138 // objectProps.remove(AuthorityItemJAXBSchema.REF_NAME); // CSPACE-3178