Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 15c88dc1

Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)

Added sentiment to Tags and SubTags, modified create/update tag/subtag endpoints, added set instance sentiment endpoint

Zobrazit rozdíly:

Backend/Backend/Controllers/AnnotationController.cs
196 196

  
197 197
        }
198 198

  
199
        [HttpPut("/annotation/{annotationId}/{instanceId}/sentiment")]
200
        [ProducesResponseType((int)HttpStatusCode.OK)]
201
        [ProducesResponseType((int)HttpStatusCode.Forbidden)]
202
        public ActionResult SetTagInstanceSentiment([FromServices] ClientInfo clientInfo, Guid annotationId, Guid instanceId, SetInstanceSentimentRequest request)
203
        {
204
            if (clientInfo.LoggedUser == null)
205
            {
206
                logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /annotations");
207
                return Problem();
208
            }
209

  
210
            try
211
            {
212
                annotationService.SetTagInstanceSentiment(annotationId, instanceId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request.Sentiment);
213
                return Ok();
214
            }
215
            catch (InvalidOperationException e)
216
            {
217
                throw new BadRequestException(e.Message);
218
            }
219
            catch (UnauthorizedAccessException)
220
            {
221
                return Forbid();
222
            }
223

  
224
        }
199 225
    }
200 226
}
Backend/Core/Entities/AnnotationTag.cs
1
using System;
1
using Models.Enums;
2
using System;
2 3
using System.Collections.Generic;
3 4
using System.ComponentModel.DataAnnotations;
4 5
using System.ComponentModel.DataAnnotations.Schema;
......
21 22
        public string Note { get; set; }
22 23
        public int Position { get; set; }
23 24
        public int Length { get; set; }
25
        public ETagSentiment? Sentiment { get; set; }
24 26
    }
25 27
}
Backend/Core/Entities/SubTag.cs
11 11
    {
12 12
        public string Name { get; set; }
13 13
        public string Description { get; set; }
14
        
15 14
        public Tag Tag { get; set; }
15
        public bool SentimentEnabled { get; set; } = false;
16 16
    }
17 17
}
Backend/Core/Entities/Tag.cs
14 14
        public string Name { get; set; }
15 15
        public string Description { get; set; }
16 16
        public string Color { get; set; }
17
        public bool SentimentEnabled { get; set; } = false;
17 18
    }
18 19
}
Backend/Core/Seeding/DummyTags.cs
33 33
                Name = "pristup_zadost",
34 34
                Description = "Informování subjektu o jeho právu na přístup k osobním údajům vztahujícím se k jeho osobě na jeho žádost.",
35 35
                Color = "#FF0000",
36
                Category = rightsCat        
36
                Category = rightsCat,
37
                SentimentEnabled = true
37 38
            };
38 39
            context.Tags.Add(pristupZadostTag);
39 40

  
Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
562 562
            {
563 563
                annotationTag.Tag = context.Tags.Where(t => t.Id == request.Id).Single();
564 564
                annotationTag.SubTag = null;
565

  
566
                if (annotationTag.Tag.SentimentEnabled)
567
                {
568
                    annotationTag.Sentiment = ETagSentiment.NEUTRAL;
569
                }
565 570
            }
566 571
            else if (request.Type == ETagType.SUBTAG)
567 572
            {
568 573
                var subTag = context.SubTags.Where(st => st.Id == request.Id).Include(st => st.Tag).Single();
569 574
                annotationTag.SubTag = subTag;
570 575
                annotationTag.Tag = subTag.Tag;
576

  
577
                if (annotationTag.SubTag.SentimentEnabled)
578
                {
579
                    annotationTag.Sentiment = ETagSentiment.NEUTRAL;
580
                }
571 581
            }
572 582
            else
573 583
            {
......
615 625

  
616 626
            context.SaveChanges();
617 627
        }
628

  
629
        public void SetTagInstanceSentiment(Guid annotationId, Guid instanceId, Guid userId, ERole userRole, ETagSentiment sentiment)
630
        {
631
            Annotation annotation = null;
632
            try
633
            {
634
                annotation = context.Annotations
635
                   .Where(a => a.Id == annotationId)
636
                   .Include(a => a.User)
637
                   .Include(a => a.Document).ThenInclude(d => d.Content)
638
                   .First();
639

  
640
            }
641
            catch (Exception ex)
642
            {
643
                throw new InvalidOperationException("Could not find annotation");
644
            }
645

  
646

  
647
            if (userRole < ERole.ADMINISTRATOR)
648
            {
649
                if (annotation.User.Id != userId)
650
                {
651
                    throw new UnauthorizedAccessException($"User {userId} does not have assigned annotation {annotationId}");
652
                }
653
            }
654

  
655

  
656
            var tagInstances = context.AnnotationTags.Where(at => at.Instance == instanceId).ToList();
657
            if (tagInstances.Count() == 0)
658
            {
659
                throw new InvalidOperationException("No such instance found");
660
            }
661

  
662
            foreach (var tagInstance in tagInstances)
663
            {
664
                tagInstance.Sentiment = sentiment;
665
            }
666

  
667
            context.SaveChanges();
668
        }
618 669
    }
619 670
}
Backend/Core/Services/AnnotationService/IAnnotationService.cs
16 16
        public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request);
17 17
        public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole);
18 18
        public void AddNoteToAnnotation(Guid annotationId, Guid userId, ERole userRole, AddNoteToAnnotationRequest request);
19
        public void SetTagInstanceSentiment(Guid annotationId, Guid instanceId, Guid userId, ERole userRole, ETagSentiment sentiment);
20

  
21

  
19 22
    }
20 23
}
Backend/Core/Services/TagService/TagServiceEF.cs
129 129

  
130 130
            if (request.DisabledForAnnotators != null)
131 131
            {
132
                category.DisabledForAnnotators = (bool) request.DisabledForAnnotators;
132
                category.DisabledForAnnotators = (bool)request.DisabledForAnnotators;
133 133
            }
134 134

  
135 135
            databaseContext.SaveChanges();
......
149 149
            var category = databaseContext.TagCategories.First(tc => tc.Id == request.CategoryId);
150 150

  
151 151
            databaseContext.Tags.Add(new Entities.Tag()
152
            databaseContext.Tags.Add(new Tag()
152 153
            {
153 154
                Name = request.Name,
154 155
                Color = request.Color,
155 156
                Description = request.Description,
156
                Category = category
157
                Category = category,
158
                SentimentEnabled = request.SentimentEnabled
157 159
            });
158 160

  
159 161
            databaseContext.SaveChanges();
......
192 194
                tag.Description = request.Description;
193 195
            }
194 196

  
197
            if (request.SentimentEnabled != null)
198
            {
199
                tag.SentimentEnabled = (bool)request.SentimentEnabled;
200
            }
201

  
195 202
            databaseContext.SaveChanges();
196 203
        }
197 204

  
......
211 218
            {
212 219
                Name = request.Name,
213 220
                Description = request.Description,
214
                Tag = tag
221
                Tag = tag,
222
                SentimentEnabled = request.SentimentEnabled
215 223
            });
216 224

  
217 225
            databaseContext.SaveChanges();
......
241 249
                subtag.Description = request.Description;
242 250
            }
243 251

  
252
            if (request.SentimentEnabled != null)
253
            {
254
                subtag.SentimentEnabled = (bool) request.SentimentEnabled;
255
            }
256

  
244 257
            databaseContext.SaveChanges();
245 258
        }
246 259

  
Backend/Models/Enums/ETagSentiment.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace Models.Enums
8
{
9
    public enum ETagSentiment
10
    {
11
        NEUTRAL, 
12
        POSITIVE,
13
        NEGATIVE
14
    }
15
}
Backend/Models/Tags/CreateSubTagRequest.cs
9 9
    public class CreateSubTagRequest
10 10
    {
11 11
        public string Name { get; set; }
12
        public string Description { get; set; }
12
        public string Description { get; set; } = "";
13 13
        public Guid TagId { get; set; }
14
        public bool SentimentEnabled { get; set; } = false;
14 15
    }
15 16
}
Backend/Models/Tags/CreateTagRequest.cs
12 12
        public string Name { get; set; }
13 13
        public string Description { get; set; } = "";
14 14
        public string Color { get; set; }
15
        public bool SentimentEnabled { get; set; } = false;
15 16
    }
16 17
}
Backend/Models/Tags/ModifySubTagRequest.cs
10 10
    {
11 11
        public string? Name { get; set; }
12 12
        public string? Description { get; set; }
13
        public bool? SentimentEnabled { get; set; }
13 14
    }
14 15
}
Backend/Models/Tags/ModifyTagRequest.cs
11 11
        public string? Name { get; set; }
12 12
        public string? Description { get; set; }
13 13
        public string? Color { get; set; }
14
        public bool? SentimentEnabled { get; set; }
14 15
    }
15 16
}
Backend/Models/Tags/SetInstanceSentimentRequest.cs
1
using Models.Enums;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7

  
8
namespace Models.Tags
9
{
10
    public class SetInstanceSentimentRequest
11
    {
12
        public ETagSentiment Sentiment { get; set; }
13
    }
14
}

Také k dispozici: Unified diff