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 Regents of the University of California
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.contact.nuxeo;
26 import java.util.Iterator;
27 import java.util.List;
30 import org.collectionspace.services.contact.ContactJAXBSchema;
31 import org.collectionspace.services.common.document.DocumentHandler.Action;
32 import org.collectionspace.services.common.document.DocumentWrapper;
33 import org.collectionspace.services.common.service.ObjectPartType;
34 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
35 import org.collectionspace.services.contact.ContactsCommon;
36 import org.collectionspace.services.contact.ContactsCommonList;
37 import org.collectionspace.services.contact.ContactsCommonList.ContactListItem;
39 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
40 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
41 import org.nuxeo.ecm.core.api.DocumentModel;
42 import org.nuxeo.ecm.core.api.DocumentModelList;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * The Class ContactDocumentModelHandler.
49 public class ContactDocumentModelHandler
50 extends RemoteDocumentModelHandlerImpl<ContactsCommon, ContactsCommonList> {
53 private final Logger logger = LoggerFactory.getLogger(ContactDocumentModelHandler.class);
56 private ContactsCommon contact;
58 /** The contact list. */
59 private ContactsCommonList contactList;
61 /** The in authority. */
62 private String inAuthority;
65 * Gets the in authority.
67 * @return the in authority
69 public String getInAuthority() {
74 * Sets the in authority.
76 * @param inAuthority the new in authority
78 public void setInAuthority(String inAuthority) {
79 this.inAuthority = inAuthority;
83 private String inItem;
90 public String getInItem() {
97 * @param inItem the new in item
99 public void setInItem(String inItem) {
100 this.inItem = inItem;
104 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
107 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
108 // first fill all the parts of the document
109 super.handleCreate(wrapDoc);
110 handleInAuthority(wrapDoc.getWrappedObject());
114 * Check the logic around the parent pointer. Note that we only need do this on
115 * create, since we have logic to make this read-only on update.
119 * @throws Exception the exception
121 private void handleInAuthority(DocumentModel docModel) throws Exception {
122 String commonPartLabel = getServiceContext().getCommonPartLabel("contacts");
123 docModel.setProperty(commonPartLabel,
124 ContactJAXBSchema.IN_AUTHORITY, inAuthority);
125 docModel.setProperty(commonPartLabel,
126 ContactJAXBSchema.IN_ITEM, inItem);
130 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPart()
133 public ContactsCommon getCommonPart() {
138 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPart(java.lang.Object)
141 public void setCommonPart(ContactsCommon contact) {
142 this.contact = contact;
146 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPartList()
149 public ContactsCommonList getCommonPartList() {
154 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
157 public void setCommonPartList(ContactsCommonList contactList) {
158 this.contactList = contactList;
162 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
165 public ContactsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
167 throw new UnsupportedOperationException();
171 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
174 public void fillCommonPart(ContactsCommon contactObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
175 throw new UnsupportedOperationException();
179 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
182 public ContactsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
183 ContactsCommonList coList = extractPagingInfo(new ContactsCommonList(), wrapDoc);
184 List<ContactsCommonList.ContactListItem> list = coList.getContactListItem();
185 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
186 while(iter.hasNext()){
187 DocumentModel docModel = iter.next();
188 ContactListItem clistItem = new ContactListItem();
189 // TODO Revisit which information unit(s) should be returned
190 // in each entry, in a list of contact information.
192 clistItem.setAddressPlace((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
193 ContactJAXBSchema.ADDRESS_PLACE));
194 String id = NuxeoUtils.extractId(docModel.getPathAsString());
195 clistItem.setUri(getServiceContextPath() + id);
196 clistItem.setCsid(id);
204 * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
207 public String getQProperty(String prop) {
208 return ContactConstants.NUXEO_SCHEMA_NAME + ":" + prop;
212 * Filters out ContactJAXBSchema.IN_AUTHORITY, and IN_ITEM, to ensure that
213 * the parent links remains untouched.
214 * @param objectProps the properties parsed from the update payload
215 * @param partMeta metadata for the object to fill
218 public void filterReadOnlyPropertiesForPart(
219 Map<String, Object> objectProps, ObjectPartType partMeta) {
220 super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
221 objectProps.remove(ContactJAXBSchema.IN_AUTHORITY);
222 objectProps.remove(ContactJAXBSchema.IN_ITEM);