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.authorization.storage;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.UUID;
30 import org.collectionspace.services.authorization.Permission;
31 import org.collectionspace.services.authorization.PermissionsList;
32 import org.collectionspace.services.common.context.ServiceContext;
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;
41 * Document handler for Permission
44 public class PermissionDocumentHandler
45 extends AbstractDocumentHandlerImpl<Permission, PermissionsList, Permission, List> {
47 private final Logger logger = LoggerFactory.getLogger(PermissionDocumentHandler.class);
48 private Permission permission;
49 private PermissionsList permissionsList;
52 public void handleCreate(DocumentWrapper<Permission> wrapDoc) throws Exception {
53 String id = UUID.randomUUID().toString();
54 Permission permission = wrapDoc.getWrappedObject();
55 permission.setCsid(id);
56 //FIXME: if admin updating the permission is a CS admin rather than
57 //the tenant admin, tenant id should be retrieved from the request
58 permission.setTenantId(getServiceContext().getTenantId());
62 public void handleUpdate(DocumentWrapper<Permission> wrapDoc) throws Exception {
63 Permission permission = wrapDoc.getWrappedObject();
64 //FIXME: if admin updating the permission is a CS admin rather than
65 //the tenant admin, tenant id should be retrieved from the request
66 permission.setTenantId(getServiceContext().getTenantId());
70 public void completeUpdate(DocumentWrapper<Permission> wrapDoc) throws Exception {
71 Permission upAcc = wrapDoc.getWrappedObject();
72 getServiceContext().setOutput(permission);
77 public void handleGet(DocumentWrapper<Permission> wrapDoc) throws Exception {
78 setCommonPart(extractCommonPart(wrapDoc));
79 sanitize(getCommonPart());
80 getServiceContext().setOutput(permission);
84 public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
85 PermissionsList permissionsList = extractCommonPartList(wrapDoc);
86 setCommonPartList(permissionsList);
87 getServiceContext().setOutput(getCommonPartList());
91 public Permission extractCommonPart(
92 DocumentWrapper<Permission> wrapDoc)
94 return wrapDoc.getWrappedObject();
98 public void fillCommonPart(Permission obj, DocumentWrapper<Permission> wrapDoc)
100 throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
104 public PermissionsList extractCommonPartList(
105 DocumentWrapper<List> wrapDoc)
108 PermissionsList permissionsList = new PermissionsList();
109 List<Permission> list = new ArrayList<Permission>();
110 permissionsList.setPermissions(list);
111 for (Object obj : wrapDoc.getWrappedObject()) {
112 Permission permission = (Permission) obj;
113 sanitize(permission);
114 list.add(permission);
116 return permissionsList;
120 public Permission getCommonPart() {
125 public void setCommonPart(Permission permission) {
126 this.permission = permission;
130 public PermissionsList getCommonPartList() {
131 return permissionsList;
135 public void setCommonPartList(PermissionsList permissionsList) {
136 this.permissionsList = permissionsList;
140 public String getQProperty(
146 public DocumentFilter createDocumentFilter() {
147 DocumentFilter filter = new PermissionJpaFilter(this.getServiceContext());
152 * sanitize removes data not needed to be sent to the consumer
155 private void sanitize(Permission permission) {
156 permission.setTenantId(null);