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