@Indexable(type = IndexableType.REINDEX) public Album addAlbum( long userId, long artistId, String name, int year, InputStream inputStream, ServiceContext serviceContext) throws PortalException { long groupId = serviceContext.getScopeGroupId(); User user = userPersistence.findByPrimaryKey(userId); Date now = new Date(); validate(name); long albumId = counterLocalService.increment(); Album album = albumPersistence.create(albumId); album.setUuid(serviceContext.getUuid()); album.setGroupId(groupId); album.setCompanyId(user.getCompanyId()); album.setUserId(user.getUserId()); album.setUserName(user.getFullName()); album.setCreateDate(serviceContext.getCreateDate(now)); album.setModifiedDate(serviceContext.getModifiedDate(now)); album.setArtistId(artistId); album.setName(name); album.setYear(year); album.setExpandoBridgeAttributes(serviceContext); albumPersistence.update(album); if (inputStream != null) { PortletFileRepositoryUtil.addPortletFileEntry( groupId, userId, Album.class.getName(), album.getAlbumId(), Constants.JUKEBOX_PORTLET_REPOSITORY, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, inputStream, String.valueOf(album.getAlbumId()), StringPool.BLANK, true); } // Resources if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) { addEntryResources( album, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions()); } else { addEntryResources( album, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions()); } // Message boards mbMessageLocalService.addDiscussionMessage( userId, album.getUserName(), groupId, Album.class.getName(), albumId, WorkflowConstants.ACTION_PUBLISH); // Asset updateAsset( userId, album, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds()); return album; }
@Indexable(type = IndexableType.REINDEX) public Album updateAlbum( long userId, long albumId, long artistId, String name, int year, InputStream inputStream, ServiceContext serviceContext) throws PortalException { // Event User user = userPersistence.findByPrimaryKey(userId); validate(name); Album album = albumPersistence.findByPrimaryKey(albumId); album.setModifiedDate(serviceContext.getModifiedDate(null)); album.setArtistId(artistId); album.setName(name); album.setYear(year); album.setExpandoBridgeAttributes(serviceContext); albumPersistence.update(album); 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(album.getAlbumId())); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug("Cannot delete album cover"); } } } PortletFileRepositoryUtil.addPortletFileEntry( serviceContext.getScopeGroupId(), userId, Album.class.getName(), album.getAlbumId(), Constants.JUKEBOX_PORTLET_REPOSITORY, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, inputStream, String.valueOf(album.getAlbumId()), StringPool.BLANK, true); } // Asset updateAsset( userId, album, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds()); return album; }