Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-48046

Opening a document via WebDAV doesn't increase the readCount

    Details

      Description

      1. Go to the 'Document and Media' portlet and upload a document.
      2. Via the portlet download the document.
      3. In the database check the corresponding record in the 'dlfileentry' table and examine the 'readCount' attribute. Upon downloading the document the value in this 'readCount' field increases.
      4. Access the document via WebDAV and attempt opening it.

      ===
      1- Prior to LPS-29678 the method getContentAsStream() looked like this:

      6012

      DLFileEntryResourceImpl(6012).java
      	@Override
      	public InputStream getContentAsStream() throws WebDAVException {
      		try {
      			String version = StringPool.BLANK;
      
      			if (PropsValues.DL_WEBDAV_HOLD_LOCK) {
      
      				// Get last version regardless of status
      
      				DLFileVersion fileVersion = _fileEntry.getLatestFileVersion();
      
      				version = fileVersion.getVersion();
      			}
      
      			return DLFileEntryLocalServiceUtil.getFileAsStream(
      				_webDavRequest.getCompanyId(), _webDavRequest.getUserId(),
      				_fileEntry.getGroupId(), _fileEntry.getFolderId(),
      				_fileEntry.getName(), version);
      		}
      		catch (Exception e) {
      			throw new WebDAVException(e);
      		}
      	}
      

      6120

      DLFileEntryResourceImpl(6120).java
      	@Override
      	public InputStream getContentAsStream() throws WebDAVException {
      		try {
      			String version = StringPool.BLANK;
      
      			return _fileEntry.getContentStream(version);
      		}
      		catch (Exception e) {
      			throw new WebDAVException(e);
      		}
      	}
      

      Then, LPS-29678 introduced this change: https://github.com/liferay/liferay-portal/commit/6d3a3530cad8353734c07fac280e66f4285b338e

      diff --git a/portal-impl/src/com/liferay/portlet/documentlibrary/webdav/DLFileEntryResourceImpl.java b/portal-impl/src/com/liferay/portlet/documentlibrary/webdav/DLFileEntryResourceImpl.java
      index 207d8e0..30e0c41 100644
      @@ -15,12 +15,14 @@
       package com.liferay.portlet.documentlibrary.webdav;
       
       import com.liferay.portal.kernel.repository.model.FileEntry;
      +import com.liferay.portal.kernel.repository.model.FileVersion;
       import com.liferay.portal.kernel.util.StringPool;
       import com.liferay.portal.kernel.webdav.BaseResourceImpl;
       import com.liferay.portal.kernel.webdav.WebDAVException;
       import com.liferay.portal.kernel.webdav.WebDAVRequest;
       import com.liferay.portal.model.Lock;
       import com.liferay.portlet.documentlibrary.model.DLFileEntry;
      +import com.liferay.portlet.documentlibrary.model.DLFileVersion;
       
       import java.io.InputStream;
       
      @@ -48,9 +50,11 @@ public class DLFileEntryResourceImpl extends BaseResourceImpl {
       	@Override
       	public InputStream getContentAsStream() throws WebDAVException {
       		try {
      +			FileVersion fileVersion = _fileEntry.getLatestFileVersion();
      +
       			String version = StringPool.BLANK;
       
      -			return _fileEntry.getContentStream(version);
      +			return fileVersion.getContentStream(false);
       		}
       		catch (Exception e) {
       			throw new WebDAVException(e);
      @@ -58,8 +62,27 @@ public class DLFileEntryResourceImpl extends BaseResourceImpl {
       	}
       
       	@Override
      +	public long getSize() {
      +		try {
      +			FileVersion fileVersion = _fileEntry.getLatestFileVersion();
      +
      +			return fileVersion.getSize();
      +		}
      +		catch (Exception e) {
      +			return _fileEntry.getSize();
      +		}
      +	}
      +
      +	@Override
       	public String getContentType() {
      -		return _fileEntry.getMimeType();
      +		try {
      +			FileVersion fileVersion = _fileEntry.getLatestFileVersion();
      +
      +			return fileVersion.getMimeType();
      +		}
      +		catch (Exception e) {
      +			return _fileEntry.getMimeType();
      +		}
       	}
       
       	@Override
      

      Why does it matter? The readCount got incremented in the old versions when properties

      asset.entry.increment.view.counter.enabled

      and

      dl.file.entry.read.count.enabled

      were set to "true", because

      in 6012

      DLFileEntryLocalServiceImpl(6012).java
      	public InputStream getFileAsStream(
      			long companyId, long userId, long groupId, long folderId,
      			String name, String version)
      		throws PortalException, SystemException {
      
      		DLFileEntry fileEntry = dlFileEntryPersistence.findByG_F_N(
      			groupId, folderId, name);
      
      		if (userId > 0) {
      			dlFileRankLocalService.updateFileRank(
      				groupId, companyId, userId, fileEntry.getFileEntryId(),
      				new ServiceContext());
      		}
      
      		if (PropsValues.DL_FILE_ENTRY_READ_COUNT_ENABLED) {
      			fileEntry.setReadCount(fileEntry.getReadCount() + 1);
      
      			dlFileEntryPersistence.update(fileEntry, false);
      
      			assetEntryLocalService.incrementViewCounter(
      				userId, DLFileEntry.class.getName(),
      				fileEntry.getFileEntryId());
      
      			List<DLFileShortcut> fileShortcuts =
      				dlFileShortcutPersistence.findByToFileEntryId(
      					fileEntry.getFileEntryId());
      
      			for (DLFileShortcut fileShortcut : fileShortcuts) {
      				assetEntryLocalService.incrementViewCounter(
      					userId, DLFileShortcut.class.getName(),
      					fileShortcut.getFileShortcutId());
      			}
      		}
      
      		if (Validator.isNotNull(version)) {
      			return dlLocalService.getFileAsStream(
      				companyId, fileEntry.getRepositoryId(), name, version);
      		}
      		else {
      			return dlLocalService.getFileAsStream(
      				companyId, fileEntry.getRepositoryId(), name,
      				fileEntry.getVersion());
      		}
      	}
      

      and in 6120, the call "_fileEntry.getContenAsStream(version)" ended up in

      LiferayFileEntry(6120).java
      	@Override
      	public InputStream getContentStream(String version) throws PortalException {
      		InputStream inputStream = _dlFileEntry.getContentStream(version);
      
      		try {
      			DLAppHelperLocalServiceUtil.getFileAsStream(
      				PrincipalThreadLocal.getUserId(), this, true);
      		}
      		catch (Exception e) {
      			_log.error(e);
      		}
      
      		return inputStream;
      	}
      

      where the last (boolean) parameter - true, in this case - controls the "incrementCount" in the service.

      2- Though, new logic calls getContentAsStream on the FileVersion with "false".

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                haoliang.wu Haoliang Wu (Inactive)
                Reporter:
                tibor.lipusz Tibor Lipusz
                Participants of an Issue:
                Recent user:
                Esther Sanz
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  5 years, 19 weeks ago

                  Packages

                  Version Package
                  6.1.X EE
                  6.2.2 CE GA3
                  6.2.X EE
                  7.0.0 M1