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 * $LastChangedRevision$
26 package org.collectionspace.services.collectionobject;
28 import org.collectionspace.services.client.CollectionObjectClient;
29 import org.collectionspace.services.client.IQueryManager;
30 import org.collectionspace.services.common.ResourceBase;
31 import org.collectionspace.services.common.profile.Profiler;
32 import org.collectionspace.services.intake.IntakeResource;
33 import org.collectionspace.services.intake.IntakesCommonList;
34 import org.collectionspace.services.jaxb.AbstractCommonList;
35 import org.collectionspace.services.relation.RelationResource;
36 import org.collectionspace.services.relation.RelationsCommonList;
37 import org.collectionspace.services.relation.RelationshipType;
38 import org.jboss.resteasy.util.HttpResponseCodes;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 import javax.ws.rs.Consumes;
43 import javax.ws.rs.GET;
44 import javax.ws.rs.Path;
45 import javax.ws.rs.PathParam;
46 import javax.ws.rs.Produces;
47 import javax.ws.rs.QueryParam;
48 import javax.ws.rs.WebApplicationException;
49 import javax.ws.rs.core.Context;
50 import javax.ws.rs.core.MultivaluedMap;
51 import javax.ws.rs.core.Response;
52 import javax.ws.rs.core.UriInfo;
53 import java.util.ArrayList;
54 import java.util.List;
57 @Path(CollectionObjectClient.SERVICE_PATH_COMPONENT)
58 @Consumes("application/xml")
59 @Produces("application/xml")
60 public class CollectionObjectResource extends ResourceBase {
62 final Logger logger = LoggerFactory.getLogger(CollectionObjectResource.class);
65 public String getVersionString() {
66 final String lastChangeRevision = "$LastChangedRevision$";
67 return lastChangeRevision;
71 public String getServiceName() {
72 return CollectionObjectClient.SERVICE_PATH_COMPONENT;
76 public Class<CollectionobjectsCommon> getCommonPartClass() {
77 return CollectionobjectsCommon.class;
82 * Gets the intakes common list.
85 * @param csid the csid
87 * @return the intakes common list
90 @Path("{csid}/intakes")
91 @Produces("application/xml")
92 public IntakesCommonList getIntakesCommonList(@Context UriInfo ui,
93 @PathParam("csid") String csid) {
94 IntakesCommonList result = null;
95 MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
99 // Find all the intake-related relation records.
101 String subjectCsid = csid;
102 String predicate = RelationshipType.COLLECTIONOBJECT_INTAKE.value();
103 String objectCsid = null;
104 RelationResource relationResource = new RelationResource();
105 RelationsCommonList relationsCommonList = relationResource.getRelationList(queryParams,
107 null, /*subjectType*/
110 null /*objectType*/);
113 // Create an array of Intake csid's
115 List<RelationsCommonList.RelationListItem> relationsListItems = relationsCommonList.getRelationListItem();
116 List<String> intakeCsidList = new ArrayList<String>();
117 for (RelationsCommonList.RelationListItem relationsListItem : relationsListItems) {
118 intakeCsidList.add(relationsListItem.getObjectCsid());
122 // Get a response list for the Intake records from the Intake resource
124 IntakeResource intakeResource = new IntakeResource();
125 result = intakeResource.getIntakeList(intakeCsidList);
126 } catch (Exception e) {
127 if (logger.isDebugEnabled()) {
128 logger.debug("Caught exception in getIntakeList", e);
130 Response response = Response.status(
131 Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
132 throw new WebApplicationException(response);
142 * This is an intentionally empty method used for getting a rough time estimate
143 * of the overhead required for a client->server request/response cycle.
144 * @param ms - milliseconds to delay
146 * @return the response
149 @Path("/{ms}/roundtrip")
150 @Produces("application/xml")
151 public Response roundtrip(
152 @PathParam("ms") String ms) {
153 Response result = null;
155 Profiler profiler = new Profiler("roundtrip():", 1);
157 result = Response.status(HttpResponseCodes.SC_OK).build();
164 * This method is deprecated. Use SearchCollectionObjects() method instead.
165 * Keywords search collection objects.
168 * @param keywords the keywords
170 * @return the collectionobjects common list
174 @Produces("application/xml")
176 public AbstractCommonList keywordsSearchCollectionObjects(@Context UriInfo ui,
177 @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
178 MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
179 return search(queryParams, keywords);