1 19 20 package org.openbravo.erpCommon.ad_forms; 21 import org.openbravo.data.Sqlc; 22 23 import org.openbravo.erpCommon.utility.ToolBar; 24 import org.openbravo.erpCommon.businessUtility.WindowTabs; 25 26 import org.openbravo.erpCommon.utility.*; 27 import org.openbravo.base.secureApp.HttpSecureAppServlet; 28 import org.openbravo.base.secureApp.VariablesSecureApp; 29 import org.openbravo.xmlEngine.XmlDocument; 30 import java.io.*; 31 import javax.servlet.*; 32 import javax.servlet.http.*; 33 34 import org.openbravo.utils.FormatUtilities; 35 import org.openbravo.utils.Replace; 36 37 public class AlertManagement extends HttpSecureAppServlet { 38 39 40 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 41 VariablesSecureApp vars = new VariablesSecureApp(request); 42 43 if (!Utility.hasProcessAccess(this, vars, "", "RV_ReportCash")) { 44 bdError(response, "AccessTableNoView", vars.getLanguage()); 45 return; 46 } 47 48 if (vars.commandIn("DEFAULT")) { 49 String strAlertRuleId=vars.getRequestGlobalVariable("inpAlertRule", "AlertManagement|AlertRule"); 50 String strActiveFilter=vars.getStringParameter("inpActiveFilter","Y").equals("")?"N":"Y"; 51 String strFixedFilter=vars.getRequestGlobalVariable("inpFixedFilter", "FixedFilter|AlertRule").equals("")?"N":"Y"; 52 printPageDataSheet(response, vars, strAlertRuleId, strActiveFilter, strFixedFilter); 53 } else if (vars.commandIn("FIND")) { 54 String strAlertRuleId=vars.getRequestGlobalVariable("inpAlertRule", "AlertManagement|AlertRule"); 55 String strActiveFilter=vars.getStringParameter("inpActiveFilter").equals("")?"N":"Y"; 56 String strFixedFilter=vars.getRequestGlobalVariable("inpFixedFilter", "FixedFilter|AlertRule").equals("")?"N":"Y"; 57 printPageDataSheet(response, vars, strAlertRuleId, strActiveFilter, strFixedFilter); 58 } else if (vars.commandIn("SAVE_EDIT_EDIT")) { 59 updateValues(request, vars); 60 String strAlertRuleId=vars.getRequestGlobalVariable("inpAlertRule", "AlertManagement|AlertRule"); 61 String strActiveFilter=vars.getStringParameter("inpActiveFilter").equals("")?"N":"Y"; 62 String strFixedFilter=vars.getRequestGlobalVariable("inpFixedFilter", "FixedFilter|AlertRule").equals("")?"N":"Y"; 63 printPageDataSheet(response, vars, strAlertRuleId, strActiveFilter, strFixedFilter); 64 } else pageError(response); 65 } 66 67 void updateValues(HttpServletRequest request, VariablesSecureApp vars) throws IOException, ServletException { 68 String [] strAlertId = request.getParameterValues("strAlertID"); 69 if (log4j.isDebugEnabled()) log4j.debug("update: alerts"+strAlertId.length); 70 for (int i=0; i<strAlertId.length; i++) { 71 72 String note = vars.getStringParameter("strNotes"+strAlertId[i]); 73 String fixed = vars.getStringParameter("strFixed"+strAlertId[i]).equals("on")?"Y":"N"; 74 String active = vars.getStringParameter("strActive"+strAlertId[i]).equals("on")?"Y":"N"; 75 76 if (log4j.isDebugEnabled()) log4j.debug("updating:"+strAlertId[i]+" - fixed:"+fixed+" - active:"+active); 77 AlertManagementData.update(this, note, fixed, active, strAlertId[i]); 78 } 79 } 80 81 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strAlertRuleId, String strActiveFilter, String strFixedFilter) throws IOException, ServletException { 82 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 83 response.setContentType("text/html; charset=UTF-8"); 84 PrintWriter out = response.getWriter(); 85 XmlDocument xmlDocument=xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_forms/AlertManagement").createXmlDocument(); 86 87 88 AlertManagementData[] rules = AlertManagementData.selectAlertRules(this, vars.getLanguage(),vars.getUser(), vars.getRole(),strAlertRuleId); 89 AlertManagementData[][] alerts=new AlertManagementData[rules.length][]; 90 91 92 if (rules!=null && rules.length!=0) { 93 for (int i=0; i<rules.length; i++) { 94 String strWhere = new UsedByLink().getWhereClause(vars,"",rules[i].filterclause); 95 try { 96 AlertManagementData[] data = AlertManagementData.select(this, strActiveFilter, strFixedFilter, 97 Utility.getContext(this, vars, "#User_Client", ""), 98 Utility.getContext(this, vars, "#User_Org", ""), 99 vars.getUser(), vars.getRole(), rules[i].adAlertruleId, 100 strWhere); 101 102 if (data==null || data.length==0) 103 rules[i].display = "none"; 104 else 105 for (int j=0; j<data.length; j++) { 106 data[j].url = FormatUtilities.replace(data[j].windowname) + "/" + FormatUtilities.replace(data[j].tabname) + "_Edition.html"; 107 data[j].columnname = "inp"+Sqlc.TransformaNombreColumna(data[j].columnname); 108 } 109 alerts[i] = data; 110 } catch (Exception ex) { 111 log4j.error("Error in Alert Query, alertRule="+rules[i].adAlertruleId+" error:"+ex.toString()); 112 } 113 } 114 } 115 116 117 xmlDocument.setParameter("adAlertruleId", strAlertRuleId); 118 126 127 xmlDocument.setData("reportAD_ALERTRULE","liststructure", AlertManagementData.selectComboAlertRules(this, vars.getLanguage(),vars.getUser(), vars.getRole())); 128 129 xmlDocument.setData("structure1", rules); 130 xmlDocument.setDataArray("reportAlertManagement","structure2", alerts); 131 xmlDocument.setParameter("active",strActiveFilter); 132 xmlDocument.setParameter("fixed",strFixedFilter); 133 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 134 xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 135 136 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "AlertManagement", false, "", "", "",false, "ad_forms", strReplaceWith, false, true); 137 toolbar.prepareSimpleSaveToolBarTemplate(); 138 xmlDocument.setParameter("toolbar", toolbar.toString()); 139 140 try { 142 KeyMap key = new KeyMap(this, vars, "AlertManagement.html"); 143 xmlDocument.setParameter("keyMap", key.getActionButtonKeyMaps()); 144 } catch (Exception ex) { 145 throw new ServletException(ex); 146 } 147 try { 148 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_forms.AlertManagement"); 149 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 150 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 151 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 152 xmlDocument.setParameter("theme", vars.getTheme()); 153 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "AlertManagement.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 154 xmlDocument.setParameter("navigationBar", nav.toString()); 155 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "AlertManagement.html", strReplaceWith); 156 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 157 } catch (Exception ex) { 158 throw new ServletException(ex); 159 } 160 { 161 OBError myMessage = vars.getMessage("AlertManagement"); 162 vars.removeMessage("AlertManagement"); 163 if (myMessage!=null) { 164 xmlDocument.setParameter("messageType", myMessage.getType()); 165 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 166 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 167 } 168 } 169 170 172 out.println(xmlDocument.print()); 173 out.close(); 174 } 175 176 } 177 178 | Popular Tags |