]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
d88983c0c2ab917a8ec40eb6c1b1c6b61838cec1
[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.relation.nuxeo;
25
26 import java.util.Iterator;
27 import java.util.List;
28 import org.collectionspace.services.common.relation.RelationJAXBSchema;
29 //import org.collectionspace.services.common.relation.nuxeo.RelationUtilsNuxeoImpl;
30 import org.collectionspace.services.common.relation.RelationsManager;
31
32 import org.collectionspace.services.relation.Relation;
33 import org.collectionspace.services.relation.RelationList;
34 import org.collectionspace.services.relation.RelationList.RelationListItem;
35
36 import org.collectionspace.services.common.repository.DocumentWrapper;
37 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
38 import org.nuxeo.ecm.core.api.DocumentModel;
39 import org.nuxeo.ecm.core.api.DocumentModelList;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 /**
44  * RelationDocumentModelHandler
45  *
46  * $LastChangedRevision: $
47  * $LastChangedDate: $
48  */
49 public class RelationDocumentModelHandler
50         extends DocumentModelHandler<Relation, RelationList> {
51
52     private final Logger logger = LoggerFactory.getLogger(RelationDocumentModelHandler.class);
53     /**
54      * relation is used to stash JAXB object to use when handle is called
55      * for Action.CREATE, Action.UPDATE or Action.GET
56      */
57     private Relation relation;
58     /**
59      * relationList is stashed when handle is called
60      * for ACTION.GET_ALL
61      */
62     private RelationList relationList;
63
64     @Override
65     public void prepare(Action action) throws Exception {
66         //no specific action needed
67     }
68
69
70     /**
71      * getCommonObject get associated Relation
72      * @return
73      */
74     @Override
75     public Relation getCommonObject() {
76         return relation;
77     }
78
79     /**
80      * setCommonObject set associated relation
81      * @param relation
82      */
83     @Override
84     public void setCommonObject(Relation relation) {
85         this.relation = relation;
86     }
87
88     /**
89      * getRelationList get associated Relation (for index/GET_ALL)
90      * @return
91      */
92     @Override
93     public RelationList getCommonObjectList() {
94         return relationList;
95     }
96
97     @Override
98     public void setCommonObjectList(RelationList relationList) {
99         this.relationList = relationList;
100     }
101
102     @Override
103     public Relation extractCommonObject(DocumentWrapper wrapDoc)
104             throws Exception {
105         DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
106         Relation co = new Relation();
107
108         return co;
109     }
110
111     @Override
112     public void fillCommonObject(Relation co, DocumentWrapper wrapDoc) throws Exception {
113         DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
114         //FIXME property setter should be dynamically set using schema inspection
115         //so it does not require hard coding
116
117     }
118
119     @Override
120     public RelationList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception {
121         DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
122
123         RelationList coList = new RelationList();
124         List<RelationList.RelationListItem> list = coList.getRelationListItem();
125
126         //FIXME: iterating over a long list of documents is not a long term
127         //strategy...need to change to more efficient iterating in future
128         Iterator<DocumentModel> iter = docList.iterator();
129         while(iter.hasNext()){
130             DocumentModel docModel = iter.next();
131             RelationListItem coListItem = new RelationListItem();
132             
133             coListItem.setCsid((String) docModel.getPropertyValue(
134                     getQProperty(RelationJAXBSchema.DOCUMENT_ID_1)));
135             
136             //need fully qualified context for URI
137             coListItem.setUri("/relations/" + docModel.getId());
138             coListItem.setCsid(docModel.getId());
139             list.add(coListItem);
140         }
141
142         return coList;
143     }
144
145     @Override
146     public void fillCommonObjectList(RelationList obj, DocumentWrapper wrapDoc) throws Exception {
147         throw new UnsupportedOperationException();
148     }
149
150     /**
151      * getQProperty converts the given property to qualified schema property
152      * @param prop
153      * @return
154      */
155     private String getQProperty(String property) {
156         return RelationsManager.getQPropertyName(property);
157     }
158 }
159