📄 inboxmanagerejb.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.qwoss.inbox.ejb;
import com.queplix.core.integrator.security.LogonSession;
import com.queplix.core.modules.inbox.InboxMessage;
import com.queplix.core.modules.inbox.InboxHelper;
import com.queplix.core.modules.inbox.utils.log.InboxLogPublisher;
import com.queplix.core.modules.jeo.ejb.JEOManagerLocal;
import com.queplix.core.modules.jeo.JEObjectHandler;
import com.queplix.core.modules.jeo.gen.AttachmentTempObject;
import com.queplix.core.modules.config.utils.SysPropertyManager;
import com.queplix.core.modules.eql.ejb.EQLManagerLocal;
import com.queplix.core.modules.eql.ejb.EQLManagerLocalHome;
import com.queplix.core.modules.eql.error.EQLException;
import com.queplix.core.modules.attachment.ejb.AttachmentManagerLocal;
import com.queplix.core.modules.attachment.ejb.AttachmentManagerLocalHome;
import com.queplix.core.utils.JNDINames;
import com.queplix.core.utils.DateHelper;
import com.queplix.core.utils.StringHelper;
import com.queplix.core.utils.cache.CacheObjectManager;
import com.queplix.core.error.GenericSystemException;
import com.queplix.qwoss.gen.*;
import com.queplix.qwoss.utils.ApplicationHelper;
import com.queplix.qwoss.inbox.CustomInboxHelper;
import java.util.Properties;
/**
* The Inbox Manager EJB.
* @author Konstantin Mironov
* @since 8 Dec 2006
*/
public class InboxManagerEJB extends com.queplix.core.modules.inbox.ejb.InboxManagerEJB {
// ------------------------------------------------------- Public methods
/**
* The method creates a ticket by the message.
* @param ls logon session object
* @param inboxMessage message object
* @return true
*/
public boolean createTicket(LogonSession ls, InboxMessage inboxMessage) {
INFO("Create a new ticket by the message...");
long time = System.currentTimeMillis();
Exception error = null;
Long ticketID = null;
JEOManagerLocal jeoManager = getJEOManager();
// Save!
try {
// check is the customer has already got
if (inboxMessage.getSenderID() == null) {
Long customerID = getCustomer(ls, inboxMessage);
if (customerID == null) {
// try to get the default customer
String emailDefaulCustomer = SysPropertyManager.getProperty("IN_EMAIL_DEFAULT_CUSTOMER_ID");
if (emailDefaulCustomer != null) {
inboxMessage.setSenderID(new Long(emailDefaulCustomer));
inboxMessage.setSenderType(CustomInboxHelper.CUSTOMER_TYPE);
} else {
// the ticket isn't linked
throw new NullPointerException("The system property IN_EMAIL_DEFAULT_CUSTOMER_ID wasn't found.");
} // if (emailDefaulCustomer != null)
} // if (customerID != null)
} // if (inboxMessage.getSenderID() == null)
Long interactionId = null;
if (inboxMessage.getObjectId() != null && inboxMessage.getObjectType() == ApplicationHelper.INTERACTION_OBJECT_TYPE)
interactionId = inboxMessage.getObjectId();
JEObjectHandler hnd = jeoManager.create(ls, TicketMailObjectHandler.class);
TicketMailObject ticketObj = (TicketMailObject)hnd.getJEObject();
// set status
String defaultTicketStatus = SysPropertyManager.getProperty("IN_EMAIL_TICKET_STATUS");
if (defaultTicketStatus == null) {
throw new NullPointerException("The system property IN_EMAIL_TICKET_STATUS wasn't found.");
}
ticketObj.setQw_status(new Integer(defaultTicketStatus));
// set priority
String defaultTicketPriority = SysPropertyManager.getProperty("IN_EMAIL_TICKET_PRIORITY");
if (defaultTicketPriority == null) {
throw new NullPointerException("The system property IN_EMAIL_TICKET_PRIORITY wasn't found.");
}
ticketObj.setQw_priority(new Integer(defaultTicketPriority));
// set type
String defaultTicketType = SysPropertyManager.getProperty("IN_EMAIL_TICKET_TYPE");
if (defaultTicketType == null) {
throw new NullPointerException("The system property IN_EMAIL_TICKET_TYPE wasn't found.");
}
ticketObj.setQw_type(new Integer(defaultTicketType));
// set source
String defaultTicketSource = SysPropertyManager.getProperty("IN_EMAIL_TICKET_SOURCE");
if (defaultTicketSource == null) {
throw new NullPointerException("The system property IN_EMAIL_TICKET_SOURCE wasn't found.");
}
ticketObj.setQw_source(new Integer(defaultTicketSource));
// set impact
String defaultTicketImpact = SysPropertyManager.getProperty("IN_EMAIL_TICKET_IMPACT");
if (defaultTicketImpact == null) {
throw new NullPointerException("The system property IN_EMAIL_TICKET_IMPACT wasn't found.");
}
ticketObj.setQw_impact(new Integer(defaultTicketImpact));
// set agent
String defaultTicketAgent = SysPropertyManager.getProperty("IN_EMAIL_TICKET_AGENT");
if (defaultTicketAgent == null) {
throw new NullPointerException("The system property IN_EMAIL_TICKET_AGENT wasn't found.");
}
ticketObj.setQw_agentid(new Long(defaultTicketAgent));
// set product
String defaultTicketProduct = SysPropertyManager.getProperty("IN_EMAIL_TICKET_PRODUCT");
if (defaultTicketProduct == null) {
throw new NullPointerException("The system property IN_EMAIL_TICKET_PRODUCT wasn't found.");
}
ticketObj.setQw_productid(new Long(defaultTicketProduct));
// set rvision
String defaultTicketRVersion = SysPropertyManager.getProperty("IN_EMAIL_TICKET_RVERSION");
if (defaultTicketRVersion == null) {
throw new NullPointerException("The system property IN_EMAIL_TICKET_RVERSION wasn't found.");
}
ticketObj.setQw_repbuildversionid(new Long(defaultTicketRVersion));
// check and set problem field
if (inboxMessage.getSubject().length() > 255)
ticketObj.setQw_problem(inboxMessage.getSubject().substring(0, 250));
else
ticketObj.setQw_problem(inboxMessage.getSubject());
// check and set description field
if (inboxMessage.getBody() == null) {
ticketObj.setQw_description(inboxMessage.getSubject());
} else {
String body = inboxMessage.getBody();
if (StringHelper.isHTML(body)) {
body = StringHelper.html2text(body);
}
if (body.length() > 2000)
ticketObj.setQw_description(body.substring(0, 1900));
else
ticketObj.setQw_description(body);
} // if (message.getBody() == null)
String messageBody;
if (inboxMessage.getBody() == null)
messageBody = inboxMessage.getSubject();
else
messageBody = inboxMessage.getBody();
String descriptionText = getSeparatorStringMemo(inboxMessage) +
messageBody
;
// set description
ticketObj.setQw_descriptiontext(descriptionText.toCharArray());
// set owner and workgroup
Long ownerID = inboxMessage.getResipient();
Long workgroupID = inboxMessage.getWorkgroupId();
if (ownerID == null && workgroupID == null) {
// set default owner
String defaultTicketOwner = SysPropertyManager.getProperty("IN_EMAIL_TICKET_OWNER");
if (defaultTicketOwner == null) {
throw new NullPointerException("The system property IN_EMAIL_TICKET_OWNER wasn't found.");
}
ticketObj.setQw_ownerid(new Long(defaultTicketOwner));
} else if (ownerID != null) {
ticketObj.setQw_ownerid(ownerID);
} else if (workgroupID != null) {
ticketObj.setQw_workgroupid(workgroupID);
} // if (ownerID == null && workgroupID == null)
ticketObj.setQw_dateowned(DateHelper.getNowDate());
// link to the customer
if (inboxMessage.getSenderType() == CustomInboxHelper.CUSTOMER_TYPE) {
ticketObj.setQw_customerid(inboxMessage.getSenderID());
} else if (inboxMessage.getSenderType() == CustomInboxHelper.CUSTOMER_INTERNAL_TYPE) {
ticketObj.setQw_employeeid(inboxMessage.getSenderID());
} else {
throw new NullPointerException("Unsupported Customer Type. The ticket wasn't created.");
} // if (inboxMessage.getSenderType() == CustomInboxHelper.CUSTOMER_TYPE)
hnd.commit();
// set ticket ID for log
ticketID = ticketObj.getQw_ticketid();
inboxMessage.setObjectInfo(ticketObj.getQw_ticketid(), ApplicationHelper.TICKET_OBJECT_TYPE);
// if the appropriate interaction was created for this ticket
if (interactionId != null)
createLinkInteractionTicket(ls, interactionId, inboxMessage.getObjectId());
} catch (Exception ex) {
error = ex;
} // try
// Logging.
try {
if (error != null) {
String logMessage = "Can't create a new ticket: " + error.getMessage();
InboxLogPublisher publisher = new InboxLogPublisher( ls );
publisher.ERROR(logMessage, inboxMessage);
ERROR(logMessage, error);
throw error;
} else {
String logMessage = "The new ticket was created. The ticket ID is " + ticketID;
INFO(logMessage + " Time (ms) - " + (System.currentTimeMillis() - time) +
". Message: " + inboxMessage);
InboxLogPublisher publisher = new InboxLogPublisher(ls);
publisher.INFO(logMessage, inboxMessage);
} // if (error != null)
} catch(Exception ex){
// Re-throwing the exception.
throwException("Known exception: " + ex.getMessage(), ex);
} // try
INFO("The new ticket was created");
return true;
} // createTicket(LogonSession, InboxMessage) : boolean
/**
* The method updates a ticket by message.
* @param ls logon session object
* @param inboxMessage message object
* @return true
*/
public boolean updateTicket(LogonSession ls, InboxMessage inboxMessage) {
INFO("Update the existing ticket by the message...");
long time = System.currentTimeMillis();
Exception error = null;
JEOManagerLocal jeoManager = getJEOManager();
JEObjectHandler ticketHnd;
// Save!
try {
ticketHnd = TicketMailObjectHandler.selectByID(jeoManager, ls, inboxMessage.getObjectId().longValue());
// If no ticket found.
if (ticketHnd == null) {
String errorMessage = "The ticket wasn't found. The ticket ID is " + inboxMessage.getObjectId().longValue();
ERROR(errorMessage);
throw new GenericSystemException(errorMessage);
} else {
TicketMailObject ticketObject = (TicketMailObject)ticketHnd.getJEObject();
String descriptionText = "";
if (ticketObject.getQw_descriptiontext() != null)
descriptionText = new String(ticketObject.getQw_descriptiontext());
String messageBody;
if (inboxMessage.getBody() == null)
messageBody = inboxMessage.getSubject();
else
messageBody = inboxMessage.getBody();
String newDescription = getSeparatorStringMemo(inboxMessage) +
messageBody +
InboxHelper.DELIMITER_HTML +
InboxHelper.DELIMITER_HTML +
descriptionText
;
ticketObject.setQw_descriptiontext(newDescription.toCharArray());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -