package org.sagebionetworks.web.server.servlet;

import org.sagebionetworks.client.exceptions.SynapseException;
import org.sagebionetworks.reflection.model.PaginatedResults;
import org.sagebionetworks.repo.model.discussion.CreateDiscussionThread;
import org.sagebionetworks.repo.model.discussion.DiscussionThreadBundle;
import org.sagebionetworks.repo.model.discussion.DiscussionThreadOrder;
import org.sagebionetworks.repo.model.discussion.Forum;
import org.sagebionetworks.repo.model.discussion.UpdateThreadMessage;
import org.sagebionetworks.repo.model.discussion.UpdateThreadTitle;
import org.sagebionetworks.web.client.DiscussionForumClient;
import org.sagebionetworks.web.shared.exceptions.ExceptionUtil;
import org.sagebionetworks.web.shared.exceptions.RestServiceException;

@SuppressWarnings("serial")
public class DiscussionForumClientImpl extends SynapseClientBase implements
		DiscussionForumClient{

	@Override
	public Forum getForumMetadata(String projectId) throws RestServiceException {
		org.sagebionetworks.client.SynapseClient synapseClient = createSynapseClient();
		try {
			return synapseClient.getForumMetadata(projectId);
		} catch (SynapseException e) {
			throw ExceptionUtil.convertSynapseException(e);
		}
	}

	@Override
	public DiscussionThreadBundle createThread(CreateDiscussionThread toCreate)
			throws RestServiceException {
		org.sagebionetworks.client.SynapseClient synapseClient = createSynapseClient();
		try {
			return synapseClient.createThread(toCreate);
		} catch (SynapseException e) {
			throw ExceptionUtil.convertSynapseException(e);
		}
	}

	@Override
	public DiscussionThreadBundle getThread(String threadId)
			throws RestServiceException {
		org.sagebionetworks.client.SynapseClient synapseClient = createSynapseClient();
		try {
			return synapseClient.getThread(threadId);
		} catch (SynapseException e) {
			throw ExceptionUtil.convertSynapseException(e);
		}
	}

	@Override
	public PaginatedResults<DiscussionThreadBundle> getThreadsForForum(
			String forumId, Long limit, Long offset,
			DiscussionThreadOrder order, Boolean ascending)
			throws RestServiceException {
		org.sagebionetworks.client.SynapseClient synapseClient = createSynapseClient();
		try {
			return synapseClient.getThreadsForForum(forumId, limit, offset, order, ascending);
		} catch (SynapseException e) {
			throw ExceptionUtil.convertSynapseException(e);
		}
	}

	@Override
	public DiscussionThreadBundle updateThreadTitle(String threadId,
			UpdateThreadTitle newTitle) throws RestServiceException {
		org.sagebionetworks.client.SynapseClient synapseClient = createSynapseClient();
		try {
			return synapseClient.updateThreadTitle(threadId, newTitle);
		} catch (SynapseException e) {
			throw ExceptionUtil.convertSynapseException(e);
		}
	}

	@Override
	public DiscussionThreadBundle updateThreadMessage(String threadId,
			UpdateThreadMessage newMessage) throws RestServiceException {
		org.sagebionetworks.client.SynapseClient synapseClient = createSynapseClient();
		try {
			return synapseClient.updateThreadMessage(threadId, newMessage);
		} catch (SynapseException e) {
			throw ExceptionUtil.convertSynapseException(e);
		}
	}

	@Override
	public void markThreadAsDeleted(String threadId)
			throws RestServiceException {
		org.sagebionetworks.client.SynapseClient synapseClient = createSynapseClient();
		try {
			synapseClient.markThreadAsDeleted(threadId);
		} catch (SynapseException e) {
			throw ExceptionUtil.convertSynapseException(e);
		}
	}

}

@@ -109,70 +109,8 @@
 on;%0A
-import org.sagebionetworks.reflection.model.PaginatedResults;%0A
 impo
@@ -178,16 +178,16 @@
 Thread;%0A
+
 import o
@@ -513,24 +513,78 @@
 hreadTitle;%0A
+import org.sagebionetworks.schema.adapter.JSONEntity;%0A
 import org.s
@@ -632,16 +632,72 @@
 Client;%0A
+import org.sagebionetworks.web.shared.PaginatedResults;%0A
 import o
@@ -928,16 +928,16 @@
 lements%0A
-
 %09%09Discus
@@ -954,16 +954,359 @@
 lient%7B%0A%0A
+%09/**%0A%09 * Helper to convert from the non-gwt compatible PaginatedResults to the compatible type.%0A%09 * @param in%0A%09 * @return%0A%09 */%0A%09public %3CT extends JSONEntity%3E PaginatedResults%3CT%3E convertPaginated(org.sagebionetworks.reflection.model.PaginatedResults%3CT%3E in)%7B%0A%09%09return  new PaginatedResults%3CT%3E(in.getResults(), in.getTotalNumberOfResults());%0A%09%7D%0A%0A
 %09@Overri
@@ -2602,32 +2602,49 @@
 try %7B%0A%09%09%09return 
+convertPaginated(
 synapseClient.ge
@@ -2701,16 +2701,17 @@
 cending)
+)
 ;%0A%09%09%7D ca

convert type