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.intake.nuxeo;
26 import java.util.Iterator;
27 import java.util.List;
29 import javax.ws.rs.PathParam;
30 import javax.ws.rs.WebApplicationException;
31 import javax.ws.rs.core.Context;
32 import javax.ws.rs.core.Response;
33 import javax.ws.rs.core.UriInfo;
35 import org.collectionspace.services.IntakeJAXBSchema;
36 import org.collectionspace.services.common.authorityref.AuthorityRefList;
37 import org.collectionspace.services.common.context.MultipartServiceContextFactory;
38 import org.collectionspace.services.common.context.MultipartServiceContextImpl;
39 import org.collectionspace.services.common.context.ServiceContext;
40 import org.collectionspace.services.common.document.DocumentHandler.Action;
41 import org.collectionspace.services.common.document.DocumentWrapper;
42 import org.collectionspace.services.common.security.UnauthorizedException;
43 import org.collectionspace.services.common.vocabulary.RefNameUtils;
44 import org.collectionspace.services.intake.IntakesCommon;
45 import org.collectionspace.services.intake.IntakesCommonList;
46 import org.collectionspace.services.intake.IntakesCommonList.IntakeListItem;
48 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
49 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
50 import org.nuxeo.ecm.core.api.DocumentModel;
51 import org.nuxeo.ecm.core.api.DocumentModelList;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
56 * IntakeDocumentModelHandler
58 * $LastChangedRevision: $
61 public class IntakeDocumentModelHandler
62 extends RemoteDocumentModelHandlerImpl<IntakesCommon, IntakesCommonList> {
64 private final Logger logger = LoggerFactory.getLogger(IntakeDocumentModelHandler.class);
66 * intake is used to stash JAXB object to use when handle is called
67 * for Action.CREATE, Action.UPDATE or Action.GET
69 private IntakesCommon intake;
71 * intakeList is stashed when handle is called
74 private IntakesCommonList intakeList;
78 * getCommonPart get associated intake
82 public IntakesCommon getCommonPart() {
87 * setCommonPart set associated intake
91 public void setCommonPart(IntakesCommon intake) {
96 * getCommonPartList get associated intake (for index/GET_ALL)
100 public IntakesCommonList getCommonPartList() {
105 public void setCommonPartList(IntakesCommonList intakeList) {
106 this.intakeList = intakeList;
110 public IntakesCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
112 throw new UnsupportedOperationException();
116 public void fillCommonPart(IntakesCommon intakeObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
117 throw new UnsupportedOperationException();
121 public IntakesCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
122 DocumentModelList docList = wrapDoc.getWrappedObject();
124 IntakesCommonList coList = new IntakesCommonList();
125 List<IntakesCommonList.IntakeListItem> list = coList.getIntakeListItem();
127 //FIXME: iterating over a long list of documents is not a long term
128 //strategy...need to change to more efficient iterating in future
129 Iterator<DocumentModel> iter = docList.iterator();
130 while(iter.hasNext()){
131 DocumentModel docModel = iter.next();
132 IntakeListItem ilistItem = new IntakeListItem();
133 ilistItem.setEntryNumber((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
134 IntakeJAXBSchema.ENTRY_NUMBER));
135 ilistItem.setDepositor((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
136 IntakeJAXBSchema.DEPOSITOR));
137 String id = NuxeoUtils.extractId(docModel.getPathAsString());
138 ilistItem.setUri(getServiceContextPath() + id);
139 ilistItem.setCsid(id);
147 * getQProperty converts the given property to qualified schema property
152 public String getQProperty(String prop) {
153 return IntakeConstants.NUXEO_SCHEMA_NAME + ":" + prop;
156 public AuthorityRefList getAuthorityRefs(
157 DocumentWrapper<DocumentModel> docWrapper,
159 List<String> authRefFields) {
160 AuthorityRefList authRefList = new AuthorityRefList();
162 DocumentModel docModel = docWrapper.getWrappedObject();
163 List<AuthorityRefList.AuthorityRefItem> list =
164 authRefList.getAuthorityRefItem();
166 for(String field:authRefFields){
167 String refName = (String)docModel.getPropertyValue(pathPrefix+field);
171 RefNameUtils.AuthorityTermInfo termInfo =
172 RefNameUtils.parseAuthorityTermInfo(refName);
173 AuthorityRefList.AuthorityRefItem ilistItem =
174 new AuthorityRefList.AuthorityRefItem();
175 ilistItem.setRefName(refName);
176 ilistItem.setAuthDisplayName(termInfo.inAuthority.displayName);
177 ilistItem.setItemDisplayName(termInfo.displayName);
178 ilistItem.setSourceField(field);
179 ilistItem.setUri(termInfo.getRelativeUri());
181 } catch( Exception e ) {
182 if (logger.isDebugEnabled()) {
183 logger.debug("Caught exception in getAuthorityRefs", e);
187 } catch (Exception e) {
188 if (logger.isDebugEnabled()) {
189 logger.debug("Caught exception in getIntakeList", e);
191 Response response = Response.status(
192 Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
193 throw new WebApplicationException(response);