Search in sources :

Example 21 with FileEntry

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

the class WebServerServlet method getImage.

protected Image getImage(HttpServletRequest request, boolean getDefault) throws PortalException, SystemException {
    Image image = null;
    long imageId = getImageId(request);
    if (imageId > 0) {
        image = ImageServiceUtil.getImage(imageId);
        String path = GetterUtil.getString(request.getPathInfo());
        if (path.startsWith("/user_female_portrait") || path.startsWith("/user_male_portrait") || path.startsWith("/user_portrait")) {
            image = getUserPortraitImageResized(image, imageId);
        }
    } else {
        String uuid = ParamUtil.getString(request, "uuid");
        long groupId = ParamUtil.getLong(request, "groupId");
        boolean igSmallImage = ParamUtil.getBoolean(request, "igSmallImage");
        java.lang.Object[] test;
        if (Validator_IW.isNotNull(test) && (groupId > 0)) {
            try {
                FileEntry fileEntry = DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
                image = convertFileEntry(igSmallImage, fileEntry);
            } catch (Exception e) {
            }
        }
    }
    if (getDefault) {
        if (image == null) {
            if (_log.isWarnEnabled()) {
                _log.warn("Get a default image for " + imageId);
            }
            image = getDefaultImage(request, imageId);
        }
    }
    return image;
}
Also used : FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) Image(com.liferay.portal.model.Image) RenderedImage(java.awt.image.RenderedImage) ServletException(javax.servlet.ServletException) RepositoryException(com.liferay.portal.kernel.repository.RepositoryException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) NoSuchGroupException(com.liferay.portal.NoSuchGroupException)

Example 22 with FileEntry

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

the class SongLocalServiceImpl method addSong.

@Indexable(type = IndexableType.REINDEX)
public Song addSong(long userId, long albumId, String name, String songFileName, InputStream songInputStream, String lyricsFileName, InputStream lyricsInputStream, ServiceContext serviceContext) throws PortalException, SystemException {
    long groupId = serviceContext.getScopeGroupId();
    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();
    long songId = counterLocalService.increment();
    Album album = albumPersistence.findByPrimaryKey(albumId);
    validate(songId, groupId, album.getArtistId(), albumId, name);
    Song song = songPersistence.create(songId);
    song.setUuid(serviceContext.getUuid());
    song.setGroupId(groupId);
    song.setCompanyId(user.getCompanyId());
    song.setUserId(user.getUserId());
    song.setUserName(user.getFullName());
    song.setCreateDate(serviceContext.getCreateDate(now));
    song.setModifiedDate(serviceContext.getModifiedDate(now));
    song.setArtistId(album.getArtistId());
    song.setAlbumId(albumId);
    song.setName(name);
    song.setExpandoBridgeAttributes(serviceContext);
    songPersistence.update(song);
    if ((songInputStream != null) || (lyricsInputStream != null)) {
        Repository repository = PortletFileRepositoryUtil.addPortletRepository(groupId, Constants.JUKEBOX_PORTLET_REPOSITORY, serviceContext);
        Folder folder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(song.getSongId()), serviceContext);
        if (songInputStream != null) {
            Folder songFolder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), folder.getFolderId(), Constants.SONGS_FOLDER_NAME, serviceContext);
            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(groupId, userId, Song.class.getName(), song.getSongId(), Constants.JUKEBOX_PORTLET_REPOSITORY, songFolder.getFolderId(), songInputStream, songFileName, StringPool.BLANK, true);
            DLProcessorRegistryUtil.trigger(fileEntry, null, true);
        }
        if (lyricsInputStream != null) {
            Folder lyricsFolder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), folder.getFolderId(), Constants.LYRICS_FOLDER_NAME, serviceContext);
            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(groupId, userId, Song.class.getName(), song.getSongId(), Constants.JUKEBOX_PORTLET_REPOSITORY, lyricsFolder.getFolderId(), lyricsInputStream, lyricsFileName, StringPool.BLANK, true);
            DLProcessorRegistryUtil.trigger(fileEntry, null, true);
        }
    }
    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {
        addEntryResources(song, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
        addEntryResources(song, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }
    // Message boards
    mbMessageLocalService.addDiscussionMessage(userId, album.getUserName(), groupId, Song.class.getName(), songId, WorkflowConstants.ACTION_PUBLISH);
    // Asset
    updateAsset(userId, song, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());
    return song;
}
Also used : Song(org.liferay.jukebox.model.Song) Repository(com.liferay.portal.model.Repository) User(com.liferay.portal.model.User) Album(org.liferay.jukebox.model.Album) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) Folder(com.liferay.portal.kernel.repository.model.Folder) Date(java.util.Date) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 23 with FileEntry

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

the class SongLocalServiceImpl method updateSong.

@Indexable(type = IndexableType.REINDEX)
public Song updateSong(long userId, long songId, long albumId, String name, String songFileName, InputStream songInputStream, String lyricsFileName, InputStream lyricsInputStream, ServiceContext serviceContext) throws PortalException, SystemException {
    // Event
    User user = userPersistence.findByPrimaryKey(userId);
    Song song = songPersistence.findByPrimaryKey(songId);
    Album album = albumPersistence.findByPrimaryKey(albumId);
    validate(songId, song.getGroupId(), album.getArtistId(), albumId, name);
    song.setModifiedDate(serviceContext.getModifiedDate(null));
    song.setArtistId(album.getArtistId());
    song.setAlbumId(albumId);
    song.setName(name);
    song.setExpandoBridgeAttributes(serviceContext);
    songPersistence.update(song);
    if ((songInputStream != null) || (lyricsInputStream != null)) {
        Repository repository = PortletFileRepositoryUtil.addPortletRepository(serviceContext.getScopeGroupId(), Constants.JUKEBOX_PORTLET_REPOSITORY, serviceContext);
        Folder folder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(song.getSongId()), serviceContext);
        if (songInputStream != null) {
            Folder songFolder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), folder.getFolderId(), Constants.SONGS_FOLDER_NAME, serviceContext);
            List<FileEntry> fileEntries = PortletFileRepositoryUtil.getPortletFileEntries(serviceContext.getScopeGroupId(), songFolder.getFolderId());
            for (FileEntry fileEntry : fileEntries) {
                PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());
                DLProcessorRegistryUtil.cleanUp(fileEntry);
            }
            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(serviceContext.getScopeGroupId(), userId, Song.class.getName(), song.getSongId(), Constants.JUKEBOX_PORTLET_REPOSITORY, songFolder.getFolderId(), songInputStream, songFileName, StringPool.BLANK, true);
            triggerDLProcessors(fileEntry);
        }
        if (lyricsInputStream != null) {
            Folder lyricsFolder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), folder.getFolderId(), Constants.LYRICS_FOLDER_NAME, serviceContext);
            List<FileEntry> fileEntries = PortletFileRepositoryUtil.getPortletFileEntries(serviceContext.getScopeGroupId(), lyricsFolder.getFolderId());
            for (FileEntry fileEntry : fileEntries) {
                PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());
                DLProcessorRegistryUtil.cleanUp(fileEntry);
            }
            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(serviceContext.getScopeGroupId(), userId, Song.class.getName(), song.getSongId(), Constants.JUKEBOX_PORTLET_REPOSITORY, lyricsFolder.getFolderId(), lyricsInputStream, lyricsFileName, StringPool.BLANK, true);
            triggerDLProcessors(fileEntry);
        }
    }
    // Asset
    updateAsset(userId, song, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());
    return song;
}
Also used : Song(org.liferay.jukebox.model.Song) Repository(com.liferay.portal.model.Repository) User(com.liferay.portal.model.User) Album(org.liferay.jukebox.model.Album) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) Folder(com.liferay.portal.kernel.repository.model.Folder) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 24 with FileEntry

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

the class SearchResultTest method getSearchResults.

public static List<SearchResult> getSearchResults(Hits hits, Locale locale, PortletURL portletURL) {
    List<SearchResult> searchResults = new ArrayList<SearchResult>();
    for (Document document : hits.getDocs()) {
        String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
        long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));
        try {
            String className = entryClassName;
            long classPK = entryClassPK;
            FileEntry fileEntry = null;
            MBMessage mbMessage = null;
            if (entryClassName.equals(DLFileEntry.class.getName()) || entryClassName.equals(MBMessage.class.getName())) {
                classPK = GetterUtil.getLong(document.get(Field.CLASS_PK));
                long classNameId = GetterUtil.getLong(document.get(Field.CLASS_NAME_ID));
                if ((classPK > 0) && (classNameId > 0)) {
                    className = PortalUtil.getClassName(classNameId);
                    if (entryClassName.equals(DLFileEntry.class.getName())) {
                        fileEntry = DLAppLocalServiceUtil.getFileEntry(entryClassPK);
                    } else if (entryClassName.equals(MBMessage.class.getName())) {
                        mbMessage = MBMessageLocalServiceUtil.getMessage(entryClassPK);
                    }
                } else {
                    className = entryClassName;
                    classPK = entryClassPK;
                }
            }
            SearchResult searchResult = new SearchResult(className, classPK);
            int index = searchResults.indexOf(searchResult);
            if (index < 0) {
                searchResults.add(searchResult);
            } else {
                searchResult = searchResults.get(index);
            }
            if (fileEntry != null) {
                Summary summary = getSummary(document, DLFileEntry.class.getName(), fileEntry.getFileEntryId(), locale, portletURL);
                searchResult.addFileEntry(fileEntry, summary);
            }
            if (mbMessage != null) {
                searchResult.addMBMessage(mbMessage);
                searchResult.getMBMessages();
                searchResult.getFileEntryTuples();
            }
            if (entryClassName.equals(JournalArticle.class.getName())) {
                String version = document.get(Field.VERSION);
                searchResult.addVersion(version);
            }
            if ((mbMessage == null) && (fileEntry == null)) {
                Summary summary = getSummary(document, className, classPK, locale, portletURL);
                searchResult.setSummary(summary);
            } else {
                if (searchResult.getSummary() == null) {
                    Summary summary = getSummary(className, classPK, locale, portletURL);
                    searchResult.setSummary(summary);
                }
            }
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn("Search index is stale and contains entry {" + entryClassPK + "}");
            }
        }
    }
    return searchResults;
}
Also used : ArrayList(java.util.ArrayList) SearchResult(com.liferay.portal.kernel.search.SearchResult) Document(com.liferay.portal.kernel.search.Document) MBMessage(com.liferay.portlet.messageboards.model.MBMessage) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) Summary(com.liferay.portal.kernel.search.Summary) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) JournalArticle(com.liferay.portlet.journal.model.JournalArticle)

Example 25 with FileEntry

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

the class LiferayMediaItemService method doGetMediaItem.

protected MediaItem doGetMediaItem(UserId userId, String appId, String albumId, String mediaItemId, Set<String> fields, SecurityToken securityToken) throws Exception {
    long mediaItemIdLong = GetterUtil.getLong(mediaItemId);
    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(mediaItemIdLong);
    return toMediaItem(fileEntry, fields, securityToken);
}
Also used : 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