KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > webui > actions > config > ShowEditAlertAction


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.actions.config;
17
18 import org.jmanage.webui.actions.BaseAction;
19 import org.jmanage.webui.util.*;
20 import org.jmanage.webui.forms.AlertForm;
21 import org.jmanage.core.config.ApplicationConfig;
22 import org.jmanage.core.config.AlertConfig;
23 import org.jmanage.core.config.AlertSourceConfig;
24 import org.jmanage.core.util.Expression;
25 import org.jmanage.core.services.AccessController;
26 import org.jmanage.core.services.MBeanService;
27 import org.jmanage.core.services.ServiceFactory;
28 import org.jmanage.core.management.ObjectAttribute;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31 import org.apache.struts.action.ActionForm;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.Iterator JavaDoc;
37
38 /**
39  * Date: Jun 21, 2005 10:57:31 AM
40  * @author Bhavana
41  */

42 public class ShowEditAlertAction extends BaseAction{
43     public ActionForward execute(WebContext context,
44                                  ActionMapping mapping,
45                                  ActionForm actionForm,
46                                  HttpServletRequest JavaDoc request,
47                                  HttpServletResponse JavaDoc response)
48             throws Exception JavaDoc {
49         AccessController.checkAccess(Utils.getServiceContext(context), ACL_EDIT_ALERT);
50         AlertForm form = (AlertForm)actionForm;
51         String JavaDoc alertId = request.getParameter(RequestParams.ALERT_ID);
52         ApplicationConfig appConfig = context.getApplicationConfig();
53         AlertConfig alertConfig = appConfig.findAlertById(alertId);
54         if(alertConfig!=null){
55             form.setAlertName(alertConfig.getAlertName());
56             form.setAlertDelivery(alertConfig.getAlertDelivery());
57             form.setEmailAddress(alertConfig.getEmailAddress());
58             AlertSourceConfig alertSrcConfig = alertConfig.getAlertSourceConfig();
59             String JavaDoc sourceType = alertSrcConfig.getSourceType();
60             form.setAlertSourceType(alertSrcConfig.getSourceType());
61             request.setAttribute("alertSourceType",sourceType);
62             request.setAttribute("sourceMBean", alertSrcConfig.getObjectName());
63             // expression
64
Expression expression = null;
65             if(sourceType.equals(AlertSourceConfig.SOURCE_TYPE_NOTIFICATION)){
66                 expression = new Expression(null, alertSrcConfig.getObjectName(),
67                         alertSrcConfig.getNotificationType());
68                 request.setAttribute("notificationType",
69                         alertSrcConfig.getNotificationType());
70             }else if(sourceType.equals(
71                     AlertSourceConfig.SOURCE_TYPE_GAUGE_MONITOR) ||sourceType.equals(
72                     AlertSourceConfig.SOURCE_TYPE_STRING_MONITOR) ){
73                 expression = new Expression(null, alertSrcConfig.getObjectName(),
74                         alertSrcConfig.getAttributeName());
75                 request.setAttribute("attribute", alertSrcConfig.getAttributeName());
76                 MBeanService mbeanService = ServiceFactory.getMBeanService();
77                 ObjectAttribute objAttr = mbeanService.getObjectAttribute(
78                     Utils.getServiceContext(context, expression),
79                     expression.getTargetName());
80                 request.setAttribute("currentAttrValue",
81                         objAttr.getDisplayValue());
82                 if(sourceType.equals(
83                     AlertSourceConfig.SOURCE_TYPE_GAUGE_MONITOR)){
84                     form.setMinAttributeValue(alertSrcConfig.getLowThreshold().toString());
85                     form.setMaxAttributeValue(alertSrcConfig.getHighThreshold().toString());
86                 }else if(sourceType.equals(
87                     AlertSourceConfig.SOURCE_TYPE_STRING_MONITOR)){
88                     form.setStringAttributeValue(alertSrcConfig.getStringAttributeValue());
89                 }
90             }
91             form.setExpression(expression.toString());
92         }
93         /*set current page for navigation*/
94         request.setAttribute(RequestAttributes.NAV_CURRENT_PAGE, "Edit Alert");
95         return mapping.findForward(Forwards.SUCCESS);
96     }
97 }
98
Popular Tags