⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inboxmanagerejb.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2006-2007 Queplix Corp. * * Licensed under the Queplix Public License, Version 1.1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.queplix.core.modules.inbox.ejb;import com.queplix.core.error.GenericSystemException;import com.queplix.core.modules.attachment.ejb.AttachmentManagerLocal;import com.queplix.core.modules.attachment.ejb.AttachmentManagerLocalHome;import com.queplix.core.modules.eql.error.EQLException;import com.queplix.core.modules.inbox.InboxHelper;import com.queplix.core.modules.inbox.InboxMessage;import com.queplix.core.modules.inbox.utils.db.DBRealmManager;import com.queplix.core.modules.inbox.utils.log.InboxLogPublisher;import com.queplix.core.modules.inbox.utils.log.OutboxLogPublisher;import com.queplix.core.modules.jeo.JEObjectHandler;import com.queplix.core.modules.jeo.ejb.JEOManagerLocal;import com.queplix.core.modules.jeo.ejb.JEOManagerLocalHome;import com.queplix.core.modules.jeo.gen.*;import com.queplix.core.modules.mail.MailAddress;import com.queplix.core.modules.mail.Attachment;import com.queplix.core.modules.mail.ejb.MailManagerLocal;import com.queplix.core.modules.mail.ejb.MailManagerLocalHome;import com.queplix.core.integrator.security.LogonSession;import com.queplix.core.utils.DateHelper;import com.queplix.core.utils.JNDINames;import com.queplix.core.utils.ejb.AbstractSessionEJB;import com.queplix.core.utils.sql.SqlWrapper;import com.queplix.core.utils.sql.SqlWrapperFactory;import javax.mail.MessagingException;import java.sql.Connection;import java.sql.SQLException;import java.util.*;import org.apache.regexp.RE;import org.apache.regexp.RESyntaxException;/** * The Inbox Manager EJB. * @author Konstantin Mironov * @since 8 Dec 2006 */public class InboxManagerEJB extends AbstractSessionEJB {    // ------------------------------------------------------- EJB API methods    /** Initializes bean. */    public void ejbCreate() {        INFO("InboxManager EJB created - " + hashCode());    }    // ------------------------------------------------------- Public methods    /**     * Generates new unique message ID.     * @return long     */    public long getUniqueMessageID() {        long id;        // SQL initialization.        String tableName = DBRealmManager.getSql("get_inbox_table");        SqlWrapper sqlWrapper = SqlWrapperFactory.getSqlWrapper();        Connection con = null;        try {            // Connecting.            con = sqlWrapper.doConnection();            // Get next unique ID from database.            id = sqlWrapper.getNextKey( con, tableName );        } catch( SQLException sqlex ) {            ERROR( sqlex );            throw new GenericSystemException( sqlex );        } finally {            sqlWrapper.closeConnection( con );        }        INFO( "Got unigue message ID = " + id );        return id;    }    /**     * Saves the mail message into <b>Inbox</b> folder.     * @param ls LogonSession     * @param message InboxMessage     * @return true     */    public boolean saveMailToInbox(LogonSession ls, InboxMessage message) {        long time = System.currentTimeMillis();        Exception error = null;        message.setMessageType(Integer.valueOf(InboxHelper.EMAIL_MESSAGE));        // save        try {            saveMail(ls, message);        } catch (Exception ex) {            error = ex;        }        // Logging.        try {            if (error != null) {                String logMessage = "Can't save the message: " + error.getMessage();                InboxLogPublisher publisher = new InboxLogPublisher(ls);                publisher.ERROR(logMessage, message);                ERROR(logMessage, error);                throw error;            } else {                String logMessage = "Message was saved to INBOX folder.";                INFO(logMessage + " Time (ms) - " + (System.currentTimeMillis() - time) + ". Message: " + message);                InboxLogPublisher publisher = new InboxLogPublisher(ls);                publisher.INFO(logMessage, message);            } // if (error != null)        } catch (Exception ex) {            // Re-throwing the exception.            throwException("Known exception: " + ex.getMessage(), ex);        } // try        return true;    } // saveMailToInbox(LogonSession, InboxMessage)    /**     * Saves the mail message into <b>Outbox</b> folder.     * @param ls LogonSession     * @param message InboxMessage     */    public void saveMailToOutbox(LogonSession ls, InboxMessage message) {        /*        long time = System.currentTimeMillis();        Exception error = null;        // Save!        try {            saveMail( ls, message, true, false );        } catch( Exception ex ) {            error = ex;        }        // Logging.        try {            if( error != null ) {                String logMessage = "Can't save the message: " + error.getMessage();                OutboxLogPublisher publisher = new OutboxLogPublisher( ls );                publisher.ERROR( logMessage, message );                ERROR( logMessage, error );                throw error;            } else {                String logMessage = "Message was saved to OUTBOX folder.";                INFO( logMessage + " Time (ms) - " + ( System.currentTimeMillis() - time ) +                      ". Message: " + message );                OutboxLogPublisher publisher = new OutboxLogPublisher( ls );                publisher.INFO( logMessage, message );            }        } catch( Exception ex ) {            // Re-throwing the exception.            throwException( "Known exception: " + ex.getMessage(), ex );        }        */    } // saveMailToOutbox()    /**     * Saves the mail message into <b>Trash</b> folder.     * @param ls LogonSession     * @param message InboxMessage     */    public void saveMailToTrash(LogonSession ls, InboxMessage message) {        /*        long time = System.currentTimeMillis();        Exception error = null;        // Save!        try {            saveMail( ls, message, false, true );        } catch( Exception ex ) {            error = ex;        }        // Logging.        try {            if( error != null ) {                String logMessage = "Can't save the message: " + error.getMessage();                TrashLogPublisher publisher = new TrashLogPublisher( ls );                publisher.ERROR( logMessage, message );                ERROR( logMessage, error );                throw error;            } else {                String logMessage = "Message was saved to TRASH folder.";                INFO( logMessage + " Time (ms) - " + ( System.currentTimeMillis() - time ) +                      ". Message: " + message );                TrashLogPublisher publisher = new TrashLogPublisher( ls );                publisher.INFO( logMessage, message );            }        } catch( Exception ex ) {            // Re-throwing the exception.            throwException( "Known exception: " + ex.getMessage(), ex );        }        */    } // saveMailToInbox()    /**     * Sends mail and copies the message data to the OUTBOX folder.     *     * @param ls user logon session     * @param inboxMessage mail message VO     * @param mailHeaders mail headers to add (<b>null</b> ignored)     * @throws MessagingException if something wrong happened     * @return true if the message was sent     */    public boolean sendEmailMessage(LogonSession ls, InboxMessage inboxMessage, Properties mailHeaders)        throws MessagingException {        // Initialization.        long time = System.currentTimeMillis();        MessagingException error = null;        OutboxLogPublisher publisher = new OutboxLogPublisher(ls);        // set image tag CID for the img resource        // 1. Set image        if (!inboxMessage.isEmptyAttachmentsList()) {            List msgAttachments = inboxMessage.getAttachments();            if (msgAttachments != null && msgAttachments.size() > 0) {                RE re;                try {                    re = new RE(InboxHelper.IMAGE_PATTERN_OUT_EMAIL, 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);                    // .. get image fullname (href) attribute                    String srcName = re.getParen(1);                    // Try to find the same attachment among temp attachments.                    // Process the attachments list.                    for (int i = 0; i < msgAttachments.size(); i++) {                        Attachment attach = (Attachment)msgAttachments.get(i);                        String fileName = attach.getFilename();                        srcName = InboxHelper.getContentId(srcName);                        if (srcName.indexOf(fileName) > -1) {                            int start = re.getParenStart(1);                            int end = re.getParenEnd(1);                            newBody = newBody.substring(0, start) +                                    InboxHelper.CONTENT_ID_CAPTION + 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);            } // if (inboxMessage.getProcessId() != null)        }        // 2. Set 'Sent Date'.        inboxMessage.setSentTime(DateHelper.getNowDate());        // 3. Making special HEADER_X_TIKET header.        Long objectId = inboxMessage.getObjectId();        Integer objectType = inboxMessage.getObjectType();        if (objectId != null) {            if (mailHeaders == null) {                mailHeaders = new Properties();            } // if (mailHeaders == null)            // Object ID and Object Type should be separated by ','            // @see com.queplix.core.modules.inbox.utils.filters.InitialFilter            String value = objectId.toString();            if (objectType != null) {                value += "," + objectType;            }            mailHeaders.setProperty(InboxHelper.HEADER_X_TIKET, value);            DEBUG(InboxHelper.HEADER_X_TIKET + " header was set to: " + objectId);        } // if (objectId != null)        // 4. Send message.        MailManagerLocal local = (MailManagerLocal)getLocalObject(JNDINames.MailManager, MailManagerLocalHome.class);        try {            if (inboxMessage.isEmptyAttachmentsList()) {                local.sendMessage(ls, inboxMessage, mailHeaders);            } else {                List msgAttachments = inboxMessage.getAttachments();                Attachment[] attachments = new Attachment[inboxMessage.getAttachments().size()];                for(int i = 0; i < inboxMessage.getAttachments().size(); i++) {                    Attachment attach = (Attachment)msgAttachments.get(i);                    attachments[i] = attach;                }                local.sendMessage(ls, inboxMessage, mailHeaders, attachments);                deleteTempAttachment(ls, inboxMessage);            }        } catch(MessagingException ex) {            error = ex;        }        boolean returnValue;        // Logging        if (error != null) {            String msg = "Cannot process the message: " + error.getMessage();            publisher.ERROR(msg, inboxMessage);            throw error;        } else {            String logMessage = "Message was sent and saved to OUTBOX folder.";            INFO(logMessage + ". Time (ms) - " + (System.currentTimeMillis() - time) + ". Message: " + inboxMessage);            publisher.INFO(logMessage, inboxMessage);            returnValue = true;        }        return returnValue;    } // sendEmailMessage(LogonSession, InboxMessage, Properties)    /**     * The method saves an alert message.     * @param ls logon session object     * @param inboxMessage message object     * @return true     */    public boolean sendAlertMessage(LogonSession ls, InboxMessage inboxMessage) {        INFO("Create non Email Message");        long time = System.currentTimeMillis();        Exception error = null;        // Now date.        Date now = DateHelper.getNowDate();        inboxMessage.setMessageType(Integer.valueOf(InboxHelper.ALERT_MESSAGE));        inboxMessage.setReceiveTime(now);        inboxMessage.setSentTime(now);        // Save!        try {            saveMail(ls, inboxMessage);        } catch(Exception ex) {            error = ex;        } // try        // Logging.        try {            if (error != null) {                String logMessage = "Can't save the message: " + error.getMessage();                InboxLogPublisher publisher = new InboxLogPublisher( ls );                publisher.ERROR(logMessage, inboxMessage);                ERROR(logMessage, error);                throw error;            } else {                String logMessage = "Message was saved to INBOX folder.";                INFO(logMessage + " Time (ms) - " + (System.currentTimeMillis() - time) +                      ". Message: " + inboxMessage);                InboxLogPublisher publisher = new InboxLogPublisher(ls);                publisher.INFO(logMessage, inboxMessage);            }        } catch(Exception ex){            // Re-throwing the exception.            throwException("Known exception: " + ex.getMessage(), ex);        } // try        INFO("Non Email Message was saved");        return true;    } // sendAlertMessage(LogonSession, InboxMessage) : boolean

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -