1 19 package org.openbravo.erpCommon.ad_actionButton; 20 21 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 import java.sql.Connection ; 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 strProcessId = vars.getStringParameter("inpProcessId"); 49 String strWindow = vars.getStringParameter("inpwindowId"); 50 String strTab = vars.getStringParameter("inpTabId"); 51 String strProjectType = vars.getStringParameter("inpcProjecttypeId", ""); 52 String 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 strWindow = vars.getStringParameter("inpwindowId"); 57 String strProjectType = vars.getStringParameter("inpcProjecttypeId"); 58 String strKey = vars.getRequestGlobalVariable("inpcProjectId", strWindow + "|C_Project_ID"); 59 String strTab = vars.getStringParameter("inpTabId"); 60 ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab); 61 String 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 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 processButton(VariablesSecureApp vars, String strKey, String strProjectType, String windowId) { 74 Connection conn = null; 75 try { 76 conn = this.getTransactionConnection(); 77 ProjectSetTypeData[] data = ProjectSetTypeData.select(this, strProjectType); 78 ProjectSetTypeData[] dataProject = ProjectSetTypeData.selectProject(this, strKey); 79 String strProjectPhase = ""; 80 String 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 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 e) { 96 try { 97 releaseRollbackConnection(conn); 98 } catch (Exception 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 strKey, String strProjectType, String windowId, String strTab, String strProcessId) 107 throws IOException, ServletException { 108 if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Project set Type"); 109 110 ActionButtonDefaultData[] data = null; 111 String 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 [] discard = {""}; 120 if (strHelp.equals("")) discard[0] = new String ("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 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 getServletInfo() { 149 return "Servlet Project set Type"; 150 } } 152 153 | Popular Tags |