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 {
158 * @see org.collectionspace.services.common.document.DocumentHandler#prepareCreate()
161 public void prepareCreate() throws Exception {
165 * @see org.collectionspace.services.common.document.DocumentHandler#prepareUpdate()
168 public void prepareUpdate() throws Exception {
172 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGet()
175 public void prepareGet() throws Exception {
179 * @see org.collectionspace.services.common.document.DocumentHandler#prepareGetAll()
182 public void prepareGetAll() throws Exception {
186 * @see org.collectionspace.services.common.document.DocumentHandler#prepareDelete()
189 public void prepareDelete() throws Exception {
193 * @see org.collectionspace.services.common.document.DocumentHandler#handle(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
196 final public void handle(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
199 handleCreate((DocumentWrapper<WT>) wrapDoc);
203 handleUpdate((DocumentWrapper<WT>) wrapDoc);
207 handleGet((DocumentWrapper<WT>) wrapDoc);
211 handleGetAll((DocumentWrapper<WTL>) wrapDoc);
215 handleDelete((DocumentWrapper<WT>) wrapDoc);
222 * @see org.collectionspace.services.common.document.DocumentHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
225 public abstract void handleCreate(DocumentWrapper<WT> wrapDoc) throws Exception;
228 * @see org.collectionspace.services.common.document.DocumentHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
231 public abstract void handleUpdate(DocumentWrapper<WT> wrapDoc) throws Exception;
234 * @see org.collectionspace.services.common.document.DocumentHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper)
237 public abstract void handleGet(DocumentWrapper<WT> wrapDoc) throws Exception;
240 * @see org.collectionspace.services.common.document.DocumentHandler#handleGetAll(org.collectionspace.services.common.document.DocumentWrapper)
243 public abstract void handleGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception;
246 * @see org.collectionspace.services.common.document.DocumentHandler#handleDelete(org.collectionspace.services.common.document.DocumentWrapper)
249 public void handleDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
254 * @see org.collectionspace.services.common.document.DocumentHandler#complete(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
257 final public void complete(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
260 completeCreate((DocumentWrapper<WT>) wrapDoc);
264 completeUpdate((DocumentWrapper<WT>) wrapDoc);
268 completeGet((DocumentWrapper<WT>) wrapDoc);
272 completeGetAll((DocumentWrapper<WTL>) wrapDoc);
276 completeDelete((DocumentWrapper<WT>) wrapDoc);
282 * @see org.collectionspace.services.common.document.DocumentHandler#completeCreate(org.collectionspace.services.common.document.DocumentWrapper)
285 public void completeCreate(DocumentWrapper<WT> wrapDoc) throws Exception {
289 * @see org.collectionspace.services.common.document.DocumentHandler#completeUpdate(org.collectionspace.services.common.document.DocumentWrapper)
292 public void completeUpdate(DocumentWrapper<WT> wrapDoc) throws Exception {
293 //no specific action needed
297 * @see org.collectionspace.services.common.document.DocumentHandler#completeGet(org.collectionspace.services.common.document.DocumentWrapper)
300 public void completeGet(DocumentWrapper<WT> wrapDoc) throws Exception {
304 * @see org.collectionspace.services.common.document.DocumentHandler#completeGetAll(org.collectionspace.services.common.document.DocumentWrapper)
307 public void completeGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception {
311 * @see org.collectionspace.services.common.document.DocumentHandler#completeDelete(org.collectionspace.services.common.document.DocumentWrapper)
314 public void completeDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
318 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
321 public abstract T extractCommonPart(DocumentWrapper<WT> wrapDoc)
325 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
328 public abstract void fillCommonPart(T obj, DocumentWrapper<WT> wrapDoc)
332 * @see org.collectionspace.services.common.document.DocumentHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
335 public abstract TL extractCommonPartList(DocumentWrapper<WTL> wrapDoc)
339 * @see org.collectionspace.services.common.document.DocumentHandler#fillCommonPartList(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
342 final public void fillCommonPartList(TL obj, DocumentWrapper<WTL> wrapDoc) throws Exception {
343 throw new UnsupportedOperationException("bulk create/update not yet supported");
347 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPart()
350 public abstract T getCommonPart();
353 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPart(java.lang.Object)
356 public abstract void setCommonPart(T obj);
359 * @see org.collectionspace.services.common.document.DocumentHandler#getCommonPartList()
362 public abstract TL getCommonPartList();
365 * @see org.collectionspace.services.common.document.DocumentHandler#setCommonPartList(java.lang.Object)
368 public abstract void setCommonPartList(TL obj);
371 * @see org.collectionspace.services.common.document.DocumentHandler#getQProperty(java.lang.String)
374 public abstract String getQProperty(String prop) throws DocumentException;
377 * Strip Nuxeo's schema name from the start of the field / element name.
379 * @see org.collectionspace.services.common.document.DocumentHandler#getUnQProperty(java.lang.String)
382 public String getUnQProperty(String qProp) {
383 StringTokenizer tkz = new StringTokenizer(qProp, ":");
384 if (tkz.countTokens() != 2) {
385 String msg = "Property must be in the form xxx:yyy, "
386 + "e.g. collectionobjects_common:objectNumber";
388 throw new IllegalArgumentException(msg);
390 tkz.nextToken(); //skip
391 return tkz.nextToken();
395 * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContextPath()
398 public String getServiceContextPath() {
399 return "/" + getServiceContext().getServiceName().toLowerCase() + "/";
405 * @param action the action
406 * @throws Exception the exception
408 private void validate(Action action) throws Exception {
409 List<ValidatorHandler> valHandlers = serviceContext.getValidatorHandlers();
410 for (ValidatorHandler handler : valHandlers) {
411 handler.validate(action, serviceContext);