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);
}
use of org.compiere.model.MAttachment in project adempiere by adempiere.
the class Scheduler method runProcess.
// doWork
/**
* Run Process or Report
* @param process process
* @return summary
* @throws Exception
*/
private String runProcess(MProcess process) throws Exception {
log.info(process.toString());
boolean isReport = (process.isReport() || process.getAD_ReportView_ID() > 0);
// Process (see also MWFActivity.performWork
int AD_Table_ID = m_model.getAD_Table_ID();
int Record_ID = m_model.getRecord_ID();
//
MPInstance pInstance = new MPInstance(process, Record_ID);
fillParameter(pInstance);
//
ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID(), AD_Table_ID, Record_ID);
pi.setAD_User_ID(getAD_User_ID());
pi.setAD_Client_ID(m_model.getAD_Client_ID());
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
MUser from = new MUser(getCtx(), pi.getAD_User_ID(), null);
if (// note, this call close the transaction, don't use m_trx below
!process.processIt(pi, m_trx)) {
// notify supervisor if error
int supervisor = m_model.getSupervisor_ID();
if (supervisor > 0) {
MUser user = new MUser(getCtx(), supervisor, null);
boolean email = user.isNotificationEMail();
boolean notice = user.isNotificationNote();
if (email || notice)
ProcessInfoUtil.setLogFromDB(pi);
if (email) {
MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID());
client.sendEMail(from, user, process.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
}
if (notice) {
// HARDCODED ProcessRunError
int AD_Message_ID = 442;
MNote note = new MNote(getCtx(), AD_Message_ID, supervisor, null);
note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
note.setTextMsg(pi.getSummary());
//note.setDescription();
note.setRecord(MPInstance.Table_ID, pi.getAD_PInstance_ID());
note.saveEx();
}
}
} else {
// notify recipients on success
Integer[] userIDs = m_model.getRecipientAD_User_IDs();
if (userIDs.length > 0) {
ProcessInfoUtil.setLogFromDB(pi);
for (int i = 0; i < userIDs.length; i++) {
MUser user = new MUser(getCtx(), userIDs[i].intValue(), null);
boolean email = user.isNotificationEMail();
boolean notice = user.isNotificationNote();
File report = null;
if (isReport) {
// Report
ReportEngine re = ReportEngine.get(m_schedulerctx, pi);
if (re == null)
return "Cannot create Report AD_Process_ID=" + process.getAD_Process_ID() + " - " + process.getName();
report = re.getPDF();
}
if (notice) {
// ProcessOK
int AD_Message_ID = 441;
if (isReport)
// HARDCODED SchedulerResult
AD_Message_ID = 884;
MNote note = new MNote(getCtx(), AD_Message_ID, userIDs[i].intValue(), null);
note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
if (isReport) {
note.setTextMsg(m_model.getName());
note.setDescription(m_model.getDescription());
note.setRecord(AD_Table_ID, Record_ID);
} else {
note.setTextMsg(pi.getSummary());
// note.setDescription();
note.setRecord(MPInstance.Table_ID, pi.getAD_PInstance_ID());
}
if (note.save()) {
if (isReport) {
// Attachment
MAttachment attachment = new MAttachment(getCtx(), MNote.Table_ID, note.getAD_Note_ID(), null);
attachment.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
attachment.addEntry(report);
attachment.setTextMsg(m_model.getName());
attachment.saveEx();
}
}
}
if (email) {
MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID());
if (isReport) {
client.sendEMail(from, user, m_model.getName(), m_model.getDescription(), report);
} else {
client.sendEMail(from, user, process.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
}
}
}
}
}
return pi.getSummary();
}
use of org.compiere.model.MAttachment in project adempiere by adempiere.
the class AlertProcessor method notifyUsers.
// processAlert
/**
* Notify users
* @param users AD_User_ID list
* @param subject email subject
* @param message email message
* @param attachments
* @return how many email were sent
*/
private int notifyUsers(Collection<Integer> users, String subject, String message, Collection<File> attachments) {
int countMail = 0;
for (int user_id : users) {
MUser user = MUser.get(getCtx(), user_id);
if (user.isNotificationEMail()) {
if (m_client.sendEMailAttachments(user_id, subject, message, attachments)) {
countMail++;
}
}
if (user.isNotificationNote()) {
Trx trx = null;
try {
trx = Trx.get(Trx.createTrxName("AP_NU"), true);
// Notice
int AD_Message_ID = 52244;
/* TODO - Hardcoded message=notes */
MNote note = new MNote(getCtx(), AD_Message_ID, user_id, trx.getTrxName());
note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
note.setTextMsg(message);
note.saveEx();
// Attachment
MAttachment attachment = new MAttachment(getCtx(), MNote.Table_ID, note.getAD_Note_ID(), trx.getTrxName());
for (File f : attachments) {
attachment.addEntry(f);
}
attachment.setTextMsg(message);
attachment.saveEx();
countMail++;
trx.commit();
} catch (Throwable e) {
if (trx != null)
trx.rollback();
} finally {
if (trx != null)
trx.close();
}
}
}
return countMail;
}
Aggregations