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.common.document;
26 import java.util.HashMap;
27 import java.util.List;
30 import java.util.StringTokenizer;
31 import org.collectionspace.services.common.context.ServiceContext;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * AbstractDocumentHandler
39 * $LastChangedRevision: $
46 public abstract class AbstractDocumentHandlerImpl<T, TL, WT, WTL>
47 implements DocumentHandler<T, TL, WT, WTL> {
50 private final Logger logger = LoggerFactory.getLogger(AbstractDocumentHandlerImpl.class);
52 /** The properties. */
53 private Map<String, Object> properties = new HashMap<String, Object>();
55 /** The doc filter. */
56 private DocumentFilter docFilter = null;
58 /** The service context. */
59 private ServiceContext serviceContext;
62 * Instantiates a new abstract document handler impl.
64 public AbstractDocumentHandlerImpl() {
69 * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContext()
72 public ServiceContext getServiceContext() {
73 return serviceContext;
77 * @see org.collectionspace.services.common.document.DocumentHandler#setServiceContext(org.collectionspace.services.common.context.ServiceContext)
80 public void setServiceContext(ServiceContext ctx) {
85 * @return the properties
88 public Map<String, Object> getProperties() {
93 * @param properties the properties to set
96 public void setProperties(Map<String, Object> properties) {
97 this.properties = properties;
100 // public void initializeDocumentFilter(ServiceContext ctx) {
101 // DocumentFilter docFilter = this.createDocumentFilter(ctx);
102 // this.setDocumentFilter(docFilter);
105 * @see org.collectionspace.services.common.document.DocumentHandler#createDocumentFilter()
108 public abstract DocumentFilter createDocumentFilter();
111 * @return the DocumentFilter
114 public DocumentFilter getDocumentFilter() {
119 * @param properties the DocumentFilter to set
122 public void setDocumentFilter(DocumentFilter docFilter) {
123 this.docFilter = docFilter;
127 * @see org.collectionspace.services.common.document.DocumentHandler#prepare(org.collectionspace.services.common.document.DocumentHandler.Action)
130 final public void prepare(Action action) throws Exception {
159 * @see org.collectionspace.services.common.document.DocumentHandler#prepareCreate()
162 public void prepareCreate() throws Exception {
166 * @see org.collectionspace.services.common.document.DocumentHandler#prepareUpdate()
169 public void prepareUpdate() throws Exception {
173 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGet()
176 public void prepareGet() throws Exception {
180 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGetAll()
183 public void prepareGetAll() throws Exception {
187 * @see org.collectionspace.services.common.document.DocumentHandler#prepareDelete()
190 public void prepareDelete() throws Exception {
194 * @see org.collectionspace.services.common.document.DocumentHandler#handle(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
197 final public void handle(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
200 handleCreate((DocumentWrapper<WT>) wrapDoc);
204 handleUpdate((DocumentWrapper<WT>) wrapDoc);
208 handleGet((DocumentWrapper<WT>) wrapDoc);
212 handleGetAll((DocumentWrapper<WTL>) wrapDoc);
216 handleDelete((DocumentWrapper<WT>) wrapDoc);
223 * @see org.collectionspace.services.common.document.DocumentHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
226 public abstract void handleCreate(DocumentWrapper<WT> wrapDoc) throws Exception;
229 * @see org.collectionspace.services.common.document.DocumentHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
232 public abstract void handleUpdate(DocumentWrapper<WT> wrapDoc) throws Exception;
235 * @see org.collectionspace.services.common.document.DocumentHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper)
238 public abstract void handleGet(DocumentWrapper<WT> wrapDoc) throws Exception;
241 * @see org.collectionspace.services.common.document.DocumentHandler#handleGetAll(org.collectionspace.services.common.document.DocumentWrapper)
244 public abstract void handleGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception;
247 * @see org.collectionspace.services.common.document.DocumentHandler#handleDelete(org.collectionspace.services.common.document.DocumentWrapper)
250 public void handleDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
255 * @see org.collectionspace.services.common.document.DocumentHandler#complete(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
258 final public void complete(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
261 completeCreate((DocumentWrapper<WT>) wrapDoc);
265 completeUpdate((DocumentWrapper<WT>) wrapDoc);
269 completeGet((DocumentWrapper<WT>) wrapDoc);
273 completeGetAll((DocumentWrapper<WTL>) wrapDoc);
277 completeDelete((DocumentWrapper<WT>) wrapDoc);
283 * @see org.collectionspace.services.common.document.DocumentHandler#completeCreate(org.collectionspace.services.common.document.DocumentWrapper)
286 public void completeCreate(DocumentWrapper<WT> wrapDoc) throws Exception {
290 * @see org.collectionspace.services.common.document.DocumentHandler#completeUpdate(org.collectionspace.services.common.document.DocumentWrapper)
293 public void completeUpdate(DocumentWrapper<WT> wrapDoc) throws Exception {
294 //no specific action needed
298 * @see org.collectionspace.services.common.document.DocumentHandler#completeGet(org.collectionspace.services.common.document.DocumentWrapper)
301 public void completeGet(DocumentWrapper<WT> wrapDoc) throws Exception {
305 * @see org.collectionspace.services.common.document.DocumentHandler#completeGetAll(org.collectionspace.services.common.document.DocumentWrapper)
308 public void completeGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception {
312 * @see org.collectionspace.services.common.document.DocumentHandler#completeDelete(org.collectionspace.services.common.document.DocumentWrapper)
315 public void completeDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
319 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
322 public abstract T extractCommonPart(DocumentWrapper<WT> wrapDoc)
326 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
329 public abstract void fillCommonPart(T obj, DocumentWrapper<WT> wrapDoc)
333 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
336 public abstract TL extractCommonPartList(DocumentWrapper<WTL> wrapDoc)
340 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPartList(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
343 final public void fillCommonPartList(TL obj, DocumentWrapper<WTL> wrapDoc) throws Exception {
344 throw new UnsupportedOperationException("bulk create/update not yet supported");
348 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPart()
351 public abstract T getCommonPart();
354 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPart(java.lang.Object)
357 public abstract void setCommonPart(T obj);
360 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPartList()
363 public abstract TL getCommonPartList();
366 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPartList(java.lang.Object)
369 public abstract void setCommonPartList(TL obj);
372 * @see org.collectionspace.services.common.document.DocumentHandler#getQProperty(java.lang.String)
375 public abstract String getQProperty(String prop) throws DocumentException;
378 * Strip Nuxeo's schema name from the start of the field / element name.
380 * @see org.collectionspace.services.common.document.DocumentHandler#getUnQProperty(java.lang.String)
383 public String getUnQProperty(String qProp) {
384 StringTokenizer tkz = new StringTokenizer(qProp, ":");
385 if (tkz.countTokens() != 2) {
386 String msg = "Property must be in the form xxx:yyy, "
387 + "e.g. collectionobjects_common:objectNumber";
389 throw new IllegalArgumentException(msg);
391 tkz.nextToken(); //skip
392 return tkz.nextToken();
396 * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContextPath()
399 public String getServiceContextPath() {
400 return "/" + getServiceContext().getServiceName().toLowerCase() + "/";
406 * @param action the action
407 * @throws Exception the exception
409 private void validate(Action action) throws Exception {
410 List<ValidatorHandler> valHandlers = serviceContext.getValidatorHandlers();
411 for (ValidatorHandler handler : valHandlers) {
412 handler.validate(action, serviceContext);
417 * Creates the CMIS query from the service context. Each document handler is responsible for returning a valid CMIS query using the
418 * information in the current service context -which includes things like the query parameters, etc.
420 public String getCMISQuery() {
422 // By default, return nothing. Child classes can override if they want.
427 public boolean isCMISQuery() {