/** * 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; }