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

📄 ticketescalationmanagerejb.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * 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.qwoss.notification;

import java.util.List;
import java.util.Date;
import java.util.Calendar;
import com.queplix.core.error.ErrorHelper;
import com.queplix.core.jxb.entity.Entity;
import com.queplix.core.modules.eql.CompoundKey;
import com.queplix.core.modules.eql.ejb.EQLManagerLocal;
import com.queplix.core.modules.eql.error.EQLException;
import com.queplix.core.modules.eqlext.GetRecordsRes;
import com.queplix.core.modules.eqlext.ejb.GetRecordsLocal;
import com.queplix.core.modules.eqlext.ejb.GetRecordsLocalHome;
import com.queplix.core.modules.eqlext.jxb.gr.*;
import com.queplix.core.modules.jeo.ejb.JEOManagerLocal;
import com.queplix.core.utils.JNDINames;
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.WorkGroup;
import com.queplix.qwoss.gen.CustomerObjectHandler;
import com.queplix.qwoss.gen.EmployeeObjectHandler;
import com.queplix.qwoss.gen.EscPriorityFieldObject;
import com.queplix.qwoss.gen.EscPriorityFieldObjectHandler;
import com.queplix.qwoss.gen.EscRecipientFieldObject;
import com.queplix.qwoss.gen.EscRecipientFieldObjectHandler;
import com.queplix.qwoss.gen.EscStatusFieldObject;
import com.queplix.qwoss.gen.EscStatusFieldObjectHandler;
import com.queplix.qwoss.gen.TicketEscalationObject;
import com.queplix.qwoss.gen.TicketEscalationObjectHandler;
import com.queplix.qwoss.gen.TicketEsclEventObject;
import com.queplix.qwoss.gen.TicketEsclEventObjectHandler;
import com.queplix.qwoss.gen.TicketObject;
import com.queplix.qwoss.gen.TicketObjectHandler;
import com.queplix.qwoss.utils.TicketEscalationHelper;
import com.queplix.qwoss.utils.TicketHelper;
import com.queplix.qwoss.utils.TicketNotificationHelper;

/**
 * Ticket Escalations Manager EJB.
 *
 * @author [ALB] Baranov Andrey
 * @version $Revision: 1.7.2.2 $ $Date: 2005/12/20 16:43:05 $
 */
public class TicketEscalationManagerEJB
    extends
    AbstractEntityEscalationManagerEJB {

    // ========================================================= Constants

    private static final String PRODUCT_ENTITY = "product";
    private static final String PRODUCT_EFIELD_ID = "qw_product";
    private static final String PRODUCT_EFIELD_NAME = "qw_name";

    // ========================================================= EJB API methods

    /** Initializes bean. */
    public void ejbCreate() {
        INFO( "TicketEscalationManagerEJB create - " + hashCode() );
    }

    // ========================================================== Public methods

    /**
     * Generates ticket escalation events for the given ticket.
     *
     * @param ls
     *            LogonSession object
     * @param entityJEO
     *            ticket JEO object
     */
    public void generateEvents( LogonSession ls, Object entityJEO ) {

        long time = System.currentTimeMillis();

        TicketObject ticketObj = ( TicketObject ) entityJEO;
        
        Long ticketCustomerId =  ticketObj.getQw_customerid();
        if(ticketCustomerId == null)
            ticketCustomerId = ticketObj.getQw_employeeid();
        
        if( getLogger().isInfoEnabled() ) {
            INFO( "Creating escalation events for the ticket:" + "\n\t ID = "
                  + ticketObj.getQw_ticketid() + "\n\t priority = "
                  + ticketObj.getQw_priority() + "\n\t status = "
                  + ticketObj.getQw_status() + "\n\t customer ID = "
                  + ticketCustomerId );
        }

        try {
            // Initialization.
            JEOManagerLocal jeoManager = getJEOManagerLocal();

            // Find All ticket escalations.
            List escalations = TicketEscalationObjectHandler.selectAll(
                jeoManager, ls );

            // For all selected escalations...
            int size = ( escalations != null ) ? escalations.size() : 0;
            for( int i = 0; i < size; i++ ) {
                TicketEscalationObjectHandler escHnd = 
                    ( TicketEscalationObjectHandler ) escalations.get( i );
                TicketEscalationObject escObj = ( TicketEscalationObject ) escHnd.getJEObject();

                // 1 Check, if event already exists.

                List events = TicketEsclEventObjectHandler
                    .selectByEscalationAndTicket( jeoManager, ls, escObj.getQw_escalationid(), 
                            ticketObj.getQw_ticketid() );

                if( events != null ) {

                    if( getLogger().isDebugEnabled() ) {
                        DEBUG( "Events for the ticket (ID = "
                               + ticketObj.getQw_ticketid() + ") already exist..." );
                        DEBUG( "Try to remove obsolete..." );
                    }

                    // Try to remove obsolete events.
                    removeObsoleteEsclEvents( ticketObj, escObj, events );

                    continue;
                }

                // 2. Check, if ticket and escalation parameters equal.

                // If a check failed - go to the next escalation.
                if( !equals( ls, ticketObj, escObj ) ) {
                    continue;
                }

                // 3 If check was ok and esclation event record not exist,
                // create a new event.

                TicketEsclEventObjectHandler eventHnd = 
                    ( TicketEsclEventObjectHandler ) jeoManager.create( ls, TicketEsclEventObjectHandler.class );
                TicketEsclEventObject eventObj = 
                    ( TicketEsclEventObject ) eventHnd.getJEObject();

                eventObj.setQw_escalationid( escObj.getQw_escalationid() );
                eventObj.setQw_ticketid( ticketObj.getQw_ticketid() );
                eventObj.setQw_next_check( getNextCheckDate( escObj.getQw_waittime(), escObj.getQw_timeunit() ) );

                if( escObj.getQw_fireif().intValue() == TicketEscalationHelper.NOT_UPDATED_FIREIF ) {
                    // Remember DateModified for this type of FireIf
                    eventObj.setQw_datemodified( ticketObj.getQw_datemodified() );
                }
                eventHnd.commit();

                if( getLogger().isDebugEnabled() ) {
                    DEBUG( "New ticket escalation event was created:"
                           + "\n\t event ID = "
                           + eventObj.getQw_esceventid()
                           + "\n\t escalation ID = "
                           + eventObj.getQw_escalationid() + "\n\t ticket ID = "
                           + eventObj.getQw_ticketid() + "\n\t last modified = "
                           + eventObj.getQw_datemodified() );
                }

            } // for

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

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

        // Ok.
        if( getLogger().isInfoEnabled() ) {
            INFO( "Escalation events for the ticket (ID = " + ticketObj.getQw_ticketid()
                  + ") were generated successfully." );
            INFO( "Time (ms) - " + ( System.currentTimeMillis() - time ) );
        }
    }

    /**
     * Fires ticket escalation events.
     *
     * @return number of fired events
     */
    public int fireEvents() {

        long time = System.currentTimeMillis();
        INFO( "Firing ticket escalation events..." );

        int eventsCount = 0;

        try {
            // Initialization.
            JEOManagerLocal jeoManager = getJEOManagerLocal();
            LogonSession ls = AccessRightsManager.getSystemLogonSession();

            Entity entity = loadTicketEntity();
            //Form form = loadCaseForm( ls );

            // String message = loadEscalationMessage();

            // Find matured ticket escalation events.
            List esclEventObjectList = TicketEsclEventObjectHandler
                .selectMatured( getJEOManagerLocal(), ls );

            // For all selected events...
            int size = ( esclEventObjectList != null ) ? esclEventObjectList.size() : 0;
            for( int i = 0; i < size; i++ ) {

                TicketEsclEventObjectHandler eventHnd = 
                    ( TicketEsclEventObjectHandler ) esclEventObjectList.get( i );
                TicketEsclEventObject eventObj = ( TicketEsclEventObject ) eventHnd.getJEObject();

                long eventID = eventObj.getQw_esceventid().longValue();
                DEBUG( "Firing the ticket escalation event (ID = " + eventID + ")" );

                // 1. Get escalation JEO object.

                long escID = eventObj.getQw_escalationid().longValue();
                TicketEscalationObjectHandler escHnd = 
                    ( TicketEscalationObjectHandler ) TicketEscalationObjectHandler.selectByPkey( jeoManager, ls, escID );

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

                TicketEscalationObject escObj = ( TicketEscalationObject ) escHnd.getJEObject();

                // If disabled - remove event.
                if( escObj.getQw_disable().intValue() == 1 ) {
                    if( getLogger().isInfoEnabled() ) {

⌨️ 快捷键说明

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