]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
71f44b007be6a6aec660104b63c07570c119cfd0
[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.intake.nuxeo;
25
26 import java.util.Iterator;
27 import java.util.List;
28
29 import org.collectionspace.services.IntakeJAXBSchema;
30 import org.collectionspace.services.common.repository.DocumentWrapper;
31 import org.collectionspace.services.intake.IntakesCommon;
32 import org.collectionspace.services.intake.IntakesCommonList;
33 import org.collectionspace.services.intake.IntakesCommonList.IntakeListItem;
34 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
35
36 import org.nuxeo.ecm.core.api.DocumentModel;
37 import org.nuxeo.ecm.core.api.DocumentModelList;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 /**
42  * IntakeDocumentModelHandler
43  *
44  * $LastChangedRevision: $
45  * $LastChangedDate: $
46  */
47 public class IntakeDocumentModelHandler
48         extends DocumentModelHandler<IntakesCommon, IntakesCommonList> {
49
50     private final Logger logger = LoggerFactory.getLogger(IntakeDocumentModelHandler.class);
51     /**
52      * intake is used to stash JAXB object to use when handle is called
53      * for Action.CREATE, Action.UPDATE or Action.GET
54      */
55     private IntakesCommon intake;
56     /**
57      * intakeList is stashed when handle is called
58      * for ACTION.GET_ALL
59      */
60     private IntakesCommonList intakeList;
61
62     @Override
63     public void prepare(Action action) throws Exception {
64         //no specific action needed
65     }
66
67     /**
68      * getCommonPart get associated intake
69      * @return
70      */
71     @Override
72     public IntakesCommon getCommonPart() {
73         return intake;
74     }
75
76     /**
77      * setCommonPart set associated intake
78      * @param intake
79      */
80     @Override
81     public void setCommonPart(IntakesCommon intake) {
82         this.intake = intake;
83     }
84
85     /**
86      * getCommonPartList get associated intake (for index/GET_ALL)
87      * @return
88      */
89     @Override
90     public IntakesCommonList getCommonPartList() {
91         return intakeList;
92     }
93
94     @Override
95     public void setCommonPartList(IntakesCommonList intakeList) {
96         this.intakeList = intakeList;
97     }
98
99     @Override
100     public IntakesCommon extractCommonPart(DocumentWrapper wrapDoc)
101             throws Exception {
102         throw new UnsupportedOperationException();
103     }
104
105     @Override
106     public void fillCommonPart(IntakesCommon intakeObject, DocumentWrapper wrapDoc) throws Exception {
107         throw new UnsupportedOperationException();
108     }
109
110     @Override
111     public IntakesCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception {
112         DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
113
114         IntakesCommonList coList = new IntakesCommonList();
115         List<IntakesCommonList.IntakeListItem> list = coList.getIntakeListItem();
116
117         //FIXME: iterating over a long list of documents is not a long term
118         //strategy...need to change to more efficient iterating in future
119         Iterator<DocumentModel> iter = docList.iterator();
120         while(iter.hasNext()){
121             DocumentModel docModel = iter.next();
122             IntakeListItem ilistItem = new IntakeListItem();
123             ilistItem.setEntryNumber((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
124                     IntakeJAXBSchema.ENTRY_NUMBER));
125             String id = docModel.getId();
126             ilistItem.setUri(getServiceContextPath() + id);
127             ilistItem.setCsid(id);
128             list.add(ilistItem);
129         }
130
131         return coList;
132     }
133
134
135     /* (non-Javadoc)
136      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getDocumentType()
137      */
138     @Override
139     public String getDocumentType() {
140         return IntakeConstants.NUXEO_DOCTYPE;
141     }
142
143     /**
144      * getQProperty converts the given property to qualified schema property
145      * @param prop
146      * @return
147      */
148     @Override
149     public String getQProperty(String prop) {
150         return IntakeConstants.NUXEO_SCHEMA_NAME + ":" + prop;
151     }
152 }
153