예제 #1
0
        public DictionaryBlock <string, long> GetMostValuedLabels(int startIndex, int count)
        {
            ListBlock <Label> labels;

            try
            {
                labels = LabelDao.ListAllRated(startIndex, count);
            }
            catch (InstanceNotFoundException <Label> )
            {
                return(new DictionaryBlock <string, long>(startIndex, false));
            }
            catch (NoMoreItemsException <Label> )
            {
                return(new DictionaryBlock <string, long>(startIndex, false));
            }

            DictionaryBlock <string, long> details = new DictionaryBlock <string, long>(labels.Index, labels.HasMore);

            foreach (Label label in labels)
            {
                int rating = RatingDao.CalculateValueForLabel(label.text);

                details.Add(label.text, rating);
            }

            return(details);
        }
예제 #2
0
        public DictionaryBlock <string, long> GetLabelsForLink(long linkId, int startIndex, int count)
        {
            if (!LinkDao.Exists(linkId))
            {
                throw new InstanceNotFoundException <LinkDetails>("linkId", linkId);
            }

            ListBlock <Label> labels;

            try
            {
                labels = LabelDao.ListForLinkRated(linkId, startIndex, count);
            }
            catch (InstanceNotFoundException <Label> )
            {
                return(new DictionaryBlock <string, long>(startIndex, false));
            }
            catch (NoMoreItemsException <Label> )
            {
                return(new DictionaryBlock <string, long>(startIndex, false));
            }

            DictionaryBlock <string, long> details = new DictionaryBlock <string, long>(labels.Index, labels.HasMore);

            foreach (Label label in labels)
            {
                int rating = RatingDao.CalculateValueForLabel(label.text);

                details.Add(label.text, rating);
            }

            return(details);
        }
예제 #3
0
        private string OnEAV_GETLABELLIST(object args)
        {
            var dao_label = new LabelDao();
            var labels    = dao_label.LoadLabel();

            return(JsonConvert.SerializeObject(labels));
        }
예제 #4
0
        private string OnEAV_GETLABELLINKCATEGORYLIST(object args)
        {
            var query        = args.ToString();
            var dao_label    = new LabelDao();
            var categoryList = dao_label.LoadLabelLinkCategory(query, 0, 0);

            return(JsonConvert.SerializeObject(categoryList));
        }
예제 #5
0
        public Label DaoToEntity(LabelDao dao)
        {
            Label entity = new Label
            {
                Id    = dao.Id,
                Value = dao.Value
            };

            return(entity);
        }
예제 #6
0
        public Label CreateTestLabel(string text)
        {
            Label label = Label.CreateLabel(
                TestData.nonExistentLabelId,
                text);

            LabelDao.Create(label);

            return(label);
        }
예제 #7
0
        public LabelDao EntityToDao(Label entity)
        {
            LabelDao dao = new LabelDao
            {
                Id    = entity.Id,
                Value = entity.Value
            };

            return(dao);
        }
예제 #8
0
        public LabelDto Find(long labelId)
        {
            Label label = LabelDao.Find(labelId);
            ICollection <CommentDto> commentsDto = new List <CommentDto>();

            foreach (Comment c in label.Comments)
            {
                commentsDto.Add(new CommentDto(c, c.Event.eventId));
            }
            return(new LabelDto(label.labelId, label.name, label.commentsNum, commentsDto));
        }
예제 #9
0
        public int GetTotalReferences()
        {
            int          count  = 0;
            List <Label> labels = LabelDao.GetAllElements();

            foreach (Label l in labels)
            {
                count += l.commentsNum;
            }
            return(count);
        }
예제 #10
0
        public ICollection <LabelDto> GetLabelsDtos()
        {
            ICollection <Label>    labels    = LabelDao.GetAllElements();
            ICollection <LabelDto> labelsDto = new List <LabelDto>();

            foreach (Label l in labels)
            {
                ICollection <CommentDto> commentsDto = new List <CommentDto>();
                foreach (Comment c in l.Comments)
                {
                    commentsDto.Add(new CommentDto(c, c.Event.eventId));
                }
                labelsDto.Add(new LabelDto(l.labelId, l.name, l.commentsNum, commentsDto));
            }
            return(labelsDto);
        }
예제 #11
0
        public Comment AddLabel(long commentId, ICollection <Label> labels)
        {
            Comment c = CommentDao.Find(commentId);

            foreach (Label l in labels)
            {
                if (!c.Labels.Contains(l))
                {
                    c.Labels.Add(l);
                    l.commentsNum++;
                    LabelDao.Update(l);
                }
            }
            CommentDao.Update(c);
            return(c);
        }
예제 #12
0
 public Label Create(Label label)
 {
     label.name = label.name.ToLower();
     try
     {
         LabelDao.FindByName(label.name);
         throw new DuplicateInstanceException(label,
                                              typeof(Label).FullName);
     }
     catch (InstanceNotFoundException)
     {
         label.commentsNum = 0;
         LabelDao.Create(label);
         return(label);
     }
 }
예제 #13
0
        public Comment RemoveLabel(long commentId, ICollection <Label> labels)
        {
            Comment comment = CommentDao.Find(commentId);

            foreach (Label l in labels)
            {
                if (comment.Labels.Contains(l))
                {
                    comment.Labels.Remove(l);
                    l.commentsNum--;
                    l.Comments.Remove(comment);
                    LabelDao.Update(l);
                }
            }
            CommentDao.Update(comment);
            return(comment);
        }
예제 #14
0
 public Label FindLabel(long labelId)
 {
     return(LabelDao.Find(labelId));
 }
예제 #15
0
 public List <Label> FindAllLabels()
 {
     return(LabelDao.ListAllRated(0, 1000));
 }
예제 #16
0
 public bool ExistsLabel(long labelId)
 {
     return(LabelDao.Exists(labelId));
 }
예제 #17
0
        public void SetLabelsForLink(long userId, long linkId, List <string> labelTexts)
        {
            if (!UserDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }

            Link link;

            try
            {
                link = LinkDao.Find(linkId);
            }
            catch (InstanceNotFoundException <Link> ex)
            {
                throw new InstanceNotFoundException <LinkDetails>(ex.Properties);
            }

            if (link.userId != userId)
            {
                throw new UserNotAuthorizedException <LinkDetails>(userId, "linkId", linkId);
            }

            List <Label> labelsToSet = new List <Label>();

            foreach (string labelText in labelTexts.Distinct())
            {
                if (labelText != null)
                {
                    string trimmedLabelText = labelText.Trim();

                    if (trimmedLabelText != "")
                    {
                        Label label;
                        try
                        {
                            label = LabelDao.FindByText(trimmedLabelText);
                        }
                        catch (InstanceNotFoundException <Label> )
                        {
                            label = Label.CreateLabel(-1, trimmedLabelText);
                            LabelDao.Create(label);
                        }
                        catch (DuplicateInstanceException <Label> ex)
                        {
                            throw new InternalErrorException(ex);
                        }
                        if (!labelsToSet.Contains(label))
                        {
                            labelsToSet.Add(label);
                        }
                    }
                }
            }

            List <Label> labelsAlreadyForLink;

            try
            {
                labelsAlreadyForLink = LabelDao.FindForLink(linkId);
            }
            catch (InstanceNotFoundException <Label> )
            {
                labelsAlreadyForLink = new List <Label>();
            }
            foreach (Label labelAlreadyForLink in labelsAlreadyForLink)
            {
                if (!labelsToSet.Contains(labelAlreadyForLink))
                {
                    link.Labels.Remove(labelAlreadyForLink);

                    if (labelAlreadyForLink.Links.Count == 1)
                    {
                        labelAlreadyForLink.Links.Remove(link);
                        try
                        {
                            LabelDao.Update(labelAlreadyForLink);
                        }
                        catch (InstanceNotFoundException <Label> ex)
                        {
                            throw new InternalErrorException(ex);
                        }
                    }
                    else
                    {
                        try
                        {
                            LabelDao.Remove(labelAlreadyForLink.labelId);
                        }
                        catch (InstanceNotFoundException <Label> ex)
                        {
                            throw new InternalErrorException(ex);
                        }
                    }
                }
                else
                {
                    labelsToSet.Remove(labelAlreadyForLink);
                }
            }

            foreach (Label label in labelsToSet)
            {
                if (!link.Labels.Contains(label))
                {
                    link.Labels.Add(label);

                    label.Links.Add(link);
                    try
                    {
                        LabelDao.Update(label);
                    }
                    catch (InstanceNotFoundException <Label> ex)
                    {
                        throw new InternalErrorException(ex);
                    }
                }
            }

            try
            {
                LinkDao.Update(link);
            }
            catch (InstanceNotFoundException <Link> ex)
            {
                throw new InternalErrorException(ex);
            }
        }
예제 #18
0
 public ICollection <Label> GetAllLabels()
 {
     return(LabelDao.GetAllElements());
 }
예제 #19
0
 public int GetNumberOfLabels()
 {
     return(LabelDao.GetAllElements().Count);
 }
예제 #20
0
 public Label FindLabelByName(string labelName)
 {
     return(LabelDao.FindByName(labelName));
 }
예제 #21
0
 public Label FindLabel(string text)
 {
     return(LabelDao.FindByText(text));
 }
예제 #22
0
        public void RemoveLabelsForLink(long userId, long linkId)
        {
            if (!UserDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }

            Link link;

            try
            {
                link = LinkDao.Find(linkId);
            }
            catch (InstanceNotFoundException <Link> ex)
            {
                throw new InstanceNotFoundException <LinkDetails>(ex.Properties);
            }

            if (link.UserProfile.userId != userId)
            {
                throw new UserNotAuthorizedException <LinkDetails>(userId, linkId);
            }

            List <Label> removableLabels = new List <Label>();

            foreach (Label label in link.Labels)
            {
                if (label.Links.Contains(link))
                {
                    removableLabels.Add(label);
                }
            }

            foreach (Label label in removableLabels)
            {
                label.Links.Remove(link);
                link.Labels.Remove(label);

                LinkDao.Update(link);

                if (label.Links.Count > 0)
                {
                    try
                    {
                        LabelDao.Update(label);
                    }
                    catch (InstanceNotFoundException <Label> ex)
                    {
                        throw new InternalErrorException(ex);
                    }
                }
                else
                {
                    try
                    {
                        LabelDao.Remove(label.labelId);
                    }
                    catch (InstanceNotFoundException <Label> ex)
                    {
                        throw new InternalErrorException(ex);
                    }
                }
            }
        }