📄 inboxmanagerejb.java
字号:
interactionObj.setQw_problem(inboxMessage.getSubject());
// check and set description field
if (inboxMessage.getBody() == null) {
interactionObj.setQw_description(inboxMessage.getSubject());
} else {
String body = inboxMessage.getBody();
if (StringHelper.isHTML(body)) {
body = StringHelper.html2text(body);
}
if (body.length() > 2000)
interactionObj.setQw_description(body.substring(0, 1900));
else
interactionObj.setQw_description(body);
} // if (message.getBody() == null)
interactionObj.setQw_customerid(ticketObject.getQw_customerid());
interactionObj.setQw_employeeid(ticketObject.getQw_employeeid());
interactionObj.setQw_agentid(ticketObject.getQw_agentid());
hnd.commit();
interactionId = interactionObj.getQw_interactionid();
} catch (Exception ex) {
error = ex;
interactionId = null;
} // try
// Logging.
try {
if (error != null) {
String logMessage = "Can't create a new interaction: " + error.getMessage();
InboxLogPublisher publisher = new InboxLogPublisher( ls );
publisher.ERROR(logMessage, inboxMessage);
ERROR(logMessage, error);
throw error;
} else {
String logMessage = "The new interaction was created. The ticket ID is " + interactionId;
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 interaction was created");
return interactionId;
} // createInteractionByTicket(LogonSession, InboxMessage) : Long
public boolean createLinkInteractionTicket(LogonSession ls, Long interactionID, Long ticketID) throws EQLException {
DEBUG("Try to create a link between the Interaction #" + interactionID +
" and the Ticket #" + ticketID
);
JEOManagerLocal jeoManager = getJEOManager();
JEObjectHandler hnd = jeoManager.create(ls, InteractionTicketObjectHandler.class);
InteractionTicketObject linkObj = (InteractionTicketObject)hnd.getJEObject();
linkObj.setQw_interactionid(interactionID);
linkObj.setQw_ticketid(ticketID);
hnd.commit();
DEBUG("The link between the Interaction #" + interactionID +
" and the Ticket #" + ticketID + " was created."
);
return true;
} // createLinkInteractionTicket(LogonSession, Long, Long) : boolean
/**
* The method sends a reply by the ticket. It updates ticket information and creates a new Interaction.
* @param ls logon session object
* @param inboxMessage inbox message object
* @param mailHeaders mail headers
* @return true the reply was sent
* @throws Exception the reply wasn't sent
*/
public boolean sendReply(LogonSession ls, InboxMessage inboxMessage, Properties mailHeaders) throws Exception {
INFO("Send reply by object...");
Long interactionID;
boolean returnValue = false;
if (inboxMessage.getObjectType().compareTo(ApplicationHelper.INTERACTION_OBJECT_TYPE) == 0) {
interactionID = createInteraction(ls, inboxMessage);
if (interactionID != null)
returnValue = true;
} else if (inboxMessage.getObjectType().compareTo(ApplicationHelper.TICKET_OBJECT_TYPE) == 0) {
interactionID = createInteractionByTicket(ls, inboxMessage);
if (interactionID != null) {
returnValue = createLinkInteractionTicket(ls, interactionID, inboxMessage.getObjectId());
if (returnValue)
returnValue = updateTicket(ls, inboxMessage);
} else {
// empty
returnValue = false;
} // if (interactionID != null)
// save new attachements for this ticket
if (inboxMessage.getProcessId() != null) {
// get temp attachments
AttachmentTempObject[] dbAttachments;
dbAttachments = getAttachments(inboxMessage.getProcessId().longValue(), ls);
if (dbAttachments.length > 0) {
// save attachements
linkAttachmentsToObject(ls, inboxMessage);
}
} // if (inboxMessage.getProcessId() != null)
} else {
throw new GenericSystemException("Unsupported object type");
} // if (inboxMessage.getObjectType() == ApplicationHelper.INTERACTION_OBJECT_TYPE)
if (returnValue) {
returnValue = super.sendEmailMessage(ls, inboxMessage, mailHeaders);
setReplyDateToInbox(ls, inboxMessage);
}
if (returnValue)
INFO("The the reply was sent");
else
INFO("The the reply wasn't sent");
return returnValue;
} // createLinkInteractionTicket(LogonSession, Long, Long) : boolean
// ------------------------------------------------------- Private methods
/**
* The method returns a separator string for memo fields.
* @param inboxMessage inbox message object
* @return separator string
*/
private String getSeparatorStringMemo(InboxMessage inboxMessage) {
return InboxHelper.INDICATION_PREFIX_HTML +
inboxMessage.getFrom().getEmail() +
InboxHelper.getDateAsString() +
InboxHelper.INDICATION_POSTFIX_HTML
;
} // getSeparatorStringMemo(InboxMessage) : String
/**
* The method gets the customer by
* @param ls logon session object
* @param inboxMessage inbox message object
* @return customer ID
*/
private Long getCustomer(LogonSession ls, InboxMessage inboxMessage) {
INFO("Get the Customer to the object...");
long time = System.currentTimeMillis();
Exception error = null;
Long customerID = null;
try {
customerID = findCustomer(ls, inboxMessage.getFrom().getEmail());
// If customer wasn't found.
if (customerID == null) {
INFO("Try to find internal customer...");
customerID = findInternalCustomer(ls, inboxMessage.getFrom().getEmail());
if (customerID == null) {
INFO("The customer wasn't found. Create new Customer...");
JEOManagerLocal jeoManager = getJEOManager();
JEObjectHandler hnd = jeoManager.create(ls, CustomerObjectHandler.class);
CustomerObject customerObj = (CustomerObject)hnd.getJEObject();
String fullName = inboxMessage.getFrom().getFullName();
if (fullName != null) {
customerObj.setQw_fullname(fullName);
} else {
// try get default customer name
String defaultCustomerName = SysPropertyManager.getProperty("IN_EMAIL_DEFAULT_CUSTOMER_NAME");
if (defaultCustomerName != null) {
customerObj.setQw_fullname(defaultCustomerName);
} else {
// leave the fullname field empty
} // if (defaultCustomerName != null)
} // if (fullName != null)
customerObj.setQw_email(inboxMessage.getFrom().getEmail());
hnd.commit();
customerID = customerObj.getQw_customerid();
inboxMessage.setSenderID(customerID);
inboxMessage.setSenderType(CustomInboxHelper.CUSTOMER_TYPE);
INFO("The new customer was created.");
} else {
inboxMessage.setSenderID(customerID);
inboxMessage.setSenderType(CustomInboxHelper.CUSTOMER_INTERNAL_TYPE);
} // if (customerID == null)
} else {
inboxMessage.setSenderID(customerID);
inboxMessage.setSenderType(CustomInboxHelper.CUSTOMER_TYPE);
} // if (customerID == null)
} catch (Exception ex) {
error = ex;
} // try
// Logging.
try {
if (error != null) {
String logMessage = "Can't get the customer to link to the object: " + error.getMessage();
InboxLogPublisher publisher = new InboxLogPublisher(ls);
publisher.ERROR(logMessage, inboxMessage);
ERROR(logMessage, error);
customerID = null;
} else {
String logMessage = "The customer was found. The customer's ID is " + customerID;
INFO(logMessage + " Time (ms) - " + (System.currentTimeMillis() - time) +
". EmailAddress: " + inboxMessage.getFrom().getEmail());
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
return customerID;
} // getCustomer(LogonSession, InboxMessage) : Long
/**
* The method searches a customer by specified parameters.
* @param ls logon session object
* @param emailAddress email address
* @return customer ID
* @throws EQLException EQLManager return an exception
*/
private Long findCustomer(LogonSession ls, String emailAddress) throws EQLException {
Long customerID;
if (emailAddress != null) {
DEBUG("Try to find the customer by email - " + emailAddress);
EQLManagerLocal eqlManager = getEQLManagerLocal();
customerID = CustomerObjectHandler.selectIDByEmail(eqlManager, ls, emailAddress);
} else {
customerID = null;
} // if
return customerID;
//return new Long(-1000);
} // findCustomer(LogonSession, String) : Long
/**
* The method searches a internal customer by specified parameters.
* @param ls logon session object
* @param emailAddress email address
* @return customer ID
* @throws EQLException EQLManager return an exception
*/
private Long findInternalCustomer(LogonSession ls, String emailAddress) throws EQLException {
Long customerID;
if (emailAddress != null) {
DEBUG("Try to find the internal customer by email - " + emailAddress);
EQLManagerLocal eqlManager = getEQLManagerLocal();
customerID = EmployeeObjectHandler.selectIDByEmail(eqlManager, ls, emailAddress);
} else {
customerID = null;
} // if
return customerID;
} // findInternalCustomer(LogonSession, String) : Long
// ------------------------------------------------------- Protected methods
private static EQLManagerLocal getEQLManagerLocal() {
CacheObjectManager com = new CacheObjectManager();
return (EQLManagerLocal)com.getLocalObject(JNDINames.EQLManager, EQLManagerLocalHome.class);
}
// Gets an array of temporary attachment value objects.
private AttachmentTempObject[] getAttachments(long process_id, LogonSession ls) {
return getAttachmentManager().getTempAttachments(ls, process_id);
}
// Gets Attachment Manager EJB reference.
private AttachmentManagerLocal getAttachmentManager() {
return (AttachmentManagerLocal)getLocalObject(JNDINames.AttachmentManager, AttachmentManagerLocalHome.class);
}
} // class InboxManagerEJB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -