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.ResourceBase;
37 import org.collectionspace.services.common.ServiceMessages;
38 import org.collectionspace.services.common.api.Tools;
39 import org.collectionspace.services.common.context.RemoteServiceContextFactory;
40 import org.collectionspace.services.common.context.ServiceContext;
41 import org.collectionspace.services.common.context.ServiceContextFactory;
42 import org.collectionspace.services.common.document.DocumentFilter;
43 import org.collectionspace.services.common.document.DocumentHandler;
44 import org.collectionspace.services.common.document.DocumentNotFoundException;
45 import org.collectionspace.services.common.query.QueryManager;
46 import org.collectionspace.services.nuxeo.client.java.CommonList;
47 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
48 import org.nuxeo.ecm.core.api.DocumentModel;
49 import org.nuxeo.ecm.core.api.DocumentModelList;
51 import javax.ws.rs.Consumes;
52 import javax.ws.rs.GET;
53 import javax.ws.rs.Path;
54 import javax.ws.rs.PathParam;
55 import javax.ws.rs.Produces;
56 import javax.ws.rs.WebApplicationException;
57 import javax.ws.rs.core.Context;
58 import javax.ws.rs.core.MultivaluedMap;
59 import javax.ws.rs.core.Response;
60 import javax.ws.rs.core.UriInfo;
62 @Path(ServiceGroupClient.SERVICE_PATH)
63 @Produces({"application/xml"})
64 @Consumes({"application/xml"})
65 public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl {
68 public String getServiceName(){
69 return ServiceGroupClient.SERVICE_NAME;
72 public String getServicePathComponent(){
73 return ServiceGroupClient.SERVICE_NAME.toLowerCase();
77 protected String getVersionString() {
78 final String lastChangeRevision = "$LastChangedRevision: 2108 $";
79 return lastChangeRevision;
83 //public Class<ServicegroupsCommon> getCommonPartClass() {
84 public Class getCommonPartClass() {
86 return Class.forName("org.collectionspace.services.servicegroup.ServicegroupsCommon");//.class;
87 } catch (ClassNotFoundException e){
93 public ServiceContextFactory<PoxPayloadIn, PoxPayloadOut> getServiceContextFactory() {
94 return RemoteServiceContextFactory.get();
98 //======================= GET ====================================================
99 // NOTE that csid is not a good name for the specifier, but if we name it anything else,
100 // our AuthZ gets confused!!!
105 @PathParam("csid") String groupname) {
106 PoxPayloadOut result = null;
107 ensureCSID(groupname, ResourceBase.READ);
109 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
110 ServicegroupsCommon common = new ServicegroupsCommon();
111 common.setName(groupname);
112 String uri = "/" + getServicePathComponent() + "/" + groupname;
114 result = new PoxPayloadOut(getServicePathComponent());
115 result.addPart("ServicegroupsCommon", common);
117 /* If we cannot get the result, then...
118 if (result == null) {
119 Response response = Response.status(Response.Status.NOT_FOUND).entity(
120 ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build();
121 throw new WebApplicationException(response);
124 } catch (Exception e) {
125 throw bigReThrow(e, ServiceMessages.READ_FAILED, groupname);
128 return result.getBytes();
132 //======================= GET without specifier: List =====================================
134 public AbstractCommonList getList(@Context UriInfo ui) {
136 CommonList commonList = new CommonList();
137 AbstractCommonList list = (AbstractCommonList)commonList;
138 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
139 String commonSchema = ctx.getCommonPartLabel();
140 ArrayList<String> svcGroups = new ArrayList<String>();
141 svcGroups.add("procedure");
142 svcGroups.add("object");
143 svcGroups.add("authority");
144 // Fetch the list of groups from the tenant-bindings config, and prepare a list item
146 // We always declare this a full list, of the size that we are returning.
147 // Not quite in the spirit of what paging means, but tells callers not to ask for more.
149 list.setPageSize(svcGroups.size());
150 list.setItemsInPage(svcGroups.size());
151 list.setTotalItems(svcGroups.size());
152 String fields[] = new String[2];
153 fields[0] = ServiceGroupListItemJAXBSchema.NAME;
154 fields[1] = ServiceGroupListItemJAXBSchema.URI;
155 commonList.setFieldsReturned(fields);
156 HashMap<String,String> item = new HashMap<String,String>();
157 for(String groupName:svcGroups){
158 item.put(ServiceGroupListItemJAXBSchema.NAME, groupName);
159 String uri = "/" + getServiceName().toLowerCase() + "/" + groupName;
160 item.put(ServiceGroupListItemJAXBSchema.URI, uri);
161 commonList.addItem(item);
165 } catch (Exception e) {
166 throw bigReThrow(e, ServiceMessages.LIST_FAILED);