1 16 package org.javabb.transaction; 17 18 import java.util.ArrayList ; 19 import java.util.HashMap ; 20 import java.util.List ; 21 import java.util.Map ; 22 23 import org.javabb.component.VelocityTemplate; 24 import org.javabb.dao.entity.IPrivMsgReciviedDAO; 25 import org.javabb.dao.entity.IPrivMsgSentDAO; 26 import org.javabb.infra.Configuration; 27 import org.javabb.infra.Constants; 28 import org.javabb.infra.Email; 29 import org.javabb.vo.PrivMsg; 30 import org.javabb.vo.PrivMsgRecivied; 31 import org.javabb.vo.PrivMsgSent; 32 import org.javabb.vo.User; 33 34 38 39 public class PrivMsgTransaction extends Transaction { 40 41 private IPrivMsgReciviedDAO _privMsgReciviedDAO = null; 42 43 private IPrivMsgSentDAO _privMsgSentDAO = null; 44 45 private UserTransaction _userTransaction; 46 47 public PrivMsgTransaction() { 48 } 49 50 public void setPrivMsgReciviedDAO(IPrivMsgReciviedDAO privMsgReciviedDAO) { 51 this._privMsgReciviedDAO = privMsgReciviedDAO; 52 } 53 54 public void setPrivMsgSentDAO(IPrivMsgSentDAO privMsgSentDAO) { 55 this._privMsgSentDAO = privMsgSentDAO; 56 } 57 58 public void setUserTransaction(UserTransaction userTransaction) { 59 _userTransaction = userTransaction; 60 } 61 62 public List getUserInbox(User u) throws Exception { 63 return _privMsgReciviedDAO.retrieveUserInbox(u); 64 } 65 66 public int countMsgByUser(User u) throws Exception { 67 if(u != null && u.getIdUser() != null){ 68 return _privMsgReciviedDAO.countMessagesByUser(u); 69 }else { 70 return 0; 71 } 72 73 } 74 75 public List getUserOutbox(User u) throws Exception { 76 return _privMsgSentDAO.retrieveUserOutbox(u); 77 } 78 79 public Long send(PrivMsg p) throws Exception { 80 Long mpId = _privMsgReciviedDAO.save(new PrivMsgRecivied(p)); 81 _privMsgSentDAO.save(new PrivMsgSent(p)); 82 return mpId; 83 } 84 85 public void deleteSent(PrivMsg p) throws Exception { 86 _privMsgSentDAO.delete((PrivMsgSent) p); 87 } 88 89 public void deleteRecivied(PrivMsg p) throws Exception { 90 _privMsgReciviedDAO.delete((PrivMsgRecivied) p); 91 } 92 93 public PrivMsg loadSent(PrivMsg p) throws Exception { 94 return _privMsgSentDAO.load(p.getId()); 95 } 96 97 public PrivMsg loadRecivied(PrivMsg p) throws Exception { 98 PrivMsgRecivied _p = _privMsgReciviedDAO.load(p.getId()); 99 _p.setRead(new Integer (1)); 100 return _p; 101 } 102 103 public void deleteSelectedInbox(List list) throws Exception { 104 if (list != null && list.size() > 0) 105 _privMsgReciviedDAO.delete(list); 106 } 107 108 public void deleteSelectedOutbox(List list) throws Exception { 109 if (list != null && list.size() > 0) 110 _privMsgSentDAO.delete(list); 111 } 112 113 public List asPrivMsgList(Long [] id) { 114 List l = new ArrayList (); 115 for (int i = 0; i < id.length; i++) 116 l.add(new PrivMsg(id[i])); 117 return l; 118 } 119 120 public void delegateMail(String message_18n,Long idUserTo, Long mpId) throws Exception { 121 User usr = _userTransaction.getUser(idUserTo); 123 String mailUser = usr.getEmail(); 124 sendMailToUser(message_18n, mpId, mailUser); 125 } 126 127 134 private void sendMailToUser(String message_18n, Long pmId, String userMail) throws Exception { 135 Configuration conf = new Configuration(); 137 138 Map mailMap = new HashMap (); 139 mailMap.put("conf", conf); 140 mailMap.put("pm_message", message_18n); 141 mailMap.put("pmId", pmId); 142 143 String template = VelocityTemplate.makeTemplate(mailMap, Constants.mpMailTemplate); 144 145 Email.sendMail(conf.adminMail, userMail, conf.forumName, template, 146 true); 147 } 148 149 }
| Popular Tags
|