use of org.compiere.util.WebUser in project adempiere by adempiere.
the class InfoServlet method processParameter.
// doPost
/**************************************************************************
* Process Parameter and check them
* @param request request
* @return true if processed
*/
private boolean processParameter(HttpServletRequest request) {
HttpSession session = request.getSession(true);
session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
Properties ctx = JSPEnv.getCtx(request);
// mode = subscribe
String mode = WebUtil.getParameter(request, "mode");
if (mode == null)
return false;
boolean subscribe = !mode.startsWith("un");
// area = 101
int R_InterestArea_ID = WebUtil.getParameterAsInt(request, "area");
MInterestArea ia = MInterestArea.get(ctx, R_InterestArea_ID);
// contact = -1
int AD_User_ID = WebUtil.getParameterAsInt(request, "contact");
//
log.fine("Subscribe=" + subscribe + ",R_InterestArea_ID=" + R_InterestArea_ID + ",AD_User_ID=" + AD_User_ID);
if (R_InterestArea_ID == 0 || AD_User_ID == 0)
return false;
//
MContactInterest ci = MContactInterest.get(ctx, R_InterestArea_ID, AD_User_ID, false, null);
ci.subscribe(subscribe);
boolean ok = ci.save();
if (ok)
log.fine("success");
else
log.log(Level.SEVERE, "subscribe failed");
// Lookup user if direct link
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
if (wu == null) {
wu = WebUser.get(ctx, AD_User_ID);
session.setAttribute(WebUser.NAME, wu);
}
sendEMail(request, wu, ia.getName(), subscribe);
return ok;
}
use of org.compiere.util.WebUser in project adempiere by adempiere.
the class UpdateServlet method doPost.
// doGet
/**
* Process the HTTP Post request
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("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);
org.compiere.util.WebLogin thisLogin = new org.compiere.util.WebLogin(request, response, ctx);
thisLogin.init();
thisLogin.setUpdate_page(UPDATE_JSP);
// Web User
WebUser wu = WebUser.get(request);
if (wu == null || (wu.getAD_User_ID() == 0) || (!wu.isLoggedIn())) {
WebUtil.reload("User not logged in", LOGIN_JSP, session, request, response, getServletContext());
return;
}
if (!thisLogin.action()) {
WebUtil.reload(thisLogin.getMessage(), thisLogin.getUpdate_page(), session, request, response, getServletContext());
return;
}
String url = thisLogin.getForward();
if (url == null || url.length() == 0)
url = "/";
session.setAttribute(WebUser.NAME, wu);
if (!url.startsWith("/"))
url = "/" + url;
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 WorkflowServlet method doPost.
// streamAttachment
/**************************************************************************
* Process the HTTP Post request.
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("doPost from " + request.getRemoteHost() + " - " + request.getRemoteAddr());
String url = "/notes.jsp";
//
// Log.setTraceLevel(9);
// WebEnv.dump(request);
//
HttpSession session = request.getSession(false);
if (session == null || session.getAttribute(WebInfo.NAME) == null)
url = "/login.jsp";
else {
session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
Properties ctx = JSPEnv.getCtx(request);
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
if (wu == null) {
log.warning("doPost - no web user");
if (!response.isCommitted())
// entry
response.sendRedirect("loginServlet?ForwardTo=note.jsp");
return;
}
// Get Feedback
int AD_WF_Activity_ID = WebUtil.getParameterAsInt(request, P_WF_Activity_ID);
boolean isConfirmed = WebUtil.getParameterAsBoolean(request, "IsConfirmed");
boolean isApproved = WebUtil.getParameterAsBoolean(request, "IsApproved");
boolean isRejected = WebUtil.getParameterAsBoolean(request, "IsApproved");
String textMsg = WebUtil.getParameter(request, "textMsg");
log.fine("doPost - TextMsg=" + textMsg);
//
MWFActivity act = new MWFActivity(ctx, AD_WF_Activity_ID, null);
log.fine("doPost - " + act);
if (AD_WF_Activity_ID == 0 || act == null || act.getAD_WF_Activity_ID() != AD_WF_Activity_ID)
session.setAttribute(WebSessionCtx.HDR_MESSAGE, "Activity not found");
else {
if (act.isUserApproval() && (isApproved || isRejected)) {
try {
act.setUserChoice(wu.getAD_User_ID(), isApproved ? "Y" : "N", DisplayType.YesNo, textMsg);
act.saveEx();
} catch (Exception e) {
}
} else // approval
if (act.isUserManual() && isConfirmed) {
act.setUserConfirmation(wu.getAD_User_ID(), textMsg);
act.saveEx();
} else if (textMsg != null && textMsg.length() > 0) {
act.setTextMsg(textMsg);
act.saveEx();
}
}
}
log.info("doGet - 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 AssetServlet method streamAsset.
// doPost
/**
* Stream asset
* @param request request
* @param response response
* @return "" or error message
*/
protected String streamAsset(HttpServletRequest request, HttpServletResponse response) {
// Get Asset ID
int A_Asset_ID = WebUtil.getParameterAsInt(request, "Asset_ID");
if (A_Asset_ID == 0) {
log.fine("No ID)");
return "No Asset ID";
}
byte[] assetInfo = String.valueOf(A_Asset_ID).getBytes();
// Get Asset
Properties ctx = JSPEnv.getCtx(request);
HttpSession session = request.getSession(true);
WebEnv.dump(request);
MAsset asset = new MAsset(ctx, A_Asset_ID, null);
if (asset.getA_Asset_ID() != A_Asset_ID) {
log.fine("Asset not found - ID=" + A_Asset_ID);
return "Asset not found";
}
// Get WebUser & Compare with invoice
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
if (wu.getC_BPartner_ID() != asset.getC_BPartner_ID()) {
log.warning("A_Asset_ID=" + A_Asset_ID + " - BP_Invoice=" + asset.getC_BPartner_ID() + " <> BP_User=" + wu.getC_BPartner_ID());
return "Your asset not found";
}
if (!asset.isDownloadable() || wu.isCreditStopHold() || !wu.isEMailVerified())
return "Asset not downloadable";
// Name & URL
String pd = WebUtil.getParameter(request, "PD");
String dl_name = null;
String dl_url = null;
InputStream in = null;
int M_ProductDownload_ID = 0;
if (pd != null && pd.length() > 0) {
MProductDownload[] pdls = asset.getProductDownloads();
if (pdls != null) {
for (int i = 0; i < pdls.length; i++) {
if (pdls[i].getDownloadURL().indexOf(pd) != -1) {
M_ProductDownload_ID = pdls[i].getM_ProductDownload_ID();
dl_name = pd;
dl_url = pdls[i].getDownloadURL();
in = pdls[i].getDownloadStream(ctx.getProperty(WebSessionCtx.CTX_DOCUMENT_DIR));
break;
}
}
}
}
log.fine(dl_name + " - " + dl_url);
if (dl_name == null || dl_url == null || in == null)
return "@NotFound@ @A_Asset_ID@: " + pd;
/**
Download SupportContract.pdf for Jorg Janke - jjanke@adempiere.org
Version = 120 - Lot = . - SerNo = .
Guarantee Date = 5/30/05
Thank you for using Adempiere Customer Asset Management
**/
String lot = asset.getLot();
if (lot == null || lot.length() == 0)
lot = ".";
String ser = asset.getSerNo();
if (ser == null || ser.length() == 0)
ser = ".";
Object[] args = new Object[] { dl_name, wu.getName() + " - " + wu.getEmail(), asset.getVersionNo(), lot, ser, asset.getGuaranteeDate() };
String readme = Msg.getMsg(ctx, "AssetDeliveryTemplate", args);
// Send File
MAssetDelivery ad = confirmDelivery(asset, request, wu.getAD_User_ID());
if (M_ProductDownload_ID != 0)
ad.setM_ProductDownload_ID(M_ProductDownload_ID);
ad.setDescription(dl_name);
//
float speed = 0;
try {
response.setContentType("application/zip");
response.setHeader("Content-Location", "asset.zip");
// response.setContentLength(length);
// 2k Buffer
int bufferSize = 2048;
response.setBufferSize(bufferSize);
//
log.fine(in + ", available=" + in.available());
long time = System.currentTimeMillis();
// Zip Output Stream
ServletOutputStream out = response.getOutputStream();
// Servlet out
ZipOutputStream zip = new ZipOutputStream(out);
zip.setMethod(ZipOutputStream.DEFLATED);
zip.setLevel(Deflater.BEST_COMPRESSION);
zip.setComment(readme);
// Readme File
ZipEntry entry = new ZipEntry("readme.txt");
entry.setExtra(assetInfo);
zip.putNextEntry(entry);
zip.write(readme.getBytes(), 0, readme.length());
zip.closeEntry();
// Payload
entry = new ZipEntry(dl_name);
entry.setExtra(assetInfo);
zip.putNextEntry(entry);
byte[] buffer = new byte[bufferSize];
int count = 0;
int totalSize = 0;
do {
// read delivery
count = in.read(buffer, 0, bufferSize);
if (count > 0) {
totalSize += count;
// write zip
zip.write(buffer, 0, count);
}
} while (count != -1);
zip.closeEntry();
// Fini
zip.finish();
zip.close();
in.close();
time = System.currentTimeMillis() - time;
speed = ((float) totalSize / 1024) / ((float) time / 1000);
String msg = (totalSize / 1024) + "kB - " + time + " ms - " + speed + " kB/sec";
log.fine(msg);
// Delivery Record
ad.setDeliveryConfirmation(msg);
ad.saveEx();
asset.saveEx();
} catch (IOException ex) {
String msg = ex.getMessage();
if (msg == null || msg.length() == 0)
msg = ex.toString();
log.warning(msg);
// Delivery Record
try {
if (msg.length() > 120)
msg = msg.substring(0, 119);
ad.setDeliveryConfirmation(msg);
ad.save();
// asset.saveEx(); not delivered
} catch (Exception ex1) {
log.log(Level.SEVERE, "2 - " + ex);
}
// nned to differentiate error message as response committed
return "** Streaming error; Please Retry";
}
//
return null;
}
use of org.compiere.util.WebUser in project adempiere by adempiere.
the class ExpenseServlet method doPost.
// doGet
/*************************************************************************/
/**
* Process the HTTP Post request
*
* @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());
// Get Session attributes
HttpSession session = request.getSession(true);
session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
//
Properties ctx = JSPEnv.getCtx(request);
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
if (wu == null) {
log.warning("No web user");
// entry
response.sendRedirect("loginServlet?ForwardTo=expense.jsp");
return;
}
int W_Expense_ID = WebUtil.getParameterAsInt(request, P_Expense_ID);
String method = WebUtil.getParameter(request, P_SubmitType_Name);
if (method.startsWith("Save")) {
// save BUT DON'T submit for approval
} else if (method.startsWith("Submit")) {
// save AND submit for approval
} else {
// invalid
}
WebUtil.createForwardPage(response, "Web Expense Under Construction", "expenses.jsp", 0);
}
Aggregations