<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[JForum Community - Latest posts for "deepacific"]]></title>
		<link>https://community.jforum.net/posts/listByUser/20</link>
		<description><![CDATA[Latest posts for "deepacific"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>[Integration Forum] Re:Create a Topic and Navigate to Topic programatically</title>
				<description><![CDATA[ Hi andowsen
<br>
<br>
Here is the code for changed PostRes.java. This handles posting replies and returning the number of posts. I still have to figure out what is the best place to add a hook for firing the event , when a new post is added
<br>
<pre class="line-numbers"><code class="language-java match-braces"><br>/*<br> * Copyright (c) JForum Team<br> * All rights reserved.<br> * <br> * Redistribution and use in source and binary forms, <br> * with or without modification, are permitted provided <br> * that the following conditions are met:<br> * <br> * 1) Redistributions of source code must retain the above <br> * copyright notice, this list of conditions and the <br> * following disclaimer.<br> * 2) Redistributions in binary form must reproduce the <br> * above copyright notice, this list of conditions and <br> * the following disclaimer in the documentation and/or <br> * other materials provided with the distribution.<br> * 3) Neither the name of "Rafael Steil" nor <br> * the names of its contributors may be used to endorse <br> * or promote products derived from this software without <br> * specific prior written permission.<br> * <br> * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT <br> * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY <br> * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, <br> * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF <br> * MERCHANTABILITY AND FITNESS FOR A PARTICULAR <br> * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <br> * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE <br> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, <br> * EXEMPLARY, OR CONSEQUENTIAL DAMAGES <br> * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF <br> * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, <br> * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER <br> * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER <br> * IN CONTRACT, STRICT LIABILITY, OR TORT <br> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN <br> * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF <br> * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE<br> * <br> * Created on 01/10/2011 14:32:22<br> * The JForum Project<br> * http://www.jforum.net<br> */<br>package net.jforum.api.rest;<br><br>import java.util.Date;<br><br>import net.jforum.Command;<br>import net.jforum.JForumExecutionContext;<br>import net.jforum.SessionFacade;<br>import net.jforum.context.RequestContext;<br>import net.jforum.context.ResponseContext;<br>import net.jforum.dao.DataAccessDriver;<br>import net.jforum.dao.UserDAO;<br>import net.jforum.entities.Post;<br>import net.jforum.entities.Topic;<br>import net.jforum.entities.User;<br>import net.jforum.entities.UserSession;<br>import net.jforum.exceptions.APIException;<br>import net.jforum.util.I18n;<br>import net.jforum.util.preferences.ConfigKeys;<br>import net.jforum.util.preferences.SystemGlobals;<br>import net.jforum.util.preferences.TemplateKeys;<br>import net.jforum.view.forum.PostAction;<br><br>import org.apache.commons.lang3.StringUtils;<br><br>import freemarker.template.SimpleHash;<br>import freemarker.template.Template;<br>import net.jforum.repository.PostRepository;<br><br>/**<br> * @author Andowson Chang<br> *<br> */<br>public class PostREST extends Command {<br><br>	/* (non-Javadoc)<br>	 * @see net.jforum.Command#list()<br>	 */<br>	@Override<br>	public void list() {<br>		try {<br>			this.authenticate();<br>			// do nothing here<br>			// TODO: add implementation<br>		}<br>		catch (Exception e) {<br>			this.setTemplateName(TemplateKeys.API_ERROR);<br>			this.context.put("exception", e);<br>		}<br>	}<br><br>	/**<br>	 * Creates a new post.<br>	 * Required parameters are "email", "forum_id", "subject" and "message".<br>	 */<br>	public void insert()<br>	{<br>		try {<br>			this.authenticate();<br>			<br>			final String email = this.requiredRequestParameter("email");<br>			final String forumId = this.requiredRequestParameter("forum_id");<br>			final String subject = this.requiredRequestParameter("subject");<br>			final String message = this.requiredRequestParameter("message");<br>                        final String topicId = this.request.getParameter("topicId");<br>                        <br>                        <br>			final UserDAO dao = DataAccessDriver.getInstance().newUserDAO();			<br>			User user = dao.findByEmail(email);<br>			// If user's email not exists, use anonymous instead<br>			if (user == null) {<br>				user = new User();<br>				user.setId(SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID));<br>				user.setUsername(I18n.getMessage("Guest"));<br>			}<br>			// OK, time to insert the post<br>			final UserSession userSession = SessionFacade.getUserSession();<br>			userSession.setUserId(user.getId());<br>			userSession.setUsername(user.getUsername());<br>			String sessionId = userSession.getSessionId(); <br>			userSession.setStartTime(new Date(System.currentTimeMillis()));<br>			SessionFacade.makeLogged();<br><br>			SessionFacade.removeAttribute(ConfigKeys.LAST_POST_TIME);<br>			SessionFacade.setAttribute(ConfigKeys.REQUEST_IGNORE_CAPTCHA, "1");<br><br>			final Post post = new Post();<br>			post.setForumId(Integer.valueOf(forumId));<br>			post.setSubject(subject);<br>			post.setText(message);<br>                        <br>                        // check if it is a reply to a post and if topic Id is not 0<br>                        if(topicId != null &amp;&amp; !topicId.equalsIgnoreCase("")){<br>                            try{<br>                                post.setTopicId(Integer.valueOf(topicId));<br>                            }catch(Exception e){<br>                              // do nothing here<br>                            }<br>                        }<br>			this.insertMessage(user, post);<br>			                        <br>			// new start<br>			String postLink = JForumExecutionContext.getRedirectTo();<br>                        JForumExecutionContext.setRedirect(null);<br>                        if(postLink == null || postLink.equals("")){<br>                            postLink = "Error";<br>                        }<br>                        JForumExecutionContext.getResponse().addHeader("postLink", postLink);<br>                        this.setTemplateName("api.post.insert");<br>                        // add a header to the response for the post link<br>                        this.context.put("postLink", postLink);<br>                        int numOfPosts = PostRepository.size(post.getTopicId());<br>                        if(numOfPosts == 0){<br>                            // not loaded in cache yet, load in cache<br>                            PostRepository.selectAllByTopicByLimit(post.getTopicId(), 0, 1);<br>                            // get the number of posts<br>                            numOfPosts = PostRepository.size(post.getTopicId());<br>                        }    <br>                        // add a header for the number of posts<br>                        JForumExecutionContext.getResponse().addHeader("numOfPosts", String.valueOf(numOfPosts));<br>                        this.context.put("numOfPosts", String.valueOf(numOfPosts));<br>                        <br>			 // new end			<br>			<br>			SessionFacade.makeUnlogged();<br>			SessionFacade.remove(sessionId);			<br>		}<br>		catch (Exception e) {<br>			this.setTemplateName(TemplateKeys.API_ERROR);<br>			this.context.put("exception", e);<br>		}<br>	}<br>	<br>	/**<br>	 * Calls {@link PostAction#insertSave()}<br>	 * @param post the post<br>	 * @param user the user who's doing the post<br>	 */<br>	private void insertMessage(final User user, final Post post)<br>	{<br>		this.addDataToRequest(user, post);<br>		<br>		final PostAction postAction = new PostAction(JForumExecutionContext.getRequest(), new SimpleHash());<br>		postAction.insertSave();<br>	}<br>	<br>	/**<br>	 * Extracts information from a mail message and adds it to the request context<br>	 * @param post the post<br>	 * @param user the user who's doing the post<br>	 */<br>	private void addDataToRequest(final User user, final Post post)<br>	{<br>		final RequestContext request = JForumExecutionContext.getRequest(); <br><br>		request.addParameter("topic_type", Integer.toString(Topic.TYPE_NORMAL));<br>		request.addParameter("quick", "1");<br>		<br>		final int topicId = post.getTopicId();<br>		if (topicId &gt; 0) {<br>			request.addParameter("topic_id", Integer.toString(topicId));<br>		}<br>		<br>		if (!user.isBbCodeEnabled()) {<br>			request.addParameter("disable_bbcode", "on");<br>		}<br>		<br>		if (!user.isSmiliesEnabled()) {<br>			request.addParameter("disable_smilies", "on");<br>		}<br>		<br>		if (!user.isHtmlEnabled()) {<br>			request.addParameter("disable_html", "on");<br>		}<br>	}	<br>	<br>	/**<br>	 * Retrieves a parameter from the request and ensures it exists<br>	 * @param paramName the parameter name to retrieve its value<br>	 * @return the parameter value<br>	 * @throws APIException if the parameter is not found or its value is empty<br>	 */<br>	private String requiredRequestParameter(final String paramName)<br>	{<br>		final String value = this.request.getParameter(paramName);<br>		<br>		if (StringUtils.isBlank(value)) {<br>			throw new APIException("The parameter '" + paramName + "' was not found");<br>		}<br>		<br>		return value;<br>	}<br><br>	/**<br>	 * Tries to authenticate the user accessing the API<br>	 * @throws APIException if the authentication fails<br>	 */<br>	private void authenticate()<br>	{<br>		final String apiKey = this.requiredRequestParameter("api_key");<br>		<br>		final RESTAuthentication auth = new RESTAuthentication();<br>		<br>		if (!auth.validateApiKey(apiKey)) {<br>			throw new APIException("The provided API authentication information is not valid");<br>		}<br>	}<br>	<br>	public Template process(final RequestContext request, final ResponseContext response, final SimpleHash context)<br>	{<br>		JForumExecutionContext.setContentType("text/xml");<br>		return super.process(request, response, context);<br>	}<br>}<br></code></pre>]]></description>
				<guid isPermaLink="true">https://community.jforum.net/posts/preList/31/94</guid>
				<link>https://community.jforum.net/posts/preList/31/94</link>
				<pubDate><![CDATA[Mon, 5 Mar 2012 22:21:20]]> GMT</pubDate>
				<author><![CDATA[ deepacific]]></author>
			</item>
			<item>
				<title>[Integration Forum] Re:Create a Topic and Navigate to Topic programatically</title>
				<description><![CDATA[ Hi andowson
<br>
<br>
I already made some changes in PostRest that allows me to:
<br>
<br>
1. Post replies on a topic - I basically added another parameter topicId and then set the topic id on the post object.
<br>
2. Return total number of posts in a topic - once again I modified the PostRest to return the numOfPosts as a header in the response object. I am getting this number from PostRepository.
<br>
3. For the event/notification, I know what needs to be done. Basically we need methods to register listeners for the different updates and then fire an event based on update type. Then people can just implement that interface and do whatever they wish to do in their application. I just wanted to make sure that if these changes are acceptable and will become part of the next release. I want to avoid synchronizing my changes with every new release of JForum.
<br>
<br>
<br>
I am more than happy to put the code here if you want.
<br>
<br>
Best
<br>
<br>
Deepacific]]></description>
				<guid isPermaLink="true">https://community.jforum.net/posts/preList/31/92</guid>
				<link>https://community.jforum.net/posts/preList/31/92</link>
				<pubDate><![CDATA[Thu, 1 Mar 2012 22:21:07]]> GMT</pubDate>
				<author><![CDATA[ deepacific]]></author>
			</item>
			<item>
				<title>[Integration Forum] Re:Create a Topic and Navigate to Topic programatically</title>
				<description><![CDATA[ Hi andowson
<br>
<br>
I did check that link and it was really helpful. I actually wanted to wrap some more calls, like
<br>
posting a reply on a topic
<br>
getting total number of posts in a topic
<br>
getting an event every time there is a new post in a topic
<br>
<br>
<br>
Are there any plans in near future for a full API for doing all this?]]></description>
				<guid isPermaLink="true">https://community.jforum.net/posts/preList/31/90</guid>
				<link>https://community.jforum.net/posts/preList/31/90</link>
				<pubDate><![CDATA[Thu, 23 Feb 2012 23:17:14]]> GMT</pubDate>
				<author><![CDATA[ deepacific]]></author>
			</item>
			<item>
				<title>[Integration Forum] Create a Topic and Navigate to Topic programatically</title>
				<description><![CDATA[ Hi
<br>
<br>
Is there any way to create a new Topic from another application and get back the URL or some info. Also, I want to be able to navigate to that topic from external application.
<br>
<br>
This is the use case I am trying to solve.
<br>
1. JForum Admin sets up some forums for users.
<br>
2. From an external application, I want to start a new topic in a specific forum. So I need to find the right forum by looking up its id or name or something unique. May be get a list of forums along with forum Ids.
<br>
3. When user clicks on new Topic, user must select a forum from the list and after selection, User enters basic Topic information e.g Name , Description etc and clicking ok creates a new topic in selected forum. It returns the topic id or some unique identifier.
<br>
4. I can bind the unique topic Id with that user in my application and construct a URL that will point to that topic.
<br>
<br>
Thank you.
<br>
<br>
deepacific
<br>]]></description>
				<guid isPermaLink="true">https://community.jforum.net/posts/preList/31/87</guid>
				<link>https://community.jforum.net/posts/preList/31/87</link>
				<pubDate><![CDATA[Fri, 17 Feb 2012 22:48:18]]> GMT</pubDate>
				<author><![CDATA[ deepacific]]></author>
			</item>
	</channel>
</rss>