use of org.compiere.util.WebUser in project adempiere by adempiere.
the class InfoLinkTag method doStartTag.
// setOneLine
/**
* Start Tag
* @return SKIP_BODY
* @throws JspException
*/
public int doStartTag() throws JspException {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
// creates wsc/wu
Properties ctx = JSPEnv.getCtx(request);
WebSessionCtx wsc = WebSessionCtx.get(request);
//
HttpSession session = pageContext.getSession();
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
if (wu != null && wu.isLoggedIn()) {
if (ctx != null) {
WebInfo info = (WebInfo) session.getAttribute(WebInfo.NAME);
if (info == null || wu.getAD_User_ID() != info.getAD_User_ID()) {
info = new WebInfo(ctx, wu);
session.setAttribute(WebInfo.NAME, info);
}
}
//
// log.fine("WebUser exists - " + wu);
//
JspWriter out = pageContext.getOut();
HtmlCode html = new HtmlCode();
//
if (wu.isCustomer() || wu.isVendor())
menuBPartner(html, wsc.wstore);
if (wu.isSalesRep())
menuSalesRep(html, wsc.wstore);
if (wu.isEmployee() || wu.isSalesRep())
menuUser(html, wu.isEmployee(), wsc.wstore);
menuAll(html, wsc.wstore);
//
html.output(out);
} else {
if (CLogMgt.isLevelFiner())
log.fine("No WebUser");
if (session.getAttribute(WebInfo.NAME) == null)
session.setAttribute(WebInfo.NAME, WebInfo.getGeneral());
}
return (SKIP_BODY);
}
use of org.compiere.util.WebUser in project adempiere by adempiere.
the class NoteServlet method streamAttachment.
// doGet
/**
* Stream Attachment
* @param request request
* @param response response
* @return "" or error message
*/
private String streamAttachment(HttpServletRequest request, HttpServletResponse response) {
// Get Note ID
int AD_Note_ID = WebUtil.getParameterAsInt(request, P_Note_ID);
if (AD_Note_ID == 0) {
log.fine("No AD_Note_ID)");
return "No Notice ID";
}
int attachmentIndex = WebUtil.getParameterAsInt(request, P_ATTACHMENT_INDEX);
if (attachmentIndex == 0) {
log.fine("No index)");
return "No Request Attachment index";
}
log.info("AD_Notice_ID=" + AD_Note_ID + " / " + attachmentIndex);
// Get Note
Properties ctx = JSPEnv.getCtx(request);
MNote doc = new MNote(ctx, AD_Note_ID, null);
if (doc.getAD_Note_ID() != AD_Note_ID) {
log.fine("Note not found - ID=" + AD_Note_ID);
return "Notice not found";
}
MAttachment attachment = doc.getAttachment(false);
if (attachment == null) {
log.fine("No Attachment for AD_Note_ID=" + AD_Note_ID);
return "Notice Attachment not found";
}
// Get WebUser & Compare with invoice
HttpSession session = request.getSession(true);
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
if (wu.getAD_User_ID() != doc.getAD_User_ID()) {
log.warning("AD_Note_ID=" + AD_Note_ID + " - User_ID=" + doc.getAD_User_ID() + " = Web_User=" + wu.getAD_User_ID());
return "Your Notice not found";
}
// Stream it
return WebUtil.streamAttachment(response, attachment, attachmentIndex);
}
use of org.compiere.util.WebUser in project adempiere by adempiere.
the class PaymentServlet method doPost.
// doGet
/**
* Process the HTTP Post request.
* The actual payment processing
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("Post from " + request.getRemoteHost() + " - " + request.getRemoteAddr());
Properties ctx = JSPEnv.getCtx(request);
HttpSession session = request.getSession(true);
// WEnv.dump(session);
// WEnv.dump(request);
// Web User/Payment
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
MPayment p = (MPayment) session.getAttribute(ATTR_PAYMENT);
WebOrder wo = (WebOrder) session.getAttribute(WebOrder.NAME);
String url = null;
if (wu == null || p == null)
url = "/index.jsp";
else if (processPayment(request, ctx, p, wu, wo))
url = "/confirm.jsp";
else
url = "/paymentInfo.jsp";
log.info("Forward to " + url);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
use of org.compiere.util.WebUser in project adempiere by adempiere.
the class PaymentServlet method doGet.
// destroy
/**************************************************************************
* Process the initial HTTP Get request.
* Reads the Parameter Amt and optional C_Invoice_ID
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("Get from " + request.getRemoteHost() + " - " + request.getRemoteAddr());
Properties ctx = JSPEnv.getCtx(request);
HttpSession session = request.getSession(true);
session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
// WEnv.dump(session);
// WEnv.dump(request);
// Non existing user or Existing Web Payment
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
MPayment p = (MPayment) session.getAttribute(ATTR_PAYMENT);
if (wu == null) {
log.info("No User");
String url = "/index.jsp";
log.info("Forward to " + url);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
// Remove any open Order
session.removeAttribute(WebOrder.NAME);
// Payment Amount
String amtParam = WebUtil.getParameter(request, "Amt");
if (amtParam == null || amtParam.length() == 0) {
log.info("No Payment Amount (" + amtParam + ")");
doPost(request, response);
return;
}
char[] chars = amtParam.toCharArray();
StringBuffer sb = new StringBuffer();
boolean decimal = false;
for (int i = chars.length - 1; i >= 0; i--) {
char c = chars[i];
if (c == ',' || c == '.') {
if (!decimal) {
sb.insert(0, '.');
decimal = true;
}
} else if (Character.isDigit(c))
sb.insert(0, c);
}
BigDecimal amt = null;
try {
if (sb.length() > 0) {
amt = new BigDecimal(sb.toString());
// make it positive
amt = amt.abs();
}
} catch (Exception ex) {
log.warning("Parsing Amount=" + amtParam + " (" + sb + ") - " + ex.toString());
}
// Need to be positive amount
if (amt == null || amt.compareTo(Env.ZERO) < 0) {
log.info("No valid Payment Amount (" + amtParam + ") - " + amt);
doPost(request, response);
return;
}
String invoiceParam = WebUtil.getParameter(request, "C_Invoice_ID");
int C_Invoice_ID = 0;
try {
if (invoiceParam != null)
C_Invoice_ID = Integer.parseInt(invoiceParam);
} catch (NumberFormatException ex) {
log.warning("Parsing C_Invoice_ID=" + invoiceParam + " - " + ex.toString());
}
log.info("Amt=" + amt + ", C_Invoice_ID=" + C_Invoice_ID);
// Create New Payment for Amt & optional Invoice
// see OrderServlet.createPayment
p = new MPayment(ctx, 0, null);
// p.setAD_Org_ID(..);
p.setIsSelfService(true);
// for CC selection ges default from Acct Currency
p.setAmount(0, amt);
p.setIsOnline(true);
// Sales CC Trx
p.setC_DocType_ID(true);
p.setTrxType(MPayment.TRXTYPE_Sales);
p.setTenderType(MPayment.TENDERTYPE_CreditCard);
// Payment Info
p.setC_Invoice_ID(C_Invoice_ID);
// BP Info
p.setBP_BankAccount(wu.getBankAccount());
//
// p.saveEx();
session.setAttribute(ATTR_PAYMENT, p);
String url = "/paymentInfo.jsp";
log.info("Forward to " + url);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
use of org.compiere.util.WebUser in project adempiere by adempiere.
the class PriceListTag method doStartTag.
// setM_PriceList_ID
/**
* Start Tag
* @return SKIP_BODY
* @throws JspException
*/
public int doStartTag() throws JspException {
// Create Price List
Properties ctx = JSPEnv.getCtx((HttpServletRequest) pageContext.getRequest());
int AD_Client_ID = Env.getContextAsInt(ctx, "AD_Client_ID");
int M_PriceList_ID = m_priceList_ID;
if (M_PriceList_ID == 0)
M_PriceList_ID = Env.getContextAsInt(ctx, "M_PriceList_ID");
// Check Business Partner
WebUser wu = (WebUser) pageContext.getSession().getAttribute(WebUser.NAME);
if (wu != null) {
int PriceList_ID = wu.getM_PriceList_ID();
if (PriceList_ID != 0) {
log.fine("- using BP PriceList_ID=" + PriceList_ID);
M_PriceList_ID = PriceList_ID;
}
}
// Get Parameters
String searchString = ctx.getProperty(ProductServlet.P_SEARCHSTRING);
String productCategory = ctx.getProperty(ProductServlet.P_M_PRODUCT_CATEGORY_ID);
// get price list
m_priceList = PriceList.get(ctx, AD_Client_ID, M_PriceList_ID, searchString, productCategory, false);
if (M_PriceList_ID == 0)
Env.setContext(ctx, "#M_PriceList_ID", m_priceList.getPriceList_ID());
// Set Price List
HttpSession session = pageContext.getSession();
session.setAttribute(PriceList.NAME, m_priceList);
log.fine("PL=" + m_priceList);
// Set Locale from Price List
String AD_Language = m_priceList.getAD_Language();
if (AD_Language == null || AD_Language.length() == 0)
AD_Language = "en_US";
Config.set(session, Config.FMT_LOCALE, AD_Language);
Config.set(session, Config.FMT_FALLBACK_LOCALE, "en_US");
//
return (SKIP_BODY);
}
Aggregations