public AlbumForApiContract( Album album, AlbumMergeRecord mergeRecord, ContentLanguagePreference languagePreference, IEntryThumbPersister thumbPersister, bool ssl, AlbumOptionalFields fields) : this(album, mergeRecord, languagePreference, fields.HasFlag(AlbumOptionalFields.Artists), fields.HasFlag(AlbumOptionalFields.Names), fields.HasFlag(AlbumOptionalFields.PVs), fields.HasFlag(AlbumOptionalFields.Tags), fields.HasFlag(AlbumOptionalFields.WebLinks)) { if (languagePreference != ContentLanguagePreference.Default || fields.HasFlag(AlbumOptionalFields.AdditionalNames)) { AdditionalNames = album.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (fields.HasFlag(AlbumOptionalFields.Identifiers)) { Identifiers = album.Identifiers.Select(i => new AlbumIdentifierContract(i)).ToArray(); } if (thumbPersister != null && fields.HasFlag(AlbumOptionalFields.MainPicture) && !string.IsNullOrEmpty(album.CoverPictureMime)) { MainPicture = new EntryThumbForApiContract(new EntryThumb(album, album.CoverPictureMime), thumbPersister, ssl); } }
public AlbumForApiContract( Album album, AlbumMergeRecord mergeRecord, ContentLanguagePreference languagePreference, IEntryThumbPersister thumbPersister, bool ssl, AlbumOptionalFields fields) : this(album, mergeRecord, languagePreference, fields.HasFlag(AlbumOptionalFields.Artists), fields.HasFlag(AlbumOptionalFields.Names), fields.HasFlag(AlbumOptionalFields.PVs), fields.HasFlag(AlbumOptionalFields.Tags), fields.HasFlag(AlbumOptionalFields.WebLinks)) { if (languagePreference != ContentLanguagePreference.Default || fields.HasFlag(AlbumOptionalFields.AdditionalNames)) { AdditionalNames = album.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (fields.HasFlag(AlbumOptionalFields.Identifiers)) { Identifiers = album.Identifiers.Select(i => new AlbumIdentifierContract(i)).ToArray(); } if (thumbPersister != null && fields.HasFlag(AlbumOptionalFields.MainPicture) && !string.IsNullOrEmpty(album.CoverPictureMime)) { MainPicture = new EntryThumbForApiContract(new EntryThumb(album, album.CoverPictureMime), thumbPersister, ssl); } }
public AlbumForApiContract(Album album, AlbumMergeRecord mergeRecord, ContentLanguagePreference languagePreference, bool artists = true, bool names = true, bool pvs = false, bool tags = true, bool webLinks = false) { ArtistString = album.ArtistString[languagePreference]; CatalogNumber = album.OriginalRelease != null ? album.OriginalRelease.CatNum : null; CreateDate = album.CreateDate; DefaultName = album.DefaultName; DefaultNameLanguage = album.Names.SortNames.DefaultLanguage; DiscType = album.DiscType; Id = album.Id; Name = album.Names.SortNames[languagePreference]; RatingAverage = album.RatingAverage; RatingCount = album.RatingCount; ReleaseDate = new OptionalDateTimeContract(album.OriginalReleaseDate); ReleaseEvent = album.OriginalReleaseEventName; Status = album.Status; Version = album.Version; if (languagePreference != ContentLanguagePreference.Default) { LocalizedName = album.Names.SortNames[languagePreference]; } if (artists) { Artists = album.Artists.Select(a => new ArtistForAlbumForApiContract(a, languagePreference)).ToArray(); } if (names) { Names = album.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (pvs) { PVs = album.PVs.Select(p => new PVContract(p)).ToArray(); } if (tags) { Tags = album.Tags.Usages.Select(u => new TagUsageForApiContract(u)).ToArray(); } if (webLinks) { WebLinks = album.WebLinks.Select(w => new WebLinkContract(w)).ToArray(); } if (mergeRecord != null) { MergedTo = mergeRecord.Target.Id; } }
public AlbumForApiContract(Album album, AlbumMergeRecord mergeRecord, ContentLanguagePreference languagePreference, bool artists = true, bool names = true, bool pvs = false, bool tags = true, bool webLinks = false) { ArtistString = album.ArtistString[languagePreference]; CatalogNumber = album.OriginalRelease != null ? album.OriginalRelease.CatNum : null; CreateDate = album.CreateDate; DefaultName = album.DefaultName; DefaultNameLanguage = album.Names.SortNames.DefaultLanguage; DiscType = album.DiscType; Id = album.Id; Name = album.Names.SortNames[languagePreference]; RatingAverage = album.RatingAverage; RatingCount = album.RatingCount; ReleaseDate = new OptionalDateTimeContract(album.OriginalReleaseDate); ReleaseEvent = album.OriginalReleaseEventName; Status = album.Status; Version = album.Version; if (languagePreference != ContentLanguagePreference.Default) { LocalizedName = album.Names.SortNames[languagePreference]; } if (artists) Artists = album.Artists.Select(a => new ArtistForAlbumForApiContract(a, languagePreference)).ToArray(); if (names) Names = album.Names.Select(n => new LocalizedStringContract(n)).ToArray(); if (pvs) PVs = album.PVs.Select(p => new PVContract(p)).ToArray(); if (tags) Tags = album.Tags.Usages.Select(u => new TagUsageForApiContract(u)).ToArray(); if (webLinks) WebLinks = album.WebLinks.Select(w => new WebLinkContract(w)).ToArray(); if (mergeRecord != null) MergedTo = mergeRecord.Target.Id; }
public AlbumForApiContract( Album album, AlbumMergeRecord mergeRecord, ContentLanguagePreference languagePreference, IAggregatedEntryImageUrlFactory thumbPersister, AlbumOptionalFields fields, SongOptionalFields songFields) { ArtistString = album.ArtistString[languagePreference]; CatalogNumber = album.OriginalRelease != null ? album.OriginalRelease.CatNum : null; CreateDate = album.CreateDate; DefaultName = album.DefaultName; DefaultNameLanguage = album.Names.SortNames.DefaultLanguage; DiscType = album.DiscType; Id = album.Id; Name = album.Names.SortNames[languagePreference]; RatingAverage = album.RatingAverage; RatingCount = album.RatingCount; ReleaseDate = new OptionalDateTimeContract(album.OriginalReleaseDate); Status = album.Status; Version = album.Version; if (fields.HasFlag(AlbumOptionalFields.AdditionalNames)) { AdditionalNames = album.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (fields.HasFlag(AlbumOptionalFields.Artists)) { Artists = album.Artists.Select(a => new ArtistForAlbumForApiContract(a, languagePreference)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.Description)) { Description = album.Description[languagePreference]; } if (fields.HasFlag(AlbumOptionalFields.Discs)) { Discs = album.Discs.Select(d => new AlbumDiscPropertiesContract(d)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.Identifiers)) { Identifiers = album.Identifiers.Select(i => new AlbumIdentifierContract(i)).ToArray(); } if (thumbPersister != null && fields.HasFlag(AlbumOptionalFields.MainPicture) && album.Thumb != null) { MainPicture = new EntryThumbForApiContract(album.Thumb, thumbPersister); } if (fields.HasFlag(AlbumOptionalFields.Names)) { Names = album.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.PVs)) { PVs = album.PVs.Select(p => new PVContract(p)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.ReleaseEvent)) { ReleaseEvent = album.OriginalReleaseEvent != null ? new ReleaseEventForApiContract(album.OriginalReleaseEvent, languagePreference, ReleaseEventOptionalFields.None, thumbPersister) : null; } if (fields.HasFlag(AlbumOptionalFields.Tags)) { Tags = album.Tags.ActiveUsages.Select(u => new TagUsageForApiContract(u, languagePreference)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.Tracks)) { Tracks = album.Songs.Select(s => new SongInAlbumForApiContract(s, languagePreference, songFields)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.WebLinks)) { WebLinks = album.WebLinks.Select(w => new WebLinkForApiContract(w)).ToArray(); } if (mergeRecord != null) { MergedTo = mergeRecord.Target.Id; } }
public void Merge(int sourceId, int targetId) { PermissionContext.VerifyPermission(PermissionToken.MergeEntries); if (sourceId == targetId) { throw new ArgumentException("Source and target albums can't be the same", "targetId"); } repository.HandleTransaction(session => { var source = session.Load(sourceId); var target = session.Load(targetId); session.AuditLogger.AuditLog(string.Format("Merging {0} to {1}", EntryLinkFactory.CreateEntryLink(source), EntryLinkFactory.CreateEntryLink(target))); NHibernateUtil.Initialize(source.CoverPictureData); NHibernateUtil.Initialize(target.CoverPictureData); foreach (var n in source.Names.Names.Where(n => !target.HasName(n))) { var name = target.CreateName(n.Value, n.Language); session.Save(name); } foreach (var w in source.WebLinks.Where(w => !target.HasWebLink(w.Url))) { var link = target.CreateWebLink(w.Description, w.Url, w.Category); session.Save(link); } var artists = source.Artists.Where(a => !target.HasArtistForAlbum(a)).ToArray(); foreach (var a in artists) { a.Move(target); session.Update(a); } var songs = source.Songs.Where(s => s.Song == null || !target.HasSong(s.Song)).ToArray(); foreach (var s in songs) { s.Move(target); session.Update(s); } var pictures = source.Pictures.ToArray(); foreach (var p in pictures) { p.Move(target); session.Update(p); } var userCollections = source.UserCollections.Where(a => !target.IsInUserCollection(a.User)).ToArray(); foreach (var u in userCollections) { u.Move(target); session.Update(u); } target.Description.CopyIfEmpty(source.Description); if (target.OriginalRelease == null) { target.OriginalRelease = new AlbumRelease(); } if (string.IsNullOrEmpty(target.OriginalRelease.CatNum) && source.OriginalRelease != null) { target.OriginalRelease.CatNum = source.OriginalRelease.CatNum; } if (target.OriginalRelease.ReleaseEvent == null && source.OriginalRelease != null) { target.OriginalRelease.ReleaseEvent = source.OriginalRelease.ReleaseEvent; } if (target.OriginalRelease.ReleaseDate == null) { target.OriginalRelease.ReleaseDate = new OptionalDateTime(); } if (target.OriginalReleaseDate.Year == null && source.OriginalRelease != null) { target.OriginalReleaseDate.Year = source.OriginalReleaseDate.Year; } if (target.OriginalReleaseDate.Month == null && source.OriginalRelease != null) { target.OriginalReleaseDate.Month = source.OriginalReleaseDate.Month; } if (target.OriginalReleaseDate.Day == null && source.OriginalRelease != null) { target.OriginalReleaseDate.Day = source.OriginalReleaseDate.Day; } // Create merge record var mergeEntry = new AlbumMergeRecord(source, target); session.Save(mergeEntry); source.Deleted = true; target.UpdateArtistString(); target.Names.UpdateSortNames(); Archive(session, source, AlbumArchiveReason.Deleted, string.Format("Merged to {0}", target)); Archive(session, target, AlbumArchiveReason.Merged, string.Format("Merged from {0}", source)); session.Update(source); session.Update(target); }); }