KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > webui > forms > AlertForm


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.jmanage.webui.forms;
17
18 import org.jmanage.core.config.AlertSourceConfig;
19 import org.jmanage.webui.util.WebErrorCodes;
20 import org.jmanage.webui.validator.Validator;
21 import org.apache.struts.action.*;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24
25 /**
26  * Date: May 26, 2005 4:46:35 PM
27  * @author Bhavana
28  */

29 public class AlertForm extends BaseForm{
30
31     private String JavaDoc alertId;
32     private String JavaDoc alertName;
33     private String JavaDoc[] alertDelivery;
34     private String JavaDoc emailAddress;
35     private String JavaDoc alertSourceType = AlertSourceConfig.SOURCE_TYPE_NOTIFICATION;
36     private String JavaDoc expression;
37     private String JavaDoc minAttributeValue;
38     private String JavaDoc maxAttributeValue;
39     private String JavaDoc stringAttributeValue;
40
41     public String JavaDoc getStringAttributeValue() {
42         return stringAttributeValue;
43     }
44
45     public void setStringAttributeValue(String JavaDoc stringAttributeValue) {
46         this.stringAttributeValue = stringAttributeValue;
47     }
48
49     public String JavaDoc getMinAttributeValue() {
50         return minAttributeValue;
51     }
52
53     public void setMinAttributeValue(String JavaDoc minAttributeValue) {
54         this.minAttributeValue = minAttributeValue;
55     }
56
57     public String JavaDoc getMaxAttributeValue() {
58         return maxAttributeValue;
59     }
60
61     public void setMaxAttributeValue(String JavaDoc maxAttributeValue) {
62         this.maxAttributeValue = maxAttributeValue;
63     }
64
65     public String JavaDoc getAlertId() {
66         return alertId;
67     }
68
69     public void setAlertId(String JavaDoc alertId) {
70         this.alertId = alertId;
71     }
72
73     public String JavaDoc getAlertName() {
74         return alertName;
75     }
76
77     public void setAlertName(String JavaDoc alertName) {
78         this.alertName = alertName;
79     }
80
81     public String JavaDoc[] getAlertDelivery() {
82         return alertDelivery;
83     }
84
85     public void setAlertDelivery(String JavaDoc[] alertDelivery) {
86         this.alertDelivery = alertDelivery;
87     }
88
89     public String JavaDoc getEmailAddress() {
90         return emailAddress;
91     }
92
93     public void setEmailAddress(String JavaDoc emailAddress) {
94         this.emailAddress = emailAddress;
95     }
96
97     public String JavaDoc getAlertSourceType() {
98         return alertSourceType;
99     }
100
101     public void setAlertSourceType(String JavaDoc alertSourceType) {
102         this.alertSourceType = alertSourceType;
103     }
104
105     public String JavaDoc getExpression() {
106         return expression;
107     }
108
109     public void setExpression(String JavaDoc expression) {
110         this.expression = expression;
111     }
112
113     /**
114      * this method is needed becuase in the generic flow for attribute selection
115      * the parameter used in attributes
116      * @param attribute
117      */

118     public void setAttributes(String JavaDoc attribute){
119         setExpression(attribute);
120     }
121
122     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request){
123         ActionErrors errors = super.validate(mapping, request);
124         if(errors==null || errors.isEmpty()){
125             if(alertDelivery[0] !=null && alertDelivery[0].equals("email")){
126                 Validator.validateRequired(emailAddress, "Email Address", errors);
127             }
128             if(alertSourceType.equals(AlertSourceConfig.SOURCE_TYPE_GAUGE_MONITOR)){
129                 boolean validMin = Validator.validateRequired(minAttributeValue,
130                         "minimum attribute value", errors);
131                 boolean validMax = Validator.validateRequired(maxAttributeValue,
132                         "maximum attribute value", errors);
133                 if(validMin && validMax){
134                     if(Double.valueOf(maxAttributeValue).doubleValue()<
135                             Double.valueOf(minAttributeValue).doubleValue()){
136                         errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
137                                 WebErrorCodes.MAX_ATTRIBUTE_VALUE_GREATER));
138                     }
139                 }
140             }if(alertSourceType.equals(AlertSourceConfig.SOURCE_TYPE_STRING_MONITOR)){
141                 Validator.validateRequired(stringAttributeValue,
142                         "Attribute Value", errors);
143             }
144         }
145         return errors;
146     }
147 }
148
Popular Tags