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