Revize 83d4581e
Přidáno uživatelem Vojtěch Bartička před téměř 3 roky(ů)
Backend/Backend/Controllers/AnnotationController.cs | ||
---|---|---|
53 | 53 |
[HttpGet("/annotation/{annotationId}")] |
54 | 54 |
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(AnnotationInfo))] |
55 | 55 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
56 |
public ActionResult<AnnotationInfo> GetAnnotation([FromServices] ClientInfo clientInfo, Guid annotationId) |
|
56 |
public ActionResult<AnnotationInfo> GetAnnotation([FromServices] ClientInfo clientInfo, Guid annotationId, [FromQuery] bool isFinal)
|
|
57 | 57 |
{ |
58 | 58 |
if (clientInfo.LoggedUser == null) |
59 | 59 |
{ |
... | ... | |
61 | 61 |
return Problem(); |
62 | 62 |
} |
63 | 63 |
|
64 |
if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR) |
|
65 |
{ |
|
66 |
Forbid(); |
|
67 |
} |
|
68 |
|
|
64 | 69 |
// Take care of - non-admin user requesting not-assigned annotation |
65 | 70 |
// non-existent annotation |
66 | 71 |
try |
67 | 72 |
{ |
68 |
var res = annotationService.GetAnnotation(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role); |
|
73 |
var res = annotationService.GetAnnotation(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, isFinal);
|
|
69 | 74 |
return Ok(res); |
70 | 75 |
} |
71 | 76 |
catch (InvalidOperationException e) |
... | ... | |
82 | 87 |
[HttpPost("/annotation/{annotationId}")] |
83 | 88 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
84 | 89 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
85 |
public ActionResult PostAnnotation([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] AnnotationInstanceAddRequest request) |
|
90 |
public ActionResult PostAnnotation([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] AnnotationInstanceAddRequest request, [FromQuery] bool isFinal)
|
|
86 | 91 |
{ |
87 | 92 |
if (clientInfo.LoggedUser == null) |
88 | 93 |
{ |
89 | 94 |
logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /annotations"); |
90 | 95 |
return Problem(); |
91 | 96 |
} |
92 |
|
|
97 |
|
|
98 |
if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR) |
|
99 |
{ |
|
100 |
Forbid(); |
|
101 |
} |
|
102 |
|
|
93 | 103 |
// Take care of - non-admin user requesting not-assigned annotation |
94 | 104 |
// non-existent annotation |
95 | 105 |
try |
96 | 106 |
{ |
97 |
annotationService.AddAnnotationInstance(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request); |
|
107 |
annotationService.AddAnnotationInstance(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request, isFinal);
|
|
98 | 108 |
return Ok(); |
99 | 109 |
} |
100 | 110 |
catch (UnauthorizedAccessException) |
... | ... | |
110 | 120 |
[HttpDelete("/annotation/{annotationId}/{occurenceId}")] |
111 | 121 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
112 | 122 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
113 |
public ActionResult DeleteAnnotationInstance([FromServices] ClientInfo clientInfo, Guid annotationId, Guid occurenceId) |
|
123 |
public ActionResult DeleteAnnotationInstance([FromServices] ClientInfo clientInfo, Guid annotationId, Guid occurenceId, [FromQuery] bool isFinal)
|
|
114 | 124 |
{ |
115 | 125 |
if (clientInfo.LoggedUser == null) |
116 | 126 |
{ |
... | ... | |
118 | 128 |
return Problem(); |
119 | 129 |
} |
120 | 130 |
|
131 |
if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR) |
|
132 |
{ |
|
133 |
Forbid(); |
|
134 |
} |
|
135 |
|
|
121 | 136 |
// Take care of - non-admin user requesting not-assigned annotation |
122 | 137 |
// non-existent annotation |
123 | 138 |
try |
124 | 139 |
{ |
125 |
annotationService.DeleteAnnotationInstance(annotationId, occurenceId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role); |
|
140 |
annotationService.DeleteAnnotationInstance(annotationId, occurenceId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, isFinal);
|
|
126 | 141 |
return Ok(); |
127 | 142 |
} |
128 | 143 |
catch (UnauthorizedAccessException) |
... | ... | |
140 | 155 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
141 | 156 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
142 | 157 |
public ActionResult AddNoteToTagOccurence([FromServices] ClientInfo clientInfo, Guid annotationId, Guid occurenceId, |
143 |
[FromBody] AddNoteToTagOccurenceRequest request) |
|
158 |
[FromBody] AddNoteToTagOccurenceRequest request, [FromBody] bool isFinal)
|
|
144 | 159 |
{ |
145 | 160 |
if (clientInfo.LoggedUser == null) |
146 | 161 |
{ |
... | ... | |
148 | 163 |
return Problem(); |
149 | 164 |
} |
150 | 165 |
|
166 |
if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR) |
|
167 |
{ |
|
168 |
Forbid(); |
|
169 |
} |
|
170 |
|
|
151 | 171 |
// Take care of - non-admin user requesting not-assigned annotation |
152 | 172 |
// non-existent annotation |
153 | 173 |
try |
154 | 174 |
{ |
155 |
tagService.AddNoteToTagInstance(annotationId, occurenceId, clientInfo.LoggedUser, request); |
|
175 |
tagService.AddNoteToTagInstance(annotationId, occurenceId, clientInfo.LoggedUser, request, isFinal);
|
|
156 | 176 |
return Ok(); |
157 | 177 |
} |
158 | 178 |
catch (InvalidOperationException e) |
... | ... | |
169 | 189 |
[HttpPost("/annotation/{annotationId}/note")] |
170 | 190 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
171 | 191 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
172 |
public ActionResult AddNoteToTagOccurence([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] AddNoteToAnnotationRequest request) |
|
192 |
public ActionResult AddNoteToTagOccurence([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] AddNoteToAnnotationRequest request, [FromQuery] bool isFinal)
|
|
173 | 193 |
{ |
174 | 194 |
if (clientInfo.LoggedUser == null) |
175 | 195 |
{ |
... | ... | |
177 | 197 |
return Problem(); |
178 | 198 |
} |
179 | 199 |
|
200 |
if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR) |
|
201 |
{ |
|
202 |
Forbid(); |
|
203 |
} |
|
204 |
|
|
180 | 205 |
// Take care of - non-admin user requesting not-assigned annotation |
181 | 206 |
// non-existent annotation |
182 | 207 |
try |
183 | 208 |
{ |
184 |
annotationService.AddNoteToAnnotation(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request); |
|
209 |
annotationService.AddNoteToAnnotation(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request, isFinal);
|
|
185 | 210 |
return Ok(); |
186 | 211 |
} |
187 | 212 |
catch (InvalidOperationException e) |
... | ... | |
198 | 223 |
[HttpPut("/annotation/{annotationId}/{instanceId}/sentiment")] |
199 | 224 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
200 | 225 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
201 |
public ActionResult SetTagInstanceSentiment([FromServices] ClientInfo clientInfo, Guid annotationId, Guid instanceId, SetInstanceSentimentRequest request) |
|
226 |
public ActionResult SetTagInstanceSentiment([FromServices] ClientInfo clientInfo, Guid annotationId, Guid instanceId, SetInstanceSentimentRequest request, [FromQuery] bool isFinal)
|
|
202 | 227 |
{ |
203 | 228 |
if (clientInfo.LoggedUser == null) |
204 | 229 |
{ |
... | ... | |
206 | 231 |
return Problem(); |
207 | 232 |
} |
208 | 233 |
|
234 |
if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR) |
|
235 |
{ |
|
236 |
Forbid(); |
|
237 |
} |
|
238 |
|
|
209 | 239 |
try |
210 | 240 |
{ |
211 |
annotationService.SetTagInstanceSentiment(annotationId, instanceId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request.Sentiment); |
|
241 |
|
|
242 |
annotationService.SetTagInstanceSentiment(annotationId, instanceId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request.Sentiment, isFinal); |
|
212 | 243 |
return Ok(); |
213 | 244 |
} |
214 | 245 |
catch (InvalidOperationException e) |
... | ... | |
225 | 256 |
[HttpPut("/annotation/{annotationId}/done")] |
226 | 257 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
227 | 258 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
228 |
public ActionResult MarkAsDone([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] MarkAnnotationDoneRequest request) |
|
259 |
public ActionResult MarkAsDone([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] MarkAnnotationDoneRequest request, [FromQuery] bool isFinal)
|
|
229 | 260 |
{ |
230 | 261 |
if (clientInfo.LoggedUser == null) |
231 | 262 |
{ |
... | ... | |
233 | 264 |
return Problem(); |
234 | 265 |
} |
235 | 266 |
|
267 |
if (isFinal && clientInfo.LoggedUser.Role < Models.Enums.ERole.ADMINISTRATOR) |
|
268 |
{ |
|
269 |
Forbid(); |
|
270 |
} |
|
271 |
|
|
236 | 272 |
try |
237 | 273 |
{ |
238 |
annotationService.MarkAnnotationAsDone(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request.Done); |
|
274 |
annotationService.MarkAnnotationAsDone(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request.Done, isFinal);
|
|
239 | 275 |
return Ok(); |
240 | 276 |
} |
241 | 277 |
catch (InvalidOperationException e) |
Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs | ||
---|---|---|
98 | 98 |
}; |
99 | 99 |
} |
100 | 100 |
|
101 |
public void AddNoteToAnnotation(Guid annotationId, Guid userId, ERole userRole, AddNoteToAnnotationRequest request) |
|
101 |
public void AddNoteToAnnotation(Guid annotationId, Guid userId, ERole userRole, AddNoteToAnnotationRequest request, bool isFinal)
|
|
102 | 102 |
{ |
103 | 103 |
Annotation annotation = null; |
104 | 104 |
try |
105 | 105 |
{ |
106 |
annotation = context.Annotations.Include(a => a.User).First(a => a.Id == annotationId); |
|
106 |
if (!isFinal) |
|
107 |
{ |
|
108 |
annotation = context.Annotations.Include(a => a.User).First(a => a.Id == annotationId); |
|
109 |
} |
|
110 |
else |
|
111 |
{ |
|
112 |
annotation = context.FinalAnnotations.Include(a => a.User).First(a => a.Id == annotationId); |
|
113 |
} |
|
107 | 114 |
} |
108 | 115 |
catch (Exception) |
109 | 116 |
{ |
... | ... | |
120 | 127 |
} |
121 | 128 |
|
122 | 129 |
|
123 |
public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole) |
|
130 |
public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole, bool isFinal)
|
|
124 | 131 |
{ |
125 |
var annotation = context.Annotations |
|
132 |
Annotation annotation = new(); |
|
133 |
if (!isFinal) |
|
134 |
{ |
|
135 |
annotation = context.Annotations |
|
126 | 136 |
.Where(a => a.Id == annotationId) |
127 | 137 |
.Include(a => a.User) |
128 | 138 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
129 | 139 |
.First(); |
140 |
} |
|
141 |
else |
|
142 |
{ |
|
143 |
annotation = context.FinalAnnotations |
|
144 |
.Where(a => a.Id == annotationId) |
|
145 |
.Include(a => a.User) |
|
146 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
147 |
.First(); |
|
148 |
} |
|
149 |
|
|
130 | 150 |
|
131 | 151 |
if (userRole < ERole.ADMINISTRATOR) |
132 | 152 |
{ |
... | ... | |
154 | 174 |
} |
155 | 175 |
|
156 | 176 |
var docToRender = ""; |
157 |
HTMLService.CachedInfo cachedInfoToReturn = new();
|
|
177 |
HTMLService.CachedInfo cachedInfoToReturn = new(); |
|
158 | 178 |
if (annotation.CachedDocumentHTML == "") |
159 | 179 |
{ |
160 | 180 |
var result = htmlService.FullPreprocessHTML(documentContent.Content, tags); |
... | ... | |
181 | 201 |
TagClosingLengths = JsonConvert.DeserializeObject<List<int>>(annotation.CachedClosingLengths), |
182 | 202 |
TagInstanceCSS = JsonConvert.DeserializeObject<List<TagInstanceCSSInfo>>(annotation.CachedCSS) |
183 | 203 |
}; |
184 |
|
|
204 |
|
|
185 | 205 |
// The annotation has been modified and we need to either add the new tag or remove the tag |
186 | 206 |
if (annotation.ModifiedType != EModified.NONE) |
187 | 207 |
{ |
... | ... | |
233 | 253 |
return text.Contains("<html>"); |
234 | 254 |
} |
235 | 255 |
|
236 |
public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request) |
|
256 |
public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request, bool isFinal)
|
|
237 | 257 |
{ |
238 |
var annotation = context.Annotations |
|
239 |
.Where(a => a.Id == annotationId) |
|
240 |
.Include(a => a.User) |
|
241 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
242 |
.First(); |
|
258 |
Annotation annotation = new(); |
|
259 |
if (!isFinal) |
|
260 |
{ |
|
261 |
annotation = context.Annotations |
|
262 |
.Where(a => a.Id == annotationId) |
|
263 |
.Include(a => a.User) |
|
264 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
265 |
.First(); |
|
266 |
} |
|
267 |
else |
|
268 |
{ |
|
269 |
annotation = context.FinalAnnotations |
|
270 |
.Where(a => a.Id == annotationId) |
|
271 |
.Include(a => a.User) |
|
272 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
273 |
.First(); |
|
274 |
} |
|
243 | 275 |
|
244 | 276 |
if (userRole < ERole.ADMINISTRATOR) |
245 | 277 |
{ |
... | ... | |
249 | 281 |
} |
250 | 282 |
} |
251 | 283 |
|
252 |
AnnotationTag annotationTag = new() |
|
284 |
AnnotationTag annotationTag = new()
|
|
253 | 285 |
{ |
254 | 286 |
Id = Guid.NewGuid(), |
255 | 287 |
Annotation = annotation, |
... | ... | |
259 | 291 |
SelectedText = request.SelectedText, |
260 | 292 |
Note = "" |
261 | 293 |
}; |
294 |
|
|
295 |
if (annotation.State == EState.NEW) |
|
296 |
annotation.State = EState.IN_PROGRESS; |
|
297 |
} |
|
298 |
|
|
299 |
AnnotationTagGeneric annotationTag = new(); |
|
300 |
if (isFinal) |
|
301 |
{ |
|
302 |
annotationTag = new FinalAnnotationTag() |
|
303 |
{ |
|
304 |
Id = Guid.NewGuid(), |
|
305 |
Annotation = annotation as FinalAnnotation, |
|
306 |
Instance = request.InstanceId == null ? Guid.NewGuid() : request.InstanceId.Value, |
|
307 |
Length = request.Length, |
|
308 |
Position = request.Position, |
|
309 |
SelectedText = request.SelectedText, |
|
310 |
Note = "" |
|
311 |
}; |
|
312 |
} |
|
313 |
else |
|
314 |
{ |
|
315 |
annotationTag = new AnnotationTag() |
|
316 |
{ |
|
317 |
Id = Guid.NewGuid(), |
|
318 |
Annotation = annotation as Annotation, |
|
319 |
Instance = request.InstanceId == null ? Guid.NewGuid() : request.InstanceId.Value, |
|
320 |
Length = request.Length, |
|
321 |
Position = request.Position, |
|
322 |
SelectedText = request.SelectedText, |
|
323 |
Note = "" |
|
324 |
}; |
|
325 |
} |
|
262 | 326 |
|
263 | 327 |
if (request.Type == ETagType.TAG) |
264 | 328 |
{ |
... | ... | |
315 | 379 |
annotation.LastModifiedTagId = annotationTag.Id; |
316 | 380 |
annotation.ModifiedType = EModified.ADDED; |
317 | 381 |
|
318 |
context.AnnotationTags.Add(annotationTag); |
|
382 |
if (isFinal) |
|
383 |
{ |
|
384 |
context.FinalAnnotationTags.Add(annotationTag as FinalAnnotationTag); |
|
385 |
} |
|
386 |
else |
|
387 |
{ |
|
388 |
context.AnnotationTags.Add(annotationTag as AnnotationTag); |
|
389 |
} |
|
390 |
|
|
319 | 391 |
context.SaveChanges(); |
320 | 392 |
} |
321 | 393 |
|
322 |
public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole) |
|
394 |
public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole, bool isFinal)
|
|
323 | 395 |
{ |
324 | 396 |
Annotation annotation = null; |
325 | 397 |
try |
326 | 398 |
{ |
327 |
annotation = context.Annotations |
|
328 |
.Where(a => a.Id == annotationId) |
|
329 |
.Include(a => a.User) |
|
330 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
331 |
.First(); |
|
399 |
if (!isFinal) |
|
400 |
{ |
|
401 |
annotation = context.Annotations |
|
402 |
.Where(a => a.Id == annotationId) |
|
403 |
.Include(a => a.User) |
|
404 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
405 |
.First(); |
|
406 |
} |
|
407 |
else |
|
408 |
{ |
|
409 |
annotation = context.FinalAnnotations |
|
410 |
.Where(a => a.Id == annotationId) |
|
411 |
.Include(a => a.User) |
|
412 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
413 |
.First(); |
|
414 |
} |
|
415 |
|
|
332 | 416 |
|
333 | 417 |
} |
334 | 418 |
catch (Exception ex) |
... | ... | |
345 | 429 |
} |
346 | 430 |
} |
347 | 431 |
|
348 |
if (!context.AnnotationTags.Any(at => at.Id == tagInstanceId)) |
|
432 |
AnnotationTagGeneric annotationTag = new(); |
|
433 |
|
|
434 |
if (isFinal) |
|
349 | 435 |
{ |
350 |
throw new InvalidOperationException("Could not find tag instance"); |
|
351 |
} |
|
436 |
if (!context.FinalAnnotationTags.Any(at => at.Id == tagInstanceId)) |
|
437 |
{ |
|
438 |
throw new InvalidOperationException("Could not find tag instance"); |
|
439 |
} |
|
440 |
annotationTag = context.FinalAnnotationTags.First(at => at.Id == tagInstanceId); |
|
352 | 441 |
|
442 |
} |
|
443 |
else |
|
444 |
{ |
|
445 |
if (!context.AnnotationTags.Any(at => at.Id == tagInstanceId)) |
|
446 |
{ |
|
447 |
throw new InvalidOperationException("Could not find tag instance"); |
|
448 |
} |
|
449 |
annotationTag = context.AnnotationTags.First(at => at.Id == tagInstanceId); |
|
450 |
} |
|
353 | 451 |
|
354 |
var annotationTag = context.AnnotationTags.First(at => at.Id == tagInstanceId); |
|
355 | 452 |
annotation.LastModifiedTagId = annotationTag.Id; |
356 | 453 |
annotation.ModifiedType = EModified.REMOVED; |
357 | 454 |
|
358 |
context.AnnotationTags.Remove(annotationTag); |
|
455 |
if (isFinal) |
|
456 |
{ |
|
457 |
context.FinalAnnotationTags.Remove(annotationTag as FinalAnnotationTag); |
|
458 |
} |
|
459 |
else |
|
460 |
{ |
|
461 |
context.AnnotationTags.Remove(annotationTag as AnnotationTag); |
|
462 |
} |
|
359 | 463 |
|
360 | 464 |
context.SaveChanges(); |
361 | 465 |
} |
362 | 466 |
|
363 |
public void SetTagInstanceSentiment(Guid annotationId, Guid instanceId, Guid userId, ERole userRole, ETagSentiment sentiment) |
|
467 |
public void SetTagInstanceSentiment(Guid annotationId, Guid instanceId, Guid userId, ERole userRole, ETagSentiment sentiment, bool isFinal)
|
|
364 | 468 |
{ |
365 | 469 |
Annotation annotation = null; |
366 | 470 |
try |
367 | 471 |
{ |
368 |
annotation = context.Annotations |
|
369 |
.Where(a => a.Id == annotationId) |
|
370 |
.Include(a => a.User) |
|
371 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
372 |
.First(); |
|
373 |
|
|
472 |
if (!isFinal) |
|
473 |
{ |
|
474 |
annotation = context.Annotations |
|
475 |
.Where(a => a.Id == annotationId) |
|
476 |
.Include(a => a.User) |
|
477 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
478 |
.First(); |
|
479 |
} |
|
480 |
else |
|
481 |
{ |
|
482 |
annotation = context.FinalAnnotations |
|
483 |
.Where(a => a.Id == annotationId) |
|
484 |
.Include(a => a.User) |
|
485 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
486 |
.First(); |
|
487 |
} |
|
374 | 488 |
} |
375 | 489 |
catch (Exception ex) |
376 | 490 |
{ |
... | ... | |
387 | 501 |
} |
388 | 502 |
|
389 | 503 |
|
390 |
var tagInstances = context.AnnotationTags.Where(at => at.Instance == instanceId).ToList(); |
|
504 |
IEnumerable<AnnotationTagGeneric> tagInstances = null; |
|
505 |
|
|
506 |
if (isFinal) |
|
507 |
{ |
|
508 |
tagInstances = context.FinalAnnotationTags.Where(at => at.Instance == instanceId).ToList(); |
|
509 |
} |
|
510 |
else |
|
511 |
{ |
|
512 |
tagInstances = context.AnnotationTags.Where(at => at.Instance == instanceId).ToList(); |
|
513 |
} |
|
514 |
|
|
391 | 515 |
if (tagInstances.Count() == 0) |
392 | 516 |
{ |
393 | 517 |
throw new InvalidOperationException("No such instance found"); |
... | ... | |
401 | 525 |
context.SaveChanges(); |
402 | 526 |
} |
403 | 527 |
|
404 |
public void MarkAnnotationAsDone(Guid annotationId, Guid userId, ERole userRole, bool done) |
|
528 |
public void MarkAnnotationAsDone(Guid annotationId, Guid userId, ERole userRole, bool done, bool isFinal)
|
|
405 | 529 |
{ |
530 |
|
|
406 | 531 |
Annotation annotation = null; |
407 | 532 |
try |
408 | 533 |
{ |
409 |
annotation = context.Annotations |
|
534 |
if (!isFinal) |
|
535 |
{ |
|
536 |
annotation = context.Annotations |
|
410 | 537 |
.Where(a => a.Id == annotationId) |
411 | 538 |
.Include(a => a.User) |
412 | 539 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
413 | 540 |
.First(); |
414 |
|
|
541 |
} |
|
542 |
else |
|
543 |
{ |
|
544 |
annotation = context.FinalAnnotations |
|
545 |
.Where(a => a.Id == annotationId) |
|
546 |
.Include(a => a.User) |
|
547 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
548 |
.First(); |
|
549 |
} |
|
415 | 550 |
} |
416 | 551 |
catch (Exception ex) |
417 | 552 |
{ |
418 | 553 |
throw new InvalidOperationException("Could not find annotation"); |
419 | 554 |
} |
420 | 555 |
|
421 |
|
|
422 | 556 |
if (userRole < ERole.ADMINISTRATOR) |
423 | 557 |
{ |
424 | 558 |
if (annotation.User.Id != userId) |
Backend/Core/Services/AnnotationService/IAnnotationService.cs | ||
---|---|---|
12 | 12 |
{ |
13 | 13 |
public void CreateDocumentAnnotations(AnnotationsAddRequest request, Guid userId); |
14 | 14 |
public AnnotationListResponse GetUserAnnotations(Guid userId); |
15 |
public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole); |
|
16 |
public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request); |
|
17 |
public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole); |
|
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 |
public void MarkAnnotationAsDone(Guid annotationId, Guid userId, ERole userRole, bool done); |
|
15 |
public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole, bool isFinal);
|
|
16 |
public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request, bool isFinal);
|
|
17 |
public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole, bool isFinal);
|
|
18 |
public void AddNoteToAnnotation(Guid annotationId, Guid userId, ERole userRole, AddNoteToAnnotationRequest request, bool isFinal);
|
|
19 |
public void SetTagInstanceSentiment(Guid annotationId, Guid instanceId, Guid userId, ERole userRole, ETagSentiment sentiment, bool isFinal);
|
|
20 |
public void MarkAnnotationAsDone(Guid annotationId, Guid userId, ERole userRole, bool done, bool isFinal);
|
|
21 | 21 |
public Guid CreateFinalAnnotation(Guid documentId, Guid userId); |
22 | 22 |
} |
23 | 23 |
} |
Backend/Core/Services/TagService/ITagService.cs | ||
---|---|---|
22 | 22 |
public void CreateSubTag(CreateSubTagRequest request); |
23 | 23 |
public void DeleteSubTag(Guid subtagId); |
24 | 24 |
public void UpdateSubTag(ModifySubTagRequest request, Guid subtagId); |
25 |
public void AddNoteToTagInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request); |
|
25 |
public void AddNoteToTagInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request, bool isFinal);
|
|
26 | 26 |
} |
27 | 27 |
} |
Backend/Core/Services/TagService/TagServiceEF.cs | ||
---|---|---|
38 | 38 |
var tags = databaseContext.Tags |
39 | 39 |
.Select(tc => tc) |
40 | 40 |
.ToList(); |
41 |
|
|
41 |
|
|
42 | 42 |
var subTags = databaseContext.SubTags |
43 | 43 |
.Select(tc => tc) |
44 | 44 |
.ToList(); |
... | ... | |
266 | 266 |
|
267 | 267 |
if (request.SentimentEnabled != null) |
268 | 268 |
{ |
269 |
subtag.SentimentEnabled = (bool) request.SentimentEnabled;
|
|
269 |
subtag.SentimentEnabled = (bool)request.SentimentEnabled; |
|
270 | 270 |
} |
271 | 271 |
|
272 | 272 |
databaseContext.SaveChanges(); |
273 | 273 |
} |
274 | 274 |
|
275 |
public void AddNoteToTagInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request) |
|
275 |
public void AddNoteToTagInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request, bool isFinal)
|
|
276 | 276 |
{ |
277 | 277 |
Annotation annotation = null; |
278 | 278 |
try |
279 | 279 |
{ |
280 |
annotation = databaseContext.Annotations.Include(a => a.User).First(a => a.Id == annotationId); |
|
280 |
if (!isFinal) |
|
281 |
{ |
|
282 |
annotation = databaseContext.Annotations.Include(a => a.User).First(a => a.Id == annotationId); |
|
283 |
} |
|
284 |
else |
|
285 |
{ |
|
286 |
annotation = databaseContext.FinalAnnotations.Include(a => a.User).First(a => a.Id == annotationId); |
|
287 |
} |
|
288 |
|
|
281 | 289 |
} |
282 | 290 |
catch (Exception) |
283 | 291 |
{ |
... | ... | |
289 | 297 |
throw new UnauthorizedAccessException("User does not have access to this annotation"); |
290 | 298 |
} |
291 | 299 |
|
292 |
AnnotationTag occurence = null; |
|
300 |
AnnotationTagGeneric occurence = null;
|
|
293 | 301 |
try |
294 | 302 |
{ |
295 |
occurence = databaseContext.AnnotationTags.Include(at => at.Annotation) |
|
303 |
if (!isFinal) |
|
304 |
{ |
|
305 |
occurence = databaseContext.AnnotationTags.Include(at => at.Annotation) |
|
296 | 306 |
.First(at => at.Annotation.Id == annotationId && at.Id == occurrenceId); |
307 |
} |
|
308 |
else |
|
309 |
{ |
|
310 |
occurence = databaseContext.FinalAnnotationTags.Include(at => at.Annotation) |
|
311 |
.First(at => at.Annotation.Id == annotationId && at.Id == occurrenceId); |
|
312 |
} |
|
297 | 313 |
} |
298 | 314 |
catch (Exception) |
299 | 315 |
{ |
Také k dispozici: Unified diff
Added final annotation endpoints