📄 alertmanagerejb.java
字号:
/* * 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.alert.ejb;import com.queplix.core.integrator.security.AccessRightsManager;import com.queplix.core.integrator.security.LogonSession;import com.queplix.core.integrator.security.User;import com.queplix.core.integrator.security.NoSuchGroupException;import com.queplix.core.modules.alert.AlertBlock;import com.queplix.core.modules.alert.AlertConstants;import com.queplix.core.modules.alert.AlertData;import com.queplix.core.modules.alert.utils.AlertCache;import com.queplix.core.modules.alert.utils.AlertPropertyFactory;import com.queplix.core.modules.alert.utils.AlertSelectorCriteria;import com.queplix.core.modules.alert.utils.AlertVO;import com.queplix.core.modules.eql.error.EQLException;import com.queplix.core.utils.DateHelper;import com.queplix.core.utils.ejb.AbstractSessionEJB;import java.util.Collection;import java.util.Collections;import java.util.Date;import java.util.SortedMap;/** * Alert manager. * Performs messaging module (alerts) business logic. * @author [ALB] Baranov Andrey * @version $Revision: 1.3 $ $Date: 2006/07/24 08:24:06 $ */public class AlertManagerEJB extends AbstractSessionEJB { // ----------------------------------------------------- variables // Manadatoru attributes private String message; private int severityId; private LogonSession ls; // Optional attributes private Long alertID; private Long creatorID; private Integer creatorType; private Long senderID; private Integer senderType; private Date dateposted; private AlertData data; // ----------------------------------------------------- create method /** * Initialize bean for sending Alerts. * @param message user alert message * @param severityId user alert severity * @param ls LogonSession object */ public void ejbCreate( String message, int severityId, LogonSession ls ) { // Init. init( ls ); if( message == null ) { throw new IllegalStateException( "Message is NULL" ); } this.message = message; switch( severityId ) { case AlertConstants.SEVERITY_CRITICAL: case AlertConstants.SEVERITY_SPECIAL: case AlertConstants.SEVERITY_HIGH: case AlertConstants.SEVERITY_MEDIUM: case AlertConstants.SEVERITY_LOW: break; default: throw new IllegalStateException( "Unsupported alert severity: " + severityId ); } this.severityId = severityId; } /** * Initialize bean for working with existing Alerts. * @param ls LogonSession object */ public void ejbCreate( LogonSession ls ) { // Init. init( ls ); } // ----------------------------------------------------- setter/getter methods // // Alert ID // public void setId( long alertID ) { this.alertID = new Long( alertID ); } public Long getId() { return alertID; } public void resetId() { this.alertID = null; } // // Alert Creator // public void setCreator( long creatorID, int creatorType ) { this.creatorID = creatorID; this.creatorType = creatorType; } public long getCreatorID() { if( creatorID == null ) { creatorID = ls.getUser().getUserID(); } return creatorID; } public int getCreatorType() { if( creatorType == null ) { creatorType = ls.getUser().getAuthenticationType(); } return creatorType; } // // Alert Sender // public void setSender( long senderID, int senderType ) { this.senderID = senderID; this.senderType = senderType; } public long getSenderID() { if( senderID == null ) { senderID = ls.getUser().getUserID(); } return senderID; } public int getSenderType() { if( senderType == null ) { senderType = new Integer( ls.getUser().getAuthenticationType() ); } return senderType; } // // Alert Date Posted // public void setDateposted( Date dateposted ) { this.dateposted = dateposted; } public Date getDateposted() { if( dateposted == null ) { dateposted = DateHelper.getNowDate(); } return dateposted; } // // Alert Add-On Data // public void setData( AlertData data ) { this.data = data; } public AlertData getData() { return data; } // ----------------------------------------------------- busines methods /** * Find alerts using search criteria <code>criteria</code>. * @param criteria search criteria * @return SortedMap of AlertVO objects */ public SortedMap getAlerts( AlertSelectorCriteria criteria ) { long time = System.currentTimeMillis(); if( getLogger().isDebugEnabled() ) { DEBUG( "Try to find alerts in cache:" ); DEBUG( " Criteria: " + criteria ); } // Do search. SortedMap ret = AlertPropertyFactory.getInstance().getAlertSelector().search( getCache(), criteria ); // Ok. if( getLogger().isInfoEnabled() ) { INFO( "Found " + ( ( ret == null ) ? 0 : ret.size() ) + " alerts." ); INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) ); } return ret; } /** * Send alert to all * @return id of new alert */ public long[] sendAlert() { long time = System.currentTimeMillis(); if( getLogger().isDebugEnabled() ) { DEBUG( "Try to send alert to All users:" ); DEBUG( toString() ); } // Initialization. long alertID = -1; // Go! try { // start process AlertVO alertVO = startCreate(); // send To All alertVO.setToAllRecipient( true ); // end process endCreate( alertVO ); // get new alert id alertID = alertVO.getAlertID(); } catch( EQLException ex ) { throwException( ex ); } if( getLogger().isInfoEnabled() ) { INFO( "Alerts to All added (ID = " + alertID + ")." ); INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) ); } return new long[] {alertID}; } /** * Send alert to user * @param recipientID ID of recipient of alert * @param recipientType Type of recipient of alert * @return id of new alert */ public long[] sendAlert( long recipientID, int recipientType ) { long time = System.currentTimeMillis(); if( getLogger().isDebugEnabled() ) { DEBUG( "Try to send alert to User:" ); DEBUG( " Recipient: " + recipientID + ", type: " + recipientType ); DEBUG( toString() ); } // Initialization. long alertID = -1; // Go! try { // start process AlertVO alertVO = startCreate(); // send to Recipient alertVO.setUserRecipient( recipientID, recipientType ); // end process endCreate( alertVO ); // get new alert id alertID = alertVO.getAlertID(); } catch( EQLException ex ) { throwException( ex ); } // Ok. if( getLogger().isInfoEnabled() ) { INFO( "Alert for user added (ID = " + alertID + ")." ); INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) ); } return new long[] {alertID}; } /** * Send alert(s) to workgroup * @param workgroupID ID of workgroup - recipient of alert * @param tier workgroup tier * @param toAll send alert to all users in workgroup * @return array of ids of new alerts */ public long[] sendAlerts( long workgroupID, Integer tier, boolean toAll ) { long time = System.currentTimeMillis(); if( getLogger().isDebugEnabled() ) { DEBUG( "Try to send alert to Workgroup:" ); DEBUG( " Workgroup: " + workgroupID + " [" + tier + "]" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -