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.document.DocumentWrapper;
29 import org.collectionspace.services.common.service.ObjectPartType;
30 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
31 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
32 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
33 import org.nuxeo.ecm.core.api.DocumentModel;
36 * AuthorityItemDocumentModelHandler
38 * $LastChangedRevision: $
41 public abstract class AuthorityItemDocumentModelHandler<AICommon, AICommonList>
42 extends RemoteDocumentModelHandlerImpl<AICommon, AICommonList> {
44 private String authorityItemCommonSchemaName;
46 //private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class);
48 * item is used to stash JAXB object to use when handle is called
49 * for Action.CREATE, Action.UPDATE or Action.GET
51 protected AICommon item;
53 * itemList is stashed when handle is called
56 protected AICommonList itemList;
59 * inVocabulary is the parent Authority for this context
61 protected String inAuthority;
63 public AuthorityItemDocumentModelHandler(String authorityItemCommonSchemaName) {
64 this.authorityItemCommonSchemaName = authorityItemCommonSchemaName;
67 public String getInAuthority() {
71 public void setInAuthority(String inAuthority) {
72 this.inAuthority = inAuthority;
76 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
79 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
80 // first fill all the parts of the document
81 super.handleCreate(wrapDoc);
82 handleInAuthority(wrapDoc.getWrappedObject());
86 * Check the logic around the parent pointer. Note that we only need do this on
87 * create, since we have logic to make this read-only on update.
91 * @throws Exception the exception
93 private void handleInAuthority(DocumentModel docModel) throws Exception {
94 docModel.setProperty(authorityItemCommonSchemaName,
95 AuthorityItemJAXBSchema.IN_AUTHORITY, inAuthority);
100 * getCommonPart get associated item
104 public AICommon getCommonPart() {
109 * setCommonPart set associated item
110 * @param vocabularyItem
113 public void setCommonPart(AICommon item) {
118 * getCommonPartList get associated item (for index/GET_ALL)
122 public AICommonList getCommonPartList() {
127 public void setCommonPartList(AICommonList itemList) {
128 this.itemList = itemList;
132 public AICommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
134 throw new UnsupportedOperationException();
138 public void fillCommonPart(AICommon itemObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
139 throw new UnsupportedOperationException();
143 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
146 protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
148 Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
150 // Add the CSID to the common part
151 if (partMeta.getLabel().equalsIgnoreCase(authorityItemCommonSchemaName)) {
152 String csid = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
153 unQObjectProperties.put("csid", csid);
156 return unQObjectProperties;
160 * Filters out AuthorityItemJAXBSchema.IN_AUTHORITY, to ensure that
161 * the parent link remains untouched.
162 * @param objectProps the properties parsed from the update payload
163 * @param partMeta metadata for the object to fill
166 public void filterReadOnlyPropertiesForPart(
167 Map<String, Object> objectProps, ObjectPartType partMeta) {
168 super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
169 objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY);
170 objectProps.remove(AuthorityItemJAXBSchema.CSID);