Exemplo n.º 1
0
 private static MusicBrainzReleaseMusicBrainzAlias NewShadow(MusicBrainzRelease release, MusicBrainzAlias alias)
 {
     return(new MusicBrainzReleaseMusicBrainzAlias
     {
         MusicBrainzRelease = release
         , MusicBrainzReleaseUniqueId = release.UniqueId
         , MusicBrainzAlias = alias
         , MusicBrainzAliasUniqueId = alias.UniqueId
     });
 }
Exemplo n.º 2
0
 private static MusicBrainzReleaseMusicBrainzArtistCredit NewShadow(MusicBrainzRelease release
                                                                    , MusicBrainzArtistCredit artistCredit)
 {
     return(new MusicBrainzReleaseMusicBrainzArtistCredit
     {
         MusicBrainzRelease = release
         , MusicBrainzReleaseUniqueId = release.UniqueId
         , MusicBrainzArtistCredit = artistCredit
         , MusicBrainzArtistCreditUniqueId = artistCredit.UniqueId
     });
 }
Exemplo n.º 3
0
 private static MusicBrainzReleaseEventMusicBrainzRelease NewShadow(MusicBrainzRelease release
                                                                    , MusicBrainzReleaseEvent releaseEvent)
 {
     return(new MusicBrainzReleaseEventMusicBrainzRelease
     {
         MusicBrainzRelease = release
         , MusicBrainzReleaseUniqueId = release.UniqueId
         , MusicBrainzReleaseEvent = releaseEvent
         , MusicBrainzReleaseEventUniqueId = releaseEvent.UniqueId
     });
 }
 public static Dictionary <String, Object> ToJsonDictionary(this MusicBrainzRelease mbr)
 {
     return(new Dictionary <String, Object>
     {
         {
             "UniqueId", mbr.UniqueId
         }
         ,
         {
             "Title", mbr.Title
         }
         ,
         {
             "Disambiguation", mbr.Disambiguation
         }
         ,
         {
             "Country", mbr.Country
         }
         ,
         {
             "Date", mbr.Date
         }
         ,
         {
             "Quality", mbr.Quality
         }
         ,
         {
             "Status", mbr.Status
         }
         ,
         {
             "TextRepresentation", new Dictionary <String, Object>
             {
                 {
                     "Language", mbr.TextRepresentation?.Language
                 }
                 ,
                 {
                     "Script", mbr.TextRepresentation?.Script
                 }
             }
         }
     });
 }
Exemplo n.º 5
0
        public IActionResult GetById(Int32?id)
        {
            try
            {
                LoggerBundle.Trace("Registered GET request on ReleasesController.GetById");
                if (!IsAuthorized(out IActionResult result))
                {
                    LoggerBundle.Trace("Request not authorized");
                    return(result);
                }

                // validate
                if (id == null)
                {
                    LoggerBundle.Trace("Validation failed: id is null");
                    return(StatusCode((Int32)HttpStatusCode.BadRequest));
                }

                // get data
                using (DataContext dc = DataContextFactory.GetInstance())
                {
                    MusicBrainzRelease release = dc.SetReleases.AsNoTracking()
                                                 .Include(x => x.TextRepresentation)
                                                 .FirstOrDefault(x => x.UniqueId.Equals(id));

                    if (null == release)
                    {
                        LoggerBundle.Trace($"No release found for given id '{id}'");
                        return(StatusCode((Int32)HttpStatusCode.NotFound));
                    }

                    return(Ok(release.ToJsonDictionary()));
                }
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }
Exemplo n.º 6
0
 public static MusicBrainzReleaseMusicBrainzRecord NewShadow(MusicBrainzRecord record, MusicBrainzRelease release)
 {
     return(new MusicBrainzReleaseMusicBrainzRecord
     {
         MusicBrainzRecord = record
         , MusicBrainzRecordUniqueId = record.UniqueId
         , MusicBrainzRelease = release
         , MusicBrainzReleaseUniqueId = release.UniqueId
     });
 }
Exemplo n.º 7
0
        public static MusicBrainzRelease Map(DataContext context, JsonMusicBrainzRequest.Release json)
        {
            // references
            List <MusicBrainzArtistCredit> credits = json.ArtistCredit?.Select(x => Map(context, x)).ToList()
                                                     ?? new List <MusicBrainzArtistCredit>();
            List <MusicBrainzReleaseEvent> events = json.ReleaseEvents?.Select(x => Map(context, x)).ToList()
                                                    ?? new List <MusicBrainzReleaseEvent>();
            List <MusicBrainzAlias> aliases =
                json.Aliases?.Select(x => Map(context, x)).ToList() ?? new List <MusicBrainzAlias>();

            // main object
            DateTime?parsedDate = DateTimeParserPipe.Process(json.Date);

            MusicBrainzRelease release = new MusicBrainzRelease
            {
                Date                 = parsedDate
                , Status             = json.Status
                , Id                 = json.Id
                , Barcode            = json.Barcode
                , Country            = json.Country
                , Disambiguation     = json.Disambiguation
                , PackagingId        = json.PackagingId
                , Quality            = json.Quality
                , StatusId           = json.StatusId
                , Title              = json.Title
                , TextRepresentation = null == json.TextRepresentation ? null : Map(context, json.TextRepresentation)
            };

            release.UniqueHash = Comparator.ComputeContentHash(release);

            MusicBrainzRelease dbRelease = context.SetReleases.Include(x => x.MusicBrainzReleaseEventMusicBrainzReleases)
                                           .ThenInclude(x => x.MusicBrainzReleaseEvent)
                                           .Include(x => x.MusicBrainzReleaseMusicBrainzAliases)
                                           .ThenInclude(x => x.MusicBrainzAlias)
                                           .Include(x => x.MusicBrainzReleaseMusicBrainzArtistCredits)
                                           .ThenInclude(x => x.MusicBrainzArtistCredit)
                                           .FirstOrDefault(x => x.UniqueHash.Equals(release.UniqueHash));

            if (null == dbRelease)
            {
                // new entry

                // save to generate primary key
                context.SetReleases.Add(release);
                context.SaveChanges();

                // references
                release.MusicBrainzReleaseMusicBrainzArtistCredits = credits.Select(x => NewShadow(release, x)).ToList();
                release.MusicBrainzReleaseEventMusicBrainzReleases = events.Select(x => NewShadow(release, x)).ToList();
                release.MusicBrainzReleaseMusicBrainzAliases       = aliases.Select(x => NewShadow(release, x)).ToList();

                context.SaveChanges();
                return(release);
            }

            // already exists, only check for new references

            // credits
            IEnumerable <Int32> existingCreditIds =
                dbRelease.MusicBrainzReleaseMusicBrainzArtistCredits.Select(x => x.MusicBrainzArtistCredit.UniqueId);
            IEnumerable <Int32> newCreditIds = credits.Select(x => x.UniqueId).Except(existingCreditIds).Distinct();
            IEnumerable <MusicBrainzReleaseMusicBrainzArtistCredit> newCredits =
                credits.Where(x => newCreditIds.Contains(x.UniqueId)).Select(x => NewShadow(dbRelease, x));

            dbRelease.MusicBrainzReleaseMusicBrainzArtistCredits.AddRange(newCredits);

            // release events
            IEnumerable <Int32> existingEventIds =
                dbRelease.MusicBrainzReleaseEventMusicBrainzReleases.Select(x => x.MusicBrainzReleaseEvent.UniqueId);
            IEnumerable <Int32> newEventIds = events.Select(x => x.UniqueId).Except(existingEventIds).Distinct();
            IEnumerable <MusicBrainzReleaseEventMusicBrainzRelease> newEvents =
                events.Where(x => newEventIds.Contains(x.UniqueId)).Select(x => NewShadow(dbRelease, x));

            dbRelease.MusicBrainzReleaseEventMusicBrainzReleases.AddRange(newEvents);

            // aliases
            IEnumerable <Int32> existingAliasIds =
                dbRelease.MusicBrainzReleaseMusicBrainzAliases.Select(x => x.MusicBrainzAlias.UniqueId);
            IEnumerable <Int32> newAliasIds = aliases.Select(x => x.UniqueId).Except(existingAliasIds).Distinct();
            IEnumerable <MusicBrainzReleaseMusicBrainzAlias> newAliases =
                aliases.Where(x => newAliasIds.Contains(x.UniqueId)).Select(x => NewShadow(dbRelease, x));

            dbRelease.MusicBrainzReleaseMusicBrainzAliases.AddRange(newAliases);

            context.SaveChanges();

            return(dbRelease);
        }