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;
29 import java.util.StringTokenizer;
31 import org.collectionspace.services.client.PoxPayloadIn;
32 import org.collectionspace.services.client.PoxPayloadOut;
33 import org.collectionspace.services.common.api.RefName;
34 import org.collectionspace.services.common.context.ServiceContext;
35 import org.collectionspace.services.common.query.QueryContext;
36 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * AbstractDocumentHandler
44 * $LastChangedRevision: $
51 public abstract class AbstractDocumentHandlerImpl<T, TL, WT, WTL>
52 implements DocumentHandler<T, TL, WT, WTL> {
55 private final Logger logger = LoggerFactory.getLogger(AbstractDocumentHandlerImpl.class);
57 /** The properties. */
58 private Map<String, Object> properties = new HashMap<String, Object>();
60 /** The doc filter. */
61 private DocumentFilter docFilter = null;
63 /** The service context. */
64 private ServiceContext serviceContext;
67 * Instantiates a new abstract document handler impl.
69 public AbstractDocumentHandlerImpl() {
73 abstract protected String getRefnameDisplayName(DocumentWrapper<WT> docWrapper);
76 * Should return a reference name for the wrapper object
78 abstract protected RefName.RefNameInterface getRefName(DocumentWrapper<WT> docWrapper, String tenantName, String serviceName);
81 * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContext()
84 public ServiceContext getServiceContext() {
85 return serviceContext;
89 * @see org.collectionspace.services.common.document.DocumentHandler#setServiceContext(org.collectionspace.services.common.context.ServiceContext)
92 public void setServiceContext(ServiceContext ctx) {
97 * @return the properties
100 public Map<String, Object> getProperties() {
105 * @param properties the properties to set
108 public void setProperties(Map<String, Object> properties) {
109 this.properties = properties;
112 // public void initializeDocumentFilter(ServiceContext ctx) {
113 // DocumentFilter docFilter = this.createDocumentFilter(ctx);
114 // this.setDocumentFilter(docFilter);
117 * @see org.collectionspace.services.common.document.DocumentHandler#createDocumentFilter()
120 public abstract DocumentFilter createDocumentFilter();
123 * @return the DocumentFilter
126 public DocumentFilter getDocumentFilter() {
131 * @param properties the DocumentFilter to set
134 public void setDocumentFilter(DocumentFilter docFilter) {
135 this.docFilter = docFilter;
139 * @see org.collectionspace.services.common.document.DocumentHandler#prepare(org.collectionspace.services.common.document.DocumentHandler.Action)
142 final public void prepare(Action action) throws Exception {
172 logger.error("Should never get to this code path. If you did, there is a bug in the code.");
177 logger.error("Should never get to this code path. If you did, there is a bug in the code.");
184 * @see org.collectionspace.services.common.document.DocumentHandler#prepareCreate()
187 public void prepareCreate() throws Exception {
191 * @see org.collectionspace.services.common.document.DocumentHandler#prepareUpdate()
194 public void prepareUpdate() throws Exception {
198 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGet()
201 public void prepareGet() throws Exception {
205 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGetAll()
208 public void prepareGetAll() throws Exception {
212 * @see org.collectionspace.services.common.document.DocumentHandler#prepareDelete()
215 public void prepareDelete() throws Exception {
219 * @see org.collectionspace.services.common.document.DocumentHandler#prepareDelete()
222 public void prepareSync() throws Exception {
223 // Do nothing. Subclasses can override if they want/need to.
227 * @see org.collectionspace.services.common.document.DocumentHandler#handle(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
230 final public void handle(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
233 handleCreate((DocumentWrapper<WT>) wrapDoc);
237 handleUpdate((DocumentWrapper<WT>) wrapDoc);
241 handleGet((DocumentWrapper<WT>) wrapDoc);
245 handleGetAll((DocumentWrapper<WTL>) wrapDoc);
249 handleDelete((DocumentWrapper<WT>) wrapDoc);
253 handleSync((DocumentWrapper<Specifier>) wrapDoc);
257 logger.error("Should never get to this code path. If you did, there is a bug in the code.");
262 logger.error("Should never get to this code path. If you did, there is a bug in the code.");
269 * @see org.collectionspace.services.common.document.DocumentHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
272 public abstract void handleCreate(DocumentWrapper<WT> wrapDoc) throws Exception;
275 * @see org.collectionspace.services.common.document.DocumentHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
278 public abstract void handleUpdate(DocumentWrapper<WT> wrapDoc) throws Exception;
281 * @see org.collectionspace.services.common.document.DocumentHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper)
284 public abstract void handleGet(DocumentWrapper<WT> wrapDoc) throws Exception;
287 * @see org.collectionspace.services.common.document.DocumentHandler#handleGetAll(org.collectionspace.services.common.document.DocumentWrapper)
290 public abstract void handleGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception;
293 * @see org.collectionspace.services.common.document.DocumentHandler#handleDelete(org.collectionspace.services.common.document.DocumentWrapper)
296 public void handleDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
297 // Do nothing. Subclasses can override if they want/need to.
301 * @see org.collectionspace.services.common.document.DocumentHandler#handleDelete(org.collectionspace.services.common.document.DocumentWrapper)
304 public void handleSync(DocumentWrapper<Specifier> wrapDoc) throws Exception {
305 // Do nothing. Subclasses can override if they want/need to.
310 * @see org.collectionspace.services.common.document.DocumentHandler#complete(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
313 final public void complete(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
316 completeCreate((DocumentWrapper<WT>) wrapDoc);
320 completeUpdate((DocumentWrapper<WT>) wrapDoc);
324 completeGet((DocumentWrapper<WT>) wrapDoc);
328 completeGetAll((DocumentWrapper<WTL>) wrapDoc);
332 completeDelete((DocumentWrapper<WT>) wrapDoc);
336 completeSync((DocumentWrapper<Specifier>) wrapDoc);
340 logger.error("Should never get to this code path. If you did, there is a bug in the code.");
345 logger.error("Should never get to this code path. If you did, there is a bug in the code.");
352 * @see org.collectionspace.services.common.document.DocumentHandler#completeCreate(org.collectionspace.services.common.document.DocumentWrapper)
355 public void completeCreate(DocumentWrapper<WT> wrapDoc) throws Exception {
359 * @see org.collectionspace.services.common.document.DocumentHandler#completeUpdate(org.collectionspace.services.common.document.DocumentWrapper)
362 public void completeUpdate(DocumentWrapper<WT> wrapDoc) throws Exception {
363 //no specific action needed
367 * @see org.collectionspace.services.common.document.DocumentHandler#completeGet(org.collectionspace.services.common.document.DocumentWrapper)
370 public void completeGet(DocumentWrapper<WT> wrapDoc) throws Exception {
374 * @see org.collectionspace.services.common.document.DocumentHandler#completeGetAll(org.collectionspace.services.common.document.DocumentWrapper)
377 public void completeGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception {
381 * @see org.collectionspace.services.common.document.DocumentHandler#completeDelete(org.collectionspace.services.common.document.DocumentWrapper)
384 public void completeDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
388 * @see org.collectionspace.services.common.document.DocumentHandler#completeDelete(org.collectionspace.services.common.document.DocumentWrapper)
391 public void completeSync(DocumentWrapper<Specifier> wrapDoc) throws Exception {
395 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
398 public abstract T extractCommonPart(DocumentWrapper<WT> wrapDoc)
402 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
405 public abstract void fillCommonPart(T obj, DocumentWrapper<WT> wrapDoc)
409 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
412 public abstract TL extractCommonPartList(DocumentWrapper<WTL> wrapDoc)
416 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPartList(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
419 final public void fillCommonPartList(TL obj, DocumentWrapper<WTL> wrapDoc) throws Exception {
420 throw new UnsupportedOperationException("bulk create/update not yet supported");
424 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPart()
427 public abstract T getCommonPart();
430 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPart(java.lang.Object)
433 public abstract void setCommonPart(T obj);
436 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPartList()
439 public abstract TL getCommonPartList();
442 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPartList(java.lang.Object)
445 public abstract void setCommonPartList(TL obj);
448 * @see org.collectionspace.services.common.document.DocumentHandler#getQProperty(java.lang.String)
451 public abstract String getQProperty(String prop) throws DocumentException;
454 * Strip Nuxeo's schema name from the start of the field / element name.
456 * @see org.collectionspace.services.common.document.DocumentHandler#getUnQProperty(java.lang.String)
459 public String getUnQProperty(String qProp) {
460 StringTokenizer tkz = new StringTokenizer(qProp, ":");
461 if (tkz.countTokens() != 2) {
462 String msg = "Property must be in the form xxx:yyy, "
463 + "e.g. collectionobjects_common:objectNumber";
465 throw new IllegalArgumentException(msg);
467 tkz.nextToken(); //skip
468 return tkz.nextToken();
474 * @throws DocumentException
477 public String getDocumentsToIndexQuery(String indexId, String csid) throws DocumentException, Exception {
482 * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContextPath()
485 public String getServiceContextPath() {
486 return "/" + getServiceContext().getServiceName().toLowerCase() + "/";
492 * @param action the action
493 * @throws Exception the exception
495 private void validate(Action action) throws Exception {
496 List<ValidatorHandler> valHandlers = serviceContext.getValidatorHandlers();
497 for (ValidatorHandler handler : valHandlers) {
498 handler.validate(action, serviceContext);
503 * Creates the CMIS query from the service context. Each document handler is responsible for returning a valid CMIS query using the
504 * information in the current service context -which includes things like the query parameters, etc.
505 * @throws DocumentException
508 public String getCMISQuery(QueryContext queryContext) throws DocumentException {
510 // By default, return nothing. Child classes can override if they want.
516 public boolean isCMISQuery() {
521 public boolean isJDBCQuery() {
526 public Map<String,String> getJDBCQueryParams() {
527 return new HashMap<>();