1 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 ; 34 import javax.servlet.http.HttpServletResponse ; 35 import java.util.List ; 36 import java.util.Iterator ; 37 38 42 public class ShowEditAlertAction extends BaseAction{ 43 public ActionForward execute(WebContext context, 44 ActionMapping mapping, 45 ActionForm actionForm, 46 HttpServletRequest request, 47 HttpServletResponse response) 48 throws Exception { 49 AccessController.checkAccess(Utils.getServiceContext(context), ACL_EDIT_ALERT); 50 AlertForm form = (AlertForm)actionForm; 51 String 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 sourceType = alertSrcConfig.getSourceType(); 60 form.setAlertSourceType(alertSrcConfig.getSourceType()); 61 request.setAttribute("alertSourceType",sourceType); 62 request.setAttribute("sourceMBean", alertSrcConfig.getObjectName()); 63 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 94 request.setAttribute(RequestAttributes.NAV_CURRENT_PAGE, "Edit Alert"); 95 return mapping.findForward(Forwards.SUCCESS); 96 } 97 } 98 | Popular Tags |