]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
ac2c147a50f78a696d3dff9d253b5b5d780518c5
[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 org.collectionspace.services.common.context.ServiceContext;
27 import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl;
28 import org.collectionspace.services.common.document.DocumentFilter;
29 import org.collectionspace.services.common.document.DocumentWrapper;
30 import org.collectionspace.services.nuxeo.client.*;
31 import org.nuxeo.ecm.core.api.DocumentModel;
32 import org.nuxeo.ecm.core.api.DocumentModelList;
33 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 /**
38  * DocumentModelHandler is a base abstract Nuxeo document handler
39  * using Nuxeo Java Remote APIs for CollectionSpace services
40  *
41  * $LastChangedRevision: $
42  * $LastChangedDate: $
43  */
44 public abstract class DocumentModelHandler<T, TL>
45         extends AbstractMultipartDocumentHandlerImpl<T, TL, DocumentModel, DocumentModelList> {
46
47     private final Logger logger = LoggerFactory.getLogger(DocumentModelHandler.class);
48     private RepositoryInstance repositorySession;
49     //key=schema, value=documentpart
50
51     /**
52      * getRepositorySession returns Nuxeo Repository Session
53      * @return
54      */
55     public RepositoryInstance getRepositorySession() {
56         return repositorySession;
57     }
58
59     /**
60      * setRepositorySession sets repository session
61      * @param repoSession
62      */
63     public void setRepositorySession(RepositoryInstance repoSession) {
64         this.repositorySession = repoSession;
65     }
66
67     @Override
68     public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
69         fillAllParts(wrapDoc);
70     }
71
72     @Override
73     public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
74         fillAllParts(wrapDoc);
75     }
76
77     @Override
78     public void handleGet(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
79         extractAllParts(wrapDoc);
80     }
81
82     @Override
83     public void handleGetAll(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
84         setCommonPartList(extractCommonPartList(wrapDoc));
85     }
86
87     @Override
88     public abstract void completeUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
89
90     @Override
91     public abstract void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
92
93     @Override
94     public abstract T extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
95
96     @Override
97     public abstract void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
98
99     @Override
100     public abstract void fillCommonPart(T obj, DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
101
102     @Override
103     public abstract TL extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception;
104
105     @Override
106     public abstract T getCommonPart();
107
108     @Override
109     public abstract void setCommonPart(T obj);
110
111     @Override
112     public abstract TL getCommonPartList();
113
114     @Override
115     public abstract void setCommonPartList(TL obj);
116     
117     @Override
118     public DocumentFilter createDocumentFilter() {
119         DocumentFilter filter = new NuxeoDocumentFilter(this.getServiceContext());
120         return filter;
121     }
122
123 }