Message Boards

Document API - How to correctly update existing documents programmatically?

Fabian Witthaus, modified 3 Years ago.

Document API - How to correctly update existing documents programmatically?

New Member Posts: 3 Join Date: 9/16/20 Recent Posts
I have to develop a portlet for uploading new documents and updating existing ones with Liferay 7.3-ga1. Creating new documents and deleting works fine but I have a problem with updating existing ones.

For the update process I use dLFileEntryService.updateFileEntry(...) and dLFileEntryService.updateStatus(...) .

updatedEntry = dLFileEntryService.updateFileEntry(...);
...
dLFileEntryService.updateStatus(
user,
updatedFileEntry.getFileVersionId(),
WorkflowConstants.STATUS_APPROVED,
ServiceContextFactory.getInstance(DLFolder.class.getName(), request),
new HashMap<>()); // ? Docs say workflowContext

If I look as admin into 'documents and media' the new version of the document is displayed there (version counter increases), but still has the status 'draft' and not 'approved'. As result the new version is (of course) not shown in my portlet but still the former.

I have no idea why the status is not set correctly. I'm new to this API and took over the work from a more experienced colleague who left the company so I'm a bit lost here. So help is appreciated.
thumbnail
Mohammed Yasin, modified 3 Years ago.

RE: Document API - How to correctly update existing documents programmatica (Answer)

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts
Hi,
Try using DlAppLocalService or DlAppService instead of DlFileEntryLocalService

DLAppLocalService.updateFileEntry(userId, fileEntryId, sourceFileName, mimeType title, description, changeLog DLVersionNumberIncrease.MINOR, file, serviceContext);  

&nbsp;DLAppService.updateFileEntry(fileEntryId, sourceFileName, mimeType, title, description, changeLog DLVersionNumberIncrease.MINOR, file, serviceContext);  
Fabian Witthaus, modified 3 Years ago.

RE: Document API - How to correctly update existing documents programmatica

New Member Posts: 3 Join Date: 9/16/20 Recent Posts
Thanks for the reply. So are all these services redundant?
thumbnail
Mohammed Yasin, modified 3 Years ago.

RE: Document API - How to correctly update existing documents programmatica (Answer)

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts
Fabian Witthaus, modified 3 Years ago.

RE: Document API - How to correctly update existing documents programmatica

New Member Posts: 3 Join Date: 9/16/20 Recent Posts
Thank you. With DLAppService.updateFileEntry(...) it works :-)