]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
c01c204e55ab63c1810ad8767f01a753baffe8f4
[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.authorization.storage;
25
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.UUID;
29
30 import org.collectionspace.services.authorization.Role;
31 import org.collectionspace.services.authorization.RolesList;
32 import org.collectionspace.services.common.context.ServiceContext;
33
34 import org.collectionspace.services.common.document.AbstractDocumentHandlerImpl;
35 import org.collectionspace.services.common.document.DocumentFilter;
36 import org.collectionspace.services.common.document.DocumentWrapper;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 /**
41  * Document handler for Role
42  * @author 
43  */
44 public class RoleDocumentHandler
45         extends AbstractDocumentHandlerImpl<Role, RolesList, Role, List> {
46
47     private final Logger logger = LoggerFactory.getLogger(RoleDocumentHandler.class);
48     private Role role;
49     private RolesList rolesList;
50
51     @Override
52     public void handleCreate(DocumentWrapper<Role> wrapDoc) throws Exception {
53         String id = UUID.randomUUID().toString();
54         Role role = wrapDoc.getWrappedObject();
55         role.setCsid(id);
56         //FIXME: if admin updating the role is a CS admin rather than
57         //the tenant admin, tenant id should be retrieved from the request
58         role.setTenantId(getServiceContext().getTenantId());
59     }
60
61     @Override
62     public void handleUpdate(DocumentWrapper<Role> wrapDoc) throws Exception {
63         Role role = wrapDoc.getWrappedObject();
64         //FIXME: if admin updating the role is a CS admin rather than
65         //the tenant admin, tenant id should be retrieved from the request
66         role.setTenantId(getServiceContext().getTenantId());
67     }
68
69     @Override
70     public void completeUpdate(DocumentWrapper<Role> wrapDoc) throws Exception {
71         Role upAcc = wrapDoc.getWrappedObject();
72         getServiceContext().setOutput(role);
73         sanitize(upAcc);
74     }
75
76     @Override
77     public void handleGet(DocumentWrapper<Role> wrapDoc) throws Exception {
78         setCommonPart(extractCommonPart(wrapDoc));
79         sanitize(getCommonPart());
80         getServiceContext().setOutput(role);
81     }
82
83     @Override
84     public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
85         RolesList rolesList = extractCommonPartList(wrapDoc);
86         setCommonPartList(rolesList);
87         getServiceContext().setOutput(getCommonPartList());
88     }
89
90     @Override
91     public Role extractCommonPart(
92             DocumentWrapper<Role> wrapDoc)
93             throws Exception {
94         return wrapDoc.getWrappedObject();
95     }
96
97     @Override
98     public void fillCommonPart(Role obj, DocumentWrapper<Role> wrapDoc)
99             throws Exception {
100         throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
101     }
102
103     @Override
104     public RolesList extractCommonPartList(
105             DocumentWrapper<List> wrapDoc)
106             throws Exception {
107
108         RolesList rolesList = new RolesList();
109         List<Role> list = new ArrayList<Role>();
110         rolesList.setRoles(list);
111         for (Object obj : wrapDoc.getWrappedObject()) {
112             Role role = (Role) obj;
113             sanitize(role);
114             list.add(role);
115         }
116         return rolesList;
117     }
118
119     @Override
120     public Role getCommonPart() {
121         return role;
122     }
123
124     @Override
125     public void setCommonPart(Role role) {
126         this.role = role;
127     }
128
129     @Override
130     public RolesList getCommonPartList() {
131         return rolesList;
132     }
133
134     @Override
135     public void setCommonPartList(RolesList rolesList) {
136         this.rolesList = rolesList;
137     }
138
139     @Override
140     public String getQProperty(
141             String prop) {
142         return null;
143     }
144
145     @Override
146     public DocumentFilter createDocumentFilter(ServiceContext ctx) {
147         DocumentFilter filter = new RoleJpaFilter();
148         filter.setPageSize(
149                 ctx.getServiceBindingPropertyValue(
150                 DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY));
151         return filter;
152     }
153
154     /**
155      * sanitize removes data not needed to be sent to the consumer
156      * @param role
157      */
158     private void sanitize(Role role) {
159         role.setTenantId(null);
160     }
161 }