use of net.jforum.JForumExecutionContext in project jforum2 by rafaelsteil.
the class POPPostAction method insertMessages.
public void insertMessages(POPParser parser) {
long ms = System.currentTimeMillis();
int counter = 0;
try {
JForumExecutionContext ex = JForumExecutionContext.get();
RequestContext request = new StandardRequestContext();
ex.setForumContext(new JForumContext("/", "", request, null));
JForumExecutionContext.set(ex);
SessionFacade.setAttribute(ConfigKeys.TOPICS_READ_TIME, new HashMap());
for (Iterator iter = parser.getMessages().iterator(); iter.hasNext(); ) {
POPMessage m = (POPMessage) iter.next();
String sessionId = ms + m.getSender() + counter++;
request.getSessionContext().setAttribute(StandardSessionContext.SESSION_ID, sessionId);
User user = this.findUser(m.getSender());
if (user == null) {
logger.warn("Could not find user with email " + m.getSender() + ". Ignoring his message.");
continue;
}
try {
UserSession us = new UserSession();
us.setUserId(user.getId());
us.setUsername(us.getUsername());
us.setSessionId(sessionId);
SessionFacade.add(us, sessionId);
SessionFacade.setAttribute(ConfigKeys.LOGGED, "1");
SessionFacade.removeAttribute(ConfigKeys.LAST_POST_TIME);
SessionFacade.setAttribute(ConfigKeys.REQUEST_IGNORE_CAPTCHA, "1");
this.insertMessage(m, user);
} finally {
SessionFacade.remove(sessionId);
}
}
} finally {
JForumExecutionContext.finish();
}
}
use of net.jforum.JForumExecutionContext in project jforum2 by rafaelsteil.
the class InstallAction method storeSupportProjectMessage.
private void storeSupportProjectMessage(Connection connection) {
StringBuffer message = new StringBuffer("[color=#3AA315][size=18][b]Support JForum - Help the project[/b][/size][/color]").append("<hr>").append("This project is Open Source, and maintained by at least one full time Senior Developer, [i]which costs US$ 3,000.00 / month[/i]. ").append("If it helped you, please consider helping this project - especially with some [b][url=http://www.jforum.net/contribute.jsp]donation[/url][/b].").append('\n').append('\n').append("[color=#137C9F][size=14][b]Why supporting this project is a good thing[/b][/size][/color]").append("<hr>").append("The JForum Project started four years ago as a completely free and Open Source program, initially entirely developed on my (Rafael Steil) ").append("free time. Today, with the help of some very valuable people, I can spend more time on JForum, to improve it and implement new features ").append("(lots of things, requested either on the [url=http://www.jforum.net/forums/list.page]forums[/url] or registered in the ").append("[url=http://www.jforum.net/jira]bug tracker[/url]).").append('\n').append("That's why I'm asking you to financially support this work. I love Open Source. I love to use good products without having to pay for it too. ").append("But when I see some program that is valuable to my work, that helps me making money, I think it's a good idea to support this project.").append('\n').append('\n').append("[b]Some reasons to support open projects[/b]:").append("<ul><li>Because Open Source is cool? Yes").append("<li>To thank for a great tool? Yes").append("<li>To help the project evolve because this will help my work and my earnings? Yes</ul>").append("Also, as the project grows more and more, it would be great to, sometimes, reward some of the great people who help JForum.").append('\n').append('\n').append("So, that's what I'm asking you: if JForum helps your work, saves your time (time is money, remember?) and increase your earnings, support ").append("this project. The simpler way is to make [url=http://www.jforum.net/contribute.jsp]any donation[/url] via PayPal.").append('\n').append('\n').append("JForum has grown a lot every day, since four years ago, which is a great thing, and initially it wasn't my intention to fully work on this tool. ").append("Lately, I'm spending a lot of time on it, specially to make JForum 3 a reality, to help users, to improve the program, to research about ").append("better solutions. So, your support is very welcome!").append('\n').append('\n').append("Thanks!").append('\n').append('\n').append(":arrow: [size=16][b][url=http://www.jforum.net/contribute.jsp]Click here[/url][/b] to go to the [i][b][url=http://www.jforum.net/contribute.jsp]").append("\"Support JForum\"[/url][/b][/i] page.[/size]").append('\n').append('\n');
try {
ConfigLoader.createLoginAuthenticator();
ConfigLoader.loadDaoImplementation();
SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_GENERIC));
SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_DRIVER));
SystemGlobals.setValue(ConfigKeys.SEARCH_INDEXING_ENABLED, "false");
JForumExecutionContext ex = JForumExecutionContext.get();
ex.setConnection(connection);
JForumExecutionContext.set(ex);
User user = new User(2);
// Create topic
Topic topic = new Topic();
topic.setPostedBy(user);
topic.setTitle("Support JForum - Please read");
topic.setTime(new Date());
topic.setType(Topic.TYPE_ANNOUNCE);
topic.setForumId(1);
TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
topicDao.addNew(topic);
// Create post
Post post = new Post();
post.setSubject(topic.getTitle());
post.setTime(topic.getTime());
post.setUserId(user.getId());
post.setText(message.toString());
post.setForumId(topic.getForumId());
post.setSmiliesEnabled(true);
post.setHtmlEnabled(true);
post.setBbCodeEnabled(true);
post.setUserIp("127.0.0.1");
post.setTopicId(topic.getId());
PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
postDao.addNew(post);
// Update topic
topic.setFirstPostId(post.getId());
topic.setLastPostId(post.getId());
topicDao.update(topic);
// Update forum stats
ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
forumDao.incrementTotalTopics(1, 1);
forumDao.setLastPost(1, post.getId());
} finally {
SystemGlobals.setValue(ConfigKeys.SEARCH_INDEXING_ENABLED, "true");
JForumExecutionContext ex = JForumExecutionContext.get();
ex.setConnection(null);
JForumExecutionContext.set(ex);
}
}
use of net.jforum.JForumExecutionContext in project jforum2 by rafaelsteil.
the class LuceneReindexer method reindex.
private void reindex() {
try {
if (recreate) {
this.settings.createIndexDirectory(SystemGlobals.getValue(ConfigKeys.LUCENE_INDEX_WRITE_PATH));
}
} catch (IOException e) {
throw new ForumException(e);
}
LuceneDAO dao = DataAccessDriver.getInstance().newLuceneDAO();
IndexSearcher searcher = null;
LuceneSearch luceneSearch = ((LuceneManager) SearchFacade.manager()).luceneSearch();
LuceneIndexer luceneIndexer = ((LuceneManager) SearchFacade.manager()).luceneIndexer();
int fetchCount = SystemGlobals.getIntValue(ConfigKeys.LUCENE_INDEXER_DB_FETCH_COUNT);
try {
if (!recreate) {
searcher = new IndexSearcher(this.settings.directory());
}
boolean hasMorePosts = true;
long processStart = System.currentTimeMillis();
int firstPostId = args.filterByMessage() ? args.getFirstPostId() : dao.firstPostIdByDate(args.getFromDate());
if (args.filterByMessage()) {
int dbFirstPostId = dao.firstPostId();
if (firstPostId < dbFirstPostId) {
firstPostId = dbFirstPostId;
}
}
int lastPostId = args.filterByMessage() ? args.getLastPostId() : dao.lastPostIdByDate(args.getToDate());
int counter = 1;
int indexTotal = 0;
long indexRangeStart = System.currentTimeMillis();
while (hasMorePosts) {
boolean contextFinished = false;
int toPostId = firstPostId + fetchCount < lastPostId ? firstPostId + fetchCount : lastPostId;
try {
JForumExecutionContext ex = JForumExecutionContext.get();
JForumExecutionContext.set(ex);
List l = dao.getPostsToIndex(firstPostId, toPostId);
if (counter >= 5000) {
long end = System.currentTimeMillis();
System.out.println("Indexed ~5000 documents in " + (end - indexRangeStart) + " ms (" + indexTotal + " so far)");
indexRangeStart = end;
counter = 0;
}
JForumExecutionContext.finish();
contextFinished = true;
for (Iterator iter = l.iterator(); iter.hasNext(); ) {
if ("0".equals(SystemGlobals.getValue(ConfigKeys.LUCENE_CURRENTLY_INDEXING))) {
hasMorePosts = false;
break;
}
Post post = (Post) iter.next();
if (!recreate && args.avoidDuplicatedRecords()) {
if (luceneSearch.findDocumentByPostId(post.getId()) != null) {
continue;
}
}
luceneIndexer.batchCreate(post);
counter++;
indexTotal++;
}
firstPostId += fetchCount;
hasMorePosts = hasMorePosts && l.size() > 0;
} finally {
if (!contextFinished) {
JForumExecutionContext.finish();
}
}
}
long end = System.currentTimeMillis();
System.out.println("**** Total: " + (end - processStart) + " ms");
} catch (IOException e) {
throw new ForumException(e);
} finally {
SystemGlobals.setValue(ConfigKeys.LUCENE_CURRENTLY_INDEXING, "0");
luceneIndexer.flushRAMDirectory();
if (searcher != null) {
try {
searcher.close();
} catch (Exception e) {
}
}
}
}
Aggregations