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