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);
74 * Should return a reference name for the wrapper object
76 abstract protected RefName.RefNameInterface getRefName(DocumentWrapper<WT> docWrapper, String tenantName, String serviceName);
79 * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContext()
82 public ServiceContext getServiceContext() {
83 return serviceContext;
87 * @see org.collectionspace.services.common.document.DocumentHandler#setServiceContext(org.collectionspace.services.common.context.ServiceContext)
90 public void setServiceContext(ServiceContext ctx) {
95 * @return the properties
98 public Map<String, Object> getProperties() {
103 * @param properties the properties to set
106 public void setProperties(Map<String, Object> properties) {
107 this.properties = properties;
110 // public void initializeDocumentFilter(ServiceContext ctx) {
111 // DocumentFilter docFilter = this.createDocumentFilter(ctx);
112 // this.setDocumentFilter(docFilter);
115 * @see org.collectionspace.services.common.document.DocumentHandler#createDocumentFilter()
118 public abstract DocumentFilter createDocumentFilter();
121 * @return the DocumentFilter
124 public DocumentFilter getDocumentFilter() {
129 * @param properties the DocumentFilter to set
132 public void setDocumentFilter(DocumentFilter docFilter) {
133 this.docFilter = docFilter;
137 * @see org.collectionspace.services.common.document.DocumentHandler#prepare(org.collectionspace.services.common.document.DocumentHandler.Action)
140 final public void prepare(Action action) throws Exception {
169 * @see org.collectionspace.services.common.document.DocumentHandler#prepareCreate()
172 public void prepareCreate() throws Exception {
176 * @see org.collectionspace.services.common.document.DocumentHandler#prepareUpdate()
179 public void prepareUpdate() throws Exception {
183 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGet()
186 public void prepareGet() throws Exception {
190 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGetAll()
193 public void prepareGetAll() throws Exception {
197 * @see org.collectionspace.services.common.document.DocumentHandler#prepareDelete()
200 public void prepareDelete() throws Exception {
204 * @see org.collectionspace.services.common.document.DocumentHandler#handle(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
207 final public void handle(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
210 handleCreate((DocumentWrapper<WT>) wrapDoc);
214 handleUpdate((DocumentWrapper<WT>) wrapDoc);
218 handleGet((DocumentWrapper<WT>) wrapDoc);
222 handleGetAll((DocumentWrapper<WTL>) wrapDoc);
226 handleDelete((DocumentWrapper<WT>) wrapDoc);
233 * @see org.collectionspace.services.common.document.DocumentHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
236 public abstract void handleCreate(DocumentWrapper<WT> wrapDoc) throws Exception;
239 * @see org.collectionspace.services.common.document.DocumentHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
242 public abstract void handleUpdate(DocumentWrapper<WT> wrapDoc) throws Exception;
245 * @see org.collectionspace.services.common.document.DocumentHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper)
248 public abstract void handleGet(DocumentWrapper<WT> wrapDoc) throws Exception;
251 * @see org.collectionspace.services.common.document.DocumentHandler#handleGetAll(org.collectionspace.services.common.document.DocumentWrapper)
254 public abstract void handleGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception;
257 * @see org.collectionspace.services.common.document.DocumentHandler#handleDelete(org.collectionspace.services.common.document.DocumentWrapper)
260 public void handleDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
265 * @see org.collectionspace.services.common.document.DocumentHandler#complete(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
268 final public void complete(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
271 completeCreate((DocumentWrapper<WT>) wrapDoc);
275 completeUpdate((DocumentWrapper<WT>) wrapDoc);
279 completeGet((DocumentWrapper<WT>) wrapDoc);
283 completeGetAll((DocumentWrapper<WTL>) wrapDoc);
287 completeDelete((DocumentWrapper<WT>) wrapDoc);
293 * @see org.collectionspace.services.common.document.DocumentHandler#completeCreate(org.collectionspace.services.common.document.DocumentWrapper)
296 public void completeCreate(DocumentWrapper<WT> wrapDoc) throws Exception {
300 * @see org.collectionspace.services.common.document.DocumentHandler#completeUpdate(org.collectionspace.services.common.document.DocumentWrapper)
303 public void completeUpdate(DocumentWrapper<WT> wrapDoc) throws Exception {
304 //no specific action needed
308 * @see org.collectionspace.services.common.document.DocumentHandler#completeGet(org.collectionspace.services.common.document.DocumentWrapper)
311 public void completeGet(DocumentWrapper<WT> wrapDoc) throws Exception {
315 * @see org.collectionspace.services.common.document.DocumentHandler#completeGetAll(org.collectionspace.services.common.document.DocumentWrapper)
318 public void completeGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception {
322 * @see org.collectionspace.services.common.document.DocumentHandler#completeDelete(org.collectionspace.services.common.document.DocumentWrapper)
325 public void completeDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
329 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
332 public abstract T extractCommonPart(DocumentWrapper<WT> wrapDoc)
336 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
339 public abstract void fillCommonPart(T obj, DocumentWrapper<WT> wrapDoc)
343 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
346 public abstract TL extractCommonPartList(DocumentWrapper<WTL> wrapDoc)
350 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPartList(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
353 final public void fillCommonPartList(TL obj, DocumentWrapper<WTL> wrapDoc) throws Exception {
354 throw new UnsupportedOperationException("bulk create/update not yet supported");
358 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPart()
361 public abstract T getCommonPart();
364 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPart(java.lang.Object)
367 public abstract void setCommonPart(T obj);
370 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPartList()
373 public abstract TL getCommonPartList();
376 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPartList(java.lang.Object)
379 public abstract void setCommonPartList(TL obj);
382 * @see org.collectionspace.services.common.document.DocumentHandler#getQProperty(java.lang.String)
385 public abstract String getQProperty(String prop) throws DocumentException;
388 * Strip Nuxeo's schema name from the start of the field / element name.
390 * @see org.collectionspace.services.common.document.DocumentHandler#getUnQProperty(java.lang.String)
393 public String getUnQProperty(String qProp) {
394 StringTokenizer tkz = new StringTokenizer(qProp, ":");
395 if (tkz.countTokens() != 2) {
396 String msg = "Property must be in the form xxx:yyy, "
397 + "e.g. collectionobjects_common:objectNumber";
399 throw new IllegalArgumentException(msg);
401 tkz.nextToken(); //skip
402 return tkz.nextToken();
406 * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContextPath()
409 public String getServiceContextPath() {
410 return "/" + getServiceContext().getServiceName().toLowerCase() + "/";
416 * @param action the action
417 * @throws Exception the exception
419 private void validate(Action action) throws Exception {
420 List<ValidatorHandler> valHandlers = serviceContext.getValidatorHandlers();
421 for (ValidatorHandler handler : valHandlers) {
422 handler.validate(action, serviceContext);
427 * Creates the CMIS query from the service context. Each document handler is responsible for returning a valid CMIS query using the
428 * information in the current service context -which includes things like the query parameters, etc.
429 * @throws DocumentException
432 public String getCMISQuery(QueryContext queryContext) throws DocumentException {
434 // By default, return nothing. Child classes can override if they want.
440 public boolean isCMISQuery() {
445 public boolean isJDBCQuery() {
450 public Map<String,String> getJDBCQueryParams() {
451 return new HashMap<>();