KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_forms > AlertManagement


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2007 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

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 JavaDoc strAlertRuleId=vars.getRequestGlobalVariable("inpAlertRule", "AlertManagement|AlertRule");
50       String JavaDoc strActiveFilter=vars.getStringParameter("inpActiveFilter","Y").equals("")?"N":"Y";
51       String JavaDoc strFixedFilter=vars.getRequestGlobalVariable("inpFixedFilter", "FixedFilter|AlertRule").equals("")?"N":"Y";
52       printPageDataSheet(response, vars, strAlertRuleId, strActiveFilter, strFixedFilter);
53     } else if (vars.commandIn("FIND")) {
54       String JavaDoc strAlertRuleId=vars.getRequestGlobalVariable("inpAlertRule", "AlertManagement|AlertRule");
55       String JavaDoc strActiveFilter=vars.getStringParameter("inpActiveFilter").equals("")?"N":"Y";
56       String JavaDoc 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 JavaDoc strAlertRuleId=vars.getRequestGlobalVariable("inpAlertRule", "AlertManagement|AlertRule");
61       String JavaDoc strActiveFilter=vars.getStringParameter("inpActiveFilter").equals("")?"N":"Y";
62       String JavaDoc 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 JavaDoc[] 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 JavaDoc note = vars.getStringParameter("strNotes"+strAlertId[i]);
73       String JavaDoc fixed = vars.getStringParameter("strFixed"+strAlertId[i]).equals("on")?"Y":"N";
74       String JavaDoc 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 JavaDoc strAlertRuleId, String JavaDoc strActiveFilter, String JavaDoc 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 JavaDoc 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 JavaDoc 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     /*try {
119       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_AlertRule_ID", "", "", Utility.getContext(this, vars, "#User_Org", "AlertManagement"), Utility.getContext(this, vars, "#User_Client", "AlertManagement"), 0);
120       Utility.fillSQLParameters(this, vars, null, comboTableData, "AlertManagement", strAlertRuleId);
121       xmlDocument.setData("reportAD_ALERTRULE","liststructure", comboTableData.select(false));
122       comboTableData = null;
123     } catch (Exception ex) {
124       throw new ServletException(ex);
125     }*/

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     // New interface paramenters
141
try {
142         KeyMap key = new KeyMap(this, vars, "AlertManagement.html");
143         xmlDocument.setParameter("keyMap", key.getActionButtonKeyMaps());
144       } catch (Exception JavaDoc 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 JavaDoc 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      ////----
171

172     out.println(xmlDocument.print());
173     out.close();
174   }
175
176 }
177
178
Popular Tags