public void deleteArtists(long groupId) throws PortalException {
    List<Artist> artists = getArtists(groupId);

    for (Artist artist : artists) {
      artistLocalService.deleteArtist(artist.getArtistId());
    }
  }
  @Override
  public void addEntryResources(Artist artist, String[] groupPermissions, String[] guestPermissions)
      throws PortalException {

    resourceLocalService.addModelResources(
        artist.getCompanyId(),
        artist.getGroupId(),
        artist.getUserId(),
        Artist.class.getName(),
        artist.getArtistId(),
        groupPermissions,
        guestPermissions);
  }
  @Override
  public void addEntryResources(
      Artist artist, boolean addGroupPermissions, boolean addGuestPermissions)
      throws PortalException {

    resourceLocalService.addResources(
        artist.getCompanyId(),
        artist.getGroupId(),
        artist.getUserId(),
        Artist.class.getName(),
        artist.getArtistId(),
        false,
        addGroupPermissions,
        addGuestPermissions);
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof Artist)) {
      return false;
    }

    Artist artist = (Artist) obj;

    long primaryKey = artist.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  @Indexable(type = IndexableType.DELETE)
  public Artist deleteArtist(long artistId) throws PortalException {
    Artist artist = artistPersistence.findByPrimaryKey(artistId);

    List<Album> albums = albumLocalService.getAlbumsByArtistId(artistId);

    for (Album album : albums) {
      albumLocalService.deleteAlbum(album.getAlbumId());
    }

    try {
      PortletFileRepositoryUtil.deletePortletFileEntry(
          artist.getGroupId(),
          DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
          String.valueOf(artistId));
    } catch (Exception e) {
    }

    return artistPersistence.remove(artistId);
  }
  @Override
  public int compareTo(Artist artist) {
    long primaryKey = artist.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
  public void updateAsset(
      long userId,
      Artist artist,
      long[] assetCategoryIds,
      String[] assetTagNames,
      long[] assetLinkEntryIds)
      throws PortalException {

    AssetEntry assetEntry =
        assetEntryLocalService.updateEntry(
            userId,
            artist.getGroupId(),
            artist.getCreateDate(),
            artist.getModifiedDate(),
            Artist.class.getName(),
            artist.getArtistId(),
            artist.getUuid(),
            0,
            assetCategoryIds,
            assetTagNames,
            true,
            null,
            null,
            null,
            ContentTypes.TEXT_HTML,
            artist.getName(),
            null,
            null,
            null,
            null,
            0,
            0,
            null,
            false);

    assetLinkLocalService.updateLinks(
        userId, assetEntry.getEntryId(), assetLinkEntryIds, AssetLinkConstants.TYPE_RELATED);
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static Artist toModel(ArtistSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    Artist model = new ArtistImpl();

    model.setUuid(soapModel.getUuid());
    model.setArtistId(soapModel.getArtistId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setGroupId(soapModel.getGroupId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setStatus(soapModel.getStatus());
    model.setStatusByUserId(soapModel.getStatusByUserId());
    model.setStatusByUserName(soapModel.getStatusByUserName());
    model.setStatusDate(soapModel.getStatusDate());
    model.setName(soapModel.getName());
    model.setBio(soapModel.getBio());

    return model;
  }
  @Indexable(type = IndexableType.REINDEX)
  public Artist addArtist(
      long userId, String name, String bio, InputStream inputStream, ServiceContext serviceContext)
      throws PortalException {

    long groupId = serviceContext.getScopeGroupId();

    User user = userPersistence.findByPrimaryKey(userId);

    Date now = new Date();

    validate(name);

    long artistId = counterLocalService.increment();

    Artist artist = artistPersistence.create(artistId);

    artist.setUuid(serviceContext.getUuid());
    artist.setGroupId(groupId);
    artist.setCompanyId(user.getCompanyId());
    artist.setUserId(user.getUserId());
    artist.setUserName(user.getFullName());
    artist.setCreateDate(serviceContext.getCreateDate(now));
    artist.setModifiedDate(serviceContext.getModifiedDate(now));
    artist.setName(name);
    artist.setBio(bio);
    artist.setExpandoBridgeAttributes(serviceContext);

    artistPersistence.update(artist);

    if (inputStream != null) {
      PortletFileRepositoryUtil.addPortletFileEntry(
          groupId,
          userId,
          Artist.class.getName(),
          artist.getArtistId(),
          Constants.JUKEBOX_PORTLET_REPOSITORY,
          DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
          inputStream,
          String.valueOf(artist.getArtistId()),
          StringPool.BLANK,
          true);
    }

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

      addEntryResources(
          artist, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      addEntryResources(
          artist, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Message boards

    mbMessageLocalService.addDiscussionMessage(
        userId,
        artist.getUserName(),
        groupId,
        Artist.class.getName(),
        artistId,
        WorkflowConstants.ACTION_PUBLISH);

    // Asset

    updateAsset(
        userId,
        artist,
        serviceContext.getAssetCategoryIds(),
        serviceContext.getAssetTagNames(),
        serviceContext.getAssetLinkEntryIds());

    return artist;
  }
  @Indexable(type = IndexableType.REINDEX)
  public Artist updateArtist(
      long userId,
      long artistId,
      String name,
      String bio,
      InputStream inputStream,
      ServiceContext serviceContext)
      throws PortalException {

    // Event

    User user = userPersistence.findByPrimaryKey(userId);

    validate(name);

    Artist artist = artistPersistence.findByPrimaryKey(artistId);

    artist.setModifiedDate(serviceContext.getModifiedDate(null));
    artist.setName(name);
    artist.setBio(bio);
    artist.setExpandoBridgeAttributes(serviceContext);

    artistPersistence.update(artist);

    if (inputStream != null) {
      Repository repository =
          PortletFileRepositoryUtil.fetchPortletRepository(
              serviceContext.getScopeGroupId(), Constants.JUKEBOX_PORTLET_REPOSITORY);

      if (repository != null) {
        try {
          PortletFileRepositoryUtil.deletePortletFileEntry(
              repository.getRepositoryId(),
              DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
              String.valueOf(artist.getArtistId()));
        } catch (Exception e) {
          if (_log.isDebugEnabled()) {
            _log.debug("Cannot delete artist image");
          }
        }
      }

      PortletFileRepositoryUtil.addPortletFileEntry(
          serviceContext.getScopeGroupId(),
          userId,
          Artist.class.getName(),
          artist.getArtistId(),
          Constants.JUKEBOX_PORTLET_REPOSITORY,
          DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
          inputStream,
          String.valueOf(artist.getArtistId()),
          StringPool.BLANK,
          true);
    }

    // Asset

    updateAsset(
        userId,
        artist,
        serviceContext.getAssetCategoryIds(),
        serviceContext.getAssetTagNames(),
        serviceContext.getAssetLinkEntryIds());

    return artist;
  }