KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_actionButton > InsertAcces


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) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

19 package org.openbravo.erpCommon.ad_actionButton;
20
21 import org.openbravo.erpCommon.utility.Utility;
22 import org.openbravo.erpCommon.utility.KeyMap;
23 import org.openbravo.erpCommon.utility.OBError;
24 import org.openbravo.utils.FormatUtilities;
25 import org.openbravo.base.secureApp.HttpSecureAppServlet;
26 import org.openbravo.base.secureApp.VariablesSecureApp;
27 import org.openbravo.xmlEngine.XmlDocument;
28 import java.io.*;
29 import javax.servlet.*;
30 import javax.servlet.http.*;
31
32 import org.openbravo.erpCommon.ad_combos.ModuleComboData;
33
34 public class InsertAcces extends HttpSecureAppServlet {
35   
36
37   public void init (ServletConfig config) {
38     super.init(config);
39     boolHist = false;
40   }
41
42   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
43     VariablesSecureApp vars = new VariablesSecureApp(request);
44
45     if (vars.commandIn("DEFAULT")) {
46       String JavaDoc strProcessId = vars.getStringParameter("inpProcessId");
47       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
48       String JavaDoc strTab = vars.getStringParameter("inpTabId");
49       String JavaDoc strKey = vars.getStringParameter("inpadRoleId");
50       String JavaDoc strMessage="";
51       printPage(response, vars, strKey, strWindow, strProcessId, strMessage, strTab);
52     } else if(vars.commandIn("GENERATE")){
53       String JavaDoc strKey = vars.getStringParameter("inpadRoleId");
54       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
55       vars.setSessionValue(strWindow + "|AD_Role_ID", strKey);
56       String JavaDoc strTab = vars.getStringParameter("inpTabId");
57       String JavaDoc strModule = vars.getStringParameter("inpModules");
58       String JavaDoc strType = vars.getStringParameter("inpType");
59       ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab);
60       String JavaDoc strWindowPath="", strTabName="";
61       if (tab!=null && tab.length!=0) {
62         strTabName = FormatUtilities.replace(tab[0].name);
63         strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html";
64       } else strWindowPath = strDefaultServlet;
65       String JavaDoc messageResult = getPrintPage(response, vars, strKey, strModule,strType);
66       vars.setSessionValue(strWindow + "|" + strTabName + ".message", messageResult);
67       printPageClosePopUp(response, vars, strWindowPath);
68     } else pageErrorPopUp(response);
69     
70
71   }
72
73
74   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc windowId, String JavaDoc strProcessId, String JavaDoc strMessage, String JavaDoc strTab)
75     throws IOException, ServletException {
76       if (log4j.isDebugEnabled()) log4j.debug("Output: Button insert acces");
77       ActionButtonDefaultData[] data = null;
78       String JavaDoc strHelp="", strDescription="";
79       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
80       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
81       if (data!=null && data.length!=0) {
82         strDescription = data[0].description;
83         strHelp = data[0].help;
84       }
85       String JavaDoc[] discard = {""};
86       if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
87       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/InsertAcces", discard).createXmlDocument();
88       xmlDocument.setParameter("key", strKey);
89       xmlDocument.setParameter("window", windowId);
90       xmlDocument.setParameter("tab", strTab);
91       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
92       xmlDocument.setData("reportModules_S","liststructure", ModuleComboData.select(this));
93       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\r\n");
94       xmlDocument.setParameter("description", strDescription);
95       xmlDocument.setParameter("help", strHelp);
96       xmlDocument.setParameter("message",strMessage.equals("")?"":"alert('" + strMessage + "');");
97
98       try {
99         KeyMap key = new KeyMap(this, vars, "InsertAcces.html");
100         xmlDocument.setParameter("keyMap", key.getActionButtonKeyMaps());
101       } catch (Exception JavaDoc ex) {
102         throw new ServletException(ex);
103       }
104       {
105         OBError myMessage = vars.getMessage("InsertAcces");
106         vars.removeMessage("InsertAcces");
107         if (myMessage!=null) {
108           xmlDocument.setParameter("messageType", myMessage.getType());
109           xmlDocument.setParameter("messageTitle", myMessage.getTitle());
110           xmlDocument.setParameter("messageMessage", myMessage.getMessage());
111         }
112       }
113       response.setContentType("text/html; charset=UTF-8");
114       PrintWriter out = response.getWriter();
115       out.println(xmlDocument.print());
116       out.close();
117     }
118
119   String JavaDoc getPrintPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strModule, String JavaDoc strType) throws IOException, ServletException {
120     try{
121     InsertAccesData[] accesData = InsertAccesData.select(this);
122     generateAcces(vars, accesData, strKey, strModule,strType);
123       return Utility.messageBD(this, "ProcessOK", vars.getLanguage());
124     } catch (Exception JavaDoc e) {
125       log4j.warn(e);
126       return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
127     }
128   }
129
130
131   public void generateAcces(VariablesSecureApp vars, InsertAccesData[] accesData, String JavaDoc roleid, String JavaDoc indice, String JavaDoc strType) throws ServletException {
132     log4j.error("longitud accesdata: " +accesData.length + " indice: " + indice + " roleid: " + roleid);
133     for (int i=0;i<accesData.length;i++) {
134       if (accesData[i].parentId.equals(indice)) {
135         if (accesData[i].issummary.equals("Y")) generateAcces(vars, accesData, roleid, accesData[i].nodeId, strType);
136         else {
137           if (accesData[i].action.equals("W") && InsertAccesData.selectWindow(this, roleid, accesData[i].adwindowid)==null && (strType.equals("W") || strType.equals(""))){
138               log4j.error("Action: " + accesData[i].action + " window: " + accesData[i].adwindowid);
139               InsertAccesData.insertWindow(this, accesData[i].adwindowid, roleid, vars.getClient(), vars.getOrg(), vars.getUser());
140           } else if (accesData[i].action.equals("P") && InsertAccesData.selectProcess(this, roleid, accesData[i].adprocessid)==null && (strType.equals("P") || strType.equals(""))) {
141               log4j.error("Action: " + accesData[i].action + " process: " + accesData[i].adprocessid);
142               InsertAccesData.insertProcess(this, accesData[i].adprocessid, roleid, vars.getClient(), vars.getOrg(), vars.getUser());
143           } else if (accesData[i].action.equals("R") && InsertAccesData.selectProcess(this, roleid, accesData[i].adprocessid)==null && (strType.equals("R") || strType.equals(""))) {
144               log4j.error("Action: " + accesData[i].action + " report: " + accesData[i].adprocessid);
145               InsertAccesData.insertProcess(this, accesData[i].adprocessid, roleid, vars.getClient(), vars.getOrg(), vars.getUser());
146           } else if (accesData[i].action.equals("X") && InsertAccesData.selectForm(this, roleid, accesData[i].adformid)==null && (strType.equals("X") || strType.equals(""))) {
147               log4j.error("Action: " + accesData[i].action + " form: " + accesData[i].adformid);
148               InsertAccesData.insertForm(this, accesData[i].adformid, roleid, vars.getClient(), vars.getOrg(), vars.getUser());
149           } else if (accesData[i].action.equals("F") && InsertAccesData.selectWorkflow(this, roleid, accesData[i].adworkflowid)==null && (strType.equals("F") || strType.equals(""))) {
150               log4j.error("Action: " + accesData[i].action + " workflow: " + accesData[i].adworkflowid);
151               InsertAccesData.insertWorkflow(this, accesData[i].adworkflowid, roleid, vars.getClient(), vars.getOrg(), vars.getUser());
152           } else if (accesData[i].action.equals("T") && InsertAccesData.selectTask(this, roleid, accesData[i].adtaskid)==null && (strType.equals("T") || strType.equals(""))) {
153               log4j.error("Action: " + accesData[i].action + " task: " + accesData[i].adtaskid);
154               InsertAccesData.insertTask(this, accesData[i].adtaskid, roleid, vars.getClient(), vars.getOrg(), vars.getUser());
155           }
156         }
157       }
158     }
159   }
160
161   public String JavaDoc getServletInfo() {
162     return "Servlet for the application's roles and permissions generation.";
163     // Servlet created by Galder
164
} // end of getServletInfo() method
165
}
166
167
168
Popular Tags