]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
e46e751c3a8958cc69462c6e6ba528870a486889
[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.nuxeo.client.java;
25
26 import java.util.List;
27
28 import org.collectionspace.services.common.authorityref.AuthorityRefList;
29 import org.collectionspace.services.common.context.ServiceContext;
30 import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl;
31 import org.collectionspace.services.common.document.DocumentFilter;
32 import org.collectionspace.services.common.document.DocumentWrapper;
33 import org.collectionspace.services.common.document.DocumentHandler.Action;
34 import org.collectionspace.services.nuxeo.client.*;
35 import org.collectionspace.services.common.profile.Profiler;
36
37 import org.nuxeo.ecm.core.api.DocumentModel;
38 import org.nuxeo.ecm.core.api.DocumentModelList;
39 import org.nuxeo.ecm.core.api.model.PropertyException;
40 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 /**
45  * DocumentModelHandler is a base abstract Nuxeo document handler
46  * using Nuxeo Java Remote APIs for CollectionSpace services
47  *
48  * $LastChangedRevision: $
49  * $LastChangedDate: $
50  */
51 public abstract class DocumentModelHandler<T, TL>
52         extends AbstractMultipartDocumentHandlerImpl<T, TL, DocumentModel, DocumentModelList> {
53
54     private final Logger logger = LoggerFactory.getLogger(DocumentModelHandler.class);
55     private RepositoryInstance repositorySession;
56     //key=schema, value=documentpart
57
58     public final static String COLLECTIONSPACE_CORE_SCHEMA = "collectionspace_core";
59     public final static String COLLECTIONSPACE_CORE_TENANTID = "tenantId";
60     
61     /**
62      * getRepositorySession returns Nuxeo Repository Session
63      * @return
64      */
65     public RepositoryInstance getRepositorySession() {
66         return repositorySession;
67     }
68
69     /**
70      * setRepositorySession sets repository session
71      * @param repoSession
72      */
73     public void setRepositorySession(RepositoryInstance repoSession) {
74         this.repositorySession = repoSession;
75     }
76
77     @Override
78     public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
79         // TODO for sub-docs - check to see if the current service context is a multipart input, 
80         // OR a docfragment, and call a variant to fill the DocModel.
81         fillAllParts(wrapDoc, Action.CREATE);
82     }
83     
84     // TODO for sub-docs - Add completeCreate in which we look for set-aside doc fragments 
85     // and create the subitems. We will create service contexts with the doc fragments
86     // and then call 
87
88
89     @Override
90     public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
91         // TODO for sub-docs - check to see if the current service context is a multipart input, 
92         // OR a docfragment, and call a variant to fill the DocModel.
93         fillAllParts(wrapDoc, Action.UPDATE);
94     }
95
96     @Override
97     public void handleGet(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
98         extractAllParts(wrapDoc);
99     }
100
101     @Override
102     public void handleGetAll(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
103         Profiler profiler = new Profiler(this, 2);
104         profiler.start();
105         setCommonPartList(extractCommonPartList(wrapDoc));
106         profiler.stop();
107     }
108
109     @Override
110     public abstract void completeUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
111
112     @Override
113     public abstract void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
114
115     @Override
116     public abstract T extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
117
118     @Override
119     public abstract void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception;
120
121     @Override
122     public abstract void fillCommonPart(T obj, DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
123
124     @Override
125     public abstract TL extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception;
126
127     @Override
128     public abstract T getCommonPart();
129
130     @Override
131     public abstract void setCommonPart(T obj);
132
133     @Override
134     public abstract TL getCommonPartList();
135
136     @Override
137     public abstract void setCommonPartList(TL obj);
138     
139     @Override
140     public DocumentFilter createDocumentFilter() {
141         DocumentFilter filter = new NuxeoDocumentFilter(this.getServiceContext());
142         return filter;
143     }
144     
145     /**
146      * Gets the authority refs.
147      *
148      * @param docWrapper the doc wrapper
149      * @param authRefFields the auth ref fields
150      * @return the authority refs
151      * @throws PropertyException the property exception
152      */
153     abstract public AuthorityRefList getAuthorityRefs(
154             DocumentWrapper<DocumentModel> docWrapper,
155                 List<String> authRefFields) throws PropertyException;    
156
157 }