1
2
3
4
5
6
7
8
9
10
11 package gov.bnl.gums.hostToGroup;
12
13 import gov.bnl.gums.configuration.ConfigElement;
14 import gov.bnl.gums.configuration.Configuration;
15 import gov.bnl.gums.util.StringUtil;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import javax.persistence.DiscriminatorColumn;
21 import javax.persistence.DiscriminatorType;
22 import javax.persistence.Entity;
23 import javax.persistence.Inheritance;
24 import javax.persistence.InheritanceType;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 @Entity
41 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
42 @DiscriminatorColumn(
43 name="type",
44 discriminatorType=DiscriminatorType.STRING
45 )
46 public abstract class HostToGroupMapping extends ConfigElement {
47 protected List<String> groupToAccountMappingsList = new ArrayList<String>();
48
49
50 String groupToAccountMappings;
51
52
53
54
55
56
57 public HostToGroupMapping() {
58 }
59
60
61
62
63
64
65 public HostToGroupMapping(Configuration configuration, String name) {
66 super(configuration, name);
67 }
68
69
70
71
72
73 public void addGroupToAccountMapping(String groupToAccountMapping) {
74 if (groupToAccountMappings!=null)
75 throw new RuntimeException("Cannot call addGroupToAccountMapping when setGroupToAccountMappings has been called");
76 this.groupToAccountMappingsList.add(groupToAccountMapping);
77 }
78
79
80
81
82 public String getGroupToAccountMappings() {
83 if (groupToAccountMappings!=null)
84 return groupToAccountMappings;
85 else
86 return StringUtil.toCommaSeparatedList(groupToAccountMappingsList);
87 }
88
89
90
91
92
93
94
95 public abstract boolean isInGroup(String hostname);
96
97
98
99
100
101 public boolean removeGroupToAccountMapping(String name) {
102 if (groupToAccountMappings!=null)
103 throw new RuntimeException("Cannot call removeGroupToAccountMapping when setGroupToAccountMappings has been called");
104 return groupToAccountMappingsList.remove(name);
105 }
106
107 @ConfigFieldAnnotation(label="Group To Account Mapping(s)", help="return account from first successful mapping", orderedList=true)
108 public void setGroupToAccountMappings(String groupToAccountMappers) {
109 this.groupToAccountMappings = groupToAccountMappers;
110 }
111 }