]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
d5b39bf06444b3a783eb1f25388c240b86ec6ffc
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 Regents of the University of California
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  */
24 package org.collectionspace.services.contact.nuxeo;
25
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.Map;
29
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;
38
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;
45
46 /**
47  * The Class ContactDocumentModelHandler.
48  */
49 public class ContactDocumentModelHandler
50         extends RemoteDocumentModelHandlerImpl<ContactsCommon, ContactsCommonList> {
51
52     /** The logger. */
53     private final Logger logger = LoggerFactory.getLogger(ContactDocumentModelHandler.class);
54     
55     /** The contact. */
56     private ContactsCommon contact;
57     
58     /** The contact list. */
59     private ContactsCommonList contactList;
60
61     /** The in authority. */
62     private String inAuthority;
63
64     /**
65      * Gets the in authority.
66      *
67      * @return the in authority
68      */
69     public String getInAuthority() {
70         return inAuthority;
71     }
72
73     /**
74      * Sets the in authority.
75      *
76      * @param inAuthority the new in authority
77      */
78     public void setInAuthority(String inAuthority) {
79         this.inAuthority = inAuthority;
80     }
81
82     /** The in item. */
83     private String inItem;
84
85     /**
86      * Gets the in item.
87      *
88      * @return the in item
89      */
90     public String getInItem() {
91         return inItem;
92     }
93
94     /**
95      * Sets the in item.
96      *
97      * @param inItem the new in item
98      */
99     public void setInItem(String inItem) {
100         this.inItem = inItem;
101     }
102
103     /* (non-Javadoc)
104      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
105      */
106     @Override
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());
111     }
112     
113     /**
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. 
116      * 
117      * @param docModel
118      * 
119      * @throws Exception the exception
120      */
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);
127     }
128
129     /* (non-Javadoc)
130      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPart()
131      */
132     @Override
133     public ContactsCommon getCommonPart() {
134         return contact;
135     }
136
137     /* (non-Javadoc)
138      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPart(java.lang.Object)
139      */
140     @Override
141     public void setCommonPart(ContactsCommon contact) {
142         this.contact = contact;
143     }
144
145     /* (non-Javadoc)
146      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPartList()
147      */
148     @Override
149     public ContactsCommonList getCommonPartList() {
150         return contactList;
151     }
152
153     /* (non-Javadoc)
154      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
155      */
156     @Override
157     public void setCommonPartList(ContactsCommonList contactList) {
158         this.contactList = contactList;
159     }
160
161     /* (non-Javadoc)
162      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
163      */
164     @Override
165     public ContactsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
166             throws Exception {
167         throw new UnsupportedOperationException();
168     }
169
170     /* (non-Javadoc)
171      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
172      */
173     @Override
174     public void fillCommonPart(ContactsCommon contactObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
175         throw new UnsupportedOperationException();
176     }
177
178     /* (non-Javadoc)
179      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
180      */
181     @Override
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.
191             // See CSPACE-1018
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);
197             list.add(clistItem);
198         }
199
200         return coList;
201     }
202
203     /* (non-Javadoc)
204      * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
205      */
206     @Override
207     public String getQProperty(String prop) {
208         return ContactConstants.NUXEO_SCHEMA_NAME + ":" + prop;
209     }
210     
211     /**
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
216      */
217     @Override
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);
223     }
224
225 }
226