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