]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
fa9daec830974dcd977cf0352ac442abbfcf3e49
[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.loanout.nuxeo;
25
26 import java.util.Iterator;
27 import java.util.List;
28
29 import org.collectionspace.services.LoanoutJAXBSchema;
30 import org.collectionspace.services.common.document.DocumentWrapper;
31 import org.collectionspace.services.jaxb.AbstractCommonList;
32 import org.collectionspace.services.loanout.LoansoutCommon;
33 import org.collectionspace.services.loanout.LoansoutCommonList;
34 import org.collectionspace.services.loanout.LoansoutCommonList.LoanoutListItem;
35 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
36 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
37 import org.nuxeo.ecm.core.api.DocumentModel;
38 import org.nuxeo.ecm.core.api.DocumentModelList;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 /**
43  * The Class LoanoutDocumentModelHandler.
44  */
45 public class LoanoutDocumentModelHandler
46         extends RemoteDocumentModelHandlerImpl<LoansoutCommon, LoansoutCommonList> {
47
48     /** The logger. */
49     private final Logger logger = LoggerFactory.getLogger(LoanoutDocumentModelHandler.class);
50     
51     /** The loanout. */
52     private LoansoutCommon loanout;
53     
54     /** The loanout list. */
55     private LoansoutCommonList loanoutList;
56
57
58     /**
59      * Gets the common part.
60      *
61      * @return the common part
62      */
63     @Override
64     public LoansoutCommon getCommonPart() {
65         return loanout;
66     }
67
68     /**
69      * Sets the common part.
70      *
71      * @param loanout the new common part
72      */
73     @Override
74     public void setCommonPart(LoansoutCommon loanout) {
75         this.loanout = loanout;
76     }
77
78     /**
79      * Gets the common part list.
80      *
81      * @return the common part list
82      */
83     @Override
84     public LoansoutCommonList getCommonPartList() {
85         return loanoutList;
86     }
87
88     /**
89      * Sets the common part list.
90      *
91      * @param loanoutList the new common part list
92      */
93     @Override
94     public void setCommonPartList(LoansoutCommonList loanoutList) {
95         this.loanoutList = loanoutList;
96     }
97
98     /**
99      * Extract common part.
100      *
101      * @param wrapDoc the wrap doc
102      * @return the loansout common
103      * @throws Exception the exception
104      */
105     @Override
106     public LoansoutCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
107             throws Exception {
108         throw new UnsupportedOperationException();
109     }
110
111     /**
112      * Fill common part.
113      *
114      * @param loanoutObject the loanout object
115      * @param wrapDoc the wrap doc
116      * @throws Exception the exception
117      */
118     @Override
119     public void fillCommonPart(LoansoutCommon loanoutObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
120         throw new UnsupportedOperationException();
121     }
122
123     /**
124      * Extract common part list.
125      *
126      * @param wrapDoc the wrap doc
127      * @return the loansout common list
128      * @throws Exception the exception
129      */
130     @Override
131     public LoansoutCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
132         LoansoutCommonList coList = extractPagingInfo(new LoansoutCommonList(), wrapDoc);
133         AbstractCommonList commonList = (AbstractCommonList) coList;
134         commonList.setFieldsReturned("loanOutNumber|borrower|loanReturnDate|uri|csid");
135         List<LoansoutCommonList.LoanoutListItem> list = coList.getLoanoutListItem();
136         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
137         String label = getServiceContext().getCommonPartLabel();
138         while(iter.hasNext()){
139             DocumentModel docModel = iter.next();
140             LoanoutListItem ilistItem = new LoanoutListItem();
141             ilistItem.setLoanOutNumber((String) docModel.getProperty(label,
142                     LoanoutJAXBSchema.LOAN_OUT_NUMBER));
143             ilistItem.setBorrower((String) docModel.getProperty(label,
144                     LoanoutJAXBSchema.BORROWER));
145             ilistItem.setLoanReturnDate((String) docModel.getProperty(label,
146                     LoanoutJAXBSchema.LOAN_RETURN_DATE));
147             String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
148             ilistItem.setUri(getServiceContextPath() + id);
149             ilistItem.setCsid(id);
150             list.add(ilistItem);
151         }
152
153         return coList;
154     }
155
156     /**
157      * Gets the q property.
158      *
159      * @param prop the prop
160      * @return the q property
161      */
162     @Override
163     public String getQProperty(String prop) {
164         return LoanoutConstants.NUXEO_SCHEMA_NAME + ":" + prop;
165     }
166  
167 }
168