1
2
3
4
5
6
7 package gov.bnl.gums.groupToAccount;
8
9 import java.lang.ref.SoftReference;
10 import java.util.ArrayList;
11 import java.util.Iterator;
12 import java.util.List;
13
14 import gov.bnl.gums.configuration.Configuration;
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public class GroupToAccountMapping {
29 private ArrayList userGroups = new ArrayList();
30 private ArrayList accountMappers = new ArrayList();
31 private String name = "";
32 private String description = "";
33 private String accountingVo = "";
34 private String accountingVoSubgroup = "";
35 private SoftReference configurationRef = null;
36
37
38
39
40 public GroupToAccountMapping() {
41 }
42
43
44
45
46
47
48 public GroupToAccountMapping(Configuration configuration) {
49 this.configurationRef = new SoftReference(configuration);
50 }
51
52
53
54
55
56
57
58 public GroupToAccountMapping(Configuration configuration, String name) {
59 this.configurationRef = new SoftReference(configuration);
60 this.name = name;
61 }
62
63
64
65
66
67
68 public void addAccountMapper(String accountMapper) {
69 accountMappers.add(accountMapper);
70 }
71
72
73
74
75
76
77 public void addUserGroup(String userGroup) {
78 userGroups.add(userGroup);
79 }
80
81
82
83
84
85
86
87 public GroupToAccountMapping clone(Configuration configuration) {
88 GroupToAccountMapping groupToAccountMapping = new GroupToAccountMapping(configuration, new String(name));
89 groupToAccountMapping.setDescription(new String(getDescription()));
90 groupToAccountMapping.setAccountingVoSubgroup(new String(accountingVoSubgroup));
91 groupToAccountMapping.setAccountingVo(new String(accountingVo));
92 Iterator it = getUserGroups().iterator();
93 while (it.hasNext())
94 groupToAccountMapping.addUserGroup( new String((String)it.next()) );
95 it = getAccountMappers().iterator();
96 while (it.hasNext())
97 groupToAccountMapping.addAccountMapper( new String((String)it.next()) );
98 return groupToAccountMapping;
99 }
100
101
102
103
104 public boolean containsAccountMapper(String accountMapperQuery) {
105 Iterator accountMapperIt = accountMappers.iterator();
106 while(accountMapperIt.hasNext()) {
107 String accountMapper = (String)accountMapperIt.next();
108 if(accountMapper.equals(accountMapperQuery))
109 return true;
110 }
111 return false;
112 }
113
114
115
116
117 public boolean containsUserGroup(String userGroupQuery) {
118 Iterator userGroupIt = userGroups.iterator();
119 while(userGroupIt.hasNext()) {
120 String userGroup = (String)userGroupIt.next();
121 if(userGroup.equals(userGroupQuery))
122 return true;
123 }
124 return false;
125 }
126
127
128
129
130
131
132 public String getAccountingVo() {
133
134 return this.accountingVo;
135 }
136
137
138
139
140
141
142 public String getAccountingVoSubgroup() {
143
144 return this.accountingVoSubgroup;
145 }
146
147
148
149
150
151
152 public ArrayList getAccountMappers() {
153 return accountMappers;
154 }
155
156
157
158
159
160
161 public Configuration getConfiguration() {
162 if (configurationRef == null)
163 return null;
164 return (Configuration)configurationRef.get();
165 }
166
167
168
169
170
171
172 public String getDescription() {
173 return description;
174 }
175
176
177
178
179
180
181 public String getName() {
182 return (name!=null ? name : "");
183 }
184
185
186
187
188
189
190 public ArrayList getUserGroups() {
191 return this.userGroups;
192 }
193
194
195
196
197
198 public void setAccountingVo(String accountingVo) {
199
200 this.accountingVo = accountingVo;
201 }
202
203
204
205
206
207
208 public void setAccountingVoSubgroup(java.lang.String accountingVoSubgroup) {
209
210 this.accountingVoSubgroup = accountingVoSubgroup;
211 }
212
213
214
215
216
217
218 public void setConfiguration(Configuration configuration) {
219 this.configurationRef = new SoftReference(configuration);
220 }
221
222
223
224
225
226
227 public void setDescription(String description) {
228 this.description = description;
229 }
230
231
232
233
234
235
236 public void setName(String name) {
237 this.name = name;
238 }
239
240 public String toString(String bgColor) {
241 return "<td bgcolor=\""+bgColor+"\"><a href=\"groupToAccountMappings.jsp?command=edit&name=" + getName() + "\">" + getName() + "</a></td><td bgcolor=\""+bgColor+"\">" + getAccountingVoSubgroup() + " </td><td bgcolor=\""+bgColor+"\">" + getAccountingVo() + " </td>";
242 }
243
244
245
246
247
248
249 public String toXML() {
250 String retStr = "\t\t<groupToAccountMapping\n"+
251 "\t\t\tname='"+name+"'\n"+
252 "\t\t\tdescription='"+getDescription()+"'\n"+
253 "\t\t\taccountingVoSubgroup='"+accountingVoSubgroup+"'\n"+
254 "\t\t\taccountingVo='"+accountingVo+"'\n"+
255 "\t\t\tuserGroups='";
256
257 List userGroups = getUserGroups();
258 Iterator it = (Iterator)userGroups.iterator();
259 while(it.hasNext()) {
260 String userGroup = (String)it.next();
261 retStr += userGroup + (it.hasNext()?", ":"");
262 }
263
264 retStr += "'\n";
265
266 retStr += "\t\t\taccountMappers='";
267
268 List accountMappers = getAccountMappers();
269 it = (Iterator)accountMappers.iterator();
270 while(it.hasNext()) {
271 String accountMapper = (String)it.next();
272 retStr += accountMapper + (it.hasNext()?", ":"");
273 }
274
275 retStr += "'/>\n\n";
276
277 return retStr;
278 }
279
280 }