]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
71ea71ed9d7140573a8a2e6543146b866b9f0290
[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 University of California at Berkeley
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.collectionobject.nuxeo;
25
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.List;
29
30 //import org.collectionspace.services.jaxb.AbstractCommonList;
31
32 import org.collectionspace.services.CollectionObjectListItemJAXBSchema;
33 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
34 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
35 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList.CollectionObjectListItem;
36 import org.collectionspace.services.common.document.DocumentUtils;
37 import org.collectionspace.services.common.document.DocumentWrapper;
38 import org.collectionspace.services.jaxb.AbstractCommonList;
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.nuxeo.ecm.core.schema.types.ComplexType;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47 /**
48  * CollectionObjectDocumentModelHandler
49  *
50  * $LastChangedRevision: $
51  * $LastChangedDate: $
52  */
53 public class CollectionObjectDocumentModelHandler
54         extends RemoteDocumentModelHandlerImpl<CollectionobjectsCommon, CollectionobjectsCommonList> {
55
56     /** The logger. */
57     private final Logger logger = LoggerFactory.getLogger(CollectionObjectDocumentModelHandler.class);
58     /**
59      * collectionObject is used to stash JAXB object to use when handle is called
60      * for Action.CREATE, Action.UPDATE or Action.GET
61      */
62     private CollectionobjectsCommon collectionObject;
63     /**
64      * collectionObjectList is stashed when handle is called
65      * for ACTION.GET_ALL
66      */
67     private CollectionobjectsCommonList collectionObjectList;
68
69     /**
70      * getCommonPart get associated CollectionobjectsCommon
71      * @return
72      */
73     @Override
74     public CollectionobjectsCommon getCommonPart() {
75         return collectionObject;
76     }
77
78     /**
79      * setCommonPart set associated collectionobject
80      * @param collectionObject
81      */
82     @Override
83     public void setCommonPart(CollectionobjectsCommon collectionObject) {
84         this.collectionObject = collectionObject;
85     }
86
87     /**
88      * getCollectionobjectsCommonList get associated CollectionobjectsCommon (for index/GET_ALL)
89      * @return
90      */
91     @Override
92     public CollectionobjectsCommonList getCommonPartList() {
93         return collectionObjectList;
94     }
95
96     /* (non-Javadoc)
97      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
98      */
99     @Override
100     public void setCommonPartList(CollectionobjectsCommonList collectionObjectList) {
101         this.collectionObjectList = collectionObjectList;
102     }
103
104     /* (non-Javadoc)
105      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
106      */
107     @Override
108     public CollectionobjectsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
109             throws Exception {
110         throw new UnsupportedOperationException();
111     }
112
113     /* (non-Javadoc)
114      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
115      */
116     @Override
117     public void fillCommonPart(CollectionobjectsCommon co, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
118         throw new UnsupportedOperationException();
119     }
120
121     /* (non-Javadoc)
122      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
123      */
124     @Override
125     public CollectionobjectsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
126         CollectionobjectsCommonList coList = this.extractPagingInfo(new CollectionobjectsCommonList(),
127                         wrapDoc);
128         AbstractCommonList commonList = (AbstractCommonList) coList;
129         commonList.setFieldsReturned("objectNumber|objectName|title|responsibleDepartment|uri|csid");
130         List<CollectionobjectsCommonList.CollectionObjectListItem> list = coList.getCollectionObjectListItem();
131         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
132         String label = getServiceContext().getCommonPartLabel();
133         while(iter.hasNext()){
134             DocumentModel docModel = iter.next();
135             CollectionObjectListItem coListItem = new CollectionObjectListItem();
136             try {
137                     coListItem.setObjectNumber((String) docModel.getProperty(label,
138                             CollectionObjectListItemJAXBSchema.OBJECT_NUMBER));
139
140                     List<Object> objectNames = (List<Object>) docModel.getProperty(label,
141                             CollectionObjectListItemJAXBSchema.OBJECT_NAME_LIST);
142                     String primaryObjectName = primaryValueFromMultivalue(objectNames,
143                             CollectionObjectListItemJAXBSchema.OBJECT_NAME);
144                     coListItem.setObjectName(primaryObjectName);
145                     
146                     List<Object> titles =
147                         (List<Object>) docModel.getProperty(label,
148                             CollectionObjectListItemJAXBSchema.TITLE_GROUP_LIST);
149                     String primaryTitle = primaryValueFromMultivalue(titles,
150                             CollectionObjectListItemJAXBSchema.TITLE);
151                     coListItem.setTitle(primaryTitle);
152
153                     List<Object> respDepts =
154                         (List<Object>) docModel.getProperty(label,
155                             CollectionObjectListItemJAXBSchema.RESPONSIBLE_DEPARTMENTS);
156                     coListItem.setResponsibleDepartment(DocumentUtils.getFirstString(respDepts));
157                     
158                     String id = NuxeoUtils.extractId(docModel.getPathAsString());
159                     coListItem.setUri(getServiceContextPath() + id);
160                     coListItem.setCsid(id);
161             } catch (ClassCastException cce) {
162                 throw new RuntimeException("Unexpected schema structure encountered", cce);
163             } catch (Exception e) {
164                 throw new RuntimeException("Problem encountered retrieving values", e);
165             }
166             list.add(coListItem);
167         }
168
169         return coList;
170     }
171
172     /* (non-Javadoc)
173      * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper)
174      */
175     @Override
176     public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
177
178         super.fillAllParts(wrapDoc, action);
179         fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
180     }
181
182     /**
183      * Fill dublin core object.
184      *
185      * @param wrapDoc the wrap doc
186      * @throws Exception the exception
187      */
188     private void fillDublinCoreObject(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
189         DocumentModel docModel = wrapDoc.getWrappedObject();
190         //FIXME property setter should be dynamically set using schema inspection
191         //so it does not require hard coding
192         // a default title for the Dublin Core schema
193         docModel.setPropertyValue("dublincore:title", CollectionObjectConstants.NUXEO_DC_TITLE);
194     }
195
196     /* (non-Javadoc)
197      * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
198      */
199     @Override
200     public String getQProperty(String prop) {
201         return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop;
202     }
203 }
204