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;
32 import org.collectionspace.services.common.query.QueryContext;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * AbstractDocumentHandler
40 * $LastChangedRevision: $
47 public abstract class AbstractDocumentHandlerImpl<T, TL, WT, WTL>
48 implements DocumentHandler<T, TL, WT, WTL> {
51 private final Logger logger = LoggerFactory.getLogger(AbstractDocumentHandlerImpl.class);
53 /** The properties. */
54 private Map<String, Object> properties = new HashMap<String, Object>();
56 /** The doc filter. */
57 private DocumentFilter docFilter = null;
59 /** The service context. */
60 private ServiceContext serviceContext;
63 * Instantiates a new abstract document handler impl.
65 public AbstractDocumentHandlerImpl() {
70 * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContext()
73 public ServiceContext getServiceContext() {
74 return serviceContext;
78 * @see org.collectionspace.services.common.document.DocumentHandler#setServiceContext(org.collectionspace.services.common.context.ServiceContext)
81 public void setServiceContext(ServiceContext ctx) {
86 * @return the properties
89 public Map<String, Object> getProperties() {
94 * @param properties the properties to set
97 public void setProperties(Map<String, Object> properties) {
98 this.properties = properties;
101 // public void initializeDocumentFilter(ServiceContext ctx) {
102 // DocumentFilter docFilter = this.createDocumentFilter(ctx);
103 // this.setDocumentFilter(docFilter);
106 * @see org.collectionspace.services.common.document.DocumentHandler#createDocumentFilter()
109 public abstract DocumentFilter createDocumentFilter();
112 * @return the DocumentFilter
115 public DocumentFilter getDocumentFilter() {
120 * @param properties the DocumentFilter to set
123 public void setDocumentFilter(DocumentFilter docFilter) {
124 this.docFilter = docFilter;
128 * @see org.collectionspace.services.common.document.DocumentHandler#prepare(org.collectionspace.services.common.document.DocumentHandler.Action)
131 final public void prepare(Action action) throws Exception {
160 * @see org.collectionspace.services.common.document.DocumentHandler#prepareCreate()
163 public void prepareCreate() throws Exception {
167 * @see org.collectionspace.services.common.document.DocumentHandler#prepareUpdate()
170 public void prepareUpdate() throws Exception {
174 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGet()
177 public void prepareGet() throws Exception {
181 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGetAll()
184 public void prepareGetAll() throws Exception {
188 * @see org.collectionspace.services.common.document.DocumentHandler#prepareDelete()
191 public void prepareDelete() throws Exception {
195 * @see org.collectionspace.services.common.document.DocumentHandler#handle(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
198 final public void handle(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
201 handleCreate((DocumentWrapper<WT>) wrapDoc);
205 handleUpdate((DocumentWrapper<WT>) wrapDoc);
209 handleGet((DocumentWrapper<WT>) wrapDoc);
213 handleGetAll((DocumentWrapper<WTL>) wrapDoc);
217 handleDelete((DocumentWrapper<WT>) wrapDoc);
224 * @see org.collectionspace.services.common.document.DocumentHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
227 public abstract void handleCreate(DocumentWrapper<WT> wrapDoc) throws Exception;
230 * @see org.collectionspace.services.common.document.DocumentHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
233 public abstract void handleUpdate(DocumentWrapper<WT> wrapDoc) throws Exception;
236 * @see org.collectionspace.services.common.document.DocumentHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper)
239 public abstract void handleGet(DocumentWrapper<WT> wrapDoc) throws Exception;
242 * @see org.collectionspace.services.common.document.DocumentHandler#handleGetAll(org.collectionspace.services.common.document.DocumentWrapper)
245 public abstract void handleGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception;
248 * @see org.collectionspace.services.common.document.DocumentHandler#handleDelete(org.collectionspace.services.common.document.DocumentWrapper)
251 public void handleDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
256 * @see org.collectionspace.services.common.document.DocumentHandler#complete(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
259 final public void complete(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
262 completeCreate((DocumentWrapper<WT>) wrapDoc);
266 completeUpdate((DocumentWrapper<WT>) wrapDoc);
270 completeGet((DocumentWrapper<WT>) wrapDoc);
274 completeGetAll((DocumentWrapper<WTL>) wrapDoc);
278 completeDelete((DocumentWrapper<WT>) wrapDoc);
284 * @see org.collectionspace.services.common.document.DocumentHandler#completeCreate(org.collectionspace.services.common.document.DocumentWrapper)
287 public void completeCreate(DocumentWrapper<WT> wrapDoc) throws Exception {
291 * @see org.collectionspace.services.common.document.DocumentHandler#completeUpdate(org.collectionspace.services.common.document.DocumentWrapper)
294 public void completeUpdate(DocumentWrapper<WT> wrapDoc) throws Exception {
295 //no specific action needed
299 * @see org.collectionspace.services.common.document.DocumentHandler#completeGet(org.collectionspace.services.common.document.DocumentWrapper)
302 public void completeGet(DocumentWrapper<WT> wrapDoc) throws Exception {
306 * @see org.collectionspace.services.common.document.DocumentHandler#completeGetAll(org.collectionspace.services.common.document.DocumentWrapper)
309 public void completeGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception {
313 * @see org.collectionspace.services.common.document.DocumentHandler#completeDelete(org.collectionspace.services.common.document.DocumentWrapper)
316 public void completeDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
320 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
323 public abstract T extractCommonPart(DocumentWrapper<WT> wrapDoc)
327 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
330 public abstract void fillCommonPart(T obj, DocumentWrapper<WT> wrapDoc)
334 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
337 public abstract TL extractCommonPartList(DocumentWrapper<WTL> wrapDoc)
341 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPartList(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
344 final public void fillCommonPartList(TL obj, DocumentWrapper<WTL> wrapDoc) throws Exception {
345 throw new UnsupportedOperationException("bulk create/update not yet supported");
349 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPart()
352 public abstract T getCommonPart();
355 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPart(java.lang.Object)
358 public abstract void setCommonPart(T obj);
361 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPartList()
364 public abstract TL getCommonPartList();
367 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPartList(java.lang.Object)
370 public abstract void setCommonPartList(TL obj);
373 * @see org.collectionspace.services.common.document.DocumentHandler#getQProperty(java.lang.String)
376 public abstract String getQProperty(String prop) throws DocumentException;
379 * Strip Nuxeo's schema name from the start of the field / element name.
381 * @see org.collectionspace.services.common.document.DocumentHandler#getUnQProperty(java.lang.String)
384 public String getUnQProperty(String qProp) {
385 StringTokenizer tkz = new StringTokenizer(qProp, ":");
386 if (tkz.countTokens() != 2) {
387 String msg = "Property must be in the form xxx:yyy, "
388 + "e.g. collectionobjects_common:objectNumber";
390 throw new IllegalArgumentException(msg);
392 tkz.nextToken(); //skip
393 return tkz.nextToken();
397 * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContextPath()
400 public String getServiceContextPath() {
401 return "/" + getServiceContext().getServiceName().toLowerCase() + "/";
407 * @param action the action
408 * @throws Exception the exception
410 private void validate(Action action) throws Exception {
411 List<ValidatorHandler> valHandlers = serviceContext.getValidatorHandlers();
412 for (ValidatorHandler handler : valHandlers) {
413 handler.validate(action, serviceContext);
418 * Creates the CMIS query from the service context. Each document handler is responsible for returning a valid CMIS query using the
419 * information in the current service context -which includes things like the query parameters, etc.
422 public String getCMISQuery(QueryContext queryContext) {
424 // By default, return nothing. Child classes can override if they want.
430 public boolean isCMISQuery() {