]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b5afe101c0316e949a31438311dd5cc1abda6d67
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  *  
24  *  $LastChangedRevision$
25  */
26 package org.collectionspace.services.collectionobject;
27
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;
41
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;
55
56
57 @Path(CollectionObjectClient.SERVICE_PATH_COMPONENT)
58 @Consumes("application/xml")
59 @Produces("application/xml")
60 public class CollectionObjectResource extends ResourceBase {
61     
62     final Logger logger = LoggerFactory.getLogger(CollectionObjectResource.class);
63
64     @Override
65     public String getVersionString() {
66         final String lastChangeRevision = "$LastChangedRevision$";
67         return lastChangeRevision;
68     }
69
70     @Override
71     public String getServiceName() {
72         return CollectionObjectClient.SERVICE_PATH_COMPONENT;
73     }
74     
75     @Override
76     public Class<CollectionobjectsCommon> getCommonPartClass() {
77         return CollectionobjectsCommon.class;
78     }
79
80
81     /**
82      * Gets the intakes common list.
83      * 
84      * @param ui the ui
85      * @param csid the csid
86      * 
87      * @return the intakes common list
88      */
89     @GET
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();
96         
97         try {
98                 //
99                 // Find all the intake-related relation records.
100                 //
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,
106                                 subjectCsid,
107                                 null, /*subjectType*/
108                                 predicate,
109                                 objectCsid,
110                                 null /*objectType*/);
111                 
112                 //
113                 // Create an array of Intake csid's
114                 //
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());
119                 }
120             
121             //
122             // Get a response list for the Intake records from the Intake resource
123             //
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);
129             }
130             Response response = Response.status(
131                     Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
132             throw new WebApplicationException(response);
133         }
134         
135         return result;
136     }
137
138
139     /**
140      * Roundtrip.
141      * 
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
145      * 
146      * @return the response
147      */
148     @GET
149     @Path("/{ms}/roundtrip")
150     @Produces("application/xml")
151     public Response roundtrip(
152                 @PathParam("ms") String ms) {
153         Response result = null;
154         
155         Profiler profiler = new Profiler("roundtrip():", 1);
156         profiler.start();
157                 result = Response.status(HttpResponseCodes.SC_OK).build();
158                 profiler.stop();
159                 
160                 return result;
161     }
162
163     /**
164      * This method is deprecated.  Use SearchCollectionObjects() method instead.
165      * Keywords search collection objects.
166      * @param ui 
167      * 
168      * @param keywords the keywords
169      * 
170      * @return the collectionobjects common list
171      */
172     @GET
173     @Path("/search")
174     @Produces("application/xml")
175     @Deprecated
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);
180     }    
181
182 }