use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.
the class WZoom method createPage.
// doPost
/**
* Create Attachment Page
* @param ctx context
* @param AD_Attachment_ID id for existing attachment
* @param AD_Table_ID table for new attachment
* @param Record_ID record for new attachment
* @param error optional error message
* @return WebDoc
*/
public static WebDoc createPage(Properties ctx, HttpServletRequest request, int AD_Record_ID, int AD_Table_ID) {
//WebDoc doc = WebDoc.createPopup (Msg.translate(ctx, "AD_Attachment_ID"));
WebDoc doc = null;
String TableName = null;
int AD_Window_ID = 0;
int PO_Window_ID = 0;
String sql = "SELECT TableName, AD_Window_ID, PO_Window_ID FROM AD_Table WHERE AD_Table_ID=?";
try {
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Table_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
TableName = rs.getString(1);
AD_Window_ID = rs.getInt(2);
PO_Window_ID = rs.getInt(3);
}
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
}
if (TableName == null || AD_Window_ID == 0) {
doc = WebDoc.createPopup("No Context");
doc.addPopupClose(ctx);
return doc;
}
// PO Zoom ?
boolean isSOTrx = true;
if (PO_Window_ID != 0) {
String whereClause = TableName + "_ID=" + AD_Record_ID;
isSOTrx = DB.isSOTrx(TableName, whereClause);
if (!isSOTrx)
AD_Window_ID = PO_Window_ID;
}
/**
* New Window data
*/
WWindowStatus ws = WWindowStatus.get(request);
HttpSession sess = request.getSession();
WebSessionCtx wsc = WebSessionCtx.get(request);
if (ws != null) {
int WindowNo = ws.mWindow.getWindowNo();
log.fine("Disposing - WindowNo=" + WindowNo + ", ID=" + ws.mWindow.getAD_Window_ID());
ws.mWindow.dispose();
Env.clearWinContext(wsc.ctx, WindowNo);
}
GridWindowVO mWindowVO = GridWindowVO.create(ctx, s_WindowNo++, AD_Window_ID, 0);
if (mWindowVO == null) {
String msg = Msg.translate(ctx, "AD_Window_ID") + " " + Msg.getMsg(ctx, "NotFound") + ", ID=" + AD_Window_ID + "/" + 0;
doc = WebDoc.createPopup(msg);
doc.addPopupClose(ctx);
return doc;
}
// Create New Window
ws = new WWindowStatus(mWindowVO);
sess.setAttribute(WWindowStatus.NAME, ws);
// Query
ws.mWindow.initTab(ws.curTab.getTabNo());
ws.curTab.setQuery(MQuery.getEqualQuery(TableName + "_ID", AD_Record_ID));
ws.curTab.query(false);
return doc;
}
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);
}
use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.
the class WReport method launchReport.
// launchReport
/**
* Launch Report
* @param pf print format
*/
private File launchReport(MPrintFormat pf, HttpServletRequest request, GridTab m_curTab, MQuery m_query) {
int Record_ID = 0;
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
//Instance pInstance = new MPInstance (wsc.ctx, 0, 0);
File fileName = null;
if (m_query.getRestrictionCount() == 1 && m_query.getCode(0) instanceof Integer) {
Record_ID = ((Integer) m_query.getCode(0)).intValue();
}
PrintInfo info = new PrintInfo(pf.getName(), pf.getAD_Table_ID(), Record_ID);
info.setDescription(m_query.getInfo());
if (pf != null && pf.getJasperProcess_ID() > 0) {
// It's a report using the JasperReports engine
ProcessInfo pi = new ProcessInfo("", pf.getJasperProcess_ID());
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
// Execute Process
WProcessCtl.process(this, m_curTab.getAD_Window_ID(), pi, trx, request);
} else {
// It's a default report using the standard printing engine
ReportEngine re = new ReportEngine(wsc.ctx, pf, m_query, info);
if (re == null) {
log.info("Could not start ReportEngine");
} else {
try {
File file = File.createTempFile("WProcess", ".pdf");
boolean ok = re.createPDF(file);
if (ok) {
fileName = file;
} else {
log.info("Could not create Report");
}
} catch (Exception e) {
log.info(e.toString());
}
}
}
return fileName;
}
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;
}
use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.
the class WValuePreference method doGet.
// init
/**
* Process the HTTP Get request.
* Initial Call
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Get Session attributes
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
if (wsc == null) {
WebUtil.createTimeoutPage(request, response, this, null);
return;
}
if (ws == null) {
WebUtil.createTimeoutPage(request, response, this, null);
return;
}
String m_UpdateResult = "";
WebDoc doc = null;
//Get/Set Parameter
m_ctx = wsc.ctx;
m_AD_Window_ID = WebUtil.getParameterAsInt(request, "AD_Window_ID");
m_AD_Client_ID = WebUtil.getParameterAsInt(request, "AD_Client_ID");
m_AD_Org_ID = WebUtil.getParameterAsInt(request, "AD_Org_ID");
m_AD_User_ID = WebUtil.getParameterAsInt(request, "AD_User_ID");
m_Attribute = WebUtil.getParameter(request, "Attribute");
m_DisplayAttribute = WebUtil.getParameter(request, "DisplayAtrribute");
m_Value = WebUtil.getParameter(request, "Value");
m_DisplayValue = WebUtil.getParameter(request, "DisplayValue");
m_DisplayType = WebUtil.getParameterAsInt(request, "DisplayType");
m_role = MRole.getDefault(wsc.ctx, false);
m_Client = false;
m_User = false;
m_Window = false;
m_Org = false;
doc = createParameterPage(ws, wsc, request, m_UpdateResult);
WebUtil.createResponse(request, response, this, null, doc, false);
}
Aggregations