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

📄 ticketescalationmanagerejb.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        WARN( "Escalation is disabled for the event (ID = " + eventID + ")" );
                    }
                    eventHnd.remove();
                    eventHnd.commit();
                    continue;
                }

                // If the esclation is repeatable, calculate its next check
                // date.
                boolean repeatedEscalation = ( escObj.getQw_repeat() != null )
                    && ( escObj.getQw_repeat().intValue() == 1 )
                    && ( escObj.getQw_waittime().intValue() > 0 );

                Date nextCheckDate = null;
                if( repeatedEscalation ) {
                    nextCheckDate = getNextCheckDate( escObj.getQw_waittime(), escObj.getQw_timeunit() );
                }

                // 2. Get ticket JEO object.

                long ticketID = eventObj.getQw_ticketid().longValue();
                TicketObjectHandler ticketHnd = 
                    ( TicketObjectHandler ) TicketObjectHandler.selectByID( jeoManager, ls, ticketID );

                // If no ticket found, remove the event.
                if( ticketHnd == null ) {
                    if( getLogger().isInfoEnabled() ) {
                        WARN( "Ticket is not found for the event (ID = "
                              + eventID + ") - removing..." );
                    }
                    eventHnd.remove();
                    eventHnd.commit();
                    continue;
                }

                TicketObject ticketObject = ( TicketObject ) ticketHnd.getJEObject();

                // 3. Check escalation and ticket attributes.

                // If a check failed - remove the event.
                if( !equals( ls, ticketObject, escObj ) ) {
                    if( getLogger().isInfoEnabled() ) {
                        WARN( "Escalation (ID = " + escID
                              + ") is inconsistent with ticket " + "(ID = "
                              + ticketID + ") - removing the event..." );
                    }
                    eventHnd.remove();
                    eventHnd.commit();
                    continue;
                }

                // Check escalation 'FireIf'.
                if( checkFireif( ticketObject, escObj, eventObj ) ) {

                    // 4. Do notification.

                    // Initialize compound key.
                    CompoundKey key = new CompoundKey();
                    key.addKey( String.valueOf( ticketObject.getQw_ticketid() ) );

                    // Initialize Notification Manager EJB.
                    NotificationManagerLocal notificationLocal = getNotificationManagerLocal(
                        ls, entity, key ); 
                    notificationLocal.setAlertSeverityId( 
                            TicketNotificationHelper.ticketPriority2AlertSeverity(ticketObject.getQw_priority()));                            

                    notificationLocal.setSubject( escObj.getQw_subject() );
                    notificationLocal.setMessage( ( escObj.getQw_mailbody() == null ) ? null
                                     : new String( escObj.getQw_mailbody() ) );
                    
                    //notificationLocal.setForm( form );

                    //determine the recipient email
                    
                    // Check recipient
                    
                    List escRecipientHandlers = EscRecipientFieldObjectHandler
                        .selectByEscalationId( jeoManager, ls, escObj.getQw_escalationid().longValue() );
                    
                    // for all recipients do --
                    if (escRecipientHandlers != null) {
                        for (int j = 0; j < escRecipientHandlers.size(); j++) {
                            EscRecipientFieldObjectHandler escRecipientFieldObjectHandler = 
                                (EscRecipientFieldObjectHandler) escRecipientHandlers.get(j);
                            EscRecipientFieldObject escRecipientFieldObject = 
                                (EscRecipientFieldObject) escRecipientFieldObjectHandler.getJEObject();
                            Integer recipinet = escRecipientFieldObject.getQw_recipient();
                            if (recipinet == null){
                                WARN( "Escalation (ID = " + escID + ") is canceled. Recipient is needed.");
                                eventHnd.remove();
                                eventHnd.commit();
                                continue;
                            } 
                            
                            switch (recipinet.intValue()) {
                                case TicketEscalationHelper.ASSIGNED_WORKGROUP_RECIPIENT:
                                    Long workGroupId = escObj.getQw_workgroupid();
                                    if( workGroupId  == null ){
                                        WARN( "Escalation (ID = " + escID + ") is canceled. Assigned workgroup is needed.");
                                        eventHnd.remove();
                                        eventHnd.commit();
                                        continue;
                                    }
                                    WorkGroup recWorkGroup = loadGroup(ls, workGroupId);
                                    if( recWorkGroup == null ){
                                        WARN( "Escalation (ID = " + escID + ") is canceled. Can't load the workgroup with ID "+workGroupId+".");
                                        eventHnd.remove();
                                        eventHnd.commit();
                                        continue;
                                    }
                                    notificationLocal.notify(recWorkGroup, null, null);
                                    break;
                                case TicketEscalationHelper.ASSIGNED_EMPLOYEE_RECIPIENT:
                                    Long employeeId = escObj.getQw_employeeid();
                                    if( employeeId == null ){
                                        WARN( "Escalation (ID = " + escID + ") is canceled. Assigned employee is needed.");
                                        eventHnd.remove();
                                        eventHnd.commit();
                                        continue;
                                    }
                                    User recEmployee = loadEmployee(ls, employeeId);
                                    if( recEmployee == null ){
                                        WARN( "Escalation (ID = " + escID + ") is canceled. Can't load the employee with ID "+employeeId+".");
                                        eventHnd.remove();
                                        eventHnd.commit();
                                        continue;
                                    }
                                    Integer notifType = escObj.getQw_sendmode();
                                    if( notifType == null)
                                        notificationLocal.notify(recEmployee);
                                    else{
                                        switch(notifType.intValue()){
                                            case TicketNotificationHelper.ALERT_METHOD:
                                                notificationLocal.notifyByAlert(recEmployee);
                                                break;
                                            case TicketNotificationHelper.EMAIL_METHOD:
                                                notificationLocal.notifyByMail(recEmployee);
                                                break;
                                        }
                                    }
                                    break;
                                case TicketEscalationHelper.ASSIGNED_EMAIL_RECIPIENT:
                                    String email = escObj.getQw_email();
                                    if( email == null ){
                                        WARN( "Escalation (ID = " + escID + ") is canceled. Assigned email is needed.");
                                        eventHnd.remove();
                                        eventHnd.commit();
                                        continue;
                                    }
                                    notificationLocal.notifyByMail(email);
                                    break;
                            }
                        }
                    }
                    
                    // Notify addressee.
                    //notificationLocal.notifyByMail( escObj.getQw_email() );

                    // Event is fired - count it.
                    eventsCount++;

                }

                // 5. Update next check date or remove event

                if( !repeatedEscalation ) {
                    // Remove event
                    if( getLogger().isDebugEnabled() ) {
                        DEBUG( "Removing the event (ID = " + eventID + ")..." );
                    }
                    eventHnd.remove();
                    eventHnd.commit();
                } else {
                    // Update event
                    if( getLogger().isDebugEnabled() ) {
                        DEBUG( "Updating the event (ID = " + eventID + ")..." );
                    }
                    eventObj.setQw_next_check( nextCheckDate );
                    eventHnd.commit();
                }

            } // for

        } catch( EQLException ex ) {
            throwException( ex );

        } catch( Throwable t ) {
            ErrorHelper.throwSystemException( t, this );
        }

        // Ok.
        if( getLogger().isInfoEnabled() ) {
            INFO( "Ticket escalation events successfully fired." );
            INFO( "Fired " + eventsCount + " events, at "
                  + ( System.currentTimeMillis() - time ) + " ms." );
        }
        return eventsCount;
    }

    // ========================================================= Private methods

    //
    // Remove obsolete escalation events.
    //
    private void removeObsoleteEsclEvents( TicketObject ticketObj,
                                           TicketEscalationObject escObj, List events )
        throws EQLException {

        // Check events in cycle.
        int count = 0;
        int size = ( events == null ) ? 0 : events.size();
        for( int i3 = 0; i3 < size; i3++ ) {
            TicketEsclEventObjectHandler eventHnd = ( TicketEsclEventObjectHandler ) events.get( i3 );
            TicketEsclEventObject eventObj = ( TicketEsclEventObject ) eventHnd.getJEObject();

            // remove only those events where Escalation Fireif is 'Not Updated'
            // but Ticket Modified Date is greater than event's or
            // where Escalation Fireif is 'Not Closed' but Ticket Type is CLOSED or
            // where Escalation Fireif is 'Not Assigned' but Ticket Type is not NEW
            
            if( checkFireif( ticketObj, escObj, eventObj ) ) {
                continue;
            }

            eventHnd.remove();
            eventHnd.commit();
            count++;
        }

        // Ok.
        if( getLogger().isInfoEnabled() ) {
            INFO( "Removed " + count
                  + " obsolete ticket escalation events for ticket #"
                  + ticketObj.getQw_ticketid() );
        }
    }

    //
    // Calculates event's next check date.
    //
    private Date getNextCheckDate( Long delay, Integer delayUnits ) {

        // Check arguments.
        if( delayUnits == null ) {
            throw new IllegalStateException( "Delay unitis null." );
        }

        // Switch by time unit.
        switch( delayUnits.intValue() ) {
        case TicketEscalationHelper.MINUTES_DELAY_UNITS:

⌨️ 快捷键说明

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