Message Boards

Creating JournalFolder from UpdateArticleMVCActionCommand.

Yogesh Chandra, modified 3 Years ago.

Creating JournalFolder from UpdateArticleMVCActionCommand.

New Member Posts: 3 Join Date: 8/10/20 Recent Posts
Hi Team,I have a requirement to create JournalFolder while creating content of a particular structure. For that, I have  Customized UpdateArticleMVCActionCommand and creating JournalFolder using the below code.
 ServiceContext serviceContext = ServiceContextFactory.getInstance(JournalFolder.class.getName(), actionRequest);
  JournalFolder folder =  JournalFolderLocalServiceUtil.addFolder(themeDisplay.getUserId(), groupId,
                                parentFolderId, folderName, folderDescription,
                                serviceContext);
Below are logs that I am getting while creating a content.Caused by: java.lang.RuntimeException: java.lang.NullPointerException
        at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.setAttributes(ExpandoBridgeImpl.java:540)
        at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.setAttributes(ExpandoBridgeImpl.java:562)
        at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.setAttributes(ExpandoBridgeImpl.java:553)
        at com.liferay.journal.model.impl.JournalFolderModelImpl.setExpandoBridgeAttributes(JournalFolderModelImpl.java:1062)
        at com.liferay.journal.service.impl.JournalFolderLocalServiceImpl.addFolder(JournalFolderLocalServiceImpl.java:116)
thumbnail
Christoph Rabel, modified 3 Years ago.

RE: Creating JournalFolder from UpdateArticleMVCActionCommand.

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
Could you check the expando attributes in the serviceContext?
serviceContext.getExpandoBridgeAttributes() returns a map.
I believe it tries to set an attribute that does exist for JournalArticle but that doesn't exist for folder.
Instead of using ServiceContextFactory.getInstance, I would simply create a new ServiceContext object and use that one. If you need to transport information, I would copy it from the JournalArticle serviceContext (e.g. if you want the folder to have the same permissions as the article).
Yogesh Chandra, modified 3 Years ago.

RE: Creating JournalFolder from UpdateArticleMVCActionCommand.

New Member Posts: 3 Join Date: 8/10/20 Recent Posts
Hi Christoph Rabel,I have tried passing the JournalArticle's ServiceContext as well as the new ServiceContext object but it did not help. This code was running in 6.2 but throwing error after migrating to 7.2
thumbnail
Christoph Rabel, modified 3 Years ago.

RE: Creating JournalFolder from UpdateArticleMVCActionCommand.

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
When you do:
 ServiceContext serviceContext = new ServiceContext();
  JournalFolder folder =  JournalFolderLocalServiceUtil.addFolder(themeDisplay.getUserId(), groupId,
                                parentFolderId, folderName, folderDescription,
                                serviceContext);
The same exception still happens? That surprises me.
Yogesh Chandra, modified 3 Years ago.

RE: Creating JournalFolder from UpdateArticleMVCActionCommand.

New Member Posts: 3 Join Date: 8/10/20 Recent Posts
Yes, it's happening. I have tried all possible ways to create ServiceContext object.
thumbnail
Christoph Rabel, modified 3 Years ago.

RE: Creating JournalFolder from UpdateArticleMVCActionCommand.

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
Please check serviceContext.getExpandoBridgeAttributes().
It returns a map. Please check the content. If this map is null or empty, nothing should happen. It simply can't throw because the relevant line is never reached. So, the map has to contain something. If you create a fresh serviceContext, the map should be empty.