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.