Search in sources :

Example 31 with WebSessionCtx

use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.

the class RequestServlet method doGet.

/**
	 * 	Process Get Request
	 *	@param request
	 *	@param response
	 *	@throws ServletException
	 *	@throws IOException
	 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String l_szRequestID = null;
    HttpSession sess = request.getSession(true);
    sess.setMaxInactiveInterval(WebEnv.TIMEOUT);
    ctx = getCtx();
    if (sess.getAttribute("ctx") != null)
        ctx = (Properties) sess.getAttribute("ctx");
    WebSessionCtx wsc = (WebSessionCtx) sess.getAttribute(WebSessionCtx.NAME);
    //	Create New Request
    if (wsc != null) {
        String mode = WebUtil.getParameter(request, "Mode");
        if (mode != null && mode.equals("RequestNew")) {
            l_szRequestID = Request.createRequest(request, ctx);
        } else if (mode != null && mode.equals("RequestChange")) {
            l_szRequestID = Request.changeRequest(request, ctx);
        }
    }
    String url = request.getParameter("ForwardTo") + l_szRequestID;
    if (!url.startsWith("/"))
        url = "/" + url;
    response.sendRedirect(url);
}
Also used : HttpSession(javax.servlet.http.HttpSession) Properties(java.util.Properties) WebSessionCtx(org.compiere.util.WebSessionCtx)

Example 32 with WebSessionCtx

use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.

the class WReport method copyFormat.

//	createNewFormat
/**
	 * 	Copy existing Format
	 * 	@param AD_PrintFormat_ID print format
	 * 	@param To_Client_ID to client
	 */
private File copyFormat(int AD_PrintFormat_ID, int To_Client_ID, HttpServletRequest request, GridTab m_curTab, MQuery m_query) {
    WebSessionCtx wsc = WebSessionCtx.get(request);
    MPrintFormat pf = MPrintFormat.copyToClient(wsc.ctx, AD_PrintFormat_ID, To_Client_ID);
    File file = launchReport(pf, request, m_curTab, m_query);
    return file;
}
Also used : MPrintFormat(org.compiere.print.MPrintFormat) WebSessionCtx(org.compiere.util.WebSessionCtx) File(java.io.File)

Example 33 with WebSessionCtx

use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.

the class WReport method getPrintFormats.

//  doPost
/**
	 * 	Get the Print Formats for the table.
	 *  Fill the list and the popup menu
	 * 	@param AD_Table_ID table
	 *  @param invoker component to display popup (optional)
	 */
private File getPrintFormats(int AD_Table_ID, HttpServletRequest request, GridTab m_curTab, MQuery m_query) {
    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    int AD_Client_ID = Env.getAD_Client_ID(wsc.ctx);
    File file = null;
    m_list = new ArrayList<KeyNamePair>();
    //
    String sql = MRole.getDefault().addAccessSQL("SELECT AD_PrintFormat_ID, Name, AD_Client_ID " + "FROM AD_PrintFormat " + "WHERE AD_Table_ID=? AND IsTableBased='Y' " + //	Own First
    "ORDER BY AD_Client_ID DESC, IsDefault DESC, Name", "AD_PrintFormat", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    KeyNamePair pp = null;
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_Table_ID);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
            if (rs.getInt(3) == AD_Client_ID) {
                m_list.add(pp);
            //m_popup.add(pp.toString()).addActionListener(this);
            }
        }
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
    //	No Format exists - create it
    if (m_list.size() == 0) {
        if (pp == null)
            //	calls launch
            file = createNewFormat(AD_Table_ID, request, m_curTab, m_query);
        else
            file = copyFormat(pp.getKey(), AD_Client_ID, request, m_curTab, m_query);
    } else
        //	One Format exists or no invoker - show it
        //else if (m_list.size() == 1 || invoker == null)
        file = launchReport((KeyNamePair) m_list.get(0), request, m_curTab, m_query);
    //m_popup.show(invoker, 0, invoker.getHeight());	//	below button
    return file;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair) WebSessionCtx(org.compiere.util.WebSessionCtx) File(java.io.File)

Example 34 with WebSessionCtx

use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.

the class WReport method createNewFormat.

//	getPrintFormats
/**
	 * 	Create and Launch new Format for table
	 * 	@param AD_Table_ID table
	 */
private File createNewFormat(int AD_Table_ID, HttpServletRequest request, GridTab m_curTab, MQuery m_query) {
    WebSessionCtx wsc = WebSessionCtx.get(request);
    MPrintFormat pf = MPrintFormat.createFromTable(wsc.ctx, AD_Table_ID);
    File file = launchReport(pf, request, m_curTab, m_query);
    return file;
}
Also used : MPrintFormat(org.compiere.print.MPrintFormat) WebSessionCtx(org.compiere.util.WebSessionCtx) File(java.io.File)

Example 35 with WebSessionCtx

use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.

the class WReport method doGet.

//  init
/**
	 * Process the HTTP Get request
	 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.fine("doGet");
    log.info(response.toString());
    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    m_curTab = ws.curTab;
    //
    WebDoc doc = null;
    File file = null;
    if (ws == null) {
        doc = WebDoc.createPopup("No Context");
        doc.addPopupClose(wsc.ctx);
    } else /**else if (fileName!=null)
		{			
			int AD_PInstance_ID = WebUtil.getParameterAsInt(request, "AD_PInstance_ID");
			File file = new File (fileName);
			String error = WebUtil.streamFile(response, file);
			if (error == null)
				return;
			doc = WebDoc.createWindow(error);
		}**/
    {
        log.info("");
        if (!MRole.getDefault().isCanReport(ws.curTab.getAD_Table_ID())) {
            doc = WebDoc.createPopup("Access Cannot Report");
            doc.addPopupClose(wsc.ctx);
        }
        //	Query
        MQuery query = new MQuery(m_curTab.getTableName());
        //	Link for detail records
        String queryColumn = m_curTab.getLinkColumnName();
        //	Current row otherwise
        if (queryColumn.length() == 0)
            queryColumn = m_curTab.getKeyColumnName();
        //	Find display
        String infoName = null;
        String infoDisplay = null;
        for (int i = 0; i < m_curTab.getFieldCount(); i++) {
            GridField field = m_curTab.getField(i);
            if (field.isKey())
                infoName = field.getHeader();
            if ((field.getColumnName().equals("Name") || field.getColumnName().equals("DocumentNo")) && field.getValue() != null)
                infoDisplay = field.getValue().toString();
            if (infoName != null && infoDisplay != null)
                break;
        }
        if (queryColumn.length() != 0) {
            if (queryColumn.endsWith("_ID"))
                query.addRestriction(queryColumn, MQuery.EQUAL, new Integer(Env.getContextAsInt(wsc.ctx, m_curTab.getWindowNo(), queryColumn)), infoName, infoDisplay);
            else
                query.addRestriction(queryColumn, MQuery.EQUAL, Env.getContext(wsc.ctx, m_curTab.getWindowNo(), queryColumn), infoName, infoDisplay);
        }
        file = getPrintFormats(m_curTab.getAD_Table_ID(), request, m_curTab, query);
        String error = WebUtil.streamFile(response, file);
        if (error == null)
            return;
        doc = WebDoc.createWindow(error);
    }
    //
    WebUtil.createResponse(request, response, this, null, doc, false);
}
Also used : WebDoc(org.compiere.util.WebDoc) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) WebSessionCtx(org.compiere.util.WebSessionCtx) File(java.io.File)

Aggregations

WebSessionCtx (org.compiere.util.WebSessionCtx)38 WebDoc (org.compiere.util.WebDoc)21 File (java.io.File)13 HttpSession (javax.servlet.http.HttpSession)11 SQLException (java.sql.SQLException)8 Properties (java.util.Properties)6 MPrintFormat (org.compiere.print.MPrintFormat)6 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ServletException (javax.servlet.ServletException)4 GridField (org.compiere.model.GridField)4 org.apache.ecs.xhtml.body (org.apache.ecs.xhtml.body)3 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)3 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)3 org.apache.ecs.xhtml.td (org.apache.ecs.xhtml.td)3 ReportEngine (org.compiere.print.ReportEngine)3 ProcessInfo (org.compiere.process.ProcessInfo)3 KeyNamePair (org.compiere.util.KeyNamePair)3 Trx (org.compiere.util.Trx)3