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 javax.management.RuntimeErrorException;
30 import org.collectionspace.services.client.PoxPayloadIn;
31 import org.collectionspace.services.client.PoxPayloadOut;
32 import org.collectionspace.services.common.api.RefName;
33 import org.collectionspace.services.common.context.MultipartServiceContext;
34 import org.collectionspace.services.common.context.ServiceContext;
35 import org.collectionspace.services.common.document.DocumentException;
36 import org.collectionspace.services.common.document.DocumentNotFoundException;
37 import org.collectionspace.services.common.document.DocumentWrapper;
38 import org.collectionspace.services.common.service.ObjectPartType;
39 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
41 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
42 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
43 import org.nuxeo.ecm.core.api.ClientException;
44 import org.nuxeo.ecm.core.api.DocumentModel;
47 * AuthorityDocumentModelHandler
49 * $LastChangedRevision: $
52 public abstract class AuthorityDocumentModelHandler<AuthCommon, AuthCommonList>
53 extends RemoteDocumentModelHandlerImpl<AuthCommon, AuthCommonList> {
55 private String authorityCommonSchemaName;
58 * authority is used to stash JAXB object to use when handle is called
59 * for Action.CREATE, Action.UPDATE or Action.GET
61 private AuthCommon authority;
63 * authorityList is stashed when handle is called
66 private AuthCommonList authorityList;
69 public AuthorityDocumentModelHandler(String authorityCommonSchemaName) {
70 this.authorityCommonSchemaName = authorityCommonSchemaName;
74 * getCommonPart get associated authority
78 public AuthCommon getCommonPart() {
83 * setCommonPart set associated authority
87 public void setCommonPart(AuthCommon authority) {
88 this.authority = authority;
92 * getCommonPartList get associated authority (for index/GET_ALL)
96 public AuthCommonList getCommonPartList() {
101 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
104 public void setCommonPartList(AuthCommonList authorityList) {
105 this.authorityList = authorityList;
109 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
112 public AuthCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
114 throw new UnsupportedOperationException();
118 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
121 public void fillCommonPart(AuthCommon vocabularyObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
122 throw new UnsupportedOperationException();
126 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
129 protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
131 Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
133 // Add the CSID to the common part
134 if (partMeta.getLabel().equalsIgnoreCase(authorityCommonSchemaName)) {
135 String csid = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
136 unQObjectProperties.put("csid", csid);
139 return unQObjectProperties;
143 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
144 super.handleCreate(wrapDoc);
145 // Uncomment once debugged and App layer is read to integrate
146 //updateRefnameForAuthority(wrapDoc, authorityCommonSchemaName);//CSPACE-3178
149 protected void updateRefnameForAuthority(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception {
150 DocumentModel docModel = wrapDoc.getWrappedObject();
151 String shortIdentifier = (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
152 String displayName = (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
153 MultipartServiceContext ctx = (MultipartServiceContext)getServiceContext();
154 RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
155 ctx.getServiceName(),
158 String refName = authority.toString();
159 docModel.setProperty(schemaName , AuthorityJAXBSchema.REF_NAME, refName);
163 public String getShortIdentifier(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) {
164 DocumentModel docModel = wrapDoc.getWrappedObject();
165 String shortIdentifier = null;
167 shortIdentifier = (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
168 } catch (ClientException ce) {
169 throw new RuntimeException("AuthorityDocHandler Internal Error: cannot get shortId!", ce);
171 return shortIdentifier;