List of usage examples for com.liferay.portal.kernel.repository Repository addFileEntry
public FileEntry addFileEntry(long userId, long folderId, String sourceFileName, String mimeType, String title, String description, String changeLog, File file, ServiceContext serviceContext) throws PortalException;
From source file:com.liferay.portlet.documentlibrary.service.impl.DLAppServiceImpl.java
License:Open Source License
/** * Adds a file entry and associated metadata. It is created based on a * {@link InputStream} object./*from ww w . ja va2s . c o m*/ * * <p> * 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. If it is <code>null</code>, the <code> * sourceFileName</code> will be used. * </p> * * @param repositoryId the primary key of the repository * @param folderId the primary key of the file entry's parent folder * @param sourceFileName the original file's name * @param mimeType the file's MIME type * @param title the name to be assigned to the file (optionally <code>null * </code>) * @param description the file's description * @param changeLog the file's version change log * @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 parent folder could not be found or if the * file entry's information was invalid * @throws SystemException if a system exception occurred */ public FileEntry addFileEntry(long repositoryId, long folderId, String sourceFileName, String mimeType, String title, String description, String changeLog, InputStream is, long size, ServiceContext serviceContext) throws PortalException, SystemException { if (is == null) { is = new UnsyncByteArrayInputStream(new byte[0]); size = 0; } Repository repository = getRepository(repositoryId); FileEntry fileEntry = repository.addFileEntry(folderId, sourceFileName, mimeType, title, description, changeLog, is, size, serviceContext); dlAppHelperLocalService.addFileEntry(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 ww . j a v a 2 s . c om*/ 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; }