Search in sources :

Example 46 with Artist

use of org.liferay.jukebox.model.Artist in project liferay-ide by liferay.

the class ArtistStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Artist artist) throws Exception {
    long userId = portletDataContext.getUserId(artist.getUserUuid());
    ServiceContext serviceContext = portletDataContext.createServiceContext(artist);
    Artist importedArtist = null;
    if (portletDataContext.isDataStrategyMirror()) {
        Artist existingArtist = ArtistLocalServiceUtil.fetchArtistByUuidAndGroupId(artist.getUuid(), portletDataContext.getScopeGroupId());
        if (existingArtist == null) {
            serviceContext.setUuid(artist.getUuid());
            importedArtist = ArtistLocalServiceUtil.addArtist(userId, artist.getName(), artist.getBio(), null, serviceContext);
        } else {
            importedArtist = ArtistLocalServiceUtil.updateArtist(userId, existingArtist.getArtistId(), artist.getName(), artist.getBio(), null, serviceContext);
        }
    } else {
        importedArtist = ArtistLocalServiceUtil.addArtist(userId, artist.getName(), artist.getBio(), null, serviceContext);
    }
    Element artistElement = portletDataContext.getImportDataStagedModelElement(artist);
    List<Element> attachmentElements = portletDataContext.getReferenceDataElements(artistElement, 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;
            }
            importedArtist = ArtistLocalServiceUtil.updateArtist(userId, importedArtist.getArtistId(), importedArtist.getName(), importedArtist.getBio(), inputStream, serviceContext);
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
    portletDataContext.importClassedModel(artist, importedArtist);
}
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) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Example 47 with Artist

use of org.liferay.jukebox.model.Artist in project liferay-ide by liferay.

the class ArtistPersistenceImpl method findByUuid_C_Last.

/**
 * Returns the last artist in the ordered set where uuid = &#63; and companyId = &#63;.
 *
 * @param uuid the uuid
 * @param companyId the company ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the last matching artist
 * @throws org.liferay.jukebox.NoSuchArtistException if a matching artist could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public Artist findByUuid_C_Last(String uuid, long companyId, OrderByComparator orderByComparator) throws NoSuchArtistException, SystemException {
    Artist artist = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
    if (artist != null) {
        return artist;
    }
    StringBundler msg = new StringBundler(6);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("uuid=");
    msg.append(uuid);
    msg.append(", companyId=");
    msg.append(companyId);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchArtistException(msg.toString());
}
Also used : Artist(org.liferay.jukebox.model.Artist) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchArtistException(org.liferay.jukebox.NoSuchArtistException)

Example 48 with Artist

use of org.liferay.jukebox.model.Artist in project liferay-ide by liferay.

the class ArtistPersistenceImpl method filterFindByU_G.

/**
 * Returns an ordered range of all the artists that the user has permissions to view where userId = &#63; and groupId = &#63;.
 *
 * <p>
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link org.liferay.jukebox.model.impl.ArtistModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param userId the user ID
 * @param groupId the group ID
 * @param start the lower bound of the range of artists
 * @param end the upper bound of the range of artists (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching artists that the user has permission to view
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Artist> filterFindByU_G(long userId, long groupId, int start, int end, OrderByComparator orderByComparator) throws SystemException {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByU_G(userId, groupId, start, end, orderByComparator);
    }
    StringBundler query = null;
    if (orderByComparator != null) {
        query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 3));
    } else {
        query = new StringBundler(4);
    }
    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_ARTIST_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_ARTIST_NO_INLINE_DISTINCT_WHERE_1);
    }
    query.append(_FINDER_COLUMN_U_G_USERID_2);
    query.append(_FINDER_COLUMN_U_G_GROUPID_2);
    if (!getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_ARTIST_NO_INLINE_DISTINCT_WHERE_2);
    }
    if (orderByComparator != null) {
        if (getDB().isSupportsInlineDistinct()) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true);
        } else {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true);
        }
    } else {
        if (getDB().isSupportsInlineDistinct()) {
            query.append(ArtistModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(ArtistModelImpl.ORDER_BY_SQL);
        }
    }
    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Artist.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
    Session session = null;
    try {
        session = openSession();
        SQLQuery q = session.createSQLQuery(sql);
        if (getDB().isSupportsInlineDistinct()) {
            q.addEntity(_FILTER_ENTITY_ALIAS, ArtistImpl.class);
        } else {
            q.addEntity(_FILTER_ENTITY_TABLE, ArtistImpl.class);
        }
        QueryPos qPos = QueryPos.getInstance(q);
        qPos.add(userId);
        qPos.add(groupId);
        return (List<Artist>) QueryUtil.list(q, getDialect(), start, end);
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : Artist(org.liferay.jukebox.model.Artist) ArrayList(java.util.ArrayList) UnmodifiableList(com.liferay.portal.kernel.util.UnmodifiableList) List(java.util.List) SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchArtistException(org.liferay.jukebox.NoSuchArtistException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 49 with Artist

use of org.liferay.jukebox.model.Artist in project liferay-ide by liferay.

the class ArtistPersistenceImpl method findByGroupId_First.

/**
 * Returns the first artist in the ordered set where groupId = &#63;.
 *
 * @param groupId the group ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the first matching artist
 * @throws org.liferay.jukebox.NoSuchArtistException if a matching artist could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public Artist findByGroupId_First(long groupId, OrderByComparator orderByComparator) throws NoSuchArtistException, SystemException {
    Artist artist = fetchByGroupId_First(groupId, orderByComparator);
    if (artist != null) {
        return artist;
    }
    StringBundler msg = new StringBundler(4);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("groupId=");
    msg.append(groupId);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchArtistException(msg.toString());
}
Also used : Artist(org.liferay.jukebox.model.Artist) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchArtistException(org.liferay.jukebox.NoSuchArtistException)

Example 50 with Artist

use of org.liferay.jukebox.model.Artist in project liferay-ide by liferay.

the class ArtistPersistenceImpl method findByG_LikeN_S_Last.

/**
 * Returns the last artist in the ordered set where groupId = &#63; and name LIKE &#63; and status = &#63;.
 *
 * @param groupId the group ID
 * @param name the name
 * @param status the status
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the last matching artist
 * @throws org.liferay.jukebox.NoSuchArtistException if a matching artist could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public Artist findByG_LikeN_S_Last(long groupId, String name, int status, OrderByComparator orderByComparator) throws NoSuchArtistException, SystemException {
    Artist artist = fetchByG_LikeN_S_Last(groupId, name, status, orderByComparator);
    if (artist != null) {
        return artist;
    }
    StringBundler msg = new StringBundler(8);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("groupId=");
    msg.append(groupId);
    msg.append(", name=");
    msg.append(name);
    msg.append(", status=");
    msg.append(status);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchArtistException(msg.toString());
}
Also used : Artist(org.liferay.jukebox.model.Artist) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchArtistException(org.liferay.jukebox.NoSuchArtistException)

Aggregations

Artist (org.liferay.jukebox.model.Artist)79 NoSuchArtistException (org.liferay.jukebox.NoSuchArtistException)45 StringBundler (com.liferay.portal.kernel.util.StringBundler)43 SystemException (com.liferay.portal.kernel.exception.SystemException)30 Session (com.liferay.portal.kernel.dao.orm.Session)28 SQLQuery (com.liferay.portal.kernel.dao.orm.SQLQuery)26 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)25 Query (com.liferay.portal.kernel.dao.orm.Query)18 ArrayList (java.util.ArrayList)15 ArtistImpl (org.liferay.jukebox.model.impl.ArtistImpl)15 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)14 List (java.util.List)14 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)9 Document (com.liferay.portal.kernel.search.Document)5 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)4 Album (org.liferay.jukebox.model.Album)4 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)3 Indexable (com.liferay.portal.kernel.search.Indexable)3 Element (com.liferay.portal.kernel.xml.Element)3 PortalException (com.liferay.portal.kernel.exception.PortalException)2