]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
48d8bb4195f1a85a8efda30f9e96c0d8ca0064b4
[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 java.util.Map;
29
30
31 import org.collectionspace.services.common.relation.IRelationsManager;
32 import org.collectionspace.services.common.relation.nuxeo.RelationConstants;
33 import org.collectionspace.services.common.relation.nuxeo.RelationsUtils;
34 import org.collectionspace.services.common.repository.DocumentHandler.Action;
35 import org.collectionspace.services.relation.RelationsCommon;
36 import org.collectionspace.services.relation.RelationsCommonList;
37 import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
38
39 import org.collectionspace.services.common.repository.DocumentWrapper;
40 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
41 import org.nuxeo.ecm.core.api.DocumentModel;
42 import org.nuxeo.ecm.core.api.DocumentModelList;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45
46 /**
47  * RelationDocumentModelHandler
48  *
49  * $LastChangedRevision: $
50  * $LastChangedDate: $
51  */
52 public class RelationDocumentModelHandler
53         extends RemoteDocumentModelHandler<RelationsCommon, RelationsCommonList> {
54
55     private final Logger logger = LoggerFactory.getLogger(RelationDocumentModelHandler.class);
56     /**
57      * relation is used to stash JAXB object to use when handle is called
58      * for Action.CREATE, Action.UPDATE or Action.GET
59      */
60     private RelationsCommon relation;
61     /**
62      * relationList is stashed when handle is called
63      * for ACTION.GET_ALL
64      */
65     private RelationsCommonList relationList;
66
67     @Override
68     public void prepare(Action action) throws Exception {
69         //no specific action needed
70     }
71
72     /**
73      * getCommonObject get associated Relation
74      * @return
75      */
76     @Override
77     public RelationsCommon getCommonPart() {
78         return relation;
79     }
80
81     /**
82      * setCommonObject set associated relation
83      * @param relation
84      */
85     @Override
86     public void setCommonPart(RelationsCommon relation) {
87         this.relation = relation;
88     }
89
90     /**
91      * getRelationList get associated Relation (for index/GET_ALL)
92      * @return
93      */
94     @Override
95     public RelationsCommonList getCommonPartList() {
96         return relationList;
97     }
98
99     @Override
100     public void setCommonPartList(RelationsCommonList relationList) {
101         this.relationList = relationList;
102     }
103
104     @Override
105     public RelationsCommon extractCommonPart(DocumentWrapper wrapDoc)
106             throws Exception {
107         throw new UnsupportedOperationException();
108     }
109
110     @Override
111     public void fillCommonPart(RelationsCommon relation, DocumentWrapper wrapDoc) throws Exception {
112         throw new UnsupportedOperationException();
113     }
114
115     @Override
116     public RelationsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception {
117         DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
118
119         Map propsFromResource = this.getProperties();
120         String subjectCsid = (String) propsFromResource.get(IRelationsManager.SUBJECT);
121         String predicate = (String) propsFromResource.get(IRelationsManager.PREDICATE);
122         String objectCsid = (String) propsFromResource.get(IRelationsManager.OBJECT);
123
124         RelationsCommonList relList = new RelationsCommonList();
125         List<RelationsCommonList.RelationListItem> itemList = relList.getRelationListItem();
126
127         //FIXME: iterating over a long itemList of documents is not a long term
128         //strategy...need to change to more efficient iterating in future
129         Iterator<DocumentModel> iter = docList.iterator();
130         while(iter.hasNext()){
131             DocumentModel docModel = iter.next();
132             if(RelationsUtils.isQueryMatch(docModel, subjectCsid,
133                     predicate, objectCsid) == true){
134                 RelationListItem relListItem = RelationsUtils.getRelationListItem(
135                         docModel, getServiceContextPath());
136                 itemList.add(relListItem);
137             }
138         }
139         return relList;
140     }
141
142   
143
144     @Override
145     public void fillAllParts(DocumentWrapper wrapDoc) throws Exception {
146         super.fillAllParts(wrapDoc);
147         fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
148     }
149
150     private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception {
151         DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
152         //FIXME property setter should be dynamically set using schema inspection
153         //so it does not require hard coding
154         // a default title for the Dublin Core schema
155         docModel.setPropertyValue("dublincore:title", RelationConstants.NUXEO_DC_TITLE);
156     }
157
158     @Override
159     public String getDocumentType() {
160         return RelationConstants.NUXEO_DOCTYPE;
161     }
162
163     @Override
164     public String getQProperty(String prop) {
165         return "/" + RelationConstants.NUXEO_SCHEMA_ROOT_ELEMENT + "/" + prop;
166     }
167 }
168