Example usage for com.liferay.portal.kernel.repository LocalRepository updateFileEntry

List of usage examples for com.liferay.portal.kernel.repository LocalRepository updateFileEntry

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.repository LocalRepository updateFileEntry.

Prototype

public FileEntry updateFileEntry(long userId, long fileEntryId, String sourceFileName, String mimeType,
            String title, String description, String changeLog, DLVersionNumberIncrease dlVersionNumberIncrease,
            InputStream is, long size, ServiceContext serviceContext) throws PortalException;

Source Link

Usage

From source file:com.liferay.portlet.documentlibrary.service.impl.DLAppLocalServiceImpl.java

License:Open Source License

/**
 * Updates a file entry and associated metadata based on an {@link
 * InputStream} object. If the file data is <code>null</code>, then only the
 * associated metadata (i.e., <code>title</code>, <code>description</code>,
 * and parameters in the <code>serviceContext</code>) will be updated.
 *
 * <p>//  w w  w.  j av  a 2  s  .  c om
 * This method takes two file names, the <code>sourceFileName</code> and the
 * <code>title</code>. The <code>sourceFileName</code> corresponds to the
 * name of the actual file being uploaded. The <code>title</code>
 * corresponds to a name the client wishes to assign this file after it has
 * been uploaded to the portal.
 * </p>
 *
 * @param  userId the primary key of the user
 * @param  fileEntryId the primary key of the file entry
 * @param  sourceFileName the original file's name (optionally
 *         <code>null</code>)
 * @param  mimeType the file's MIME type (optionally <code>null</code>)
 * @param  title the new name to be assigned to the file (optionally <code>
 *         <code>null</code></code>)
 * @param  description the file's new description
 * @param  changeLog the file's version change log (optionally
 *         <code>null</code>)
 * @param  majorVersion whether the new file version is a major version
 * @param  is the file's data (optionally <code>null</code>)
 * @param  size the file's size (optionally <code>0</code>)
 * @param  serviceContext the service context to be applied. Can set the
 *         asset category IDs, asset tag names, and expando bridge
 *         attributes for the file entry. In a Liferay repository, it may
 *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
 *         type </li> <li> fieldsMap - mapping for fields associated with a
 *         custom file entry type </li> </ul>
 * @return the file entry
 * @throws PortalException if the file entry could not be found
 * @throws SystemException if a system exception occurred
 */
public FileEntry updateFileEntry(long userId, long fileEntryId, String sourceFileName, String mimeType,
        String title, String description, String changeLog, boolean majorVersion, InputStream is, long size,
        ServiceContext serviceContext) throws PortalException, SystemException {

    LocalRepository localRepository = getLocalRepository(0, fileEntryId, 0);

    FileEntry fileEntry = localRepository.updateFileEntry(userId, fileEntryId, sourceFileName, mimeType, title,
            description, changeLog, majorVersion, is, size, serviceContext);

    if (is != null) {
        DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
    }

    dlAppHelperLocalService.updateFileEntry(userId, fileEntry, fileEntry.getFileVersion(), serviceContext);

    return fileEntry;
}

From source file:com.liferay.portlet.documentlibrary.service.impl.DLAppLocalServiceImpl.java

License:Open Source License

protected FileEntry copyFileEntry(long userId, LocalRepository toLocalRepository, FileEntry fileEntry,
        long newFolderId, ServiceContext serviceContext) throws PortalException, SystemException {

    List<FileVersion> fileVersions = fileEntry.getFileVersions(WorkflowConstants.STATUS_ANY);

    FileVersion latestFileVersion = fileVersions.get(fileVersions.size() - 1);

    FileEntry destinationFileEntry = toLocalRepository.addFileEntry(userId, newFolderId, fileEntry.getTitle(),
            latestFileVersion.getMimeType(), latestFileVersion.getTitle(), latestFileVersion.getDescription(),
            StringPool.BLANK, latestFileVersion.getContentStream(false), latestFileVersion.getSize(),
            serviceContext);/*from   w  w  w .j  a va  2  s .c  o  m*/

    for (int i = fileVersions.size() - 2; i >= 0; i--) {
        FileVersion fileVersion = fileVersions.get(i);

        FileVersion previousFileVersion = fileVersions.get(i + 1);

        try {
            destinationFileEntry = toLocalRepository.updateFileEntry(userId,
                    destinationFileEntry.getFileEntryId(), fileEntry.getTitle(),
                    destinationFileEntry.getMimeType(), destinationFileEntry.getTitle(),
                    destinationFileEntry.getDescription(), StringPool.BLANK,
                    isMajorVersion(fileVersion, previousFileVersion), fileVersion.getContentStream(false),
                    fileVersion.getSize(), serviceContext);
        } catch (PortalException pe) {
            toLocalRepository.deleteFileEntry(destinationFileEntry.getFileEntryId());

            throw pe;
        }
    }

    dlAppHelperLocalService.addFileEntry(userId, destinationFileEntry, destinationFileEntry.getFileVersion(),
            serviceContext);

    return destinationFileEntry;
}