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.context.MultipartServiceContext;
30 import org.collectionspace.services.common.document.DocumentWrapper;
31 import org.collectionspace.services.common.service.ObjectPartType;
32 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
34 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
35 import org.nuxeo.ecm.core.api.ClientException;
36 import org.nuxeo.ecm.core.api.DocumentModel;
39 * AuthorityDocumentModelHandler
41 * $LastChangedRevision: $
44 public abstract class AuthorityDocumentModelHandler<AuthCommon>
45 extends DocHandlerBase<AuthCommon> {
47 private String authorityCommonSchemaName;
49 public AuthorityDocumentModelHandler(String authorityCommonSchemaName) {
50 this.authorityCommonSchemaName = authorityCommonSchemaName;
54 * Non standard injection of CSID into common part, since caller may access through
55 * shortId, and not know the CSID.
56 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
59 protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
61 Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
63 // Add the CSID to the common part
64 if (partMeta.getLabel().equalsIgnoreCase(authorityCommonSchemaName)) {
65 String csid = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
66 unQObjectProperties.put("csid", csid);
69 return unQObjectProperties;
73 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
74 super.handleCreate(wrapDoc);
76 // Uncomment once debugged and App layer is read to integrate
77 // Experimenting with this uncommented now ...
78 updateRefnameForAuthority(wrapDoc, authorityCommonSchemaName);//CSPACE-3178
81 protected void updateRefnameForAuthority(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception {
82 DocumentModel docModel = wrapDoc.getWrappedObject();
83 String suppliedRefName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.REF_NAME);
85 // Temporarily accept client-supplied refName values, rather than always generating such values,
86 // Remove the surrounding 'if' statement when clients should no longer supply refName values.
87 if (suppliedRefName == null || suppliedRefName.isEmpty()) {
88 String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
89 String displayName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
90 MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
91 RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
95 String refName = authority.toString();
96 docModel.setProperty(schemaName, AuthorityJAXBSchema.REF_NAME, refName);
100 public String getShortIdentifier(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) {
101 DocumentModel docModel = wrapDoc.getWrappedObject();
102 String shortIdentifier = null;
104 shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
105 } catch (ClientException ce) {
106 throw new RuntimeException("AuthorityDocHandler Internal Error: cannot get shortId!", ce);
108 return shortIdentifier;
112 * Filters out selected values supplied in an update request.
114 * @param objectProps the properties filtered out from the update payload
115 * @param partMeta metadata for the object to fill
118 public void filterReadOnlyPropertiesForPart(
119 Map<String, Object> objectProps, ObjectPartType partMeta) {
120 super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
121 String commonPartLabel = getServiceContext().getCommonPartLabel();
122 if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) {
123 objectProps.remove(AuthorityJAXBSchema.CSID);
124 objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
125 // Enable when clients should no longer supply refName values
126 // objectProps.remove(AuthorityItemJAXBSchema.REF_NAME); // CSPACE-3178