KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.mail.smtp.SMTPMessage;
22
import org.openbravo.erpCommon.utility.SequenceIdData;
23 import org.openbravo.erpCommon.utility.Utility;
24 import org.openbravo.erpCommon.utility.ComboTableData;
25 import org.openbravo.utils.FormatUtilities;
26 import org.openbravo.base.secureApp.HttpSecureAppServlet;
27 import org.openbravo.base.secureApp.VariablesSecureApp;
28 import org.openbravo.xmlEngine.XmlDocument;
29 import java.io.*;
30 import javax.servlet.*;
31 import javax.servlet.http.*;
32
33 // imports for transactions
34
import java.sql.Connection JavaDoc;
35
36 public class ProjectSetType extends HttpSecureAppServlet {
37   
38
39   public void init (ServletConfig config) {
40     super.init(config);
41     boolHist = false;
42   }
43
44   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
45     VariablesSecureApp vars = new VariablesSecureApp(request);
46
47     if (vars.commandIn("DEFAULT")) {
48       String JavaDoc strProcessId = vars.getStringParameter("inpProcessId");
49       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
50       String JavaDoc strTab = vars.getStringParameter("inpTabId");
51       String JavaDoc strProjectType = vars.getStringParameter("inpcProjecttypeId", "");
52       String JavaDoc strKey = vars.getRequiredGlobalVariable("inpcProjectId", strWindow + "|C_Project_ID");
53       if (!ProjectSetTypeData.hasProjectType(this, strKey)) printPage(response, vars, strKey, strProjectType, strWindow, strTab, strProcessId);
54       else bdError(response, "ProjectSetTypeError", vars.getLanguage());
55     } else if (vars.commandIn("SAVE")) {
56       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
57       String JavaDoc strProjectType = vars.getStringParameter("inpcProjecttypeId");
58       String JavaDoc strKey = vars.getRequestGlobalVariable("inpcProjectId", strWindow + "|C_Project_ID");
59       String JavaDoc strTab = vars.getStringParameter("inpTabId");
60       ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab);
61       String JavaDoc strWindowPath="", strTabName="";
62       if (tab!=null && tab.length!=0) {
63         strTabName = FormatUtilities.replace(tab[0].name);
64         strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html";
65       } else strWindowPath = strDefaultServlet;
66       String JavaDoc messageResult = processButton(vars, strKey, strProjectType, strWindow);
67       vars.setSessionValue(strWindow + "|" + strTabName + ".message", messageResult);
68       printPageClosePopUp(response, vars, strWindowPath);
69     } else pageErrorPopUp(response);
70   }
71
72
73   String JavaDoc processButton(VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strProjectType, String JavaDoc windowId) {
74     Connection JavaDoc conn = null;
75     try {
76       conn = this.getTransactionConnection();
77       ProjectSetTypeData[] data = ProjectSetTypeData.select(this, strProjectType);
78       ProjectSetTypeData[] dataProject = ProjectSetTypeData.selectProject(this, strKey);
79       String JavaDoc strProjectPhase = "";
80       String JavaDoc strProjectTask = "";
81       for (int i=0;data!=null && i<data.length;i++){
82         strProjectPhase = SequenceIdData.getSequence(this, "C_ProjectPhase", dataProject[0].adClientId);
83         if (ProjectSetTypeData.insertProjectPhase(conn, this, strKey, dataProject[0].adClientId, dataProject[0].adOrgId, vars.getUser(), data[i].description, data[i].mProductId, data[i].cPhaseId, strProjectPhase, data[i].help, data[i].name, data[i].standardqty, data[i].seqno)==1){
84             ProjectSetTypeData[] data1 = ProjectSetTypeData.selectTask(this, data[i].cPhaseId);
85             for (int j=0;data1!=null && j<data1.length;j++){
86                 strProjectTask = SequenceIdData.getSequence(this, "C_ProjectTask", dataProject[0].adClientId);
87                 ProjectSetTypeData.insertProjectTask(conn, this,strProjectTask,data1[j].cTaskId, dataProject[0].adClientId, dataProject[0].adOrgId, vars.getUser(), data1[j].seqno, data1[j].name,data1[j].description, data1[j].help, data1[j].mProductId, strProjectPhase, data1[j].standardqty);
88             }
89         }
90       }
91       String JavaDoc strProjectCategory = ProjectSetTypeData.selectProjectCategory(this, strProjectType);
92       ProjectSetTypeData.update(conn, this, vars.getUser(), strProjectType, strProjectCategory, strKey);
93       releaseCommitConnection(conn);
94       return Utility.messageBD(this, "ProcessOK", vars.getLanguage());
95     } catch (Exception JavaDoc e) {
96       try {
97         releaseRollbackConnection(conn);
98       } catch (Exception JavaDoc ignored) {}
99       e.printStackTrace();
100       log4j.warn("Rollback in transaction");
101       return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
102     }
103   }
104
105
106   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strProjectType, String JavaDoc windowId, String JavaDoc strTab, String JavaDoc strProcessId)
107     throws IOException, ServletException {
108       if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Project set Type");
109
110       ActionButtonDefaultData[] data = null;
111       String JavaDoc strHelp="", strDescription="";
112       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
113       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
114
115       if (data!=null && data.length!=0) {
116         strDescription = data[0].description;
117         strHelp = data[0].help;
118       }
119       String JavaDoc[] discard = {""};
120       if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
121       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/ProjectSetType", discard).createXmlDocument();
122       xmlDocument.setParameter("key", strKey);
123       xmlDocument.setParameter("window", windowId);
124       xmlDocument.setParameter("tab", strTab);
125       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
126       xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage()));
127       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
128       xmlDocument.setParameter("description", strDescription);
129       xmlDocument.setParameter("help", strHelp);
130
131     try {
132       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_ProjectType_ID", "", "Project type service", Utility.getContext(this, vars, "#User_Org", ""), Utility.getContext(this, vars, "#User_Client", ""), 0);
133       Utility.fillSQLParameters(this, vars, null, comboTableData, "", strProjectType);
134       xmlDocument.setData("reportcProjecttypeId", "liststructure", comboTableData.select(false));
135       comboTableData = null;
136     } catch (Exception JavaDoc ex) {
137       throw new ServletException(ex);
138     }
139
140     xmlDocument.setParameter("cProjecttypeId", strProjectType);
141
142     response.setContentType("text/html; charset=UTF-8");
143     PrintWriter out = response.getWriter();
144     out.println(xmlDocument.print());
145     out.close();
146   }
147
148   public String JavaDoc getServletInfo() {
149     return "Servlet Project set Type";
150   } // end of getServletInfo() method
151
}
152
153
Popular Tags