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;
76 public void prepare(Action action) throws Exception {
77 //no specific action needed
80 /* Override handleGet so we can deal with defaulting the displayName
81 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper)
84 public void handleGet(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
85 DocumentModel docModel = wrapDoc.getWrappedObject();
86 String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
87 OrganizationJAXBSchema.DISPLAY_NAME);
88 if(displayName == null) {
89 displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
90 OrganizationJAXBSchema.SHORT_NAME);
91 docModel.setProperty(getServiceContext().getCommonPartLabel("organizations"),
92 OrganizationJAXBSchema.DISPLAY_NAME, displayName);
94 super.handleGet(wrapDoc);
98 * getCommonPart get associated organization
102 public OrganizationsCommon getCommonPart() {
107 * setCommonPart set associated organization
108 * @param organization
111 public void setCommonPart(OrganizationsCommon organization) {
112 this.organization = organization;
116 * getCommonPartList get associated organization (for index/GET_ALL)
120 public OrganizationsCommonList getCommonPartList() {
121 return organizationList;
125 public void setCommonPartList(OrganizationsCommonList organizationList) {
126 this.organizationList = organizationList;
130 public OrganizationsCommon extractCommonPart(DocumentWrapper wrapDoc)
132 throw new UnsupportedOperationException();
136 public void fillCommonPart(OrganizationsCommon organizationObject, DocumentWrapper wrapDoc) throws Exception {
137 throw new UnsupportedOperationException();
141 public OrganizationsCommonList extractCommonPartList(DocumentWrapper wrapDoc)
143 OrganizationsCommonList coList = new OrganizationsCommonList();
145 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
147 List<OrganizationsCommonList.OrganizationListItem> list =
148 coList.getOrganizationListItem();
150 //FIXME: iterating over a long list of documents is not a long term
151 //strategy...need to change to more efficient iterating in future
152 Iterator<DocumentModel> iter = docList.iterator();
153 while(iter.hasNext()){
154 DocumentModel docModel = iter.next();
155 OrganizationListItem ilistItem = new OrganizationListItem();
156 // We look for a set display name, and fall back to teh short name if there is none
157 String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
158 OrganizationJAXBSchema.DISPLAY_NAME);
159 if(displayName == null)
160 displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
161 OrganizationJAXBSchema.SHORT_NAME);
162 ilistItem.setDisplayName( displayName );
163 ilistItem.setRefName(
164 (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
165 OrganizationJAXBSchema.REF_NAME));
167 * These are not currently included in the listing - only in the details
168 ilistItem.setLongName(
169 (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
170 OrganizationJAXBSchema.LONG_NAME));
171 ilistItem.setDescription(
172 (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
173 OrganizationJAXBSchema.DESCRIPTION));
175 String id = NuxeoUtils.extractId(docModel.getPathAsString());
176 ilistItem.setUri("/orgauthorities/"+inAuthority+"/items/" + id);
177 ilistItem.setCsid(id);
181 if(logger.isDebugEnabled()){
182 logger.debug("Caught exception in extractCommonPartList", e);
190 * getQProperty converts the given property to qualified schema property
195 public String getQProperty(String prop) {
196 return OrganizationConstants.NUXEO_SCHEMA_NAME + ":" + prop;