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 org.collectionspace.services.common.repository.DocumentHandler;
27 import org.collectionspace.services.common.repository.DocumentWrapper;
28 import org.collectionspace.services.common.repository.DocumentException;
29 import java.util.HashMap;
31 import org.collectionspace.services.nuxeo.client.*;
32 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
33 import org.dom4j.Document;
34 import org.nuxeo.ecm.core.api.DocumentModel;
35 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * DocumentModelHandler is a base abstract Nuxeo document handler
41 * using Nuxeo Java Remote APIs for CollectionSpace services
43 * $LastChangedRevision: $
46 public abstract class DocumentModelHandler<T, TL>
47 implements DocumentHandler<T, TL> {
49 private final Logger logger = LoggerFactory.getLogger(DocumentModelHandler.class);
50 private Map<String, Object> properties = new HashMap<String, Object>();
51 private RepositoryInstance repositorySession;
54 public abstract void prepare(Action action) throws Exception;
57 public void handle(Action action, DocumentWrapper wrapDoc) throws Exception {
60 handleCreate(wrapDoc);
63 handleUpdate(wrapDoc);
69 handleGetAll(wrapDoc);
75 public void handleCreate(DocumentWrapper wrapDoc) throws Exception {
76 if(getCommonObject() == null){
77 String msg = "Error creating document: Missing input data";
79 throw new IllegalStateException(msg);
81 //FIXME set other parts as well
82 fillCommonObject(getCommonObject(), wrapDoc);
86 public void handleUpdate(DocumentWrapper wrapDoc) throws Exception {
87 if(getCommonObject() == null){
88 String msg = "Error updating document: Missing input data";
90 throw new IllegalStateException(msg);
92 //FIXME set other parts as well
93 fillCommonObject(getCommonObject(), wrapDoc);
97 public void handleGet(DocumentWrapper wrapDoc) throws Exception {
98 setCommonObject(extractCommonObject(wrapDoc));
100 //FIXME retrive other parts as well
104 public void handleGetAll(DocumentWrapper wrapDoc) throws Exception {
105 setCommonObjectList(extractCommonObjectList(wrapDoc));
109 * getRepositorySession returns Nuxeo Repository Session
112 public RepositoryInstance getRepositorySession() {
113 return repositorySession;
117 * setRepositorySession sets repository session
120 public void setRepositorySession(RepositoryInstance repoSession) {
121 this.repositorySession = repoSession;
125 public abstract T extractCommonObject(DocumentWrapper wrapDoc) throws Exception;
128 public abstract void fillCommonObject(T obj, DocumentWrapper wrapDoc) throws Exception;
131 public abstract TL extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception;
134 public abstract void fillCommonObjectList(TL obj, DocumentWrapper wrapDoc) throws Exception;
137 public abstract T getCommonObject();
140 public abstract void setCommonObject(T obj);
143 public abstract TL getCommonObjectList();
146 public abstract void setCommonObjectList(TL obj);
149 public Document getDocument(DocumentWrapper wrapDoc) throws DocumentException {
150 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
151 return NuxeoUtils.getDocument(getRepositorySession(), docModel);
155 * @see org.collectionspace.services.common.repository.DocumentHandler#getDocumentType()
158 public abstract String getDocumentType();
161 * @return the properties
164 public Map<String, Object> getProperties() {
169 * @param properties the properties to set
172 public void setProperties(Map<String, Object> properties) {
173 this.properties = properties;