use of org.jivesoftware.openfire.fastpath.providers.ChatNotes in project Openfire by igniterealtime.
the class ChatSearchManager method getChatsInformation.
/**
* Returns information about the chats that took place since a given date. The result is
* sorted from oldest chats to newest chats.
*
* @param since the date to use as the lower limit.
* @return information about the chats that took place since a given date.
*/
private List<ChatInformation> getChatsInformation(Date since) {
List<ChatInformation> chats = new ArrayList<ChatInformation>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet result = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(CHATS_SINCE_DATE);
pstmt.setLong(1, workgroup.getID());
pstmt.setString(2, StringUtils.dateToMillis(since));
result = pstmt.executeQuery();
while (result.next()) {
String sessionID = result.getString(1);
String transcript = result.getString(2);
String startTime = result.getString(3);
ChatNotes chatNotes = new ChatNotes();
String notes = chatNotes.getNotes(sessionID);
// Create a ChatInformation with the retrieved information
ChatInformation chatInfo = new ChatInformation(sessionID, transcript, startTime, notes);
if (chatInfo.getTranscript() != null) {
chats.add(chatInfo);
}
}
result.close();
// For each ChatInformation add the agents involved in the chat
for (ChatInformation chatInfo : chats) {
pstmt.close();
pstmt = con.prepareStatement(AGENTS_IN_SESSION);
pstmt.setString(1, chatInfo.getSessionID());
result = pstmt.executeQuery();
while (result.next()) {
chatInfo.getAgentJIDs().add(result.getString(1));
}
result.close();
}
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
// Reset the answer if an error happened
chats = new ArrayList<ChatInformation>();
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
try {
if (result != null) {
result.close();
}
} catch (SQLException e) {
Log.error(e.getMessage(), e);
}
try {
if (con != null) {
con.close();
}
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
try {
if (result != null) {
result.close();
}
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
// Return the chats order by startTime
return chats;
}
use of org.jivesoftware.openfire.fastpath.providers.ChatNotes in project Openfire by igniterealtime.
the class ChatSearchManager method rebuildIndex.
/**
* Retrieves information about each transcript that took place since the specified date and
* adds it to the index.<p>
* <p/>
* Note: In order to cope with large volumes of data we don't want to load
* all the information into memory. Therefore, for each retrieved row we create a
* ChatInformation instance and add it to the index.
*
* @param since the date to use as the lower limit.
* @throws IOException if rebuilding the index fails.
*/
private void rebuildIndex(Date since) throws IOException {
Date lastDate = null;
IndexWriter writer = getWriter(true);
Connection con = null;
PreparedStatement pstmt = null;
ResultSet result = null;
try {
// TODO Review logic for JDBC drivers that load all the answer into memory
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(CHATS_SINCE_DATE);
pstmt.setLong(1, workgroup.getID());
pstmt.setString(2, StringUtils.dateToMillis(since));
result = pstmt.executeQuery();
while (result.next()) {
String sessionID = result.getString(1);
String transcript = result.getString(2);
String startTime = result.getString(3);
String chatNotes = new ChatNotes().getNotes(sessionID);
ChatInformation chatInfo = new ChatInformation(sessionID, transcript, startTime, chatNotes);
if (chatInfo.getTranscript() != null) {
addAgentHistoryToChatInformation(chatInfo);
// Add the ChatInformation to the index
addTranscriptToIndex(chatInfo, writer);
lastDate = chatInfo.getCreationDate();
}
}
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
// Reset the lastDate if an error happened
lastDate = null;
} finally {
try {
if (result != null) {
result.close();
}
} catch (SQLException e) {
Log.error(e.getMessage(), e);
}
DbConnectionManager.closeConnection(pstmt, con);
}
writer.optimize();
writer.close();
if (lastDate != null) {
closeSearcherReader();
// Reset the filters cache
cachedFilters.clear();
// Update the last updated and optimized dates
lastOptimization = new Date();
lastUpdated = lastDate;
lastExecution = new Date();
pendingTranscripts.set(0);
// Save the last updated and optimized dates to the database
saveDates();
}
}
Aggregations