Skip to content

Commit 42a96f9

Browse files
Ticket #105 : Can update notification + escalation + fix integration tests
1 parent efee5d9 commit 42a96f9

File tree

37 files changed

+603
-151
lines changed

37 files changed

+603
-151
lines changed

src/CaseManagement.BPMN/Infrastructure/Jobs/Notifications/StateTransitionNotification.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public JObject JObjContent
1919
{
2020
get
2121
{
22+
if (Content == null)
23+
{
24+
return null;
25+
}
26+
2227
return JObject.Parse(Content);
2328
}
2429
}

src/CaseManagement.BPMN/ProcessInstance/Processors/Activities/Handlers/WsHumanTaskHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Newtonsoft.Json.Linq;
99
using System;
1010
using System.Collections.Generic;
11+
using System.Diagnostics;
1112
using System.Linq;
1213
using System.Net.Http;
1314
using System.Text;
@@ -113,6 +114,7 @@ public async Task<ICollection<MessageToken>> Execute(BPMNExecutionContext execut
113114
result.Add(MessageToken.NewMessage(userTask.Id, stateTransition.Content));
114115
}
115116

117+
Debug.WriteLine("COUCOU");
116118
return result;
117119
}
118120
}

src/CaseManagement.HumanTask.AspNetCore/Apis/HumanTaskDefsController.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,37 @@ public async Task<IActionResult> AddDeadlineEscalation(string id, string deadLin
420420
}
421421
}
422422

423+
[HttpPut("{id}/deadlines/{deadLineId}/escalations/{escalationId}")]
424+
public async Task<IActionResult> UpdateDeadlineEscalation(string id, string deadLineId, string escalationId, [FromBody] UpdateHumanTaskDefEscalationDeadlineCommand updateHumanTaskDefEscalationStartDeadlineCommand, CancellationToken token)
425+
{
426+
try
427+
{
428+
updateHumanTaskDefEscalationStartDeadlineCommand.Id = id;
429+
updateHumanTaskDefEscalationStartDeadlineCommand.DeadlineId = deadLineId;
430+
updateHumanTaskDefEscalationStartDeadlineCommand.EscalationId = escalationId;
431+
var newId = await _mediator.Send(updateHumanTaskDefEscalationStartDeadlineCommand, token);
432+
return new NoContentResult();
433+
}
434+
catch (BadRequestException ex)
435+
{
436+
return this.ToError(new List<KeyValuePair<string, string>>
437+
{
438+
new KeyValuePair<string, string>("bad_request", ex.Message)
439+
}, HttpStatusCode.BadRequest, Request);
440+
}
441+
catch (UnknownHumanTaskDefException ex)
442+
{
443+
return this.ToError(new List<KeyValuePair<string, string>>
444+
{
445+
new KeyValuePair<string, string>("bad_request", ex.Message)
446+
}, HttpStatusCode.NotFound, Request);
447+
}
448+
catch (AggregateValidationException ex)
449+
{
450+
return this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request);
451+
}
452+
}
453+
423454
[HttpDelete("{id}/deadlines/{deadLineId}/escalations/{escalationId}")]
424455
public async Task<IActionResult> DeleteStartDeadlineEscalation(string id, string deadLineId, string escalationId, CancellationToken token)
425456
{

src/CaseManagement.HumanTask.AspNetCore/Apis/NotificationDefsController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ public async Task<IActionResult> Add([FromBody] AddNotificationDefCommand parame
3939
}
4040
}
4141

42+
[HttpGet]
43+
public async Task<IActionResult> GetAll(CancellationToken token)
44+
{
45+
var result = await _mediator.Send(new GetAllNotificationDefQuery(), token);
46+
return new OkObjectResult(result);
47+
}
48+
4249
[HttpPost(".search")]
4350
public async Task<IActionResult> Search([FromBody] SearchNotificationDefQuery parameter, CancellationToken token)
4451
{

src/CaseManagement.HumanTask/Domains/HumanTaskDef/Events/HumanTaskDefEscalationDeadlineAddedEvent.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ public HumanTaskDefEscalationDeadlineAddedEvent(string id,
1313
string deadlineId,
1414
string escalationId,
1515
string condition,
16+
string notificationId,
1617
DateTime updateDateTime) : base(id, aggregateId, version)
1718
{
1819
DeadLineId = deadlineId;
1920
EscalationId = escalationId;
2021
Condition = condition;
22+
NotificationId = notificationId;
2123
UpdateDateTime = updateDateTime;
2224
}
2325

2426
public string DeadLineId { get; set; }
2527
public string EscalationId { get; set; }
2628
public string Condition { get; set; }
29+
public string NotificationId { get; set; }
2730
public DateTime UpdateDateTime { get; set; }
2831
}
2932
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using CaseManagement.Common.Domains;
2+
using System;
3+
using System.Diagnostics;
4+
5+
namespace CaseManagement.HumanTask.Domains
6+
{
7+
[DebuggerDisplay("Escalation is updated")]
8+
public class HumanTaskDefEscalationDeadlineUpdatedEvent : DomainEvent
9+
{
10+
public HumanTaskDefEscalationDeadlineUpdatedEvent(string id, string aggregateId, int version, string deadlineId, string escalationId, string condition, string notificationId, DateTime updateDateTime) : base(id, aggregateId, version)
11+
{
12+
DeadLineId = deadlineId;
13+
EscalationId = escalationId;
14+
Condition = condition;
15+
NotificationId = notificationId;
16+
UpdateDateTime = updateDateTime;
17+
}
18+
19+
public string DeadLineId { get; set; }
20+
public string EscalationId { get; set; }
21+
public string Condition { get; set; }
22+
public string NotificationId { get; set; }
23+
public DateTime UpdateDateTime { get; set; }
24+
}
25+
}

src/CaseManagement.HumanTask/Domains/HumanTaskDef/HumanTaskDefinitionAggregate.cs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,20 @@ public void UpdateDeadline(string id, string name, string forExpr, string untilE
210210
Handle(evt);
211211
}
212212

213-
public string AddEscalationDeadline(string startDeadlineId, string condition)
213+
public string AddEscalationDeadline(string startDeadlineId, string condition, string notificationId)
214214
{
215215
var result = Guid.NewGuid().ToString();
216-
var evt = new HumanTaskDefEscalationDeadlineAddedEvent(Guid.NewGuid().ToString(), AggregateId, Version + 1, startDeadlineId, result, condition, DateTime.UtcNow);
216+
var evt = new HumanTaskDefEscalationDeadlineAddedEvent(Guid.NewGuid().ToString(), AggregateId, Version + 1, startDeadlineId, result, condition, notificationId, DateTime.UtcNow);
217217
Handle(evt);
218218
return result;
219219
}
220220

221+
public void UpdateEscalationDeadline(string deadlineId, string escalationId, string condition, string notificationId)
222+
{
223+
var evt = new HumanTaskDefEscalationDeadlineUpdatedEvent(Guid.NewGuid().ToString(), AggregateId, Version + 1, deadlineId, escalationId, condition, notificationId, DateTime.UtcNow);
224+
Handle(evt);
225+
}
226+
221227
public void DeleteEscalationDeadline(string completionDeadLineId, string escalationId)
222228
{
223229
var evt = new HumanTaskDefEscalationDeadlineRemovedEvent(Guid.NewGuid().ToString(), AggregateId, Version + 1, completionDeadLineId, escalationId, DateTime.UtcNow);
@@ -390,34 +396,64 @@ private void Handle(HumanTaskDefDeadLineRemovedEvent evt)
390396
private void Handle(HumanTaskDefEscalationDeadlineAddedEvent evt)
391397
{
392398
var errors = new List<KeyValuePair<string, string>>();
393-
var completionDeadLine = DeadLines.FirstOrDefault(_ => _.Id == evt.DeadLineId);
394-
if (completionDeadLine == null)
399+
var deadline = DeadLines.FirstOrDefault(_ => _.Id == evt.DeadLineId);
400+
if (deadline == null)
395401
{
396-
errors.Add(new KeyValuePair<string, string>("validation", Global.UnknownStartDeadline));
402+
errors.Add(new KeyValuePair<string, string>("validation", Global.UnknownDeadline));
397403
}
398404

399405
if (errors.Any())
400406
{
401407
throw new AggregateValidationException(errors);
402408
}
403409

404-
completionDeadLine.Escalations.Add(new Escalation
410+
deadline.Escalations.Add(new Escalation
405411
{
412+
NotificationId = evt.NotificationId,
406413
Condition = evt.Condition,
407414
Id = evt.EscalationId
408415
});
409416
UpdateDateTime = evt.UpdateDateTime;
410417
Version = evt.Version;
411418
}
412419

420+
private void Handle(HumanTaskDefEscalationDeadlineUpdatedEvent evt)
421+
{
422+
Escalation escalation = null;
423+
var errors = new List<KeyValuePair<string, string>>();
424+
var deadline = DeadLines.FirstOrDefault(_ => _.Id == evt.DeadLineId);
425+
if (deadline == null)
426+
{
427+
errors.Add(new KeyValuePair<string, string>("validation", Global.UnknownDeadline));
428+
}
429+
else
430+
{
431+
escalation = deadline.Escalations.FirstOrDefault(_ => _.Id == evt.EscalationId);
432+
if (escalation == null)
433+
{
434+
errors.Add(new KeyValuePair<string, string>("validation", Global.UnknownEscalation));
435+
}
436+
}
437+
438+
if (errors.Any())
439+
{
440+
throw new AggregateValidationException(errors);
441+
}
442+
443+
escalation.NotificationId = evt.NotificationId;
444+
escalation.Condition = evt.Condition;
445+
UpdateDateTime = evt.UpdateDateTime;
446+
Version = evt.Version;
447+
}
448+
413449
private void Handle(HumanTaskDefDeadlineUpdatedEvent evt)
414450
{
415451
var d = DeadLines.FirstOrDefault(_ => _.Id == evt.DeadLineId);
416452
if (d == null)
417453
{
418454
throw new AggregateValidationException(new List<KeyValuePair<string, string>>
419455
{
420-
new KeyValuePair<string, string>("validation", Global.UnknownStartDeadline)
456+
new KeyValuePair<string, string>("validation", Global.UnknownDeadline)
421457
});
422458
}
423459

src/CaseManagement.HumanTask/HumanTaskDef/Commands/AddHumanTaskDefEscalationDeadlineCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public class AddHumanTaskDefEscalationDeadlineCommand : IRequest<string>
77
public string Id { get; set; }
88
public string DeadlineId { get; set; }
99
public string Condition { get; set; }
10+
public string NotificationId { get; set; }
1011
}
1112
}

src/CaseManagement.HumanTask/HumanTaskDef/Commands/Handlers/AddHumanTaskDefEscalationDeadlineCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public async Task<string> Handle(AddHumanTaskDefEscalationDeadlineCommand reques
4040
throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
4141
}
4242

43-
var id = result.AddEscalationDeadline(request.DeadlineId, request.Condition);
43+
var id = result.AddEscalationDeadline(request.DeadlineId, request.Condition, request.NotificationId);
4444
await _humanTaskDefCommandRepository.Update(result, cancellationToken);
4545
await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);
4646
_logger.LogInformation("Escalation has been added to deadline");
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using CaseManagement.Common.Exceptions;
2+
using CaseManagement.HumanTask.Exceptions;
3+
using CaseManagement.HumanTask.Persistence;
4+
using CaseManagement.HumanTask.Resources;
5+
using MediatR;
6+
using Microsoft.Extensions.Logging;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace CaseManagement.HumanTask.HumanTaskDef.Commands.Handlers
11+
{
12+
public class UpdateHumanTaskDefEscalationDeadlineCommandHandler : IRequestHandler<UpdateHumanTaskDefEscalationDeadlineCommand, bool>
13+
{
14+
private readonly IHumanTaskDefCommandRepository _humanTaskDefCommandRepository;
15+
private readonly IHumanTaskDefQueryRepository _humanTaskDefQueryRepository;
16+
private readonly ILogger<UpdateHumanTaskDefEscalationDeadlineCommandHandler> _logger;
17+
18+
public UpdateHumanTaskDefEscalationDeadlineCommandHandler(
19+
IHumanTaskDefCommandRepository humanTaskDefCommandRepository,
20+
IHumanTaskDefQueryRepository humanTaskDefQueryRepository,
21+
ILogger<UpdateHumanTaskDefEscalationDeadlineCommandHandler> logger)
22+
{
23+
_humanTaskDefCommandRepository = humanTaskDefCommandRepository;
24+
_humanTaskDefQueryRepository = humanTaskDefQueryRepository;
25+
_logger = logger;
26+
}
27+
28+
public async Task<bool> Handle(UpdateHumanTaskDefEscalationDeadlineCommand request, CancellationToken cancellationToken)
29+
{
30+
if (string.IsNullOrWhiteSpace(request.Condition))
31+
{
32+
_logger.LogError("the parameter 'condition' is missing");
33+
throw new BadRequestException(string.Format(Global.MissingParameter, "condition"));
34+
}
35+
36+
var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);
37+
if (result == null)
38+
{
39+
_logger.LogError($"The human task definition '{request.Id}' doesn't exist");
40+
throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
41+
}
42+
43+
result.UpdateEscalationDeadline(request.DeadlineId, request.EscalationId, request.Condition, request.NotificationId);
44+
await _humanTaskDefCommandRepository.Update(result, cancellationToken);
45+
await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);
46+
_logger.LogInformation("Escalation has been updated");
47+
return true;
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)