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.acquisition.nuxeo;
26 import java.util.Iterator;
27 import java.util.List;
29 import org.collectionspace.services.AcquisitionJAXBSchema;
30 import org.collectionspace.services.common.repository.DocumentWrapper;
31 import org.collectionspace.services.acquisition.AcquisitionsCommon;
32 import org.collectionspace.services.acquisition.AcquisitionsCommonList;
33 import org.collectionspace.services.acquisition.AcquisitionsCommonList.AcquisitionListItem;
34 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
36 import org.nuxeo.ecm.core.api.DocumentModel;
37 import org.nuxeo.ecm.core.api.DocumentModelList;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * AcquisitionDocumentModelHandler
44 * $LastChangedRevision: $
47 public class AcquisitionDocumentModelHandler
48 extends DocumentModelHandler<AcquisitionsCommon, AcquisitionsCommonList> {
50 private final Logger logger = LoggerFactory.getLogger(AcquisitionDocumentModelHandler.class);
52 * acquisition is used to stash JAXB object to use when handle is called
53 * for Action.CREATE, Action.UPDATE or Action.GET
55 private AcquisitionsCommon acquisition;
57 * acquisitionList is stashed when handle is called
60 private AcquisitionsCommonList acquisitionList;
63 public void prepare(Action action) throws Exception {
64 //no specific action needed
68 * getCommonPart get associated acquisition
72 public AcquisitionsCommon getCommonPart() {
77 * setCommonPart set associated acquisition
81 public void setCommonPart(AcquisitionsCommon acquisition) {
82 this.acquisition = acquisition;
86 * getAcquisitionList get associated acquisition (for index/GET_ALL)
90 public AcquisitionsCommonList getCommonPartList() {
91 return acquisitionList;
95 public void setCommonPartList(AcquisitionsCommonList acquisitionList) {
96 this.acquisitionList = acquisitionList;
100 public AcquisitionsCommon extractCommonPart(DocumentWrapper wrapDoc)
102 throw new UnsupportedOperationException();
106 public void fillCommonPart(AcquisitionsCommon acquisitionObject, DocumentWrapper wrapDoc) throws Exception {
107 throw new UnsupportedOperationException();
111 public AcquisitionsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception {
112 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
114 AcquisitionsCommonList coList = new AcquisitionsCommonList();
115 List<AcquisitionsCommonList.AcquisitionListItem> list = coList.getAcquisitionListItem();
117 //FIXME: iterating over a long list of documents is not a long term
118 //strategy...need to change to more efficient iterating in future
119 Iterator<DocumentModel> iter = docList.iterator();
120 while(iter.hasNext()){
121 DocumentModel docModel = iter.next();
122 AcquisitionListItem listItem = new AcquisitionListItem();
123 listItem.setAccessiondate((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
124 AcquisitionJAXBSchema.ACCESSIONDATE));
125 //need fully qualified context for URI
126 String id = docModel.getId();
127 listItem.setUri(getServiceContextPath() + id);
128 listItem.setCsid(id);
136 public void fillAllParts(DocumentWrapper wrapDoc) throws Exception {
138 super.fillAllParts(wrapDoc);
139 fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
142 private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception {
143 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
144 //FIXME property setter should be dynamically set using schema inspection
145 //so it does not require hard coding
146 // a default title for the Dublin Core schema
147 docModel.setPropertyValue("dublincore:title", AcquisitionConstants.NUXEO_DC_TITLE);
152 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getDocumentType()
154 public String getDocumentType() {
155 return AcquisitionConstants.NUXEO_DOCTYPE;
159 * getQProperty converts the given property to qualified schema property
164 public String getQProperty(String prop) {
165 return AcquisitionConstants.NUXEO_SCHEMA_NAME + ":" + prop;