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.organization.nuxeo;
26 import java.util.Iterator;
27 import java.util.List;
29 import org.collectionspace.services.OrganizationJAXBSchema;
30 import org.collectionspace.services.common.document.DocumentWrapper;
31 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
32 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
33 import org.collectionspace.services.organization.OrganizationsCommon;
34 import org.collectionspace.services.organization.OrganizationsCommonList;
35 import org.collectionspace.services.organization.OrganizationsCommonList.OrganizationListItem;
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 * OrganizationDocumentModelHandler
44 * $LastChangedRevision: $
47 public class OrganizationDocumentModelHandler
48 extends RemoteDocumentModelHandler<OrganizationsCommon, OrganizationsCommonList> {
50 private final Logger logger = LoggerFactory.getLogger(OrganizationDocumentModelHandler.class);
52 * organization is used to stash JAXB object to use when handle is called
53 * for Action.CREATE, Action.UPDATE or Action.GET
55 private OrganizationsCommon organization;
57 * organizationList is stashed when handle is called
60 private OrganizationsCommonList organizationList;
63 * inAuthority is the parent OrgAuthority for this context
65 private String inAuthority;
67 public String getInAuthority() {
71 public void setInAuthority(String inAuthority) {
72 this.inAuthority = inAuthority;
77 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
78 // first fill all the parts of the document
79 super.handleCreate(wrapDoc);
80 handleGetDisplayName(wrapDoc.getWrappedObject());
83 private String prepareDefaultDisplayName(DocumentModel docModel) throws Exception {
86 result = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
87 OrganizationJAXBSchema.SHORT_NAME);
93 * Handle get display name.
95 * @param docModel the doc model
99 * @throws Exception the exception
101 private String handleGetDisplayName(DocumentModel docModel) throws Exception {
102 return handleGetDisplayName(docModel, true);
106 * Handle get display name.
108 * @param wrapDoc the wrap doc
112 * @throws Exception the exception
114 private String handleGetDisplayName(DocumentModel docModel, boolean updateDocModel) throws Exception {
115 String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
116 OrganizationJAXBSchema.DISPLAY_NAME);
117 if (displayName == null) {
118 displayName = prepareDefaultDisplayName(docModel);
119 if (updateDocModel == true) {
120 docModel.setProperty(getServiceContext().getCommonPartLabel(
121 "organizations"), OrganizationJAXBSchema.DISPLAY_NAME,
129 /* Override handleGet so we can deal with defaulting the displayName
130 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper)
133 public void handleGet(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
134 handleGetDisplayName(wrapDoc.getWrappedObject());
135 super.handleGet(wrapDoc);
139 * getCommonPart get associated organization
143 public OrganizationsCommon getCommonPart() {
148 * setCommonPart set associated organization
149 * @param organization
152 public void setCommonPart(OrganizationsCommon organization) {
153 this.organization = organization;
157 * getCommonPartList get associated organization (for index/GET_ALL)
161 public OrganizationsCommonList getCommonPartList() {
162 return organizationList;
166 public void setCommonPartList(OrganizationsCommonList organizationList) {
167 this.organizationList = organizationList;
171 public OrganizationsCommon extractCommonPart(DocumentWrapper wrapDoc)
173 throw new UnsupportedOperationException();
177 public void fillCommonPart(OrganizationsCommon organizationObject, DocumentWrapper wrapDoc) throws Exception {
178 throw new UnsupportedOperationException();
182 public OrganizationsCommonList extractCommonPartList(DocumentWrapper wrapDoc)
184 OrganizationsCommonList coList = new OrganizationsCommonList();
186 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
188 List<OrganizationsCommonList.OrganizationListItem> list =
189 coList.getOrganizationListItem();
191 //FIXME: iterating over a long list of documents is not a long term
192 //strategy...need to change to more efficient iterating in future
193 Iterator<DocumentModel> iter = docList.iterator();
194 while(iter.hasNext()){
195 DocumentModel docModel = iter.next();
196 OrganizationListItem ilistItem = new OrganizationListItem();
197 // We look for a set display name, and fall back to the short name if there is none
198 String displayName = handleGetDisplayName(docModel, false);
199 ilistItem.setDisplayName(displayName);
200 ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(
201 "organizations"), OrganizationJAXBSchema.REF_NAME));
203 * These are not currently included in the listing - only in the details
204 ilistItem.setLongName(
205 (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
206 OrganizationJAXBSchema.LONG_NAME));
207 ilistItem.setDescription(
208 (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
209 OrganizationJAXBSchema.DESCRIPTION));
211 String id = NuxeoUtils.extractId(docModel.getPathAsString());
212 ilistItem.setUri("/orgauthorities/"+inAuthority+"/items/" + id);
213 ilistItem.setCsid(id);
217 if(logger.isDebugEnabled()){
218 logger.debug("Caught exception in extractCommonPartList", e);
226 * getQProperty converts the given property to qualified schema property
231 public String getQProperty(String prop) {
232 return OrganizationConstants.NUXEO_SCHEMA_NAME + ":" + prop;