cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a forum post from restlet

jana01_
Champ on-the-rise
Champ on-the-rise

Hi,

I have a forum topic and I try to add a post to it.

I have the following restlet:

@Name(value = "discussionService")
@Scope(ScopeType.EVENT)
public class DiscussionService extends BaseStatelessNuxeoRestlet {...

And declaration:

    <restletPlugin
        name="discussionService"
        class="com.sirma.itt.rs.rest.DiscussionService"
        enabled="true"
        useSeam="true"
        useConversation="true">
        <urlPatterns>
            <urlPattern>/discussionService</urlPattern>
        </urlPatterns>
    </restletPlugin>

Also, navigationContext is injected:

@In(create = true)
private transient NavigationContext navigationContext;

Then I get a json request, that contains Nuxeo UID of an existing forum topic and I try to add a post to it:

    documentManager = SessionFactory.getSession(getHttpRequest(req));

    DocumentModel replyToDoc = documentManager.getDocument(new IdRef(replyTo));

    log.debug("replyToDoc "+replyTo); // this is the topic; it exists

    if (replyToDoc != null) {
        navigationContext.setCurrentDocument(replyToDoc);
        navigationContext.setChangeableDocument(replyToDoc);
    }

    DocumentModel dm = documentManager.createDocumentModel("CustomPost");
    dm.setProperty(....);
    dm.setProperty(....);
    ....

    dm = commentManagerActions.addComment(dm);
    ....

I am getting the following exception:

java.lang.NullPointerException
	at org.nuxeo.ecm.webapp.context.NavigationContextBean.setCurrentDocument(NavigationContextBean.java:192)

Unfortunately, I could not get the 5.5 source code so I have no idea what's on row 192 in NavigationContextBean.

Is this the proper way of doing this task? Is there a similar example somewhere? And what is the reason for the NullPointerException?

Thanks!

1 ACCEPTED ANSWER

jana01_
Champ on-the-rise
Champ on-the-rise

I changed my code to:

    navigationContext.setCurrentServerLocation(new RepositoryLocation("default"));
    documentManager = navigationContext.getOrCreateDocumentManager();

and saving the post seems to work.

View answer in original post

3 REPLIES 3

jana01_
Champ on-the-rise
Champ on-the-rise

I changed my code to:

    navigationContext.setCurrentServerLocation(new RepositoryLocation("default"));
    documentManager = navigationContext.getOrCreateDocumentManager();

and saving the post seems to work.

I strongly recommend you to look example of Nuxeo into our source code. You have many examples in the nuxeo-platform-ui-web project.

Benjamin_Jalon1
Elite Collaborator
Elite Collaborator
  • If you want the source code download it fom [here][1] and go to the 5.5 branch.
Getting started

Attention: Blogs & Forums are in READ-ONLY mode from Oct 9-19 as we transition to our new platform. Learn more.

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.