While adding documents to documents library there are two ways of doing it using the liferay API, DLFileEntryLocalServiceUtil or DLAppLocalServiceUtil
Where as DLApp (DLAppService & DLAppLocalService) services take into account these things i.e. to say that they take care of syncing documents between liferay database and other repositories, and not just store entries in Liferay database.
Adding documents to Documents Library
1. Get the File object (using input stream) of the file which is being inserting to the document library.
2. Get the FileInputStream
InputStream inputStream = new FileInputStream( file );
3. Get the ThemeDisplay from the request. This is used for retrieving the user id and group id while adding the documents which is depicted in the further steps down.
ThemeDisplay themeDisplay = ( ThemeDisplay ) actionRequest.getAttribute( WebKeys.THEME_DISPLAY );
4. Get the Service Context object
ServiceContext serviceContext = ServiceContextFactory.getInstance( actionRequest );
5. Get the access folder in which the document would be placed.
Folder folder = DLAppLocalServiceUtil.getFolder( themeDisplay.getScopeGroupId(), 0, "<<Name of the folder>>" );
Here the first argument is the repository ID, If the repository is a default Liferay repository, the repositoryId is the groupId or scopeGroupId. Otherwise, the repositoryId will correspond to values obtained from RepositoryLocalServiceUtil.
6. Now finally the inserting to the document library using DLAppLocalServiceUtil
FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry( themeDisplay.getUserId(), folder.getRepositoryId(), folder.getFolderId(), fileName,
contentType, fileName, fileName, "changeLog", inputStream, file.length(), serviceContext );
That is all we need to do, document is now inserted in the document library.
hey i really hope you can help me out :) because this is the only useful post i could find so far. I am triying to extend the DLAppLocalService by overwriting a service via a hook. What i try to achieve is to set an initial folder structure for the DL. But i cannot add a folder because i cannot reach a request var therefor i cannot get themeDisplay or groupId etc.
ReplyDeletemaybe you can help me out how i can do this :)
how do we retrieve it sir?
ReplyDelete