]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b0667ee2f67b082ec787fb6525609cf3defa5930
[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     }
57
58     @Override
59     public void handleUpdate(DocumentWrapper<Role> wrapDoc) throws Exception {
60     }
61
62     @Override
63     public void completeUpdate(DocumentWrapper<Role> wrapDoc) throws Exception {
64         Role upAcc = wrapDoc.getWrappedObject();
65         getServiceContext().setOutput(role);
66         sanitize(upAcc);
67     }
68
69     @Override
70     public void handleGet(DocumentWrapper<Role> wrapDoc) throws Exception {
71         setCommonPart(extractCommonPart(wrapDoc));
72         sanitize(getCommonPart());
73         getServiceContext().setOutput(role);
74     }
75
76     @Override
77     public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
78         RolesList rolesList = extractCommonPartList(wrapDoc);
79         setCommonPartList(rolesList);
80         getServiceContext().setOutput(getCommonPartList());
81     }
82
83     @Override
84     public Role extractCommonPart(
85             DocumentWrapper<Role> wrapDoc)
86             throws Exception {
87         return wrapDoc.getWrappedObject();
88     }
89
90     @Override
91     public void fillCommonPart(Role obj, DocumentWrapper<Role> wrapDoc)
92             throws Exception {
93         throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
94     }
95
96     @Override
97     public RolesList extractCommonPartList(
98             DocumentWrapper<List> wrapDoc)
99             throws Exception {
100
101         RolesList rolesList = new RolesList();
102         List<Role> list = new ArrayList<Role>();
103         rolesList.setRoles(list);
104         for (Object obj : wrapDoc.getWrappedObject()) {
105             Role role = (Role) obj;
106             list.add(role);
107         }
108         return rolesList;
109     }
110
111     @Override
112     public Role getCommonPart() {
113         return role;
114     }
115
116     @Override
117     public void setCommonPart(Role role) {
118         this.role = role;
119     }
120
121     @Override
122     public RolesList getCommonPartList() {
123         return rolesList;
124     }
125
126     @Override
127     public void setCommonPartList(RolesList rolesList) {
128         this.rolesList = rolesList;
129     }
130
131     @Override
132     public String getQProperty(
133             String prop) {
134         return null;
135     }
136
137     @Override
138     public DocumentFilter createDocumentFilter(ServiceContext ctx) {
139         DocumentFilter filter = new RoleJpaFilter();
140         filter.setPageSize(
141                 ctx.getServiceBindingPropertyValue(
142                 DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY));
143         return filter;
144     }
145
146     /**
147      * sanitize removes data not needed to be sent to the consumer
148      * @param role
149      */
150     private void sanitize(Role role) {
151     }
152 }