Liferay provides very rich environment to create versions for the Uploaded documents. You can achieve Document Version Control very easily in Liferay by using the below code.
Create the object of ServiceContext as below:
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),actionRequest);
String fileTitle =userName+"-"+Long.toString(System.currentTimeMillis());
Now you need to add new file entry into Store while uploading file as below:
// Add file entry
FileEntry fileEntry = DLAppServiceUtil.addFileEntry(
repositoryId, folder.getFolderId(), sourceFileName, contentType, fileTitle,
fileTitle, fileTitle, inputStream, size, serviceContext);
// This will save file into Store for the further use
AssetPublisherUtil.addAndStoreSelection(
actionRequest, DLFileEntry.class.getName(),
fileEntry.getFileEntryId(), -1);
After that we can easily create versions if the fileEntry already exist for the particular document by using below code:
FileEntry entry = DLAppLocalServiceUtil.getFileEntry(fileEntryId);
FileVersion fileVersion=entry.getLatestFileVersion();
fileEntry = DLAppServiceUtil.updateFileEntry(
fileEntryId, sourceFileName, contentType, fileVersion.getTitle(),
fileVersion.getDescription(), "", true, inputStream, size,
serviceContext);
The above will update the fileEntry with the different version.
Hope this will help you :)
0 Comment(s)