]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b8f7a08d6f10bfa9f03beec9b958ccc2e17fb98e
[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 package org.collectionspace.services.servicegroup;
25
26 import java.util.ArrayList;
27 import java.util.HashMap;
28
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;
49
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;
60
61 @Path(ServiceGroupClient.SERVICE_PATH)
62 @Produces({"application/xml"})
63 @Consumes({"application/xml"})
64 public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl {
65         
66     @Override
67     public String getServiceName(){
68         return ServiceGroupClient.SERVICE_NAME;
69     }
70
71     @Override
72     protected String getVersionString() {
73         final String lastChangeRevision = "$LastChangedRevision: 2108 $";
74         return lastChangeRevision;
75     }
76
77     @Override
78     //public Class<ServicegroupsCommon> getCommonPartClass() {
79     public Class getCommonPartClass() {
80         try {
81             return Class.forName("org.collectionspace.services.servicegroup.ServicegroupsCommon");//.class;
82         } catch (ClassNotFoundException e){
83             return null;
84         }
85     }
86
87     @Override
88     public ServiceContextFactory<PoxPayloadIn, PoxPayloadOut> getServiceContextFactory() {
89         return RemoteServiceContextFactory.get();
90     }
91
92
93     //======================= GET ====================================================
94     /*
95     @GET
96     @Path("{groupname}")
97     public byte[] get(
98             @Context UriInfo ui,
99             @PathParam("csid") String csid) {
100         PoxPayloadOut result = null;
101         ensureCSID(csid, READ);
102         try {
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);
110             }
111         } catch (Exception e) {
112             throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
113         }
114
115         return result.getBytes();
116     }
117     */
118
119
120     //======================= GET without specifier: List  =====================================
121     @GET
122     public AbstractCommonList getList(@Context UriInfo ui) {
123         try {
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
133                 // for each one.
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.
136                 list.setPageNum(0);
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);
150                     item.clear();
151                 }
152                 return list;
153         } catch (Exception e) {
154             throw bigReThrow(e, ServiceMessages.LIST_FAILED);
155         }
156         
157     }
158
159     
160 }