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;
32 import org.collectionspace.services.common.api.RefName;
33 import org.collectionspace.services.common.context.ServiceContext;
34 import org.collectionspace.services.common.query.QueryContext;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * AbstractDocumentHandler
42 * $LastChangedRevision: $
49 public abstract class AbstractDocumentHandlerImpl<T, TL, WT, WTL>
50 implements DocumentHandler<T, TL, WT, WTL> {
53 private final Logger logger = LoggerFactory.getLogger(AbstractDocumentHandlerImpl.class);
55 /** The properties. */
56 private Map<String, Object> properties = new HashMap<String, Object>();
58 /** The doc filter. */
59 private DocumentFilter docFilter = null;
61 /** The service context. */
62 private ServiceContext serviceContext;
65 * Instantiates a new abstract document handler impl.
67 public AbstractDocumentHandlerImpl() {
71 abstract protected String getRefnameDisplayName(DocumentWrapper<WT> docWrapper);
73 abstract protected String getOrderByField();
76 * Should return a reference name for the wrapper object
78 abstract public 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 {
171 * @see org.collectionspace.services.common.document.DocumentHandler#prepareCreate()
174 public void prepareCreate() throws Exception {
178 * @see org.collectionspace.services.common.document.DocumentHandler#prepareUpdate()
181 public void prepareUpdate() throws Exception {
185 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGet()
188 public void prepareGet() throws Exception {
192 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGetAll()
195 public void prepareGetAll() throws Exception {
199 * @see org.collectionspace.services.common.document.DocumentHandler#prepareDelete()
202 public void prepareDelete() throws Exception {
206 * @see org.collectionspace.services.common.document.DocumentHandler#handle(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
209 final public void handle(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
212 handleCreate((DocumentWrapper<WT>) wrapDoc);
216 handleUpdate((DocumentWrapper<WT>) wrapDoc);
220 handleGet((DocumentWrapper<WT>) wrapDoc);
224 handleGetAll((DocumentWrapper<WTL>) wrapDoc);
228 handleDelete((DocumentWrapper<WT>) wrapDoc);
235 * @see org.collectionspace.services.common.document.DocumentHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
238 public abstract void handleCreate(DocumentWrapper<WT> wrapDoc) throws Exception;
241 * @see org.collectionspace.services.common.document.DocumentHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
244 public abstract void handleUpdate(DocumentWrapper<WT> wrapDoc) throws Exception;
247 * @see org.collectionspace.services.common.document.DocumentHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper)
250 public abstract void handleGet(DocumentWrapper<WT> wrapDoc) throws Exception;
253 * @see org.collectionspace.services.common.document.DocumentHandler#handleGetAll(org.collectionspace.services.common.document.DocumentWrapper)
256 public abstract void handleGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception;
259 * @see org.collectionspace.services.common.document.DocumentHandler#handleDelete(org.collectionspace.services.common.document.DocumentWrapper)
262 public void handleDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
267 * @see org.collectionspace.services.common.document.DocumentHandler#complete(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
270 final public void complete(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
273 completeCreate((DocumentWrapper<WT>) wrapDoc);
277 completeUpdate((DocumentWrapper<WT>) wrapDoc);
281 completeGet((DocumentWrapper<WT>) wrapDoc);
285 completeGetAll((DocumentWrapper<WTL>) wrapDoc);
289 completeDelete((DocumentWrapper<WT>) wrapDoc);
295 * @see org.collectionspace.services.common.document.DocumentHandler#completeCreate(org.collectionspace.services.common.document.DocumentWrapper)
298 public void completeCreate(DocumentWrapper<WT> wrapDoc) throws Exception {
302 * @see org.collectionspace.services.common.document.DocumentHandler#completeUpdate(org.collectionspace.services.common.document.DocumentWrapper)
305 public void completeUpdate(DocumentWrapper<WT> wrapDoc) throws Exception {
306 //no specific action needed
310 * @see org.collectionspace.services.common.document.DocumentHandler#completeGet(org.collectionspace.services.common.document.DocumentWrapper)
313 public void completeGet(DocumentWrapper<WT> wrapDoc) throws Exception {
317 * @see org.collectionspace.services.common.document.DocumentHandler#completeGetAll(org.collectionspace.services.common.document.DocumentWrapper)
320 public void completeGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception {
324 * @see org.collectionspace.services.common.document.DocumentHandler#completeDelete(org.collectionspace.services.common.document.DocumentWrapper)
327 public void completeDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
331 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
334 public abstract T extractCommonPart(DocumentWrapper<WT> wrapDoc)
338 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
341 public abstract void fillCommonPart(T obj, DocumentWrapper<WT> wrapDoc)
345 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
348 public abstract TL extractCommonPartList(DocumentWrapper<WTL> wrapDoc)
352 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPartList(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
355 final public void fillCommonPartList(TL obj, DocumentWrapper<WTL> wrapDoc) throws Exception {
356 throw new UnsupportedOperationException("bulk create/update not yet supported");
360 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPart()
363 public abstract T getCommonPart();
366 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPart(java.lang.Object)
369 public abstract void setCommonPart(T obj);
372 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPartList()
375 public abstract TL getCommonPartList();
378 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPartList(java.lang.Object)
381 public abstract void setCommonPartList(TL obj);
384 * @see org.collectionspace.services.common.document.DocumentHandler#getQProperty(java.lang.String)
387 public abstract String getQProperty(String prop) throws DocumentException;
390 * Strip Nuxeo's schema name from the start of the field / element name.
392 * @see org.collectionspace.services.common.document.DocumentHandler#getUnQProperty(java.lang.String)
395 public String getUnQProperty(String qProp) {
396 StringTokenizer tkz = new StringTokenizer(qProp, ":");
397 if (tkz.countTokens() != 2) {
398 String msg = "Property must be in the form xxx:yyy, "
399 + "e.g. collectionobjects_common:objectNumber";
401 throw new IllegalArgumentException(msg);
403 tkz.nextToken(); //skip
404 return tkz.nextToken();
408 * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContextPath()
411 public String getServiceContextPath() {
412 return "/" + getServiceContext().getServiceName().toLowerCase() + "/";
418 * @param action the action
419 * @throws Exception the exception
421 private void validate(Action action) throws Exception {
422 List<ValidatorHandler> valHandlers = serviceContext.getValidatorHandlers();
423 for (ValidatorHandler handler : valHandlers) {
424 handler.validate(action, serviceContext);
429 * Creates the CMIS query from the service context. Each document handler is responsible for returning a valid CMIS query using the
430 * information in the current service context -which includes things like the query parameters, etc.
433 public String getCMISQuery(QueryContext queryContext) {
435 // By default, return nothing. Child classes can override if they want.
441 public boolean isCMISQuery() {