use of org.compiere.model.MRequest in project adempiere by adempiere.
the class WebInfo method getRequest.
// getRequests
/**
* Get Request.
* Needs to have ID set first; Check that it is owned / created by requestor
* @return invoice of BP with ID
*/
public MRequest getRequest() {
m_infoMessage = null;
MRequest retValue = null;
String sql = "SELECT * FROM R_Request " + "WHERE R_Request_ID=?" + " AND (C_BPartner_ID=?" + " OR SalesRep_ID IN (SELECT AD_User_ID FROM AD_User WHERE C_BPartner_ID=?))";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_id);
pstmt.setInt(2, getC_BPartner_ID());
pstmt.setInt(3, getC_BPartner_ID());
rs = pstmt.executeQuery();
if (rs.next())
retValue = new MRequest(m_ctx, rs, null);
} catch (Exception e) {
log.log(Level.SEVERE, "R_Request_ID=" + m_id, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
log.fine("R_Request_ID=" + m_id + " - " + retValue);
return retValue;
}
use of org.compiere.model.MRequest in project adempiere by adempiere.
the class RequestServlet 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 {
String contentType = request.getContentType();
log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr() + " - " + contentType);
// 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");
if (!response.isCommitted())
// entry
response.sendRedirect("loginServlet?ForwardTo=request.jsp");
return;
}
if (contentType != null && contentType.indexOf("multipart/form-data") != -1) {
uploadFile(request, response);
return;
}
// Addl Info
String requestURL = request.getRequestURL().toString();
String requestRef = request.getHeader("referer");
String source = WebUtil.getParameter(request, P_SOURCE);
String info = WebUtil.getParameter(request, P_INFO);
String forwardTo = WebUtil.getParameter(request, P_FORWARDTO);
log.fine("Referer=" + requestRef + ", Source=" + source + ", ForwardTo=" + forwardTo);
if (requestURL == null)
requestURL = "";
if (// if URL and Referrer are the same, get source
requestURL.equals(requestRef)) {
requestRef = source;
source = null;
}
int AD_Client_ID = Env.getContextAsInt(ctx, "AD_Client_ID");
int R_RequestType_ID = WebUtil.getParameterAsInt(request, P_REQUESTTYPE_ID);
int C_Order_ID = WebUtil.getParameterAsInt(request, P_REF_ORDER_ID);
int R_Request_ID = WebUtil.getParameterAsInt(request, P_REQUEST_ID);
int SalesRep_ID = WebUtil.getParameterAsInt(request, P_SALESREP_ID);
if (SalesRep_ID != 0 && !MUser.isSalesRep(SalesRep_ID)) {
log.warning("Invalid (set to 0) SalesRep_ID=" + SalesRep_ID);
SalesRep_ID = 0;
}
// The text
String Summary = WebUtil.getParameter(request, P_SUMMARY);
if (Summary == null || Summary.length() == 0) {
WebUtil.createErrorPage(request, response, this, "No Data Received");
return;
}
boolean IsConfidential = WebUtil.getParameterAsBoolean(request, P_CONFIDENTIAL);
boolean IsClose = WebUtil.getParameterAsBoolean(request, P_CLOSE);
boolean IsEscalate = WebUtil.getParameterAsBoolean(request, P_ESCALATE);
MRequest req = null;
// New SelfService Request
if (R_Request_ID == 0) {
req = new MRequest(ctx, SalesRep_ID, R_RequestType_ID, Summary, true, null);
req.setC_BPartner_ID(wu.getC_BPartner_ID());
req.setAD_User_ID(wu.getAD_User_ID());
if (C_Order_ID > 0)
req.setC_Order_ID(C_Order_ID);
if (IsConfidential)
req.setConfidentialType(MRequest.CONFIDENTIALTYPE_PartnerConfidential);
//
StringBuffer sb = new StringBuffer();
sb.append("From:").append(request.getRemoteHost()).append("-").append(request.getRemoteAddr());
sb.append(", Request:").append(requestURL).append("-").append(requestRef);
if (source != null)
sb.append("-").append(source);
sb.append("-").append(info);
sb.append(", User=").append(request.getHeader("accept-language")).append("-").append(request.getHeader("user-agent"));
req.setLastResult(sb.toString());
//
if (!req.save()) {
log.log(Level.SEVERE, "New Request NOT saved");
WebUtil.createErrorPage(request, response, this, "Request Save Error. Shorten Text!");
return;
}
} else // existing Request
{
req = new MRequest(ctx, R_Request_ID, null);
if (req.get_ID() == 0) {
log.log(Level.SEVERE, "Request NOT found - R_Request_ID=" + R_Request_ID);
WebUtil.createErrorPage(request, response, this, "Request Not found.");
return;
}
// Update Info
if (C_Order_ID != 0 && req.getC_Order_ID() == 0)
req.setC_Order_ID(C_Order_ID);
if (!req.webUpdate(Summary)) {
WebUtil.createErrorPage(request, response, this, "Request Cannot be updated.");
return;
}
// Flags
if (IsConfidential)
req.setConfidentialTypeEntry(MRequest.CONFIDENTIALTYPEENTRY_PartnerConfidential);
if (IsClose)
req.doClose();
else if (IsEscalate) {
boolean isUser = req.getC_BPartner_ID() == wu.getC_BPartner_ID();
if (// allow only user or sales rep to escalate
isUser || wu.isSalesRep())
req.doEscalate(isUser);
}
if (!req.save()) {
log.log(Level.SEVERE, "Request Action Error");
WebUtil.createErrorPage(request, response, this, "Request Process Error.");
return;
}
}
// Requests
// Send EMail to Customer
StringBuffer message = new StringBuffer(req.getSummary());
String result = req.getResult();
if (result != null && result.length() > 0)
message.append("\n----------\n").append(req.getResult());
JSPEnv.sendEMail(request, wu, MMailMsg.MAILMSGTYPE_Request, new Object[] { req.getDocumentNo(), wu.getName(), message, "\n---------- " + req.getMailTag() });
// -- Fini
String webStoreURL = "http://" + request.getServerName() + request.getContextPath() + "/";
if (forwardTo == null || forwardTo.length() == 0)
forwardTo = requestRef;
if (forwardTo != null && (forwardTo.indexOf("request.jsp") != -1 || forwardTo.indexOf("requestDetails.jsp") != -1))
// list of requests
forwardTo = "requests.jsp";
if (forwardTo == null || forwardTo.length() == 0)
forwardTo = webStoreURL;
if (forwardTo.indexOf("Servlet") != -1)
forwardTo = webStoreURL;
WebUtil.createForwardPage(response, "Web Request Received - Thanks", forwardTo, 10);
}
use of org.compiere.model.MRequest in project adempiere by adempiere.
the class RequestServlet method streamAttachment.
// doGet
/**
* Stream Attachment
* @param request request
* @param response response
* @return null or error message
*/
private String streamAttachment(HttpServletRequest request, HttpServletResponse response) {
// Get Request ID
int R_Request_ID = WebUtil.getParameterAsInt(request, P_REQUEST_ID);
if (R_Request_ID == 0) {
log.fine("No R_Request_ID)");
return "No Request ID";
}
int attachmentIndex = WebUtil.getParameterAsInt(request, P_ATTACHMENT_INDEX);
if (attachmentIndex == 0) {
log.fine("No index)");
return "No Request Attachment index";
}
log.info("R_Request_ID=" + R_Request_ID + " / " + attachmentIndex);
// Get Request
Properties ctx = JSPEnv.getCtx(request);
MRequest doc = new MRequest(ctx, R_Request_ID, null);
if (doc.getR_Request_ID() != R_Request_ID) {
log.fine("Request not found - R_Request_ID=" + R_Request_ID);
return "Request not found";
}
MAttachment attachment = doc.getAttachment(false);
if (attachment == null) {
log.fine("No Attachment for R_Request_ID=" + R_Request_ID);
return "Request 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() || wu.getAD_User_ID() == doc.getSalesRep_ID())
;
else {
log.warning("R_Request_ID=" + R_Request_ID + " Web_User=" + wu.getAD_User_ID() + " <> AD_User_ID=" + doc.getAD_User_ID() + " | SalesRep_ID=" + doc.getSalesRep_ID());
return "Your Request not found";
}
// Stream it
return WebUtil.streamAttachment(response, attachment, attachmentIndex);
}
use of org.compiere.model.MRequest in project adempiere by adempiere.
the class RequestServlet method uploadFile.
// doPost
/**
* Upload File
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
private void uploadFile(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
FileUpload upload = new FileUpload(request);
String error = upload.getError();
if (error != null) {
WebUtil.createForwardPage(response, error, "requests.jsp", 10);
return;
}
Properties ctx = JSPEnv.getCtx(request);
// Get Request:
int R_Request_ID = upload.getParameterAsInt("R_Request_ID");
MRequest req = null;
if (R_Request_ID != 0)
req = new MRequest(ctx, R_Request_ID, null);
if (R_Request_ID == 0 || req == null || req.get_ID() != R_Request_ID) {
WebUtil.createForwardPage(response, "Request not found", "requests.jsp", 10);
return;
}
if (!req.isWebCanUpdate()) {
WebUtil.createForwardPage(response, "Request cannot be updated", "requests.jsp", 10);
return;
}
String fileName = upload.getFileName();
log.fine("R_Request_ID=" + R_Request_ID + " - " + fileName);
// Add Attachment
MAttachment attachment = req.createAttachment();
attachment.addEntry(fileName, upload.getData());
if (attachment.save()) {
String msg = Msg.parseTranslation(ctx, "@Added@: @AD_Attachment_ID@ " + fileName);
req.webUpdate(msg);
req.saveEx();
WebUtil.createForwardPage(response, msg, "requests.jsp", 10);
} else
WebUtil.createForwardPage(response, "File Upload Error - Please try again", "requests.jsp", 10);
log.fine(attachment.toString());
}
use of org.compiere.model.MRequest in project adempiere by adempiere.
the class RequestProcessor method findSalesRep.
// processEMail
/**************************************************************************
* Allocate Sales Rep
*/
private void findSalesRep() {
int changed = 0;
int notFound = 0;
Properties ctx = new Properties();
//
String sql = "SELECT * FROM R_Request " + "WHERE AD_Client_ID=?" + " AND SalesRep_ID=0 AND Processed='N'";
if (m_model.getR_RequestType_ID() != 0)
sql += " AND R_RequestType_ID=?";
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_model.getAD_Client_ID());
if (m_model.getR_RequestType_ID() != 0)
pstmt.setInt(2, m_model.getR_RequestType_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
MRequest request = new MRequest(ctx, rs, null);
if (request.getSalesRep_ID() != 0)
continue;
int SalesRep_ID = findSalesRep(request);
if (SalesRep_ID != 0) {
request.setSalesRep_ID(SalesRep_ID);
request.saveEx();
changed++;
} else
notFound++;
}
rs.close();
} catch (SQLException ex) {
log.log(Level.SEVERE, sql, ex);
} finally {
DB.close(pstmt);
}
pstmt = null;
//
if (changed == 0 && notFound == 0)
m_summary.append("No unallocated Requests");
else
m_summary.append("Allocated SalesRep=").append(changed);
if (notFound > 0)
m_summary.append(",Not=").append(notFound);
m_summary.append(" - ");
}
Aggregations