KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > services > servicetypes > CertificateExpirationNotifierWorkerType


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13 package org.ejbca.ui.web.admin.services.servicetypes;
14
15 import java.io.IOException JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.Collection JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Properties JavaDoc;
21
22 import javax.faces.model.SelectItem;
23
24 import org.ejbca.core.model.services.intervals.PeriodicalInterval;
25 import org.ejbca.core.model.services.workers.CertificateExpirationNotifierWorker;
26 import org.ejbca.ui.web.admin.configuration.EjbcaJSFHelper;
27
28 /**
29  * Class managing the view of the Certificate Exiration Notifier Worker
30  *
31  * @author Philip Vendil
32  *
33  * $id$
34  */

35 public class CertificateExpirationNotifierWorkerType extends WorkerType {
36
37     public static final String JavaDoc NAME = "CERTNOTIFICATIONWORKER";
38     
39     private Collection JavaDoc compatibleActionTypeNames = new ArrayList JavaDoc();
40     private Collection JavaDoc compatibleIntervalTypeNames = new ArrayList JavaDoc();
41     
42     
43     public static final String JavaDoc DEFAULT_TIMEUNIT = CertificateExpirationNotifierWorker.UNIT_DAYS;
44     public static final String JavaDoc DEFAULT_TIMEVALUE = "7";
45     
46     public static final boolean DEFAULT_USEENDUSERNOTIFICATIONS = false;
47     public static final boolean DEFAULT_USEADMINNOTIFICATIONS = false;
48     
49     
50     private List JavaDoc selectedCANamesToCheck = new ArrayList JavaDoc();
51     private String JavaDoc timeUnit = DEFAULT_TIMEUNIT;
52     private String JavaDoc timeValue = DEFAULT_TIMEVALUE;
53     private boolean useEndUserNotifications = DEFAULT_USEENDUSERNOTIFICATIONS;
54     private boolean useAdminNotifications = DEFAULT_USEADMINNOTIFICATIONS;
55     private String JavaDoc endUserSubject = "";
56     private String JavaDoc adminSubject = "";
57     private String JavaDoc endUserMessage = "";
58     private String JavaDoc adminMessage = "";
59     
60     
61     
62     public CertificateExpirationNotifierWorkerType(){
63         super("certnotificationworker.jsp", NAME, true);
64         
65         compatibleActionTypeNames.add(MailActionType.NAME);
66         
67         compatibleIntervalTypeNames.add(PeriodicalIntervalType.NAME);
68     }
69     /**
70      *
71      * @see org.ejbca.ui.web.admin.services.servicetypes.WorkerType#getCompatibleActionTypeNames()
72      */

73     public Collection JavaDoc getCompatibleActionTypeNames() {
74         return compatibleActionTypeNames;
75     }
76
77     /**
78      * @see org.ejbca.ui.web.admin.services.servicetypes.WorkerType#getCompatibleIntervalTypeNames()
79      */

80     public Collection JavaDoc getCompatibleIntervalTypeNames() {
81         return compatibleIntervalTypeNames;
82     }
83
84     /**
85      * @see org.ejbca.ui.web.admin.services.servicetypes.ServiceType#getClassPath()
86      */

87     public String JavaDoc getClassPath() {
88         return "org.ejbca.core.model.services.workers.CertificateExpirationNotifierWorker";
89     }
90
91     /**
92      * @see org.ejbca.ui.web.admin.services.servicetypes.ServiceType#getProperties()
93      */

94     public Properties JavaDoc getProperties(ArrayList JavaDoc errorMessages) throws IOException JavaDoc {
95         Properties JavaDoc retval = new Properties JavaDoc();
96         
97         Iterator JavaDoc iter = selectedCANamesToCheck.iterator();
98         String JavaDoc caIdString = "";
99         while(iter.hasNext()){
100             String JavaDoc cAid = (String JavaDoc) iter.next();
101             if(!cAid.trim().equals("")){
102               if(caIdString.equals("")){
103                 caIdString = cAid;
104               }else{
105                 caIdString += ";"+cAid;
106               }
107             }
108         }
109         retval.setProperty(CertificateExpirationNotifierWorker.PROP_CAIDSTOCHECK, caIdString);
110         
111         retval.setProperty(CertificateExpirationNotifierWorker.PROP_TIMEUNIT, timeUnit);
112         
113         try{
114             int value = Integer.parseInt(timeValue);
115             if(value < 1){
116                 throw new NumberFormatException JavaDoc();
117             }
118         }catch(NumberFormatException JavaDoc e){
119             errorMessages.add("TIMEBEFOREEXPIRATIONERROR");
120         }
121         retval.setProperty(CertificateExpirationNotifierWorker.PROP_TIMEBEFOREEXPIRING, timeValue);
122         
123         if(useEndUserNotifications){
124             retval.setProperty(CertificateExpirationNotifierWorker.PROP_SENDTOENDUSERS, "TRUE");
125             retval.setProperty(CertificateExpirationNotifierWorker.PROP_USERSUBJECT,endUserSubject);
126             retval.setProperty(CertificateExpirationNotifierWorker.PROP_USERMESSAGE,endUserMessage);
127         }else{
128             retval.setProperty(CertificateExpirationNotifierWorker.PROP_SENDTOENDUSERS, "FALSE");
129             retval.setProperty(CertificateExpirationNotifierWorker.PROP_USERSUBJECT,"");
130             retval.setProperty(CertificateExpirationNotifierWorker.PROP_USERMESSAGE,"");
131         }
132         
133         if(useAdminNotifications){
134             retval.setProperty(CertificateExpirationNotifierWorker.PROP_SENDTOADMINS, "TRUE");
135             retval.setProperty(CertificateExpirationNotifierWorker.PROP_ADMINSUBJECT,adminSubject);
136             retval.setProperty(CertificateExpirationNotifierWorker.PROP_ADMINMESSAGE,adminMessage);
137         }else{
138             retval.setProperty(CertificateExpirationNotifierWorker.PROP_SENDTOADMINS, "FALSE");
139             retval.setProperty(CertificateExpirationNotifierWorker.PROP_ADMINSUBJECT,"");
140             retval.setProperty(CertificateExpirationNotifierWorker.PROP_ADMINMESSAGE,"");
141         }
142         
143     
144         return retval;
145     }
146
147     /**
148      * @see org.ejbca.ui.web.admin.services.servicetypes.ServiceType#isCustom()
149      */

150     public boolean isCustom() {
151         return false;
152     }
153
154     /**
155      * @see org.ejbca.ui.web.admin.services.servicetypes.ServiceType#setProperties(java.util.Properties)
156      */

157     public void setProperties(Properties JavaDoc properties) throws IOException JavaDoc {
158         selectedCANamesToCheck = new ArrayList JavaDoc();
159         
160         
161         String JavaDoc[] caIdsToCheck = properties.getProperty(CertificateExpirationNotifierWorker.PROP_CAIDSTOCHECK,"").split(";");
162         for(int i=0;i<caIdsToCheck.length;i++){
163             selectedCANamesToCheck.add(caIdsToCheck[i]);
164         }
165
166          
167         timeUnit = properties.getProperty(CertificateExpirationNotifierWorker.PROP_TIMEUNIT,DEFAULT_TIMEUNIT);
168         timeValue = properties.getProperty(CertificateExpirationNotifierWorker.PROP_TIMEBEFOREEXPIRING,DEFAULT_TIMEVALUE);
169
170         useEndUserNotifications = properties.getProperty(CertificateExpirationNotifierWorker.PROP_SENDTOENDUSERS,"").equalsIgnoreCase("TRUE");
171         useAdminNotifications = properties.getProperty(CertificateExpirationNotifierWorker.PROP_SENDTOADMINS,"").equalsIgnoreCase("TRUE");
172         
173         endUserSubject = properties.getProperty(CertificateExpirationNotifierWorker.PROP_USERSUBJECT,"");
174         adminSubject = properties.getProperty(CertificateExpirationNotifierWorker.PROP_ADMINSUBJECT,"");
175         endUserMessage = properties.getProperty(CertificateExpirationNotifierWorker.PROP_USERMESSAGE,"");
176         adminMessage = properties.getProperty(CertificateExpirationNotifierWorker.PROP_ADMINMESSAGE,"");
177
178     }
179     
180     public String JavaDoc getTimeUnit() {
181         return timeUnit;
182     }
183
184     public void setTimeUnit(String JavaDoc unit) {
185         this.timeUnit = unit;
186     }
187     
188     public List JavaDoc getAvailableUnits(){
189         ArrayList JavaDoc retval = new ArrayList JavaDoc();
190         for(int i = 0 ; i<PeriodicalInterval.AVAILABLE_UNITS.length; i++){
191             retval.add(new SelectItem(PeriodicalInterval.AVAILABLE_UNITS[i],(String JavaDoc) EjbcaJSFHelper.getBean().getText().get(PeriodicalInterval.AVAILABLE_UNITS[i])));
192         }
193         
194         return retval;
195     }
196     public String JavaDoc getAdminMessage() {
197         return adminMessage;
198     }
199     public void setAdminMessage(String JavaDoc adminMessage) {
200         this.adminMessage = adminMessage;
201     }
202     public String JavaDoc getAdminSubject() {
203         return adminSubject;
204     }
205     public void setAdminSubject(String JavaDoc adminSubject) {
206         this.adminSubject = adminSubject;
207     }
208     public String JavaDoc getEndUserMessage() {
209         return endUserMessage;
210     }
211     public void setEndUserMessage(String JavaDoc endUserMessage) {
212         this.endUserMessage = endUserMessage;
213     }
214     public String JavaDoc getEndUserSubject() {
215         return endUserSubject;
216     }
217     public void setEndUserSubject(String JavaDoc endUserSubject) {
218         this.endUserSubject = endUserSubject;
219     }
220     public List JavaDoc getSelectedCANamesToCheck() {
221         return selectedCANamesToCheck;
222     }
223     public void setSelectedCANamesToCheck(List JavaDoc selectedCANamesToCheck) {
224         this.selectedCANamesToCheck = selectedCANamesToCheck;
225     }
226     public String JavaDoc getTimeValue() {
227         return timeValue;
228     }
229     public void setTimeValue(String JavaDoc timeValue) {
230         this.timeValue = timeValue;
231     }
232     public boolean isUseAdminNotifications() {
233         return useAdminNotifications;
234     }
235     public void setUseAdminNotifications(boolean useAdminNotifications) {
236         this.useAdminNotifications = useAdminNotifications;
237     }
238     public boolean isUseEndUserNotifications() {
239         return useEndUserNotifications;
240     }
241     public void setUseEndUserNotifications(boolean useEndUserNotifications) {
242         this.useEndUserNotifications = useEndUserNotifications;
243     }
244
245 }
246
Popular Tags