留言板

How to programmatically change the status of some document in liferay 7?

thumbnail
Abhishek Jain,修改在7 年前。

How to programmatically change the status of some document in liferay 7?

Regular Member 帖子: 226 加入日期: 16-8-20 最近的帖子
I want to change the status of some document to approved in the Documents and Media portlet in liferay 7. For that I am using the below function in some jsp file:-

DLFileEntryLocalServiceUtil.updateStatus(themeDisplay.getUserId(), fileEntry1.getFileVersion().getFileVersionId() ,0, null, null);


But doing so I am getting the NullPointerException as follows:-

java.lang.NullPointerException
at com.liferay.portlet.documentlibrary.service.impl.DLAppHelperLocalServiceImpl.updateStatus(DLAppHelperLocalServiceImpl.java:1144)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:153)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:85)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:58)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:127)
at com.liferay.portal.service.ServiceContextAdvice.invoke(ServiceContextAdvice.java:40)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:127)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:127)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:173)
at com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl.updateStatus(DLFileEntryLocalServiceImpl.java:2028)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:153)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:85)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:58)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:127)
at com.liferay.portal.service.ServiceContextAdvice.invoke(ServiceContextAdvice.java:40)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:127)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:127)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:173)


Here when I change the status of document to a non-zero value it is successfully updated but when I change the status to 0, I am getting the NPE. Can you tell me why and how to remove it? Thanx in advance..
Anji E,修改在7 年前。

RE: How to programmatically change the status of some document in liferay 7

Junior Member 帖子: 49 加入日期: 14-11-18 最近的帖子
Did you get any solution ??

Even i have same requirement .
thumbnail
Abhishek Jain,修改在7 年前。

RE: How to programmatically change the status of some document in liferay 7 (答复)

Regular Member 帖子: 226 加入日期: 16-8-20 最近的帖子
I just passed the value as non null for servicecontext and workflowcontext in updatestatus() . The reference for servicecontext is by the following code :-
serviceContext = ServiceContextFactory.getInstance(com.liferay.document.library.web.internal.portlet.DLAdminPortlet.class.getName(), renderRequest);

whereas I got reference of workflowContext by the folowing code:-
Map<string, serializable> workflowContext =
			(Map<string, serializable>)serviceContext.removeAttribute(
				"workflowContext");
	if (workflowContext == null) {
		workflowContext = Collections.emptyMap();
	}</string,></string,>

And called the updateStatus() method as follows:-
DLFileEntryLocalServiceUtil.updateStatus(themeDisplay.getUserId(), fileEntry.getFileVersion().getFileVersionId() ,102, serviceContext, workflowContext);

Hope this helps.. emoticon
Anji E,修改在6 年前。

RE: How to programmatically change the status of some document in liferay 7

Junior Member 帖子: 49 加入日期: 14-11-18 最近的帖子
Hi Abhishek ,

Thanks a lot for your suggestion . Its worked .

I have one more concern .
As soon document uploaded via Custom portlet , we are uploading document with status as "draft" .
draft records are not getting index , hence its not available for search ( we are retrieving documents using indexer ).
I have also tried do reindex as soon document uploaded still records are not getting indexing .
Ravikant Sirswa,修改在6 年前。

RE: How to programmatically change the status of some document in liferay 7

New Member 发布: 1 加入日期: 17-5-30 最近的帖子
If You want to changes your document and media status programmatically from draft to Approved.Follow below code
long companyId = PortalUtil.getDefaultCompanyId();
Company companyObj = CompanyLocalServiceUtil.getCompany(companyId);
Group group = GroupLocalServiceUtil.getGroup(companyId, String.valueOf(companyId));

DLFolder folder = DLFolderLocalServiceUtil.getFolder(group.getGroupId(), PARENT_FOLDER_ID,
"SirswaPartnerDocuments");
int workFlowStatus = WorkflowConstants.STATUS_APPROVED;

dlFileEntry = DLFileEntryLocalServiceUtil.updateStatus(folder.getUserId(),dlFileEntry.getFileVersion().getFileVersionId(),workFlowStatus, serviceContext,new HashMap<String, Serializable>());