001: /**
002: * Copyright 2004-2005 jManage.org
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */package org.jmanage.webui.forms;
016:
017: import org.jmanage.core.config.AlertSourceConfig;
018: import org.jmanage.webui.util.WebErrorCodes;
019: import org.jmanage.webui.validator.Validator;
020: import org.apache.struts.action.*;
021:
022: import javax.servlet.http.HttpServletRequest;
023:
024: /**
025: * Date: May 26, 2005 4:46:35 PM
026: * @author Bhavana
027: */
028: public class AlertForm extends BaseForm {
029:
030: private String alertId;
031: private String alertName;
032: private String[] alertDelivery;
033: private String emailAddress;
034: private String alertSourceType = AlertSourceConfig.SOURCE_TYPE_NOTIFICATION;
035: private String expression;
036: private String minAttributeValue;
037: private String maxAttributeValue;
038: private String stringAttributeValue;
039:
040: public String getStringAttributeValue() {
041: return stringAttributeValue;
042: }
043:
044: public void setStringAttributeValue(String stringAttributeValue) {
045: this .stringAttributeValue = stringAttributeValue;
046: }
047:
048: public String getMinAttributeValue() {
049: return minAttributeValue;
050: }
051:
052: public void setMinAttributeValue(String minAttributeValue) {
053: this .minAttributeValue = minAttributeValue;
054: }
055:
056: public String getMaxAttributeValue() {
057: return maxAttributeValue;
058: }
059:
060: public void setMaxAttributeValue(String maxAttributeValue) {
061: this .maxAttributeValue = maxAttributeValue;
062: }
063:
064: public String getAlertId() {
065: return alertId;
066: }
067:
068: public void setAlertId(String alertId) {
069: this .alertId = alertId;
070: }
071:
072: public String getAlertName() {
073: return alertName;
074: }
075:
076: public void setAlertName(String alertName) {
077: this .alertName = alertName;
078: }
079:
080: public String[] getAlertDelivery() {
081: return alertDelivery;
082: }
083:
084: public void setAlertDelivery(String[] alertDelivery) {
085: this .alertDelivery = alertDelivery;
086: }
087:
088: public String getEmailAddress() {
089: return emailAddress;
090: }
091:
092: public void setEmailAddress(String emailAddress) {
093: this .emailAddress = emailAddress;
094: }
095:
096: public String getAlertSourceType() {
097: return alertSourceType;
098: }
099:
100: public void setAlertSourceType(String alertSourceType) {
101: this .alertSourceType = alertSourceType;
102: }
103:
104: public String getExpression() {
105: return expression;
106: }
107:
108: public void setExpression(String expression) {
109: this .expression = expression;
110: }
111:
112: /**
113: * this method is needed becuase in the generic flow for attribute selection
114: * the parameter used in attributes
115: * @param attribute
116: */
117: public void setAttributes(String attribute) {
118: setExpression(attribute);
119: }
120:
121: public ActionErrors validate(ActionMapping mapping,
122: HttpServletRequest request) {
123: ActionErrors errors = super .validate(mapping, request);
124: if (errors == null || errors.isEmpty()) {
125: if (alertDelivery[0] != null
126: && alertDelivery[0].equals("email")) {
127: Validator.validateRequired(emailAddress,
128: "Email Address", errors);
129: }
130: if (alertSourceType
131: .equals(AlertSourceConfig.SOURCE_TYPE_GAUGE_MONITOR)) {
132: boolean validMin = Validator.validateRequired(
133: minAttributeValue, "minimum attribute value",
134: errors);
135: boolean validMax = Validator.validateRequired(
136: maxAttributeValue, "maximum attribute value",
137: errors);
138: if (validMin && validMax) {
139: if (Double.valueOf(maxAttributeValue).doubleValue() < Double
140: .valueOf(minAttributeValue).doubleValue()) {
141: errors
142: .add(
143: ActionErrors.GLOBAL_ERROR,
144: new ActionError(
145: WebErrorCodes.MAX_ATTRIBUTE_VALUE_GREATER));
146: }
147: }
148: }
149: if (alertSourceType
150: .equals(AlertSourceConfig.SOURCE_TYPE_STRING_MONITOR)) {
151: Validator.validateRequired(stringAttributeValue,
152: "Attribute Value", errors);
153: }
154: }
155: return errors;
156: }
157: }
|