Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to achieve Document Version Contorl in Liferay?

    • 0
    • 2
    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 692
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: