]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
994573380d989f605b74352d22f93622abaed475
[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.movement.nuxeo;
25
26 import java.util.Calendar;
27 import java.util.GregorianCalendar;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Map.Entry;
32
33 import org.collectionspace.services.MovementJAXBSchema;
34 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
35 import org.collectionspace.services.common.document.DocumentWrapper;
36 import org.collectionspace.services.common.service.ObjectPartType;
37 import org.collectionspace.services.movement.MovementsCommon;
38 import org.collectionspace.services.movement.MovementsCommonList;
39 import org.collectionspace.services.movement.MovementsCommonList.MovementListItem;
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 MovementDocumentModelHandler.
49  */
50 public class MovementDocumentModelHandler
51         extends RemoteDocumentModelHandlerImpl<MovementsCommon, MovementsCommonList> {
52
53     /** The logger. */
54     private final Logger logger = LoggerFactory.getLogger(MovementDocumentModelHandler.class);
55
56     private static final String COMMON_PART_LABEL = "movements_common";
57     
58     /** The Movement. */
59     private MovementsCommon Movement;
60     
61     /** The Movement list. */
62     private MovementsCommonList MovementList;
63
64
65     /**
66      * Gets the common part.
67      *
68      * @return the common part
69      */
70     @Override
71     public MovementsCommon getCommonPart() {
72         return Movement;
73     }
74
75     /**
76      * Sets the common part.
77      *
78      * @param Movement the new common part
79      */
80     @Override
81     public void setCommonPart(MovementsCommon Movement) {
82         this.Movement = Movement;
83     }
84
85     /**
86      * Gets the common part list.
87      *
88      * @return the common part list
89      */
90     @Override
91     public MovementsCommonList getCommonPartList() {
92         return MovementList;
93     }
94
95     /**
96      * Sets the common part list.
97      *
98      * @param MovementList the new common part list
99      */
100     @Override
101     public void setCommonPartList(MovementsCommonList MovementList) {
102         this.MovementList = MovementList;
103     }
104
105     /* (non-Javadoc)
106      * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
107      */
108     @Override
109     protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
110             throws Exception {
111         Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
112
113         // For each dateTime field in the common part, return an
114         // appropriately formatted representation of its value.
115         if (partMeta.getLabel().equalsIgnoreCase(COMMON_PART_LABEL)) {
116             for(Entry<String, Object> entry : unQObjectProperties.entrySet()){
117                 if (isDateTimeType(entry)) {
118                     entry.setValue(
119                         GregorianCalendarDateTimeUtils.formatAsISO8601Timestamp(
120                             (GregorianCalendar) entry.getValue()));
121                 }
122             }
123         }
124
125         return unQObjectProperties;
126     }
127
128     /**
129      * Extract common part.
130      *
131      * @param wrapDoc the wrap doc
132      * @return the Movements common
133      * @throws Exception the exception
134      */
135     @Override
136     public MovementsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
137             throws Exception {
138         throw new UnsupportedOperationException();
139     }
140
141     /**
142      * Fill common part.
143      *
144      * @param MovementObject the Movement object
145      * @param wrapDoc the wrap doc
146      * @throws Exception the exception
147      */
148     @Override
149     public void fillCommonPart(MovementsCommon MovementObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
150         throw new UnsupportedOperationException();
151     }
152
153     /**
154      * Extract common part list.
155      *
156      * @param wrapDoc the wrap doc
157      * @return the Movements common list
158      * @throws Exception the exception
159      */
160     @Override
161     public MovementsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
162         MovementsCommonList coList = extractPagingInfo(new MovementsCommonList(), wrapDoc);
163         List<MovementsCommonList.MovementListItem> list = coList.getMovementListItem();
164         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
165         while(iter.hasNext()){
166             DocumentModel docModel = iter.next();
167             MovementListItem ilistItem = new MovementListItem();
168             ilistItem.setMovementReferenceNumber((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
169                     MovementJAXBSchema.MOVEMENT_REFERENCE_NUMBER));
170             GregorianCalendar gcal = (GregorianCalendar) docModel.getProperty(getServiceContext().getCommonPartLabel(),
171                     MovementJAXBSchema.LOCATION_DATE);
172             ilistItem.setLocationDate(GregorianCalendarDateTimeUtils.formatAsISO8601Timestamp(gcal));
173             String id = NuxeoUtils.extractId(docModel.getPathAsString());
174             ilistItem.setUri(getServiceContextPath() + id);
175             ilistItem.setCsid(id);
176             list.add(ilistItem);
177         }
178
179         return coList;
180     }
181
182     /**
183      * Gets the q property.
184      *
185      * @param prop the prop
186      * @return the q property
187      */
188     @Override
189     public String getQProperty(String prop) {
190         return MovementConstants.NUXEO_SCHEMA_NAME + ":" + prop;
191     }
192
193     private boolean isDateTimeType(Entry<String, Object> entry) {
194         boolean isDateTimeType = false;
195
196         if (entry.getValue() instanceof Calendar) {
197             isDateTimeType = true;
198         }
199
200         return isDateTimeType;
201     }
202  
203 }
204