]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
33d3cc4d9d99d4bc628110b46a3f2bf2257a6afa
[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.acquisition.nuxeo;
25
26 import java.util.Iterator;
27 import java.util.List;
28
29 import org.collectionspace.services.AcquisitionJAXBSchema;
30 import org.collectionspace.services.common.repository.DocumentWrapper;
31 import org.collectionspace.services.acquisition.AcquisitionsCommon;
32 import org.collectionspace.services.acquisition.AcquisitionsCommonList;
33 import org.collectionspace.services.acquisition.AcquisitionsCommonList.AcquisitionListItem;
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  * AcquisitionDocumentModelHandler
43  *
44  * $LastChangedRevision: $
45  * $LastChangedDate: $
46  */
47 public class AcquisitionDocumentModelHandler
48         extends DocumentModelHandler<AcquisitionsCommon, AcquisitionsCommonList> {
49
50     private final Logger logger = LoggerFactory.getLogger(AcquisitionDocumentModelHandler.class);
51     /**
52      * acquisition is used to stash JAXB object to use when handle is called
53      * for Action.CREATE, Action.UPDATE or Action.GET
54      */
55     private AcquisitionsCommon acquisition;
56     /**
57      * acquisitionList is stashed when handle is called
58      * for ACTION.GET_ALL
59      */
60     private AcquisitionsCommonList acquisitionList;
61
62     @Override
63     public void prepare(Action action) throws Exception {
64         //no specific action needed
65     }
66
67     /**
68      * getCommonPart get associated acquisition
69      * @return
70      */
71     @Override
72     public AcquisitionsCommon getCommonPart() {
73         return acquisition;
74     }
75
76     /**
77      * setCommonPart set associated acquisition
78      * @param acquisition
79      */
80     @Override
81     public void setCommonPart(AcquisitionsCommon acquisition) {
82         this.acquisition = acquisition;
83     }
84
85     /**
86      * getAcquisitionList get associated acquisition (for index/GET_ALL)
87      * @return
88      */
89     @Override
90     public AcquisitionsCommonList getCommonPartList() {
91         return acquisitionList;
92     }
93
94     @Override
95     public void setCommonPartList(AcquisitionsCommonList acquisitionList) {
96         this.acquisitionList = acquisitionList;
97     }
98
99     @Override
100     public AcquisitionsCommon extractCommonPart(DocumentWrapper wrapDoc)
101             throws Exception {
102         throw new UnsupportedOperationException();
103     }
104
105     @Override
106     public void fillCommonPart(AcquisitionsCommon acquisitionObject, DocumentWrapper wrapDoc) throws Exception {
107         throw new UnsupportedOperationException();
108     }
109
110     @Override
111     public AcquisitionsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception {
112         DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
113
114         AcquisitionsCommonList coList = new AcquisitionsCommonList();
115         List<AcquisitionsCommonList.AcquisitionListItem> list = coList.getAcquisitionListItem();
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             AcquisitionListItem listItem = new AcquisitionListItem();
123             listItem.setAccessiondate((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
124                     AcquisitionJAXBSchema.ACCESSIONDATE));
125             //need fully qualified context for URI
126             String id = docModel.getId();
127             listItem.setUri(getServiceContextPath() + id);
128             listItem.setCsid(id);
129             list.add(listItem);
130         }
131
132         return coList;
133     }
134
135     @Override
136     public void fillAllParts(DocumentWrapper wrapDoc) throws Exception {
137
138         super.fillAllParts(wrapDoc);
139         fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
140     }
141
142     private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception {
143         DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
144         //FIXME property setter should be dynamically set using schema inspection
145         //so it does not require hard coding
146         // a default title for the Dublin Core schema
147         docModel.setPropertyValue("dublincore:title", AcquisitionConstants.NUXEO_DC_TITLE);
148     }
149
150
151     /* (non-Javadoc)
152      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getDocumentType()
153      */
154     public String getDocumentType() {
155         return AcquisitionConstants.NUXEO_DOCTYPE;
156     }
157
158     /**
159      * getQProperty converts the given property to qualified schema property
160      * @param prop
161      * @return
162      */
163     @Override
164     public String getQProperty(String prop) {
165         return AcquisitionConstants.NUXEO_SCHEMA_NAME + ":" + prop;
166     }
167 }
168