I have the following code, where xhtmlContent was injected into the object.
AbstractPage page = pageManager.getAbstractPage(pageId); try { String html = xhtmlContent.convertWikiToView("{blog-posts}", new DefaultConversionContext(page.toPageContext()), null); } catch (XhtmlException e) { e.printStackTrace(); } catch (XMLStreamException e) { e.printStackTrace(); } System.out.println(html);
If I navigate to that particular page in confluence, the macro renders properly and displays a bunch of blogs. However the code above just renders "No blogposts found".
Why does my code end up rendering the macro differently from when I load the actual page? I suspect it is an issue when it is actually searching for blogs, but shouldn't the context take care of that for me?
Edit: If it makes a difference I am calling this code from within a scheduled job module.
Community moderators have prevented the ability to post new answers.
I think you're right - if the blog-posts macro is doing some permission checking, it's not going to work within a scheduled job because jobs run in an anonymous user context by default.
You can set a user to be the "current" user with the following code:
com.atlassian.confluence.user.AuthenticatedUserThreadLocal.setUser(theUser);
You need to obtain the user object by calling getUser on com.atlassian.confluence.user.UserAccessor, which you can get injected into your job in the same manner as your xhtmlContent and pageManager components.
Hi Nick.Unltd,
instead of using xhtmlContent in constructor you can try.
com.atlassian.renderer.WikiStyleRenderer.
or
com.atlassian.confluence.content.render.xhtml.Renderer;
regards,
tousif shaikh.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems that this is most likely caused by the SiteSearchPermissionsSearchFilter the macro uses when searching for blogs. Since this code is being run in a scheduled job I'm guessing it doesn't have the right permissions when searching. Does anyone know how to set proper permissions so that my scheduled job can run the search, or perhaps a workaround?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.