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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 package org.collectionspace.services.nuxeo.client.java;
26 import java.util.List;
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;
43 * DocumentModelHandler is a base abstract Nuxeo document handler
44 * using Nuxeo Java Remote APIs for CollectionSpace services
46 * $LastChangedRevision: $
49 public abstract class DocumentModelHandler<T, TL>
50 extends AbstractMultipartDocumentHandlerImpl<T, TL, DocumentModel, DocumentModelList> {
52 private final Logger logger = LoggerFactory.getLogger(DocumentModelHandler.class);
53 private RepositoryInstance repositorySession;
54 //key=schema, value=documentpart
56 public final static String COLLECTIONSPACE_CORE_SCHEMA = "collectionspace_core";
57 public final static String COLLECTIONSPACE_CORE_TENANTID = "tenantId";
60 * getRepositorySession returns Nuxeo Repository Session
63 public RepositoryInstance getRepositorySession() {
64 return repositorySession;
68 * setRepositorySession sets repository session
71 public void setRepositorySession(RepositoryInstance repoSession) {
72 this.repositorySession = repoSession;
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);
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
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);
95 public void handleGet(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
96 extractAllParts(wrapDoc);
100 public void handleGetAll(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
101 setCommonPartList(extractCommonPartList(wrapDoc));
105 public abstract void completeUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
108 public abstract void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
111 public abstract T extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
114 public abstract void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception;
117 public abstract void fillCommonPart(T obj, DocumentWrapper<DocumentModel> wrapDoc) throws Exception;
120 public abstract TL extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception;
123 public abstract T getCommonPart();
126 public abstract void setCommonPart(T obj);
129 public abstract TL getCommonPartList();
132 public abstract void setCommonPartList(TL obj);
135 public DocumentFilter createDocumentFilter() {
136 DocumentFilter filter = new NuxeoDocumentFilter(this.getServiceContext());
141 * Gets the authority refs.
143 * @param docWrapper the doc wrapper
144 * @param authRefFields the auth ref fields
145 * @return the authority refs
146 * @throws PropertyException the property exception
148 abstract public AuthorityRefList getAuthorityRefs(
149 DocumentWrapper<DocumentModel> docWrapper,
150 List<String> authRefFields) throws PropertyException;