]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
1bdd44e54955adc8b99e64ae34ae9af1a91c35c2
[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.rest;
25
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;
31 import java.util.Map;
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;
37
38 /**
39  * RepresentationHandler is a base abstract Nuxeo document handler
40  * using Nuxeo RESTful APIs for CollectionSpace services
41  *
42  * $LastChangedRevision: $
43  * $LastChangedDate: $
44  */
45 public abstract class RepresentationHandler<T, TL>
46         extends AbstractDocumentHandler<T, TL> {
47
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;
53
54     @Override
55     public void handleCreate(DocumentWrapper wrapDoc) throws Exception {
56         fillAllParts(wrapDoc);
57     }
58
59     @Override
60     public void handleUpdate(DocumentWrapper wrapDoc) throws Exception {
61         fillAllParts(wrapDoc);
62     }
63
64     @Override
65     public void handleGet(DocumentWrapper wrapDoc) throws Exception {
66         extractAllParts(wrapDoc);
67     }
68
69     @Override
70     public void handleGetAll(DocumentWrapper wrapDoc) throws Exception {
71         setCommonPartList(extractCommonPartList(wrapDoc));
72     }
73
74     @Override
75     public void extractAllParts(DocumentWrapper wrapDoc) throws Exception {
76         setCommonPart(extractCommonPart(wrapDoc));
77
78         //FIXME retrive other parts as well
79     }
80
81     @Override
82     public abstract T extractCommonPart(DocumentWrapper wrapDoc) throws Exception;
83
84     @Override
85     public void fillAllParts(DocumentWrapper wrapDoc) throws Exception {
86         if(getCommonPart() == null){
87             String msg = "Error creating document: Missing input data";
88             logger.error(msg);
89             throw new IllegalStateException(msg);
90         }
91         //FIXME set other parts as well
92         fillCommonPart(getCommonPart(), wrapDoc);
93     }
94
95     @Override
96     public abstract void fillCommonPart(T obj, DocumentWrapper wrapDoc) throws Exception;
97
98     @Override
99     public abstract TL extractCommonPartList(DocumentWrapper wrapDoc) throws Exception;
100
101     @Override
102     public abstract T getCommonPart();
103
104     @Override
105     public abstract void setCommonPart(T obj);
106
107     @Override
108     public abstract TL getCommonPartList();
109
110     @Override
111     public abstract void setCommonPartList(TL obj);
112
113     /**
114      * @return the pathParams
115      */
116     public List<String> getPathParams() {
117         return pathParams;
118     }
119
120     /**
121      * @param pathParams the pathParams to set
122      */
123     public void setPathParams(List<String> pathParams) {
124         this.pathParams = pathParams;
125     }
126
127     /**
128      * @return the queryParams
129      */
130     public Map<String, String> getQueryParams() {
131         return queryParams;
132     }
133
134     /**
135      * @param queryParams the queryParams to set
136      */
137     public void setQueryParams(Map<String, String> queryParams) {
138         this.queryParams = queryParams;
139     }
140
141     /**
142      * getInputStream to retrieve input stream by client for posting a document
143      * @return the inputStream
144      */
145     public InputStream getInputStream() {
146         return inputStream;
147     }
148
149     /**
150      * setInputStream to set input stream to read for posting document
151      * @param inputStream the inputStream to set
152      */
153     public void setInputStream(InputStream inputStream) {
154         this.inputStream = inputStream;
155     }
156
157     /**
158      * @return the document
159      */
160     public Document getDocument() {
161         return document;
162     }
163
164     /**
165      * @param document the document to set
166      */
167     public void setDocument(Document document) {
168         this.document = document;
169     }
170 }