blob: 7b9c48ca1cfb7b301d5dbcfaf9be0c5a5997bec5 [file] [log] [blame]
margaretha56e8e552017-12-05 16:31:21 +01001package de.ids_mannheim.korap.config;
2
3import java.io.IOException;
margarethadfecb4b2017-12-12 19:32:30 +01004import java.util.ArrayList;
5import java.util.List;
margaretha56e8e552017-12-05 16:31:21 +01006import java.util.Properties;
7import java.util.regex.Pattern;
8
margaretha56e8e552017-12-05 16:31:21 +01009/** Configuration for Kustvakt full version including properties concerning
10 * authentication and licenses.
11 *
12 * @author margaretha
13 *
14 */
margarethadfecb4b2017-12-12 19:32:30 +010015
margaretha2afb97d2017-12-07 19:18:44 +010016public class FullConfiguration extends KustvaktConfiguration {
margaretha56e8e552017-12-05 16:31:21 +010017
18 private String ldapConfig;
19
20 private String freeOnlyRegex;
21 private String publicOnlyRegex;
22 private String allOnlyRegex;
23
margarethadfecb4b2017-12-12 19:32:30 +010024 private List<String> freeRegexList;
25 private List<String> publicRegexList;
26 private List<String> allRegexList;
27
margaretha56e8e552017-12-05 16:31:21 +010028 private Pattern publicLicensePattern;
29 private Pattern freeLicensePattern;
30 private Pattern allLicensePattern;
31
32 private String authenticationScheme;
33
margaretha2c019fa2018-02-01 19:50:51 +010034 private boolean isSoftDeleteAutoGroup;
35 private boolean isSoftDeleteGroup;
36 private boolean isSoftDeleteGroupMember;
37
margaretha56e8e552017-12-05 16:31:21 +010038 public FullConfiguration (Properties properties) throws IOException {
39 super(properties);
40 }
41
42 @Override
43 public void load (Properties properties) throws IOException {
44
45 super.load(properties);
46 // EM: regex used for storing vc
47 setLicenseRegex(properties);
48
49 // EM: pattern for matching availability in Krill matches
50 setLicensePatterns(properties);
margaretha2c019fa2018-02-01 19:50:51 +010051 setDeleteConfiguration(properties);
margaretha2afb97d2017-12-07 19:18:44 +010052 ldapConfig = properties.getProperty("ldap.config");
margaretha56e8e552017-12-05 16:31:21 +010053 }
54
margaretha2c019fa2018-02-01 19:50:51 +010055 private void setDeleteConfiguration (Properties properties) {
56 setSoftDeleteGroup(parseDeleteConfig(properties.getProperty("delete.group", "")));
57 setSoftDeleteAutoGroup(parseDeleteConfig(properties.getProperty("delete.auto.group", "")));
58 setSoftDeleteGroupMember(parseDeleteConfig(
59 properties.getProperty("delete.group.member", "")));
60 }
61
62 private boolean parseDeleteConfig (String deleteConfig) {
63 return deleteConfig.equals("soft") ? true : false;
64 }
65
margaretha56e8e552017-12-05 16:31:21 +010066 private void setLicensePatterns (Properties properties) {
margaretha979a2e62017-12-12 19:47:04 +010067 setFreeLicensePattern(compilePattern(getFreeOnlyRegex()));
margaretha2c019fa2018-02-01 19:50:51 +010068 setPublicLicensePattern(compilePattern(
69 getFreeOnlyRegex() + "|" + getPublicOnlyRegex()));
70 setAllLicensePattern(compilePattern(getFreeOnlyRegex() + "|"
71 + getPublicOnlyRegex() + "|" + getAllOnlyRegex()));
margaretha56e8e552017-12-05 16:31:21 +010072 }
73
74 private void setLicenseRegex (Properties properties) {
margaretha979a2e62017-12-12 19:47:04 +010075 setFreeOnlyRegex(properties.getProperty("availability.regex.free", ""));
76 freeRegexList = splitAndAddToList(getFreeOnlyRegex());
margarethadfecb4b2017-12-12 19:32:30 +010077
margaretha2c019fa2018-02-01 19:50:51 +010078 setPublicOnlyRegex(
79 properties.getProperty("availability.regex.public", ""));
margaretha979a2e62017-12-12 19:47:04 +010080 publicRegexList = splitAndAddToList(getPublicOnlyRegex());
margarethadfecb4b2017-12-12 19:32:30 +010081
margaretha979a2e62017-12-12 19:47:04 +010082 setAllOnlyRegex(properties.getProperty("availability.regex.all", ""));
83 allRegexList = splitAndAddToList(getAllOnlyRegex());
margarethadfecb4b2017-12-12 19:32:30 +010084 }
85
86 private List<String> splitAndAddToList (String regex) {
87 List<String> list;
88 if (regex.contains("|")) {
89 String[] regexes = regex.split("\\|");
90 list = new ArrayList<>(regexes.length);
91 for (String s : regexes) {
92 list.add(s.trim());
93 }
94 }
margaretha2c019fa2018-02-01 19:50:51 +010095 else {
margarethadfecb4b2017-12-12 19:32:30 +010096 list = new ArrayList<>(1);
97 list.add(regex);
98 }
99 return list;
margaretha56e8e552017-12-05 16:31:21 +0100100 }
101
102
103 private Pattern compilePattern (String patternStr) {
104 if (!patternStr.isEmpty()) {
105 return Pattern.compile(patternStr);
106 }
107 else {
108 return null;
109 }
110 }
111
margarethadfecb4b2017-12-12 19:32:30 +0100112 public String getLdapConfig () {
113 return ldapConfig;
114 }
115
116 public Pattern getPublicLicensePattern () {
117 return publicLicensePattern;
118 }
119
120 public void setPublicLicensePattern (Pattern publicLicensePattern) {
121 this.publicLicensePattern = publicLicensePattern;
122 }
123
124 public Pattern getFreeLicensePattern () {
125 return freeLicensePattern;
126 }
127
128 public void setFreeLicensePattern (Pattern freeLicensePattern) {
129 this.freeLicensePattern = freeLicensePattern;
130 }
131
132 public Pattern getAllLicensePattern () {
133 return allLicensePattern;
134 }
135
136 public void setAllLicensePattern (Pattern allLicensePattern) {
137 this.allLicensePattern = allLicensePattern;
138 }
139
140 public String getAuthenticationScheme () {
141 return authenticationScheme;
142 }
143
144 public void setAuthenticationScheme (String authenticationScheme) {
145 this.authenticationScheme = authenticationScheme;
146 }
147
148 public List<String> getFreeRegexList () {
149 return freeRegexList;
150 }
151
152 public void setFreeRegexList (List<String> freeRegexList) {
153 this.freeRegexList = freeRegexList;
154 }
155
156 public List<String> getPublicRegexList () {
157 return publicRegexList;
158 }
159
160 public void setPublicRegexList (List<String> publicRegexList) {
161 this.publicRegexList = publicRegexList;
162 }
163
164 public List<String> getAllRegexList () {
165 return allRegexList;
166 }
167
168 public void setAllRegexList (List<String> allRegexList) {
169 this.allRegexList = allRegexList;
170 }
171
margaretha979a2e62017-12-12 19:47:04 +0100172 public String getFreeOnlyRegex () {
173 return freeOnlyRegex;
174 }
175
176 public void setFreeOnlyRegex (String freeOnlyRegex) {
177 this.freeOnlyRegex = freeOnlyRegex;
178 }
179
180 public String getPublicOnlyRegex () {
181 return publicOnlyRegex;
182 }
183
184 public void setPublicOnlyRegex (String publicOnlyRegex) {
185 this.publicOnlyRegex = publicOnlyRegex;
186 }
187
188 public String getAllOnlyRegex () {
189 return allOnlyRegex;
190 }
191
192 public void setAllOnlyRegex (String allOnlyRegex) {
193 this.allOnlyRegex = allOnlyRegex;
194 }
195
margaretha2c019fa2018-02-01 19:50:51 +0100196 public boolean isSoftDeleteGroup () {
197 return isSoftDeleteGroup;
198 }
199
200 public void setSoftDeleteGroup (boolean isSoftDeleteGroup) {
201 this.isSoftDeleteGroup = isSoftDeleteGroup;
202 }
203
204 public boolean isSoftDeleteGroupMember () {
205 return isSoftDeleteGroupMember;
206 }
207
208 public void setSoftDeleteGroupMember (boolean isSoftDeleteGroupMember) {
209 this.isSoftDeleteGroupMember = isSoftDeleteGroupMember;
210 }
211
212 public boolean isSoftDeleteAutoGroup () {
213 return isSoftDeleteAutoGroup;
214 }
215
216 public void setSoftDeleteAutoGroup (boolean isSoftDeleteAutoGroup) {
217 this.isSoftDeleteAutoGroup = isSoftDeleteAutoGroup;
218 }
219
margaretha56e8e552017-12-05 16:31:21 +0100220}