source: trunk/src/org/expeditee/auth/tags/AuthenticationTag.java@ 1243

Last change on this file since 1243 was 1243, checked in by bln4, 5 years ago

Alterations to how mail works to work better in a cloud environment.
General code tidying and updating to work with larger changes happening to Expeditee.

File size: 2.0 KB
Line 
1package org.expeditee.auth.tags;
2
3import java.util.Collection;
4import java.util.HashMap;
5import java.util.Map;
6import java.util.Optional;
7
8import org.expeditee.items.Text;
9
10public enum AuthenticationTag {
11 Username ("txtUsername", System.getProperty("user.name")),
12 Password ("txtPassword", System.getProperty("user.password")),
13 PasswordAgain ("txtPasswordAgain", System.getProperty("user.password.again")),
14 NewPassword ("txtNewPassword", System.getProperty("user.new.password")),
15 NewPasswordAgain ("txtNewPasswordAgain", System.getProperty("user.new.password.again")),
16 Email ("txtEmail", System.getProperty("user.email")),
17 EmailAgain ("txtEmailAgain", System.getProperty("user.email.again")),
18 ColleagueOne ("txtColleagueOne", System.getProperty("user.colleague.one")),
19 ColleagueTwo ("txtColleagueTwo", System.getProperty("user.colleague.two")),
20 Frameset ("txtFrameset", System.getProperty("user.toshare.frameset"));
21
22 public String val;
23 public String def;
24
25 private AuthenticationTag(String tag, String def) {
26 this.val = tag;
27 this.def = def;
28 }
29
30 public static Optional<Map<AuthenticationTag, String>> fetchUserData(Collection<Text> from, boolean useDefaults, AuthenticationTag... tags) {
31 final Map<AuthenticationTag, String> fetchedData = new HashMap<AuthenticationTag, String>();
32
33 for (AuthenticationTag tag: tags) {
34 for (Text canditate: from) {
35 // use the canditate if it exists
36 if (canditate.hasData(tag.val)) {
37 if (tag.val.equals("txtUsername")) {
38 fetchedData.put(tag, canditate.getText().toLowerCase());
39 } else {
40 fetchedData.put(tag, canditate.getText());
41 }
42 break;
43 }
44 // otherwise try use the default
45 String property = tag.def;
46 if (property != null && !property.isEmpty()) {
47 fetchedData.put(tag, useDefaults ? property : null);
48 }
49 }
50 }
51
52 if (fetchedData.entrySet().size() == tags.length) {
53 return Optional.of(fetchedData);
54 } else {
55 return Optional.empty();
56 }
57 }
58}
Note: See TracBrowser for help on using the repository browser.