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.jaxb.AbstractCommonList;
40 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
41 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
42 import org.nuxeo.ecm.core.api.DocumentModel;
43 import org.nuxeo.ecm.core.api.DocumentModelList;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * The Class ContactDocumentModelHandler.
50 public class ContactDocumentModelHandler
51 extends RemoteDocumentModelHandlerImpl<ContactsCommon, ContactsCommonList> {
54 private final Logger logger = LoggerFactory.getLogger(ContactDocumentModelHandler.class);
57 private ContactsCommon contact;
59 /** The contact list. */
60 private ContactsCommonList contactList;
62 /** The in authority. */
63 private String inAuthority;
66 * Gets the in authority.
68 * @return the in authority
70 public String getInAuthority() {
75 * Sets the in authority.
77 * @param inAuthority the new in authority
79 public void setInAuthority(String inAuthority) {
80 this.inAuthority = inAuthority;
84 private String inItem;
91 public String getInItem() {
98 * @param inItem the new in item
100 public void setInItem(String inItem) {
101 this.inItem = inItem;
105 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
108 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
109 // first fill all the parts of the document
110 super.handleCreate(wrapDoc);
111 handleInAuthority(wrapDoc.getWrappedObject());
115 * Check the logic around the parent pointer. Note that we only need do this on
116 * create, since we have logic to make this read-only on update.
120 * @throws Exception the exception
122 private void handleInAuthority(DocumentModel docModel) throws Exception {
123 String commonPartLabel = getServiceContext().getCommonPartLabel("contacts");
124 docModel.setProperty(commonPartLabel,
125 ContactJAXBSchema.IN_AUTHORITY, inAuthority);
126 docModel.setProperty(commonPartLabel,
127 ContactJAXBSchema.IN_ITEM, inItem);
131 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPart()
134 public ContactsCommon getCommonPart() {
139 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPart(java.lang.Object)
142 public void setCommonPart(ContactsCommon contact) {
143 this.contact = contact;
147 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPartList()
150 public ContactsCommonList getCommonPartList() {
155 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
158 public void setCommonPartList(ContactsCommonList contactList) {
159 this.contactList = contactList;
163 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
166 public ContactsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
168 throw new UnsupportedOperationException();
172 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
175 public void fillCommonPart(ContactsCommon contactObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
176 throw new UnsupportedOperationException();
180 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
183 public ContactsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
184 ContactsCommonList coList = extractPagingInfo(new ContactsCommonList(), wrapDoc);
185 AbstractCommonList commonList = (AbstractCommonList) coList;
186 commonList.setFieldsReturned("addressPlace|uri|csid");
187 List<ContactsCommonList.ContactListItem> list = coList.getContactListItem();
188 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
189 while(iter.hasNext()){
190 DocumentModel docModel = iter.next();
191 ContactListItem clistItem = new ContactListItem();
192 // TODO Revisit which information unit(s) should be returned
193 // in each entry, in a list of contact information.
195 clistItem.setAddressPlace((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
196 ContactJAXBSchema.ADDRESS_PLACE));
197 String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
198 clistItem.setUri(getServiceContextPath() + id);
199 clistItem.setCsid(id);
207 * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
210 public String getQProperty(String prop) {
211 return ContactConstants.NUXEO_SCHEMA_NAME + ":" + prop;
215 * Filters out ContactJAXBSchema.IN_AUTHORITY, and IN_ITEM, to ensure that
216 * the parent links remains untouched.
217 * @param objectProps the properties parsed from the update payload
218 * @param partMeta metadata for the object to fill
221 public void filterReadOnlyPropertiesForPart(
222 Map<String, Object> objectProps, ObjectPartType partMeta) {
223 super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
224 objectProps.remove(ContactJAXBSchema.IN_AUTHORITY);
225 objectProps.remove(ContactJAXBSchema.IN_ITEM);