]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
94563b5f4317c3ee6efada50445ab1a22e3a38fd
[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.client;
25
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.List;
29 import org.collectionspace.services.authorization.PermissionRole;
30 import org.collectionspace.services.authorization.PermissionValue;
31 import org.collectionspace.services.authorization.RoleValue;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  *
37  * @author 
38  */
39 public class PermissionRoleFactory {
40
41     static private final Logger logger = LoggerFactory.getLogger(PermissionRoleFactory.class);
42
43     /**
44      * create permRolerole instance with permission as object and role as subject
45      * @param pv permvalue
46      * @param rvs roleValues
47      * @param userPermId
48      * @param useRoleId
49      * @return
50      */
51     public static PermissionRole createPermissionRoleInstance(PermissionValue pv,
52             List<RoleValue> rvs,
53             boolean usePermId,
54             boolean useRoleId) {
55
56         PermissionRole permRole = new PermissionRole();
57         //service consume is not required to provide subject as it is determined
58         //from URI used
59 //        permRole.setSubject(SubjectType.ROLE);
60         if (usePermId) {
61             ArrayList<PermissionValue> pvs = new ArrayList<PermissionValue>();
62             pvs.add(pv);
63             permRole.setPermission(pvs);
64         }
65         if (useRoleId) {
66             permRole.setRole(rvs);
67         }
68
69         return permRole;
70     }
71
72
73     /**
74      * create permRolerole instance with role as object and permission as subject
75      * @param rv roleValue
76      * @param pvs permValues
77      * @param userPermId
78      * @param useRoleId
79      * @return
80      */
81     public static PermissionRole createPermissionRoleInstance(RoleValue rv,
82             List<PermissionValue> pvs,
83             boolean usePermId,
84             boolean useRoleId) {
85
86         PermissionRole permRole = new PermissionRole();
87         //service consume is not required to provide subject as it is determined
88         //from URI used
89 //        permRole.setSubject(SubjectType.ROLE);
90         if (useRoleId) {
91             ArrayList<RoleValue> rvs = new ArrayList<RoleValue>();
92             rvs.add(rv);
93             permRole.setRole(rvs);
94         }
95         if (usePermId) {
96             permRole.setPermission(pvs);
97         }
98
99         return permRole;
100     }
101 }