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

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

Introduction

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

Prototype

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

Source Link

Usage

From source file:com.liferay.portlet.documentlibrary.service.impl.DLAppServiceImpl.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>//from w ww  .  j  av  a  2  s  .co m
 * 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  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 fileEntryId, String sourceFileName, String mimeType, String title,
        String description, String changeLog, boolean majorVersion, InputStream is, long size,
        ServiceContext serviceContext) throws PortalException, SystemException {

    Repository repository = getRepository(0, fileEntryId, 0);

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

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

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

    return fileEntry;
}

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

License:Open Source License

public FileEntry updateFileEntryAndCheckIn(long fileEntryId, String sourceFileName, String mimeType,
        String title, String description, String changeLog, boolean majorVersion, InputStream is, long size,
        ServiceContext serviceContext) throws PortalException, SystemException {

    Repository repository = getRepository(0, fileEntryId, 0);

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

    if (is != null) {
        DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
    }//w  w w  . jav  a2  s  . com

    repository.checkInFileEntry(fileEntryId, majorVersion, changeLog, serviceContext);

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

    return fileEntry;
}

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

License:Open Source License

protected FileEntry copyFileEntry(Repository toRepository, 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 = toRepository.addFileEntry(newFolderId, fileEntry.getTitle(),
            latestFileVersion.getMimeType(), latestFileVersion.getTitle(), latestFileVersion.getDescription(),
            StringPool.BLANK, latestFileVersion.getContentStream(false), latestFileVersion.getSize(),
            serviceContext);/*  w  w  w .  j  a  va  2  s.  co  m*/

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

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

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

            throw pe;
        }
    }

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

    return destinationFileEntry;
}