]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
c6475100a80ba65437c1cab1a5f93422d45a516a
[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     public final static String COLLECTIONSPACE_CORE_CREATED_AT = "createdAt";
61     public final static String COLLECTIONSPACE_CORE_UPDATED_AT = "updatedAt";
62
63     /**
64      * getRepositorySession returns Nuxeo Repository Session
65      * @return
66      */
67     public RepositoryInstance getRepositorySession() {
68         return repositorySession;
69     }
70
71     /**
72      * setRepositorySession sets repository session
73      * @param repoSession
74      */
75     public void setRepositorySession(RepositoryInstance repoSession) {
76         this.repositorySession = repoSession;
77     }
78
79     @Override
80     public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
81         // TODO for sub-docs - check to see if the current service context is a multipart input, 
82         // OR a docfragment, and call a variant to fill the DocModel.
83         fillAllParts(wrapDoc, Action.CREATE);
84     }
85     
86     // TODO for sub-docs - Add completeCreate in which we look for set-aside doc fragments 
87     // and create the subitems. We will create service contexts with the doc fragments
88     // and then call 
89
90
91     @Override
92     public void handleUpdate(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.UPDATE);
96     }
97
98     @Override
99     public void handleGet(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
100         extractAllParts(wrapDoc);
101     }
102
103     @Override
104     public void handleGetAll(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
105         Profiler profiler = new Profiler(this, 2);
106         profiler.start();
107         setCommonPartList(extractCommonPartList(wrapDoc));
108         profiler.stop();
109     }
110
111     @Override
112     public abstract void completeUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
113
114     @Override
115     public abstract void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
116
117     @Override
118     public abstract T extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
119
120     @Override
121     public abstract void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception;
122
123     @Override
124     public abstract void fillCommonPart(T obj, DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
125
126     @Override
127     public abstract TL extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception;
128
129     @Override
130     public abstract T getCommonPart();
131
132     @Override
133     public abstract void setCommonPart(T obj);
134
135     @Override
136     public abstract TL getCommonPartList();
137
138     @Override
139     public abstract void setCommonPartList(TL obj);
140     
141     @Override
142     public DocumentFilter createDocumentFilter() {
143         DocumentFilter filter = new NuxeoDocumentFilter(this.getServiceContext());
144         return filter;
145     }
146     
147     /**
148      * Gets the authority refs.
149      *
150      * @param docWrapper the doc wrapper
151      * @param authRefFields the auth ref fields
152      * @return the authority refs
153      * @throws PropertyException the property exception
154      */
155     abstract public AuthorityRefList getAuthorityRefs(
156             DocumentWrapper<DocumentModel> docWrapper,
157                 List<String> authRefFields) throws PropertyException;    
158
159 }