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.servicegroup;
26 import java.util.ArrayList;
27 import java.util.HashMap;
29 import org.collectionspace.services.ServiceGroupListItemJAXBSchema;
30 import org.collectionspace.services.client.IQueryManager;
31 import org.collectionspace.services.client.PoxPayloadIn;
32 import org.collectionspace.services.client.PoxPayloadOut;
33 import org.collectionspace.services.client.ServiceGroupClient;
34 import org.collectionspace.services.jaxb.AbstractCommonList;
35 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
36 import org.collectionspace.services.common.ServiceMessages;
37 import org.collectionspace.services.common.api.Tools;
38 import org.collectionspace.services.common.context.RemoteServiceContextFactory;
39 import org.collectionspace.services.common.context.ServiceContext;
40 import org.collectionspace.services.common.context.ServiceContextFactory;
41 import org.collectionspace.services.common.document.DocumentFilter;
42 import org.collectionspace.services.common.document.DocumentHandler;
43 import org.collectionspace.services.common.document.DocumentNotFoundException;
44 import org.collectionspace.services.common.query.QueryManager;
45 import org.collectionspace.services.nuxeo.client.java.CommonList;
46 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
47 import org.nuxeo.ecm.core.api.DocumentModel;
48 import org.nuxeo.ecm.core.api.DocumentModelList;
50 import javax.ws.rs.Consumes;
51 import javax.ws.rs.GET;
52 import javax.ws.rs.Path;
53 import javax.ws.rs.PathParam;
54 import javax.ws.rs.Produces;
55 import javax.ws.rs.WebApplicationException;
56 import javax.ws.rs.core.Context;
57 import javax.ws.rs.core.MultivaluedMap;
58 import javax.ws.rs.core.Response;
59 import javax.ws.rs.core.UriInfo;
61 @Path(ServiceGroupClient.SERVICE_PATH)
62 @Produces({"application/xml"})
63 @Consumes({"application/xml"})
64 public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl {
67 public String getServiceName(){
68 return ServiceGroupClient.SERVICE_NAME;
72 protected String getVersionString() {
73 final String lastChangeRevision = "$LastChangedRevision: 2108 $";
74 return lastChangeRevision;
78 //public Class<ServicegroupsCommon> getCommonPartClass() {
79 public Class getCommonPartClass() {
81 return Class.forName("org.collectionspace.services.servicegroup.ServicegroupsCommon");//.class;
82 } catch (ClassNotFoundException e){
88 public ServiceContextFactory<PoxPayloadIn, PoxPayloadOut> getServiceContextFactory() {
89 return RemoteServiceContextFactory.get();
93 //======================= GET ====================================================
99 @PathParam("csid") String csid) {
100 PoxPayloadOut result = null;
101 ensureCSID(csid, READ);
103 MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
104 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(queryParams);
105 result = Need to fetch info and prepare it.
106 if (result == null) {
107 Response response = Response.status(Response.Status.NOT_FOUND).entity(
108 ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build();
109 throw new WebApplicationException(response);
111 } catch (Exception e) {
112 throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
115 return result.getBytes();
120 //======================= GET without specifier: List =====================================
122 public AbstractCommonList getList(@Context UriInfo ui) {
124 CommonList commonList = new CommonList();
125 AbstractCommonList list = (AbstractCommonList)commonList;
126 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
127 String commonSchema = ctx.getCommonPartLabel();
128 ArrayList<String> svcGroups = new ArrayList<String>();
129 svcGroups.add("procedure");
130 svcGroups.add("object");
131 svcGroups.add("authority");
132 // Fetch the list of groups from the tenant-bindings config, and prepare a list item
134 // We always declare this a full list, of the size that we are returning.
135 // Not quite in the spirit of what paging means, but tells callers not to ask for more.
137 list.setPageSize(svcGroups.size());
138 list.setItemsInPage(svcGroups.size());
139 list.setTotalItems(svcGroups.size());
140 String fields[] = new String[2];
141 fields[0] = ServiceGroupListItemJAXBSchema.NAME;
142 fields[1] = ServiceGroupListItemJAXBSchema.URI;
143 commonList.setFieldsReturned(fields);
144 HashMap<String,String> item = new HashMap<String,String>();
145 for(String groupName:svcGroups){
146 item.put(ServiceGroupListItemJAXBSchema.NAME, groupName);
147 String uri = "/" + getServiceName().toLowerCase() + "/" + groupName;
148 item.put(ServiceGroupListItemJAXBSchema.URI, uri);
149 commonList.addItem(item);
153 } catch (Exception e) {
154 throw bigReThrow(e, ServiceMessages.LIST_FAILED);