commit 83d4581e8cc40b7399062a2451cfe1da6145365f
Author: Vojtěch Bartička <aitakaitov@gmail.com>
Date:   Sun May 15 15:16:21 2022 +0200

    Added final annotation endpoints

diff --git a/Backend/Backend/Controllers/AnnotationController.cs b/Backend/Backend/Controllers/AnnotationController.cs
index 0578570..721f96e 100644
--- a/Backend/Backend/Controllers/AnnotationController.cs
+++ b/Backend/Backend/Controllers/AnnotationController.cs
@@ -53,7 +53,7 @@ namespace RestAPI.Controllers
         [HttpGet("/annotation/{annotationId}")]
         [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(AnnotationInfo))]
         [ProducesResponseType((int)HttpStatusCode.Forbidden)]
-        public ActionResult<AnnotationInfo> GetAnnotation([FromServices] ClientInfo clientInfo, Guid annotationId)
+        public ActionResult<AnnotationInfo> GetAnnotation([FromServices] ClientInfo clientInfo, Guid annotationId, [FromQuery] bool isFinal)
         {
             if (clientInfo.LoggedUser == null)
             {
@@ -61,11 +61,16 @@ namespace RestAPI.Controllers
                 return Problem();
             }
 
+            if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR)
+            {
+                Forbid();
+            }
+
             // Take care of - non-admin user requesting not-assigned annotation
             // non-existent annotation
             try
             {
-                var res = annotationService.GetAnnotation(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role);
+                var res = annotationService.GetAnnotation(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, isFinal);
                 return Ok(res);
             }
             catch (InvalidOperationException e)
@@ -82,19 +87,24 @@ namespace RestAPI.Controllers
         [HttpPost("/annotation/{annotationId}")]
         [ProducesResponseType((int)HttpStatusCode.OK)]
         [ProducesResponseType((int)HttpStatusCode.Forbidden)]
-        public ActionResult PostAnnotation([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] AnnotationInstanceAddRequest request)
+        public ActionResult PostAnnotation([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] AnnotationInstanceAddRequest request, [FromQuery] bool isFinal)
         {
             if (clientInfo.LoggedUser == null)
             {
                 logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /annotations");
                 return Problem();
             }
-            
+
+            if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR)
+            {
+                Forbid();
+            }
+
             // Take care of - non-admin user requesting not-assigned annotation
             // non-existent annotation
             try
             {
-                annotationService.AddAnnotationInstance(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request);
+                annotationService.AddAnnotationInstance(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request, isFinal);
                 return Ok();
             }
             catch (UnauthorizedAccessException)
@@ -110,7 +120,7 @@ namespace RestAPI.Controllers
         [HttpDelete("/annotation/{annotationId}/{occurenceId}")]
         [ProducesResponseType((int)HttpStatusCode.OK)]
         [ProducesResponseType((int)HttpStatusCode.Forbidden)]
-        public ActionResult DeleteAnnotationInstance([FromServices] ClientInfo clientInfo, Guid annotationId, Guid occurenceId)
+        public ActionResult DeleteAnnotationInstance([FromServices] ClientInfo clientInfo, Guid annotationId, Guid occurenceId, [FromQuery] bool isFinal)
         {
             if (clientInfo.LoggedUser == null)
             {
@@ -118,11 +128,16 @@ namespace RestAPI.Controllers
                 return Problem();
             }
 
+            if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR)
+            {
+                Forbid();
+            }
+
             // Take care of - non-admin user requesting not-assigned annotation
             // non-existent annotation
             try
             {
-                annotationService.DeleteAnnotationInstance(annotationId, occurenceId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role);
+                annotationService.DeleteAnnotationInstance(annotationId, occurenceId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, isFinal);
                 return Ok();
             }
             catch (UnauthorizedAccessException)
@@ -140,7 +155,7 @@ namespace RestAPI.Controllers
         [ProducesResponseType((int)HttpStatusCode.OK)]
         [ProducesResponseType((int)HttpStatusCode.Forbidden)]
         public ActionResult AddNoteToTagOccurence([FromServices] ClientInfo clientInfo, Guid annotationId, Guid occurenceId,
-            [FromBody] AddNoteToTagOccurenceRequest request)
+            [FromBody] AddNoteToTagOccurenceRequest request, [FromBody] bool isFinal)
         {
             if (clientInfo.LoggedUser == null)
             {
@@ -148,11 +163,16 @@ namespace RestAPI.Controllers
                 return Problem();
             }
 
+            if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR)
+            {
+                Forbid();
+            }
+
             // Take care of - non-admin user requesting not-assigned annotation
             // non-existent annotation
             try
             {
-                tagService.AddNoteToTagInstance(annotationId, occurenceId, clientInfo.LoggedUser, request);
+                tagService.AddNoteToTagInstance(annotationId, occurenceId, clientInfo.LoggedUser, request, isFinal);
                 return Ok();
             }
             catch (InvalidOperationException e)
@@ -169,7 +189,7 @@ namespace RestAPI.Controllers
         [HttpPost("/annotation/{annotationId}/note")]
         [ProducesResponseType((int)HttpStatusCode.OK)]
         [ProducesResponseType((int)HttpStatusCode.Forbidden)]
-        public ActionResult AddNoteToTagOccurence([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] AddNoteToAnnotationRequest request)
+        public ActionResult AddNoteToTagOccurence([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] AddNoteToAnnotationRequest request, [FromQuery] bool isFinal)
         {
             if (clientInfo.LoggedUser == null)
             {
@@ -177,11 +197,16 @@ namespace RestAPI.Controllers
                 return Problem();
             }
 
+            if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR)
+            {
+                Forbid();
+            }
+
             // Take care of - non-admin user requesting not-assigned annotation
             // non-existent annotation
             try
             {
-                annotationService.AddNoteToAnnotation(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request);
+                annotationService.AddNoteToAnnotation(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request, isFinal);
                 return Ok();
             }
             catch (InvalidOperationException e)
@@ -198,7 +223,7 @@ namespace RestAPI.Controllers
         [HttpPut("/annotation/{annotationId}/{instanceId}/sentiment")]
         [ProducesResponseType((int)HttpStatusCode.OK)]
         [ProducesResponseType((int)HttpStatusCode.Forbidden)]
-        public ActionResult SetTagInstanceSentiment([FromServices] ClientInfo clientInfo, Guid annotationId, Guid instanceId, SetInstanceSentimentRequest request)
+        public ActionResult SetTagInstanceSentiment([FromServices] ClientInfo clientInfo, Guid annotationId, Guid instanceId, SetInstanceSentimentRequest request, [FromQuery] bool isFinal)
         {
             if (clientInfo.LoggedUser == null)
             {
@@ -206,9 +231,15 @@ namespace RestAPI.Controllers
                 return Problem();
             }
 
+            if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR)
+            {
+                Forbid();
+            }
+
             try
             {
-                annotationService.SetTagInstanceSentiment(annotationId, instanceId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request.Sentiment);
+
+                annotationService.SetTagInstanceSentiment(annotationId, instanceId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request.Sentiment, isFinal);
                 return Ok();
             }
             catch (InvalidOperationException e)
@@ -225,7 +256,7 @@ namespace RestAPI.Controllers
         [HttpPut("/annotation/{annotationId}/done")]
         [ProducesResponseType((int)HttpStatusCode.OK)]
         [ProducesResponseType((int)HttpStatusCode.Forbidden)]
-        public ActionResult MarkAsDone([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] MarkAnnotationDoneRequest request)
+        public ActionResult MarkAsDone([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] MarkAnnotationDoneRequest request, [FromQuery] bool isFinal)
         {
             if (clientInfo.LoggedUser == null)
             {
@@ -233,9 +264,14 @@ namespace RestAPI.Controllers
                 return Problem();
             }
 
+            if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR)
+            {
+                Forbid();
+            }
+
             try
             {
-                annotationService.MarkAnnotationAsDone(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request.Done);
+                annotationService.MarkAnnotationAsDone(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request.Done, isFinal);
                 return Ok();
             }
             catch (InvalidOperationException e)
diff --git a/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs b/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
index a2c681e..7596083 100644
--- a/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
+++ b/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
@@ -98,12 +98,19 @@ namespace Core.Services.AnnotationService
             };
         }
 
-        public void AddNoteToAnnotation(Guid annotationId, Guid userId, ERole userRole, AddNoteToAnnotationRequest request)
+        public void AddNoteToAnnotation(Guid annotationId, Guid userId, ERole userRole, AddNoteToAnnotationRequest request, bool isFinal)
         {
             Annotation annotation = null;
             try
             {
-                annotation = context.Annotations.Include(a => a.User).First(a => a.Id == annotationId);
+                if (!isFinal)
+                {
+                    annotation = context.Annotations.Include(a => a.User).First(a => a.Id == annotationId);
+                }
+                else
+                {
+                    annotation = context.FinalAnnotations.Include(a => a.User).First(a => a.Id == annotationId);
+                }
             }
             catch (Exception)
             {
@@ -120,13 +127,26 @@ namespace Core.Services.AnnotationService
         }
 
 
-        public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole)
+        public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole, bool isFinal)
         {
-            var annotation = context.Annotations
+            Annotation annotation = new();
+            if (!isFinal)
+            {
+                annotation = context.Annotations
                 .Where(a => a.Id == annotationId)
                 .Include(a => a.User)
                 .Include(a => a.Document).ThenInclude(d => d.Content)
                 .First();
+            }
+            else
+            {
+                annotation = context.FinalAnnotations
+                .Where(a => a.Id == annotationId)
+                .Include(a => a.User)
+                .Include(a => a.Document).ThenInclude(d => d.Content)
+                .First();
+            }
+
 
             if (userRole < ERole.ADMINISTRATOR)
             {
@@ -154,7 +174,7 @@ namespace Core.Services.AnnotationService
             }
 
             var docToRender = "";
-            HTMLService.CachedInfo cachedInfoToReturn = new(); 
+            HTMLService.CachedInfo cachedInfoToReturn = new();
             if (annotation.CachedDocumentHTML == "")
             {
                 var result = htmlService.FullPreprocessHTML(documentContent.Content, tags);
@@ -181,7 +201,7 @@ namespace Core.Services.AnnotationService
                     TagClosingLengths = JsonConvert.DeserializeObject<List<int>>(annotation.CachedClosingLengths),
                     TagInstanceCSS = JsonConvert.DeserializeObject<List<TagInstanceCSSInfo>>(annotation.CachedCSS)
                 };
-                
+
                 // The annotation has been modified and we need to either add the new tag or remove the tag
                 if (annotation.ModifiedType != EModified.NONE)
                 {
@@ -233,13 +253,25 @@ namespace Core.Services.AnnotationService
             return text.Contains("<html>");
         }
 
-        public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request)
+        public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request, bool isFinal)
         {
-            var annotation = context.Annotations
-               .Where(a => a.Id == annotationId)
-               .Include(a => a.User)
-               .Include(a => a.Document).ThenInclude(d => d.Content)
-               .First();
+            Annotation annotation = new();
+            if (!isFinal)
+            {
+                annotation = context.Annotations
+                    .Where(a => a.Id == annotationId)
+                    .Include(a => a.User)
+                    .Include(a => a.Document).ThenInclude(d => d.Content)
+                    .First();
+            }
+            else
+            {
+                annotation = context.FinalAnnotations
+                    .Where(a => a.Id == annotationId)
+                    .Include(a => a.User)
+                    .Include(a => a.Document).ThenInclude(d => d.Content)
+                    .First();
+            }
 
             if (userRole < ERole.ADMINISTRATOR)
             {
@@ -249,7 +281,7 @@ namespace Core.Services.AnnotationService
                 }
             }
 
-            AnnotationTag annotationTag = new()
+            AnnotationTag annotationTag = new() 
             {
                 Id = Guid.NewGuid(),
                 Annotation = annotation,
@@ -259,6 +291,38 @@ namespace Core.Services.AnnotationService
                 SelectedText = request.SelectedText,
                 Note = ""
             };
+            
+            if (annotation.State == EState.NEW)
+                annotation.State = EState.IN_PROGRESS;
+            }
+
+            AnnotationTagGeneric annotationTag = new();
+            if (isFinal)
+            {
+                annotationTag = new FinalAnnotationTag()
+                {
+                    Id = Guid.NewGuid(),
+                    Annotation = annotation as FinalAnnotation,
+                    Instance = request.InstanceId == null ? Guid.NewGuid() : request.InstanceId.Value,
+                    Length = request.Length,
+                    Position = request.Position,
+                    SelectedText = request.SelectedText,
+                    Note = ""
+                };
+            }
+            else
+            {
+                annotationTag = new AnnotationTag()
+                {
+                    Id = Guid.NewGuid(),
+                    Annotation = annotation as Annotation,
+                    Instance = request.InstanceId == null ? Guid.NewGuid() : request.InstanceId.Value,
+                    Length = request.Length,
+                    Position = request.Position,
+                    SelectedText = request.SelectedText,
+                    Note = ""
+                };
+            }
 
             if (request.Type == ETagType.TAG)
             {
@@ -315,20 +379,40 @@ namespace Core.Services.AnnotationService
             annotation.LastModifiedTagId = annotationTag.Id;
             annotation.ModifiedType = EModified.ADDED;
 
-            context.AnnotationTags.Add(annotationTag);
+            if (isFinal)
+            {
+                context.FinalAnnotationTags.Add(annotationTag as FinalAnnotationTag);
+            }
+            else
+            {
+                context.AnnotationTags.Add(annotationTag as AnnotationTag);
+            }
+
             context.SaveChanges();
         }
 
-        public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole)
+        public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole, bool isFinal)
         {
             Annotation annotation = null;
             try
             {
-                annotation = context.Annotations
-                   .Where(a => a.Id == annotationId)
-                   .Include(a => a.User)
-                   .Include(a => a.Document).ThenInclude(d => d.Content)
-                   .First();
+                if (!isFinal)
+                {
+                    annotation = context.Annotations
+                    .Where(a => a.Id == annotationId)
+                    .Include(a => a.User)
+                    .Include(a => a.Document).ThenInclude(d => d.Content)
+                    .First();
+                }
+                else
+                {
+                    annotation = context.FinalAnnotations
+                    .Where(a => a.Id == annotationId)
+                    .Include(a => a.User)
+                    .Include(a => a.Document).ThenInclude(d => d.Content)
+                    .First();
+                }
+
 
             }
             catch (Exception ex)
@@ -345,32 +429,62 @@ namespace Core.Services.AnnotationService
                 }
             }
 
-            if (!context.AnnotationTags.Any(at => at.Id == tagInstanceId))
+            AnnotationTagGeneric annotationTag = new();
+
+            if (isFinal)
             {
-                throw new InvalidOperationException("Could not find tag instance");
-            }
+                if (!context.FinalAnnotationTags.Any(at => at.Id == tagInstanceId))
+                {
+                    throw new InvalidOperationException("Could not find tag instance");
+                }
+                annotationTag = context.FinalAnnotationTags.First(at => at.Id == tagInstanceId);
 
+            }
+            else
+            {
+                if (!context.AnnotationTags.Any(at => at.Id == tagInstanceId))
+                {
+                    throw new InvalidOperationException("Could not find tag instance");
+                }
+                annotationTag = context.AnnotationTags.First(at => at.Id == tagInstanceId);
+            }
 
-            var annotationTag = context.AnnotationTags.First(at => at.Id == tagInstanceId);
             annotation.LastModifiedTagId = annotationTag.Id;
             annotation.ModifiedType = EModified.REMOVED;
 
-            context.AnnotationTags.Remove(annotationTag);
+            if (isFinal)
+            {
+                context.FinalAnnotationTags.Remove(annotationTag as FinalAnnotationTag);
+            }
+            else
+            {
+                context.AnnotationTags.Remove(annotationTag as AnnotationTag);
+            }
 
             context.SaveChanges();
         }
 
-        public void SetTagInstanceSentiment(Guid annotationId, Guid instanceId, Guid userId, ERole userRole, ETagSentiment sentiment)
+        public void SetTagInstanceSentiment(Guid annotationId, Guid instanceId, Guid userId, ERole userRole, ETagSentiment sentiment, bool isFinal)
         {
             Annotation annotation = null;
             try
             {
-                annotation = context.Annotations
-                   .Where(a => a.Id == annotationId)
-                   .Include(a => a.User)
-                   .Include(a => a.Document).ThenInclude(d => d.Content)
-                   .First();
-
+                if (!isFinal)
+                {
+                    annotation = context.Annotations
+                    .Where(a => a.Id == annotationId)
+                    .Include(a => a.User)
+                    .Include(a => a.Document).ThenInclude(d => d.Content)
+                    .First();
+                }
+                else
+                {
+                    annotation = context.FinalAnnotations
+                    .Where(a => a.Id == annotationId)
+                    .Include(a => a.User)
+                    .Include(a => a.Document).ThenInclude(d => d.Content)
+                    .First();
+                }
             }
             catch (Exception ex)
             {
@@ -387,7 +501,17 @@ namespace Core.Services.AnnotationService
             }
 
 
-            var tagInstances = context.AnnotationTags.Where(at => at.Instance == instanceId).ToList();
+            IEnumerable<AnnotationTagGeneric> tagInstances = null;
+
+            if (isFinal)
+            {
+                tagInstances = context.FinalAnnotationTags.Where(at => at.Instance == instanceId).ToList();
+            }
+            else
+            {
+                tagInstances = context.AnnotationTags.Where(at => at.Instance == instanceId).ToList();
+            }
+
             if (tagInstances.Count() == 0)
             {
                 throw new InvalidOperationException("No such instance found");
@@ -401,24 +525,34 @@ namespace Core.Services.AnnotationService
             context.SaveChanges();
         }
 
-        public void MarkAnnotationAsDone(Guid annotationId, Guid userId, ERole userRole, bool done)
+        public void MarkAnnotationAsDone(Guid annotationId, Guid userId, ERole userRole, bool done, bool isFinal)
         {
+
             Annotation annotation = null;
             try
             {
-                annotation = context.Annotations
+                if (!isFinal)
+                {
+                    annotation = context.Annotations
                    .Where(a => a.Id == annotationId)
                    .Include(a => a.User)
                    .Include(a => a.Document).ThenInclude(d => d.Content)
                    .First();
-
+                }
+                else
+                {
+                    annotation = context.FinalAnnotations
+                   .Where(a => a.Id == annotationId)
+                   .Include(a => a.User)
+                   .Include(a => a.Document).ThenInclude(d => d.Content)
+                   .First();
+                }
             }
             catch (Exception ex)
             {
                 throw new InvalidOperationException("Could not find annotation");
             }
 
-
             if (userRole < ERole.ADMINISTRATOR)
             {
                 if (annotation.User.Id != userId)
diff --git a/Backend/Core/Services/AnnotationService/IAnnotationService.cs b/Backend/Core/Services/AnnotationService/IAnnotationService.cs
index f20fcee..a94ef87 100644
--- a/Backend/Core/Services/AnnotationService/IAnnotationService.cs
+++ b/Backend/Core/Services/AnnotationService/IAnnotationService.cs
@@ -12,12 +12,12 @@ namespace Core.Services.AnnotationService
     {
         public void CreateDocumentAnnotations(AnnotationsAddRequest request, Guid userId);
         public AnnotationListResponse GetUserAnnotations(Guid userId);
-        public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole);
-        public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request);
-        public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole);
-        public void AddNoteToAnnotation(Guid annotationId, Guid userId, ERole userRole, AddNoteToAnnotationRequest request);
-        public void SetTagInstanceSentiment(Guid annotationId, Guid instanceId, Guid userId, ERole userRole, ETagSentiment sentiment);
-        public void MarkAnnotationAsDone(Guid annotationId, Guid userId, ERole userRole, bool done);
+        public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole, bool isFinal);
+        public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request, bool isFinal);
+        public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole, bool isFinal);
+        public void AddNoteToAnnotation(Guid annotationId, Guid userId, ERole userRole, AddNoteToAnnotationRequest request, bool isFinal);
+        public void SetTagInstanceSentiment(Guid annotationId, Guid instanceId, Guid userId, ERole userRole, ETagSentiment sentiment, bool isFinal);
+        public void MarkAnnotationAsDone(Guid annotationId, Guid userId, ERole userRole, bool done, bool isFinal);
         public Guid CreateFinalAnnotation(Guid documentId, Guid userId);
     }
 }
diff --git a/Backend/Core/Services/TagService/ITagService.cs b/Backend/Core/Services/TagService/ITagService.cs
index 86175de..7b3b19a 100644
--- a/Backend/Core/Services/TagService/ITagService.cs
+++ b/Backend/Core/Services/TagService/ITagService.cs
@@ -22,6 +22,6 @@ namespace Core.Services.TagService
         public void CreateSubTag(CreateSubTagRequest request);
         public void DeleteSubTag(Guid subtagId);
         public void UpdateSubTag(ModifySubTagRequest request, Guid subtagId);
-        public void AddNoteToTagInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request);
+        public void AddNoteToTagInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request, bool isFinal);
     }
 }
diff --git a/Backend/Core/Services/TagService/TagServiceEF.cs b/Backend/Core/Services/TagService/TagServiceEF.cs
index af0bb73..1504567 100644
--- a/Backend/Core/Services/TagService/TagServiceEF.cs
+++ b/Backend/Core/Services/TagService/TagServiceEF.cs
@@ -38,7 +38,7 @@ namespace Core.Services.TagService
             var tags = databaseContext.Tags
                 .Select(tc => tc)
                 .ToList();
-            
+
             var subTags = databaseContext.SubTags
                 .Select(tc => tc)
                 .ToList();
@@ -266,18 +266,26 @@ namespace Core.Services.TagService
 
             if (request.SentimentEnabled != null)
             {
-                subtag.SentimentEnabled = (bool) request.SentimentEnabled;
+                subtag.SentimentEnabled = (bool)request.SentimentEnabled;
             }
 
             databaseContext.SaveChanges();
         }
 
-        public void AddNoteToTagInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request)
+        public void AddNoteToTagInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request, bool isFinal)
         {
             Annotation annotation = null;
             try
             {
-                annotation = databaseContext.Annotations.Include(a => a.User).First(a => a.Id == annotationId);
+                if (!isFinal)
+                {
+                    annotation = databaseContext.Annotations.Include(a => a.User).First(a => a.Id == annotationId);
+                }
+                else
+                {
+                    annotation = databaseContext.FinalAnnotations.Include(a => a.User).First(a => a.Id == annotationId);
+                }
+
             }
             catch (Exception)
             {
@@ -289,11 +297,19 @@ namespace Core.Services.TagService
                 throw new UnauthorizedAccessException("User does not have access to this annotation");
             }
 
-            AnnotationTag occurence = null;
+            AnnotationTagGeneric occurence = null;
             try
             {
-                occurence = databaseContext.AnnotationTags.Include(at => at.Annotation)
+                if (!isFinal)
+                {
+                    occurence = databaseContext.AnnotationTags.Include(at => at.Annotation)
                     .First(at => at.Annotation.Id == annotationId && at.Id == occurrenceId);
+                }
+                else
+                {
+                    occurence = databaseContext.FinalAnnotationTags.Include(at => at.Annotation)
+                    .First(at => at.Annotation.Id == annotationId && at.Id == occurrenceId);
+                }
             }
             catch (Exception)
             {
