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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 package org.collectionspace.services.movement.nuxeo;
26 import java.util.Calendar;
27 import java.util.GregorianCalendar;
28 import java.util.Iterator;
29 import java.util.List;
31 import java.util.Map.Entry;
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;
48 * The Class MovementDocumentModelHandler.
50 public class MovementDocumentModelHandler
51 extends RemoteDocumentModelHandlerImpl<MovementsCommon, MovementsCommonList> {
54 private final Logger logger = LoggerFactory.getLogger(MovementDocumentModelHandler.class);
56 private static final String COMMON_PART_LABEL = "movements_common";
59 private MovementsCommon Movement;
61 /** The Movement list. */
62 private MovementsCommonList MovementList;
65 * Gets the common part.
67 * @return the common part
70 public MovementsCommon getCommonPart() {
75 * Sets the common part.
77 * @param Movement the new common part
80 public void setCommonPart(MovementsCommon Movement) {
81 this.Movement = Movement;
85 * Gets the common part list.
87 * @return the common part list
90 public MovementsCommonList getCommonPartList() {
95 * Sets the common part list.
97 * @param MovementList the new common part list
100 public void setCommonPartList(MovementsCommonList MovementList) {
101 this.MovementList = MovementList;
105 * Extract common part.
107 * @param wrapDoc the wrap doc
108 * @return the Movements common
109 * @throws Exception the exception
112 public MovementsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
114 throw new UnsupportedOperationException();
120 * @param MovementObject the Movement object
121 * @param wrapDoc the wrap doc
122 * @throws Exception the exception
125 public void fillCommonPart(MovementsCommon MovementObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
126 throw new UnsupportedOperationException();
130 * Extract common part list.
132 * @param wrapDoc the wrap doc
133 * @return the Movements common list
134 * @throws Exception the exception
137 public MovementsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
138 MovementsCommonList coList = extractPagingInfo(new MovementsCommonList(), wrapDoc);
139 List<MovementsCommonList.MovementListItem> list = coList.getMovementListItem();
140 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
141 while(iter.hasNext()){
142 DocumentModel docModel = iter.next();
143 MovementListItem ilistItem = new MovementListItem();
144 ilistItem.setMovementReferenceNumber((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
145 MovementJAXBSchema.MOVEMENT_REFERENCE_NUMBER));
146 GregorianCalendar gcal = (GregorianCalendar) docModel.getProperty(getServiceContext().getCommonPartLabel(),
147 MovementJAXBSchema.LOCATION_DATE);
148 ilistItem.setLocationDate(GregorianCalendarDateTimeUtils.formatAsISO8601Timestamp(gcal));
149 String id = NuxeoUtils.extractId(docModel.getPathAsString());
150 ilistItem.setUri(getServiceContextPath() + id);
151 ilistItem.setCsid(id);
159 * Gets the q property.
161 * @param prop the prop
162 * @return the q property
165 public String getQProperty(String prop) {
166 return MovementConstants.NUXEO_SCHEMA_NAME + ":" + prop;
169 private boolean isDateTimeType(Object obj) {
170 boolean isDateTimeType = false;
172 if (obj != null && obj instanceof Calendar) {
173 isDateTimeType = true;
176 return isDateTimeType;