1
2
3
4
5
6
7 package gov.bnl.gums.groupToAccount;
8
9 import java.util.ArrayList;
10 import java.util.List;
11
12 import javax.persistence.DiscriminatorColumn;
13 import javax.persistence.DiscriminatorType;
14 import javax.persistence.Entity;
15 import javax.persistence.Inheritance;
16 import javax.persistence.InheritanceType;
17 import javax.persistence.Transient;
18
19 import gov.bnl.gums.configuration.ConfigElement;
20 import gov.bnl.gums.configuration.Configuration;
21 import gov.bnl.gums.util.StringUtil;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 @Entity
39 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
40 @DiscriminatorColumn(
41 name="type",
42 discriminatorType=DiscriminatorType.STRING
43 )
44 public class GroupToAccountMapping extends ConfigElement {
45 protected List<String> userGroupsList = new ArrayList<String>();
46 protected List<String> accountMappersList = new ArrayList<String>();
47
48
49 protected String accountingVo;
50 protected String accountingVoSubgroup;
51 protected String userGroups;
52 protected String accountMappers;
53
54
55
56
57 public GroupToAccountMapping() {
58 }
59
60
61
62
63
64
65
66 public GroupToAccountMapping(Configuration configuration, String name) {
67 super(configuration, name);
68 }
69
70
71
72
73
74
75 public void addAccountMapper(int index, String accountMapper) {
76 if (accountMappers!=null)
77 throw new RuntimeException("Cannot call removeAccountMapper when setAccountMappers has been called");
78 accountMappersList.add(index, accountMapper);
79 }
80
81
82
83
84
85
86 public void addAccountMapper(String accountMapper) {
87 if (accountMappers!=null)
88 throw new RuntimeException("Cannot call removeAccountMapper when setAccountMappers has been called");
89 accountMappersList.add(accountMapper);
90 }
91
92
93
94
95
96
97 public void addUserGroup(int index, String userGroup) {
98 if (userGroups!=null)
99 throw new RuntimeException("Cannot call removeUserGroup when setUserGroups has been called");
100 userGroupsList.add(index, userGroup);
101 }
102
103
104
105
106
107
108 public void addUserGroup(String userGroup) {
109 if (userGroups!=null)
110 throw new RuntimeException("Cannot call removeUserGroup when setUserGroups has been called");
111 userGroupsList.add(userGroup);
112 }
113
114
115
116
117
118
119 public String getAccountingVo() {
120 return this.accountingVo;
121 }
122
123
124
125
126
127
128 public String getAccountingVoSubgroup() {
129 return this.accountingVoSubgroup;
130 }
131
132
133
134
135
136
137 public String getAccountMappers() {
138
139 if (accountMappers!=null)
140 return accountMappers;
141 else
142 return StringUtil.toCommaSeparatedList(accountMappersList);
143 }
144
145
146
147
148
149
150 public String getUserGroups() {
151
152 if (userGroups!=null)
153 return userGroups;
154 else
155 return StringUtil.toCommaSeparatedList(userGroupsList);
156 }
157
158 public boolean removeAccountMapper(int index) {
159 if (accountMappers!=null)
160 throw new RuntimeException("Cannot call removeAccountMapper when setAccountMappers has been called");
161 return accountMappersList.remove(index)!=null;
162 }
163
164 public boolean removeAccountMapper(String accountMapperName) {
165 if (userGroups!=null)
166 throw new RuntimeException("Cannot call removeAccountMapper when setAccountMappers has been called");
167 return accountMappersList.remove(accountMapperName);
168 }
169
170 public boolean removeUserGroup(int index) {
171 if (userGroups!=null)
172 throw new RuntimeException("Cannot call removeUserGroup when setUserGroups has been called");
173 return userGroupsList.remove(index)!=null;
174 }
175
176 public boolean removeUserGroup(String userGroupName) {
177 if (userGroups!=null)
178 throw new RuntimeException("Cannot call removeUserGroup when setUserGroups has been called");
179 return userGroupsList.remove(userGroupName);
180 }
181
182
183
184
185
186 @ConfigFieldAnnotation(label="Accounting VO", help="to be included in OSG-user-VO-map")
187 public void setAccountingVo(String accountingVo) {
188 this.accountingVo = accountingVo;
189 }
190
191
192
193
194
195
196 @ConfigFieldAnnotation(label="Accounting VO Subgroup", help="to be included in OSG-user-VO-map")
197 public void setAccountingVoSubgroup(java.lang.String accountingVoSubgroup) {
198 this.accountingVoSubgroup = accountingVoSubgroup;
199 }
200
201 @ConfigFieldAnnotation (label="Account Mapper(s)", help="map using first successful account mapper", orderedList=true)
202 public void setAccountMappers(String accountMappers) {
203 this.accountMappers = accountMappers;
204 }
205
206 @ConfigFieldAnnotation(label="User Group(s)", help="validate membership from first successful user group", orderedList=true)
207 public void setUserGroups(String userGroups) {
208 this.userGroups = userGroups;
209 }
210
211 }