Search in sources :

Example 11 with FileEntry

use of com.liferay.portal.kernel.repository.model.FileEntry in project liferay-ide by liferay.

the class BaseKBPortlet method serveAttachment.

public void serveAttachment(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
    long fileEntryId = ParamUtil.getLong(resourceRequest, "fileEntryId");
    FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(fileEntryId);
    PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileEntry.getTitle(), fileEntry.getContentStream(), fileEntry.getMimeType());
}
Also used : FileEntry(com.liferay.portal.kernel.repository.model.FileEntry)

Example 12 with FileEntry

use of com.liferay.portal.kernel.repository.model.FileEntry in project liferay-blade-samples by liferay.

the class BladeActionConfigurationIcon method getURL.

public String getURL(PortletRequest portletRequest, PortletResponse portletResponse) {
    HttpServletRequest servletRequest = _portal.getHttpServletRequest(portletRequest);
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
    FileEntry fileEntry = _retrieveFile(servletRequest);
    PortletURL portletURL = PortletURLFactoryUtil.create(servletRequest, "blade_document_action_portlet_BladeDocumentActionPortlet", themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);
    String fileName = fileEntry.getFileName();
    String mimeType = fileEntry.getMimeType();
    String version = fileEntry.getVersion();
    String createdDate = String.valueOf(fileEntry.getCreateDate());
    String createdUserName = fileEntry.getUserName();
    String statusLabel = null;
    try {
        FileVersion fileVersion = fileEntry.getLatestFileVersion();
        int status = fileVersion.getStatus();
        statusLabel = WorkflowConstants.getStatusLabel(status);
    } catch (PortalException pe) {
        _log.log(LogService.LOG_ERROR, pe.getMessage(), pe);
    }
    portletURL.setParameter("fileName", fileName);
    portletURL.setParameter("mimeType", mimeType);
    portletURL.setParameter("version", version);
    portletURL.setParameter("statusLabel", statusLabel);
    portletURL.setParameter("createdDate", createdDate);
    portletURL.setParameter("createdUserName", createdUserName);
    try {
        portletURL.setWindowState(LiferayWindowState.POP_UP);
    } catch (WindowStateException wse) {
        _log.log(LogService.LOG_ERROR, wse.getMessage(), wse);
    }
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("javascript:Liferay.Util.openWindow(");
    stringBuilder.append("{dialog: {cache: false,width:800,modal: true},");
    stringBuilder.append("title: 'basic information',id: ");
    stringBuilder.append("'testPopupIdUnique',uri: '");
    stringBuilder.append(portletURL.toString() + "'});");
    return stringBuilder.toString();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WindowStateException(javax.portlet.WindowStateException) FileVersion(com.liferay.portal.kernel.repository.model.FileVersion) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) PortalException(com.liferay.portal.kernel.exception.PortalException) ThemeDisplay(com.liferay.portal.kernel.theme.ThemeDisplay) PortletURL(javax.portlet.PortletURL)

Example 13 with FileEntry

use of com.liferay.portal.kernel.repository.model.FileEntry in project com-liferay-apio-architect by liferay.

the class MediaObjectNestedCollectionResource method _getPageItems.

private PageItems<FileEntry> _getPageItems(Pagination pagination, Long folderId) throws PortalException {
    Folder folder = _dlAppService.getFolder(folderId);
    List<FileEntry> dlFileEntries = _dlAppService.getFileEntries(folder.getGroupId(), folder.getFolderId(), pagination.getStartPosition(), pagination.getEndPosition());
    int count = _dlAppService.getFileEntriesCount(folder.getGroupId(), folder.getFolderId());
    return new PageItems<>(dlFileEntries, count);
}
Also used : FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) PageItems(com.liferay.apio.architect.pagination.PageItems) Folder(com.liferay.portal.kernel.repository.model.Folder)

Example 14 with FileEntry

use of com.liferay.portal.kernel.repository.model.FileEntry in project liferay-ide by liferay.

the class AlbumStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Album album) throws Exception {
    long userId = portletDataContext.getUserId(album.getUserUuid());
    ServiceContext serviceContext = portletDataContext.createServiceContext(album);
    String artistPath = ExportImportPathUtil.getModelPath(portletDataContext, Artist.class.getName(), album.getArtistId());
    Artist artist = (Artist) portletDataContext.getZipEntryAsObject(artistPath);
    if (artist != null) {
        StagedModelDataHandlerUtil.importReferenceStagedModel(portletDataContext, album, Artist.class, album.getArtistId());
    }
    Map<Long, Long> artistIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Artist.class);
    long artistId = MapUtil.getLong(artistIds, album.getArtistId(), album.getArtistId());
    Album importedAlbum = null;
    if (portletDataContext.isDataStrategyMirror()) {
        Album existingAlbum = AlbumLocalServiceUtil.fetchAlbumByUuidAndGroupId(album.getUuid(), portletDataContext.getScopeGroupId());
        if (existingAlbum == null) {
            serviceContext.setUuid(album.getUuid());
            importedAlbum = AlbumLocalServiceUtil.addAlbum(userId, artistId, album.getName(), album.getYear(), null, serviceContext);
        } else {
            importedAlbum = AlbumLocalServiceUtil.updateAlbum(userId, existingAlbum.getAlbumId(), artistId, album.getName(), album.getYear(), null, serviceContext);
        }
    } else {
        importedAlbum = AlbumLocalServiceUtil.addAlbum(userId, artistId, album.getName(), album.getYear(), null, serviceContext);
    }
    Element albumElement = portletDataContext.getImportDataStagedModelElement(album);
    List<Element> attachmentElements = portletDataContext.getReferenceDataElements(albumElement, FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);
    for (Element attachmentElement : attachmentElements) {
        String path = attachmentElement.attributeValue("path");
        FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path);
        InputStream inputStream = null;
        try {
            String binPath = attachmentElement.attributeValue("bin-path");
            if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) {
                try {
                    inputStream = _getContentStream(fileEntry);
                } catch (NoSuchFileException nsfe) {
                }
            } else {
                inputStream = portletDataContext.getZipEntryAsInputStream(binPath);
            }
            if (inputStream == null) {
                if (_log.isWarnEnabled()) {
                    _log.warn("Unable to import attachment for file entry " + fileEntry.getFileEntryId());
                }
                continue;
            }
            importedAlbum = AlbumLocalServiceUtil.updateAlbum(userId, importedAlbum.getAlbumId(), importedAlbum.getArtistId(), importedAlbum.getName(), importedAlbum.getYear(), inputStream, serviceContext);
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
    portletDataContext.importClassedModel(album, importedAlbum);
}
Also used : Artist(org.liferay.jukebox.model.Artist) ServiceContext(com.liferay.portal.service.ServiceContext) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) InputStream(java.io.InputStream) Element(com.liferay.portal.kernel.xml.Element) NoSuchFileException(com.liferay.portlet.documentlibrary.NoSuchFileException) Album(org.liferay.jukebox.model.Album) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) Map(java.util.Map)

Example 15 with FileEntry

use of com.liferay.portal.kernel.repository.model.FileEntry in project liferay-ide by liferay.

the class ArtistStagedModelDataHandler method doExportStagedModel.

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, Artist artist) throws Exception {
    Element artistElement = portletDataContext.getExportDataElement(artist);
    if (artist.hasCustomImage()) {
        FileEntry fileEntry = artist.getCustomImage();
        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, artist, Artist.class, fileEntry, FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);
    }
    portletDataContext.addClassedModel(artistElement, ExportImportPathUtil.getModelPath(artist), artist);
}
Also used : Element(com.liferay.portal.kernel.xml.Element) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Aggregations

FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)34 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)15 PortalException (com.liferay.portal.kernel.exception.PortalException)8 Folder (com.liferay.portal.kernel.repository.model.Folder)7 ServiceContext (com.liferay.portal.service.ServiceContext)6 IOException (java.io.IOException)6 SystemException (com.liferay.portal.kernel.exception.SystemException)5 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 Element (com.liferay.portal.kernel.xml.Element)5 User (com.liferay.portal.model.User)5 NoSuchFileEntryException (com.liferay.portlet.documentlibrary.NoSuchFileEntryException)5 InputStream (java.io.InputStream)5 StringBundler (com.liferay.portal.kernel.util.StringBundler)4 ArrayList (java.util.ArrayList)4 NoSuchGroupException (com.liferay.portal.NoSuchGroupException)3 RepositoryException (com.liferay.portal.kernel.repository.RepositoryException)3 FileVersion (com.liferay.portal.kernel.repository.model.FileVersion)3 Group (com.liferay.portal.model.Group)3 Repository (com.liferay.portal.model.Repository)3 PrincipalException (com.liferay.portal.security.auth.PrincipalException)3