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

📄 alertmanagerejb.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            DEBUG( "   To All: " + toAll );            DEBUG( toString() );        }        // Initialization.        long[] alertIDs = null;        // Go!        if( toAll ) {            //            // Add alert for any user in workgroup            //            Collection<User> memeberList = getGroupMemebers( workgroupID, tier );            int size = ( memeberList == null ) ? 0 : memeberList.size();            if( size > 0 ) {                alertIDs = new long[size];                int counter = 0;                for(User recipient : memeberList) {                    try {                        // start process                        AlertVO alertVO = startCreate();                        // send to Recipient                        alertVO.setUserRecipient( recipient.getUserID(), recipient.getAuthenticationType() );                        // end process                        endCreate( alertVO );                        // get new alert id                        alertIDs[counter++] = alertVO.getAlertID();                        // Reset ID for next cycle                        if( size > 1 ) {                            resetId();                        }                    } catch( EQLException ex ) {                        throwException( ex );                    }                }            }        } else {            //            // Add alert only for workgroup            //            alertIDs = new long[1];            try {                // start process                AlertVO alertVO = startCreate();                // send to Recipient                alertVO.setWorkgroupRecipient( workgroupID, tier );                // end process                endCreate( alertVO );                // get new alert id                alertIDs[0] = alertVO.getAlertID();            } catch( EQLException ex ) {                throwException( ex );            }        }        // Ok.        if( getLogger().isInfoEnabled() ) {            INFO( "Alerts for workgroup added:" );            for( int i = 0; i < alertIDs.length; i++ ) {                INFO( "     " + alertIDs[i] );            }            INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) );        }        return alertIDs;    }    /**     * Update alerts.     * WARNING: now it update alert by ID <code>this.alertID</code>     * @return long[] ID of updated alerts.     */    public long[] updateAlert() {        long time = System.currentTimeMillis();        Long id = getId();        if( getLogger().isDebugEnabled() ) {            DEBUG( "Try to update alert:" );            DEBUG( toString() );        }        // Initialization.        if( id == null ) {            throw new NullPointerException( "Alert ID is not set" );        }        AlertCache cache = getCache();        // Get alert by ID.        AlertVO alertVO = ( AlertVO ) cache.get( alertID );        if( alertVO == null ) {            throw new NullPointerException( "Alert #" + alertID + " not found in the cache" );        }        // Set new message and severity.        alertVO.setMessage( message );        alertVO.setSeverity( severityId );        // Try to update alert.        AlertPropertyFactory.getInstance().getAlertDAO().updateAlertVO( alertVO );        // Notify cache that object has been updated.        cache.put( id, alertVO );        if( getLogger().isInfoEnabled() ) {            INFO( "Alert updated (ID = " + alertID + ")." );            INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) );        }        return new long[] {id.longValue()};    }    /**     * Delete alerts.     * WARNING: now it deletes alert by ID <code>this.alertID</code>     * and for current user <code>ls</code> only.     * @return long[] ID of deleted alerts.     */    public long[] deleteAlerts() {        long time = System.currentTimeMillis();        Long id = getId();        User user = ls.getUser();        if( getLogger().isDebugEnabled() ) {            DEBUG( "Try to delete alerts:" );            DEBUG( "   ID: " + id );        }        // Initialization.        if( id == null ) {            throw new NullPointerException( "Alert ID is not set" );        }        AlertCache cache = getCache();        // Get alert by ID.        AlertVO alertVO = ( AlertVO ) cache.get( id );        // Try to remove it.        long[] alertIDs = null;        if( alertVO != null ) {//            if( SecurityManager.isAdmin( user ) || alertVO.isOwner( user ) || alertVO.isSender( user ) ) {            if( alertVO.isOwner( user ) || alertVO.isSender( user ) ) {                // Dedicated alert - remove it                AlertPropertyFactory.getInstance().getAlertDAO().                    deleteAlertVO( alertVO );                // Remove from the cache.                cache.remove( id );                if( getLogger().isDebugEnabled() ) {                    DEBUG( "Alert: " + alertVO + " has been removed physically" );                }            } else {                // Alert sent for workgroup - just create block for target user                AlertBlock block = new AlertBlock( user.getUserID(), user.getAuthenticationType() );                AlertPropertyFactory.getInstance().getAlertDAO().blockAlertVO( alertVO, block );                // Add <code>user</code> to blocked list.                alertVO.addBlock( block );                // Notify cache that object has been updated.                cache.put( id, alertVO );                if( getLogger().isDebugEnabled() ) {                    DEBUG( "User: " + user + " has been placed to the block list of alert: " +                           alertVO );                }            }            // Add to the list.            alertIDs = new long[1];            alertIDs[0] = alertID.longValue();        }        // Ok.        if( getLogger().isInfoEnabled() ) {            INFO( "Alerts removed:" );            int size = ( alertIDs == null ) ? 0 : alertIDs.length;            for( int i = 0; i < size; i++ ) {                INFO( "     " + alertIDs[i] );            }            INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) );        }        return alertIDs;    }    /*     * No javadoc     * @see Object#toString     */    public String toString() {        return            "   ID: " + alertID + "\n" +            "   Message: " + message + "\n" +            "   Severity: " + severityId + "\n" +            "   Date: " + dateposted + "\n" +            "   Creator: " + creatorID + ", type: " + creatorType + "\n" +            "   Sender: " + senderID + ", type: " + senderType + "\n" +            "   Data: " + data;    }    // ----------------------------------------------------- private methods    //    // Initialization.    //    private void init( LogonSession ls ) {        if( ls == null ) {            throw new IllegalStateException( "Logon session is NULL" );        }        this.ls = ls;    }    /**     * Alert Cache instance getter.     * @return AlertCache     */    private AlertCache getCache() {        // Get cache reference.        AlertCache cache = AlertPropertyFactory.getInstance().getAlertCache();        if( !cache.isInitialized() ) {            // Init cache.            long t = System.currentTimeMillis();            cache.init();            INFO( "Cache initialized! Time(ms): " + ( System.currentTimeMillis() - t ) );            if( getLogger().isDebugEnabled() ) {                DEBUG( "Cache: " + cache );            }        }        return cache;    }    //    // Prepare for Alert creation.    //    private AlertVO startCreate()        throws EQLException {        // Checking.        if( message == null ) {            throw new NullPointerException( "Bean AlertManager initialized improperly" );        }        // Get alert ID.        long id;        if( alertID == null ) {            id = AlertPropertyFactory.getInstance().getAlertDAO().getNextAlertID();        } else {            id = alertID.longValue();        }        // Create new AlertVO.        AlertVO alertVO = new AlertVO( id,                                       getCreatorID(),                                       getCreatorType(),                                       getSenderID(),                                       getSenderType(),                                       message,                                       severityId,                                       getDateposted() );        // Set Add-On data.        alertVO.setData( data );        return alertVO;    }    //    // Create new Alert and store instance in the cache.    //    private void endCreate( AlertVO alertVO )        throws EQLException {        // Init.        AlertCache cache = getCache();        // Save alert.        AlertPropertyFactory.getInstance().getAlertDAO().storeAlertVO( alertVO );        // Add to the cache.        cache.put( alertVO );        if( getLogger().isDebugEnabled() ) {            DEBUG( "New cache instance added: " + alertVO );            DEBUG( "Cache state: " + cache );        }    }    //    // Get group members    //    private Collection<User> getGroupMemebers( long workgroupID, Integer tier ) {        try {            return AccessRightsManager.getUsersInGroup(workgroupID, tier);        } catch (NoSuchGroupException e) {            return Collections.EMPTY_LIST;        }    }} // end of class

⌨️ 快捷键说明

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