use of org.compiere.model.MAttachment 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.model.MAttachment in project adempiere by adempiere.
the class WorkflowServlet method streamAttachment.
// doGet
/**
* Stream Attachment
* @param request request
* @param response response
* @return "" or error message
*/
private String streamAttachment(HttpServletRequest request, HttpServletResponse response) {
// Get Activity ID
int AD_WF_Activity_ID = WebUtil.getParameterAsInt(request, P_WF_Activity_ID);
if (AD_WF_Activity_ID == 0) {
log.fine("streamAttachment - no AD_WF_Activity_ID)");
return "No Activity ID";
}
int attachmentIndex = WebUtil.getParameterAsInt(request, P_ATTACHMENT_INDEX);
if (attachmentIndex == 0) {
log.fine("streamAttachment - no index)");
return "No Request Attachment index";
}
log.info("streamAttachment - AD_WF_Activity_ID=" + AD_WF_Activity_ID + " / " + attachmentIndex);
// Get Note
Properties ctx = JSPEnv.getCtx(request);
MWFActivity doc = new MWFActivity(ctx, AD_WF_Activity_ID, null);
if (doc.get_ID() != AD_WF_Activity_ID) {
log.fine("streamAttachment - Activity not found - ID=" + AD_WF_Activity_ID);
return "Activity not found";
}
MAttachment attachment = doc.getAttachment(false);
if (attachment == null) {
log.fine("streamAttachment - No Attachment for AD_WF_Activity_ID=" + AD_WF_Activity_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("streamAttachment - AD_WF_Activity_ID=" + AD_WF_Activity_ID + " - User_Activity=" + doc.getAD_User_ID() + " = Web_User=" + wu.getAD_User_ID());
return "Your Activity not found";
}
// Stream it
return WebUtil.streamAttachment(response, attachment, attachmentIndex);
}
use of org.compiere.model.MAttachment 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.MAttachment 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.MAttachment in project adempiere by adempiere.
the class WAttachment method doGet.
/**
* Process the HTTP Get request.
* Initial display and streaming
* @param request request
* @param response response
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr());
HttpSession session = request.getSession(false);
WWindowStatus ws = WWindowStatus.get(request);
WebDoc doc = null;
if (session == null || ws == null) {
doc = WebDoc.createPopup("No Context");
//Modified by Rob Klein 4/29/07
doc.addPopupClose(ws.ctx);
} else {
m_error = null;
int AD_Attachment_ID = WebUtil.getParameterAsInt(request, P_Attachment_ID);
if (AD_Attachment_ID != 0) {
int attachmentIndex = WebUtil.getParameterAsInt(request, P_ATTACHMENT_INDEX);
if (attachmentIndex != 0) {
m_error = streamAttachment(AD_Attachment_ID, attachmentIndex, response, ws);
if (m_error == null)
return;
}
}
MAttachment attachment = null;
if (AD_Attachment_ID != 0)
attachment = new MAttachment(ws.ctx, ws.curTab.getAD_AttachmentID(), null);
else
attachment = new MAttachment(ws.ctx, ws.curTab.getAD_Table_ID(), ws.curTab.getRecord_ID(), null);
doc = createPage(ws.ctx, attachment, m_error);
}
//
WebUtil.createResponse(request, response, this, null, doc, false);
}
Aggregations