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.rest;
26 import org.collectionspace.services.common.repository.DocumentWrapper;
27 import java.io.InputStream;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
32 import org.collectionspace.services.common.repository.AbstractDocumentHandler;
33 import org.collectionspace.services.nuxeo.client.*;
34 import org.w3c.dom.Document;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 * RepresentationHandler is a base abstract Nuxeo document handler
40 * using Nuxeo RESTful APIs for CollectionSpace services
42 * $LastChangedRevision: $
45 public abstract class RepresentationHandler<T, TL>
46 extends AbstractDocumentHandler<T, TL> {
48 private final Logger logger = LoggerFactory.getLogger(RepresentationHandler.class);
49 private List<String> pathParams = new ArrayList<String>();
50 private Map<String, String> queryParams = new HashMap<String, String>();
51 private Document document;
52 private InputStream inputStream = null;
55 public void handleCreate(DocumentWrapper wrapDoc) throws Exception {
56 fillAllParts(wrapDoc);
60 public void handleUpdate(DocumentWrapper wrapDoc) throws Exception {
61 fillAllParts(wrapDoc);
65 public void handleGet(DocumentWrapper wrapDoc) throws Exception {
66 extractAllParts(wrapDoc);
70 public void handleGetAll(DocumentWrapper wrapDoc) throws Exception {
71 setCommonPartList(extractCommonPartList(wrapDoc));
75 public void extractAllParts(DocumentWrapper wrapDoc) throws Exception {
76 setCommonPart(extractCommonPart(wrapDoc));
78 //FIXME retrive other parts as well
82 public abstract T extractCommonPart(DocumentWrapper wrapDoc) throws Exception;
85 public void fillAllParts(DocumentWrapper wrapDoc) throws Exception {
86 if(getCommonPart() == null){
87 String msg = "Error creating document: Missing input data";
89 throw new IllegalStateException(msg);
91 //FIXME set other parts as well
92 fillCommonPart(getCommonPart(), wrapDoc);
96 public abstract void fillCommonPart(T obj, DocumentWrapper wrapDoc) throws Exception;
99 public abstract TL extractCommonPartList(DocumentWrapper wrapDoc) throws Exception;
102 public abstract T getCommonPart();
105 public abstract void setCommonPart(T obj);
108 public abstract TL getCommonPartList();
111 public abstract void setCommonPartList(TL obj);
114 * @return the pathParams
116 public List<String> getPathParams() {
121 * @param pathParams the pathParams to set
123 public void setPathParams(List<String> pathParams) {
124 this.pathParams = pathParams;
128 * @return the queryParams
130 public Map<String, String> getQueryParams() {
135 * @param queryParams the queryParams to set
137 public void setQueryParams(Map<String, String> queryParams) {
138 this.queryParams = queryParams;
142 * getInputStream to retrieve input stream by client for posting a document
143 * @return the inputStream
145 public InputStream getInputStream() {
150 * setInputStream to set input stream to read for posting document
151 * @param inputStream the inputStream to set
153 public void setInputStream(InputStream inputStream) {
154 this.inputStream = inputStream;
158 * @return the document
160 public Document getDocument() {
165 * @param document the document to set
167 public void setDocument(Document document) {
168 this.document = document;