Rev 1041 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
924 | dev | 1 | package ak.hostadmiral.core.model; |
919 | dev | 2 | |
1041 | dev | 3 | import java.util.Collection; |
4 | import java.util.ArrayList; |
||
5 | import java.util.Iterator; |
||
6 | import java.util.Map; |
||
7 | import java.util.Comparator; |
||
8 | |||
9 | import ak.hostadmiral.util.ConfigInit; |
||
10 | import ak.hostadmiral.util.CollectionInfo; |
||
924 | dev | 11 | import ak.hostadmiral.util.ModelException; |
12 | import ak.hostadmiral.util.ModelSecurityException; |
||
1041 | dev | 13 | import ak.hostadmiral.core.model.store.MailAliasDestinationStore; |
919 | dev | 14 | |
15 | public class MailAliasDestinationManager |
||
1041 | dev | 16 | implements |
17 | ConfigInit |
||
919 | dev | 18 | { |
1011 | dev | 19 | // FIXME create, delete and modify listeners are not implemented, bacause |
20 | // all operations are done via MailAliasManager. Do we need them? |
||
21 | |||
1041 | dev | 22 | private MailAliasDestinationStore store; |
919 | dev | 23 | |
1041 | dev | 24 | public MailAliasDestinationManager() |
25 | throws ModelException |
||
919 | dev | 26 | { |
27 | } |
||
28 | |||
29 | public MailAliasDestination create(User editor) |
||
30 | throws ModelException |
||
31 | { |
||
32 | if(!allowedToCreate(editor)) throw new ModelSecurityException(); |
||
33 | |||
34 | return new MailAliasDestination(); |
||
35 | } |
||
36 | |||
37 | public boolean allowedToCreate(User editor) |
||
38 | throws ModelException |
||
39 | { |
||
922 | dev | 40 | return MailAliasDestination.allowedToCreate(this, editor); |
919 | dev | 41 | } |
42 | |||
43 | public MailAliasDestination get(User editor, Long id) |
||
44 | throws ModelException |
||
45 | { |
||
1041 | dev | 46 | MailAliasDestination dest = store.get(id); |
919 | dev | 47 | |
48 | if(!dest.viewableBy(editor)) |
||
49 | throw new ModelSecurityException(); |
||
50 | |||
51 | return dest; |
||
52 | } |
||
53 | |||
54 | public void save(User editor, MailAliasDestination mailAliasDestination) |
||
55 | throws ModelException |
||
56 | { |
||
57 | if(!mailAliasDestination.editableBy(editor)) |
||
58 | throw new ModelSecurityException(); |
||
59 | |||
1010 | dev | 60 | //mailAliasDestination.setModUser(editor); // FIXME |
923 | dev | 61 | // FIXME: the mod_user is not set when changing a destination as element of collection |
919 | dev | 62 | |
1041 | dev | 63 | store.save(mailAliasDestination); |
919 | dev | 64 | } |
65 | |||
66 | public void delete(User editor, MailAliasDestination mailAliasDestination) |
||
67 | throws ModelException |
||
68 | { |
||
69 | if(!mailAliasDestination.deleteableBy(editor)) |
||
70 | throw new ModelSecurityException(); |
||
71 | |||
1041 | dev | 72 | store.delete(mailAliasDestination); |
919 | dev | 73 | } |
74 | |||
75 | public Collection listMailAliasesDestination(MailAlias alias) |
||
76 | throws ModelException |
||
77 | { |
||
1041 | dev | 78 | return store.listMailAliasesDestination(alias); |
919 | dev | 79 | } |
80 | |||
81 | public boolean areMailAliasesDestinationsAvailable(User editor) |
||
82 | throws ModelException |
||
83 | { |
||
84 | return true; |
||
85 | } |
||
86 | |||
87 | public static final Comparator EMAIL_COMPARATOR = new EmailComparator(); |
||
88 | |||
89 | private static class EmailComparator |
||
90 | implements Comparator |
||
91 | { |
||
92 | public int compare(Object o1, Object o2) |
||
93 | { |
||
94 | if(!(o1 instanceof MailAliasDestination) || !(o2 instanceof MailAliasDestination)) |
||
95 | throw new ClassCastException("not a MailAliasDestination"); |
||
96 | |||
97 | MailAliasDestination a1 = (MailAliasDestination)o1; |
||
98 | MailAliasDestination a2 = (MailAliasDestination)o2; |
||
99 | |||
100 | if(a1 == null && a2 == null) |
||
101 | return 0; |
||
102 | else if(a1 == null && a2 != null) |
||
103 | return -1; |
||
104 | else if(a1 != null && a2 == null) |
||
105 | return 1; |
||
106 | else |
||
107 | return a1.getEmail().compareToIgnoreCase(a2.getEmail()); |
||
108 | } |
||
109 | |||
110 | public boolean equals(Object obj) |
||
111 | { |
||
112 | return (obj instanceof EmailComparator); |
||
113 | } |
||
114 | } |
||
1041 | dev | 115 | |
116 | public void init(Map params) |
||
117 | throws ModelException |
||
118 | { |
||
119 | try { |
||
120 | mailAliasDestinationManager = this; |
||
121 | |||
1046 | dev | 122 | Class c = Class.forName(((String[])params.get("store"))[0]); |
1041 | dev | 123 | store = (MailAliasDestinationStore)c.newInstance(); |
124 | } |
||
125 | catch(Exception ex) { |
||
126 | throw new ModelException(ex); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | private static MailAliasDestinationManager mailAliasDestinationManager = null; |
||
131 | |||
132 | public static MailAliasDestinationManager getInstance() |
||
133 | { |
||
134 | return mailAliasDestinationManager; |
||
135 | } |
||
919 | dev | 136 | } |