]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
c4c5dc406320ec7d3fe364f8e4314e76db47cffa
[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.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;
46
47 /**
48  * The Class ContactDocumentModelHandler.
49  */
50 public class ContactDocumentModelHandler
51         extends RemoteDocumentModelHandlerImpl<ContactsCommon, ContactsCommonList> {
52
53     /** The logger. */
54     private final Logger logger = LoggerFactory.getLogger(ContactDocumentModelHandler.class);
55     
56     /** The contact. */
57     private ContactsCommon contact;
58     
59     /** The contact list. */
60     private ContactsCommonList contactList;
61
62     /** The in authority. */
63     private String inAuthority;
64
65     /**
66      * Gets the in authority.
67      *
68      * @return the in authority
69      */
70     public String getInAuthority() {
71         return inAuthority;
72     }
73
74     /**
75      * Sets the in authority.
76      *
77      * @param inAuthority the new in authority
78      */
79     public void setInAuthority(String inAuthority) {
80         this.inAuthority = inAuthority;
81     }
82
83     /** The in item. */
84     private String inItem;
85
86     /**
87      * Gets the in item.
88      *
89      * @return the in item
90      */
91     public String getInItem() {
92         return inItem;
93     }
94
95     /**
96      * Sets the in item.
97      *
98      * @param inItem the new in item
99      */
100     public void setInItem(String inItem) {
101         this.inItem = inItem;
102     }
103
104     /* (non-Javadoc)
105      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
106      */
107     @Override
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());
112     }
113     
114     /**
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. 
117      * 
118      * @param docModel
119      * 
120      * @throws Exception the exception
121      */
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);
128     }
129
130     /* (non-Javadoc)
131      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPart()
132      */
133     @Override
134     public ContactsCommon getCommonPart() {
135         return contact;
136     }
137
138     /* (non-Javadoc)
139      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPart(java.lang.Object)
140      */
141     @Override
142     public void setCommonPart(ContactsCommon contact) {
143         this.contact = contact;
144     }
145
146     /* (non-Javadoc)
147      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPartList()
148      */
149     @Override
150     public ContactsCommonList getCommonPartList() {
151         return contactList;
152     }
153
154     /* (non-Javadoc)
155      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
156      */
157     @Override
158     public void setCommonPartList(ContactsCommonList contactList) {
159         this.contactList = contactList;
160     }
161
162     /* (non-Javadoc)
163      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
164      */
165     @Override
166     public ContactsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
167             throws Exception {
168         throw new UnsupportedOperationException();
169     }
170
171     /* (non-Javadoc)
172      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
173      */
174     @Override
175     public void fillCommonPart(ContactsCommon contactObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
176         throw new UnsupportedOperationException();
177     }
178
179     /* (non-Javadoc)
180      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
181      */
182     @Override
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.
194             // See CSPACE-1018
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);
200             list.add(clistItem);
201         }
202
203         return coList;
204     }
205
206     /* (non-Javadoc)
207      * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
208      */
209     @Override
210     public String getQProperty(String prop) {
211         return ContactConstants.NUXEO_SCHEMA_NAME + ":" + prop;
212     }
213     
214     /**
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
219      */
220     @Override
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);
226     }
227
228 }
229