📄 inboxmanagerejb.java
字号:
/** * The method sets the image loader for the inner images. * @param ls logon session object * @param inboxMessage message object * @return true */ public boolean setImageAttachmentLoader(LogonSession ls, InboxMessage inboxMessage) { // check if the attachements have alrready saved if (!inboxMessage.isAttachmentSaved()) { saveAttachment(ls, inboxMessage); } // if (!inboxMessage.isAttachmentSaved()) Set attachments = inboxMessage.getAttachmentIDsList().keySet(); // RE to find '<img' inside HTML body RE re; try { re = new RE(InboxHelper.IMAGE_PATTERN_INCOM, RE.MATCH_CASEINDEPENDENT); } catch (RESyntaxException ex) { ERROR(ex); throw new GenericSystemException(ex); } // try // Main cycle. int pos = 0; //body = body.toUpperCase(); String newBody = inboxMessage.getBody(); while (re.match(newBody, pos)) { // .. next start position pos = re.getParenEnd(0); // .. get image fullname (href) attribute String srcName = re.getParen(1); // Try to find the same attachment among temp attachments. // Process the attachments list. for (Iterator it = attachments.iterator(); it.hasNext();) { Long attachId = (Long)it.next(); String fileName = (String)inboxMessage.getAttachmentIDsList().get(attachId); srcName = InboxHelper.getContentId(srcName); if (fileName.indexOf(srcName) > -1) { int start = re.getParenStart(1); int end = re.getParenEnd(1); newBody = newBody.substring(0, start) + InboxHelper.SERVLET_UPLOAD_NAME + inboxMessage.getProcessId() + InboxHelper.SERVLET_UPLOAD_FILENAME + fileName + newBody.substring(end); break; } // if (fileName.indexOf(srcName) > -1) } // for (Iterator it = bodyAttachments.iterator(); it.hasNext();) } // while (re.match(body, pos)) inboxMessage.setBody(newBody); return true; } // setImageAttachmentLoader(LogonSession, InboxMessage) : boolean /** * The method sets the image loader for the inner images. * @param ls logon session object * @param inboxMessage message object * @return true */ public boolean changeReferenceHTMLATAG(LogonSession ls, InboxMessage inboxMessage) { INFO("Change <a> html tag ..."); // RE to find '<img' inside HTML body RE re; try { re = new RE(InboxHelper.TAG_A_PATTERN, RE.MATCH_CASEINDEPENDENT); } catch(RESyntaxException ex) { ERROR(ex); throw new GenericSystemException(ex); } // try // Main cycle. int pos = 0; String newBody = inboxMessage.getBody(); while (re.match(newBody, pos)) { // .. next start position pos = re.getParenEnd(0); int end = re.getParenEnd(1); newBody = newBody.substring(0, end + 1) + InboxHelper.TAG_A_TARGET + newBody.substring(end +1); } // while (re.match(body, pos)) inboxMessage.setBody(newBody); return true; } // changeReferenceHTMLATAG(LogonSession, InboxMessage) : boolean // // Gets the JEO Manager EJB local interface. // public JEOManagerLocal getJEOManager() { return (JEOManagerLocal)getLocalObject(JNDINames.JEOManager, JEOManagerLocalHome.class); } // getJEOManager() : JEOManagerLocal /** * The method deletes temp attachments from the DB. * @param ls logon session object * @param inboxMessage message object */ public void deleteTempAttachment(LogonSession ls, InboxMessage inboxMessage) { INFO("Delete temp attachments..."); if (inboxMessage.getProcessId() != null) { long processId = inboxMessage.getProcessId().longValue(); AttachmentManagerLocal attachMgr = getAttachmentManager(); // Clear temp attachments. attachMgr.deleteTempAttachments(ls, processId); } INFO("Temp attachments were deleted..."); } // deleteTempAttachment(LogonSession, InboxMessage) /** * The method saves attachments to the DB. * @param ls logon session object * @param inboxMessage message object * @return true */ public boolean saveAttachment(LogonSession ls, InboxMessage inboxMessage) { INFO("Save message attachments..."); boolean returnValue; if (inboxMessage.getProcessId() != null) { if (!inboxMessage.isAttachmentSaved()) { long processId = inboxMessage.getProcessId().longValue(); AttachmentManagerLocal attachMgr = getAttachmentManager(); // Create normal attachments from temp. HashMap attachmentsId = attachMgr.addAttachments(ls, processId); inboxMessage.setAttachmentIDsList(attachmentsId); // Clear temp attachments. //attachMgr.deleteTempAttachments(ls, processId); returnValue = true; INFO("The attachments were saved."); } else { returnValue = true; INFO("The attachments have already saved."); } // if (!inboxMessage.isAttachmentSaved()) inboxMessage.setIsAttachmentSaved(true); } else { returnValue = true; } // if (message.getProcessId() != null) return returnValue; } // saveAttachment(LogonSession, InboxMessage) : boolean /** * The method links attachments to the object. * @param ls logon session object * @param inboxMessage message object * @return true */ public boolean linkAttachmentsToObject(LogonSession ls, InboxMessage inboxMessage) { return linkAttachmentsToObject(ls, inboxMessage, false, null); } // linkAttachmentsToObject(LogonSession, InboxMessage) : boolean /** * The method links attachments to the object. * @param ls logon session object * @param inboxMessage message object * @return true */ public boolean setReplyDateToInbox(LogonSession ls, InboxMessage inboxMessage) { INFO("Update Inbox Record, set the Replied Date field ..."); // try to find the lastest message by the object JEOManagerLocal jeoManager = getJEOManager(); long time = System.currentTimeMillis(); Exception error = null; boolean returnValue = false; try { List inboxHandList = InboxObjectHandler.selectByLinkObj(jeoManager, ls, inboxMessage.getObjectId().longValue(), inboxMessage.getObjectType()); // check if the message exist if (inboxHandList == null) { returnValue = true; } else { // get the latest record InboxObjectHandler inboxHndRecord = (InboxObjectHandler)inboxHandList.get(0); InboxObject inboxObject = (InboxObject)inboxHndRecord.getJEObject(); inboxObject.setReplied_date(DateHelper.getNowDate()); inboxHndRecord.commit(); } } catch (Exception ex) { error = ex; } // try // Logging. try { if (error != null) { String logMessage = "The Inbox Record wasn't updated: " + error.getMessage(); InboxLogPublisher publisher = new InboxLogPublisher(ls); publisher.ERROR(logMessage, inboxMessage); ERROR(logMessage, error); throw error; } else { String logMessage = "The Inbox Record was updated. The object ID is " + inboxMessage.getObjectId().longValue() + " The object type is " + inboxMessage.getObjectType(); INFO(logMessage + " Time (ms) - " + (System.currentTimeMillis() - time) + ". Message: " + inboxMessage); InboxLogPublisher publisher = new InboxLogPublisher(ls); publisher.INFO(logMessage, inboxMessage); returnValue = true; } // if (error != null) } catch(Exception ex){ // Re-throwing the exception. throwException("Known exception: " + ex.getMessage(), ex); } // try INFO("Update Inbox Record, the Replied Date field was set ..."); return returnValue; } // setReplyDateToInbox(LogonSession, InboxMessage) : boolean // ------------------------------------------------------- Private methods // // Saves the mail message in the mail store database table. // private void saveMail(LogonSession ls, InboxMessage inboxMessage) { // Initialization. JEOManagerLocal jeoManager = getJEOManager(); // Go! try { // 1. Saving message. // ================== JEObjectHandler hnd = jeoManager.create(ls, InboxObjectHandler.class); InboxObject obj = (InboxObject)hnd.getJEObject(); // Message ID. Long messageID = inboxMessage.getMessageId(); if (messageID == null) { // Generate new message ID. messageID = new Long(getUniqueMessageID()); // Update message object. inboxMessage.setMessageId(messageID); } // if (messageID == null) // 'From'. if (inboxMessage.getResipient() == null && inboxMessage.getWorkgroupId() == null) { throw new NullPointerException("The message wasn't saved. The Recipient or Worgroup field should be filled in."); } // if (message.getFrom() == null) // Sender ID. obj.setMessage_sender(inboxMessage.getSender()); // Owner ID. obj.setRecipient_id(inboxMessage.getResipient()); // Workgroup ID. obj.setWorkgroup_id(inboxMessage.getWorkgroupId()); // Linked object. obj.setObject_id(inboxMessage.getObjectId()); obj.setObject_type(inboxMessage.getObjectType()); if (inboxMessage.getFrom() != null) { obj.setMessage_sender_email(inboxMessage.getFrom().toRfcString()); } if (inboxMessage.getTo() != null) { obj.setEmail_to(MailAddress.toRfcString(inboxMessage.getTo())); } // if (message.getTo() != null) // 'Cc'. if (inboxMessage.getCc() != null) { obj.setEmail_cc(MailAddress.toRfcString(inboxMessage.getCc())); } // if (message.getCc() != null) // Mail subject. obj.setSubject(inboxMessage.getSubject()); // Mail body. String body = inboxMessage.getBody(); if (body != null) { obj.setMessage(body.toCharArray()); if (inboxMessage.getMessageDigest() != null && inboxMessage.getMessageDigest().length() > 0) obj.setDigest_src(inboxMessage.getMessageDigest()); } // if (body != null) // Process ID.. if (inboxMessage.getProcessId() != null) { obj.setProcess_id(inboxMessage.getProcessId()); } obj.setMessage_type(inboxMessage.getMessageType()); // Sent Date. obj.setSent_date(inboxMessage.getSentTime()); // Received Date. if (inboxMessage.getMessageType().compareTo(Integer.valueOf(InboxHelper.EMAIL_MESSAGE)) == 0) { obj.setServer_received_date(inboxMessage.getReceiveTime()); obj.setReceived_date(DateHelper.getNowDate()); } else { if (inboxMessage.getReceiveTime() == null) obj.setReceived_date(DateHelper.getNowDate()); else obj.setReceived_date(inboxMessage.getReceiveTime()); } // Account ID. if (inboxMessage.getAccountId() != null) { obj.setAccount_id(inboxMessage.getAccountId()); } // Adding the message record. hnd.commit(); // 2. Handling attachments. // ======================== if (inboxMessage.getProcessId() != null) { linkAttachmentsToObject(ls, inboxMessage, true, obj.getPkey()); } } catch(EQLException ex) { throwException(ex); } // try } // saveMail(LogonSession, InboxMessage) /** * The method links attachments to the object. * @param ls logon session object * @param inboxMessage message object * @param isInboxMessage save link for the inbox message * @param inboxId record inbox indetificator * @return true */ private boolean linkAttachmentsToObject(LogonSession ls, InboxMessage inboxMessage, boolean isInboxMessage, Long inboxId) { INFO("Link attachments to the object..."); boolean returnValue = false; // check if the attachements have alrready saved if (!inboxMessage.isAttachmentSaved()) { saveAttachment(ls, inboxMessage); } // if (!inboxMessage.isAttachmentSaved()) // Initialization. JEOManagerLocal jeoManager = getJEOManager(); Integer objectType; Long objectId; if (isInboxMessage) { objectType = inboxMessage.getMessageObjectType(); objectId = inboxId; } else { objectType = inboxMessage.getObjectType(); objectId = inboxMessage.getObjectId(); } // create attachement links to the object try { Set attachmentIDsList = inboxMessage.getAttachmentIDsList().keySet(); if (attachmentIDsList != null) { for (Iterator it = attachmentIDsList.iterator(); it.hasNext();) { Long attachId = (Long)it.next(); JEObjectHandler hnd = jeoManager.create(ls, AttachmentObjectsObjectHandler.class); AttachmentObjectsObject attachObj = (AttachmentObjectsObject)hnd.getJEObject(); attachObj.setAttachment_id(attachId); attachObj.setObject_id(objectId); attachObj.setObject_type(objectType.intValue()); hnd.commit(); } // for (Iterator it = attachmentIDsList.iterator(); it.hasNext();) } else { INFO("Link attachments wasn't set. The Attachments list wasn't found."); } // if (attachmentIDsList != null) } catch(EQLException ex) { throwException(ex); } // try INFO("Link attachments to the object were created..."); return returnValue; } // linkAttachmentsToObject(LogonSession, InboxMessage, boolean) : boolean // // Gets Attachment Manager EJB reference. // private AttachmentManagerLocal getAttachmentManager() { return (AttachmentManagerLocal)getLocalObject(JNDINames.AttachmentManager, AttachmentManagerLocalHome.class); }} // class InboxManagerEJB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -