]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
4bb538d31a59eed4dc163dddd936e0af8e5a6096
[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.GregorianCalendar;
27 import java.util.Iterator;
28 import java.util.List;
29
30 import org.collectionspace.services.MovementJAXBSchema;
31 import org.collectionspace.services.common.datetime.DateTimeFormatUtils;
32 import org.collectionspace.services.common.document.DocumentWrapper;
33 import org.collectionspace.services.jaxb.AbstractCommonList;
34 import org.collectionspace.services.movement.MovementsCommon;
35 import org.collectionspace.services.movement.MovementsCommonList;
36 import org.collectionspace.services.movement.MovementsCommonList.MovementListItem;
37 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
38 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
39 import org.nuxeo.ecm.core.api.DocumentModel;
40 import org.nuxeo.ecm.core.api.DocumentModelList;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 /**
45  * The Class MovementDocumentModelHandler.
46  *
47  * $LastChangedRevision$
48  * $LastChangedDate$
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     /** The Movement. */
57     private MovementsCommon Movement;
58     
59     /** The Movement list. */
60     private MovementsCommonList MovementList;
61
62     /**
63      * Gets the common part.
64      *
65      * @return the common part
66      */
67     @Override
68     public MovementsCommon getCommonPart() {
69         return Movement;
70     }
71
72     /**
73      * Sets the common part.
74      *
75      * @param Movement the new common part
76      */
77     @Override
78     public void setCommonPart(MovementsCommon Movement) {
79         this.Movement = Movement;
80     }
81
82     /**
83      * Gets the common part list.
84      *
85      * @return the common part list
86      */
87     @Override
88     public MovementsCommonList getCommonPartList() {
89         return MovementList;
90     }
91
92     /**
93      * Sets the common part list.
94      *
95      * @param MovementList the new common part list
96      */
97     @Override
98     public void setCommonPartList(MovementsCommonList MovementList) {
99         this.MovementList = MovementList;
100     }
101
102     /**
103      * Extract common part.
104      *
105      * @param wrapDoc the wrap doc
106      * @return the Movements common
107      * @throws Exception the exception
108      */
109     @Override
110     public MovementsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
111             throws Exception {
112         throw new UnsupportedOperationException();
113     }
114
115     /**
116      * Fill common part.
117      *
118      * @param MovementObject the Movement object
119      * @param wrapDoc the wrap doc
120      * @throws Exception the exception
121      */
122     @Override
123     public void fillCommonPart(MovementsCommon MovementObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
124         throw new UnsupportedOperationException();
125     }
126
127     /**
128      * Extract common part list.
129      *
130      * @param wrapDoc the wrap doc
131      * @return the Movements common list
132      * @throws Exception the exception
133      */
134     @Override
135     public MovementsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
136         MovementsCommonList coList = extractPagingInfo(new MovementsCommonList(), wrapDoc);
137         AbstractCommonList commonList = (AbstractCommonList) coList;
138         commonList.setFieldsReturned("movementReferenceNumber|currentLocation|locationDate|uri|csid");
139         List<MovementsCommonList.MovementListItem> list = coList.getMovementListItem();
140         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
141         String label = getServiceContext().getCommonPartLabel();
142         while(iter.hasNext()){
143             DocumentModel docModel = iter.next();
144             MovementListItem ilistItem = new MovementListItem();
145             ilistItem.setMovementReferenceNumber((String) docModel.getProperty(label,
146                     MovementJAXBSchema.MOVEMENT_REFERENCE_NUMBER));
147             ilistItem.setCurrentLocation((String) docModel.getProperty(label,
148                     MovementJAXBSchema.CURRENT_LOCATION));
149             GregorianCalendar gcal = (GregorianCalendar) docModel.getProperty(label,
150                     MovementJAXBSchema.LOCATION_DATE);
151             ilistItem.setLocationDate(DateTimeFormatUtils.formatAsISO8601Timestamp(gcal));
152             String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
153             ilistItem.setUri(getServiceContextPath() + id);
154             ilistItem.setCsid(id);
155             list.add(ilistItem);
156         }
157
158         return coList;
159     }
160
161     /**
162      * Gets the q property.
163      *
164      * @param prop the prop
165      * @return the q property
166      */
167     @Override
168     public String getQProperty(String prop) {
169         return MovementConstants.NUXEO_SCHEMA_NAME + ":" + prop;
170     }
171
172 }
173