Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Document API - How to correctly update existing documents programmatica
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.
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.
Hi,
Try using DlAppLocalService or DlAppService instead of DlFileEntryLocalService
Try using DlAppLocalService or DlAppService instead of DlFileEntryLocalService
DLAppLocalService.updateFileEntry(userId, fileEntryId, sourceFileName, mimeType title, description, changeLog DLVersionNumberIncrease.MINOR, file, serviceContext); DLAppService.updateFileEntry(fileEntryId, sourceFileName, mimeType, title, description, changeLog DLVersionNumberIncrease.MINOR, file, serviceContext);
Thanks for the reply. So are all these services redundant?
Not redundant , all have there own uses DlFileEntrylocalservice api are for DLFileEntry Entity , DLApp Services should be used for document and media.
You can go refer below links for more information
https://help.liferay.com/hc/en-us/articles/360019952312-Getting-Started-with-the-Documents-and-Media-API
https://help.liferay.com/hc/en-us/articles/360019952332-Creating-Files-Folders-and-Shortcuts
https://help.liferay.com/hc/en-us/articles/360020197211-Creating-Files-
https://help.liferay.com/hc/en-us/articles/360019952432-Updating-Files
You can go refer below links for more information
https://help.liferay.com/hc/en-us/articles/360019952312-Getting-Started-with-the-Documents-and-Media-API
https://help.liferay.com/hc/en-us/articles/360019952332-Creating-Files-Folders-and-Shortcuts
https://help.liferay.com/hc/en-us/articles/360020197211-Creating-Files-
https://help.liferay.com/hc/en-us/articles/360019952432-Updating-Files
Thank you. With DLAppService.updateFileEntry(...) it works :-)