Skip to content

Commit 1a6de79

Browse files
Thierry Habarthabarthierry-hue
authored andcommitted
Ticket 27 : Add or edit the roles
1 parent 2e1d2f7 commit 1a6de79

File tree

112 files changed

+3022
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+3022
-62
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using CaseManagement.CMMN.AspNet.Extensions;
2+
using CaseManagement.CMMN.Infrastructures;
3+
using CaseManagement.CMMN.Roles;
4+
using CaseManagement.CMMN.Roles.Commands;
5+
using CaseManagement.CMMN.Roles.Exceptions;
6+
using System.Net;
7+
using System.Net.Http;
8+
using System.Threading.Tasks;
9+
using System.Web.Http;
10+
11+
namespace CaseManagement.CMMN.AspNet.Apis
12+
{
13+
[RoutePrefix(CMMNConstants.RouteNames.Roles)]
14+
public class RolesController : ApiController
15+
{
16+
private readonly IRoleService _roleService;
17+
18+
public RolesController(IRoleService roleService)
19+
{
20+
_roleService = roleService;
21+
}
22+
23+
[HttpGet]
24+
[Route("{id:string}")]
25+
public async Task<IHttpActionResult> Get(string id)
26+
{
27+
try
28+
{
29+
var result = await _roleService.Get(id);
30+
return Ok(result);
31+
}
32+
catch (UnknownRoleException)
33+
{
34+
return NotFound();
35+
}
36+
}
37+
38+
[HttpGet]
39+
[Route("search")]
40+
public async Task<IHttpActionResult> Search()
41+
{
42+
var query = this.Request.GetQueryNameValuePairs();
43+
var result = await _roleService.Search(query);
44+
return Ok(result);
45+
}
46+
47+
[HttpPost]
48+
public async Task<IHttpActionResult> Add([FromBody] AddRoleCommand command)
49+
{
50+
try
51+
{
52+
var result = await _roleService.Add(command);
53+
return Content(HttpStatusCode.Created, result);
54+
}
55+
catch (AggregateValidationException ex)
56+
{
57+
return Content(HttpStatusCode.BadRequest, this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request));
58+
}
59+
}
60+
61+
[HttpDelete]
62+
[Route("{id:string}")]
63+
public async Task<IHttpActionResult> Delete(string id)
64+
{
65+
try
66+
{
67+
await _roleService.Delete(new DeleteRoleCommand { Role = id });
68+
return Ok();
69+
}
70+
catch (UnknownRoleException)
71+
{
72+
return NotFound();
73+
}
74+
catch (AggregateValidationException ex)
75+
{
76+
return Content(HttpStatusCode.BadRequest, this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request));
77+
}
78+
}
79+
80+
[HttpPut]
81+
[Route("{id:string}")]
82+
public async Task<IHttpActionResult> Update(string id, [FromBody] UpdateRoleCommand updateRoleCommand)
83+
{
84+
try
85+
{
86+
updateRoleCommand.Role = id;
87+
await _roleService.Update(updateRoleCommand);
88+
return Ok();
89+
}
90+
catch (UnknownRoleException)
91+
{
92+
return NotFound();
93+
}
94+
catch (AggregateValidationException ex)
95+
{
96+
return Content(HttpStatusCode.BadRequest, this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request));
97+
}
98+
}
99+
}
100+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using CaseManagement.CMMN.AspNetCore.Extensions;
2+
using CaseManagement.CMMN.Infrastructures;
3+
using CaseManagement.CMMN.Roles;
4+
using CaseManagement.CMMN.Roles.Commands;
5+
using CaseManagement.CMMN.Roles.Exceptions;
6+
using Microsoft.AspNetCore.Authorization;
7+
using Microsoft.AspNetCore.Mvc;
8+
using System.Net;
9+
using System.Threading.Tasks;
10+
11+
namespace CaseManagement.CMMN.AspNetCore.Apis
12+
{
13+
[Route(CMMNConstants.RouteNames.Roles)]
14+
public class RolesController : Controller
15+
{
16+
private readonly IRoleService _roleService;
17+
18+
public RolesController(IRoleService roleService)
19+
{
20+
_roleService = roleService;
21+
}
22+
23+
[HttpGet("{id}")]
24+
[Authorize("get_role")]
25+
public async Task<IActionResult> Get(string id)
26+
{
27+
try
28+
{
29+
var result = await _roleService.Get(id);
30+
return new OkObjectResult(result);
31+
}
32+
catch(UnknownRoleException)
33+
{
34+
return new NotFoundResult();
35+
}
36+
}
37+
38+
[HttpGet("search")]
39+
[Authorize("search_role")]
40+
public async Task<IActionResult> Search()
41+
{
42+
var query = HttpContext.Request.Query.ToEnumerable();
43+
var result = await _roleService.Search(query);
44+
return new OkObjectResult(result);
45+
}
46+
47+
[HttpPost]
48+
[Authorize("add_role")]
49+
public async Task<IActionResult> Add([FromBody] AddRoleCommand command)
50+
{
51+
try
52+
{
53+
var result = await _roleService.Add(command);
54+
return new ContentResult
55+
{
56+
StatusCode = (int)HttpStatusCode.Created,
57+
Content = result.ToString(),
58+
ContentType = "application/json"
59+
};
60+
}
61+
catch (AggregateValidationException ex)
62+
{
63+
return this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request);
64+
}
65+
}
66+
67+
[HttpDelete("{id}")]
68+
[Authorize("delete_role")]
69+
public async Task<IActionResult> Delete(string id)
70+
{
71+
try
72+
{
73+
await _roleService.Delete(new DeleteRoleCommand { Role = id });
74+
return new OkResult();
75+
}
76+
catch(UnknownRoleException)
77+
{
78+
return new NotFoundResult();
79+
}
80+
catch(AggregateValidationException ex)
81+
{
82+
return this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request);
83+
}
84+
}
85+
86+
[HttpPut("{id}")]
87+
[Authorize("update_role")]
88+
public async Task<IActionResult> Update(string id, [FromBody] UpdateRoleCommand updateRoleCommand)
89+
{
90+
try
91+
{
92+
updateRoleCommand.Role = id;
93+
await _roleService.Update(updateRoleCommand);
94+
return new OkResult();
95+
}
96+
catch (UnknownRoleException)
97+
{
98+
return new NotFoundResult();
99+
}
100+
catch (AggregateValidationException ex)
101+
{
102+
return this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request);
103+
}
104+
}
105+
}
106+
}

src/CaseManagement.CMMN.Host/Startup.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ public void ConfigureServices(IServiceCollection services)
200200
policy.AddPolicy("get_performance", p => p.RequireClaim("scope", "get_performance"));
201201
// Statistic
202202
policy.AddPolicy("get_statistic", p => p.RequireClaim("scope", "get_statistic"));
203+
// Role
204+
policy.AddPolicy("get_role", p => p.RequireClaim("scope", "get_role"));
205+
policy.AddPolicy("search_role", p => p.RequireClaim("scope", "search_role"));
206+
policy.AddPolicy("add_role", p => p.RequireClaim("scope", "add_role"));
207+
policy.AddPolicy("delete_role", p => p.RequireClaim("scope", "delete_role"));
208+
policy.AddPolicy("update_role", p => p.RequireClaim("scope", "update_role"));
203209
});
204210
services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
205211
.AllowAnyMethod()

src/CaseManagement.CMMN/CMMNConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static class RouteNames
3030
public const string Statistics = "statistics";
3131
public const string Performances = "performances";
3232
public const string Forms = "forms";
33+
public const string Roles = "roles";
3334
}
3435

3536
public static class ProcessImplementationTypes

src/CaseManagement.CMMN/CasePlan/EventHandlers/CasePlanEventHandler.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
using CaseManagement.CMMN.Domains.Events;
33
using CaseManagement.CMMN.Infrastructures;
44
using CaseManagement.CMMN.Infrastructures.Bus;
5+
using CaseManagement.CMMN.Infrastructures.Lock;
56
using CaseManagement.CMMN.Parser;
67
using CaseManagement.CMMN.Persistence;
8+
using System.Diagnostics;
79
using System.Threading;
810
using System.Threading.Tasks;
911

@@ -14,18 +16,26 @@ public class CasePlanEventHandler : IMessageBrokerConsumerGeneric<CaseFilePublis
1416
private readonly ICaseFileQueryRepository _caseFileQueryRepository;
1517
private readonly ICasePlanCommandRepository _casePlanCommandRepository;
1618
private readonly ICommitAggregateHelper _commitAggregateHelper;
19+
private readonly IDistributedLock _distributedLock;
1720

18-
public CasePlanEventHandler(ICaseFileQueryRepository caseFileQueryRepository, ICasePlanCommandRepository casePlanCommandRepository, ICommitAggregateHelper commitAggregateHelper)
21+
public CasePlanEventHandler(ICaseFileQueryRepository caseFileQueryRepository, ICasePlanCommandRepository casePlanCommandRepository, ICommitAggregateHelper commitAggregateHelper, IDistributedLock distributedLock)
1922
{
2023
_caseFileQueryRepository = caseFileQueryRepository;
2124
_casePlanCommandRepository = casePlanCommandRepository;
2225
_commitAggregateHelper = commitAggregateHelper;
26+
_distributedLock = distributedLock;
2327
}
2428

2529
public string QueueName => CMMNConstants.QueueNames.CaseFiles;
2630

2731
public async Task Handle(CaseFilePublishedEvent @event, CancellationToken cancellationToken)
2832
{
33+
var lockId = $"case-file-published-{@event.Id}";
34+
if (!await _distributedLock.AcquireLock(lockId))
35+
{
36+
return;
37+
}
38+
2939
var caseFile = await _caseFileQueryRepository.FindById(@event.AggregateId);
3040
var tDefinitions = CMMNParser.ParseWSDL(caseFile.Payload);
3141
foreach (var casePlan in CMMNParser.ExtractCasePlans(tDefinitions, caseFile))
@@ -35,6 +45,7 @@ public async Task Handle(CaseFilePublishedEvent @event, CancellationToken cancel
3545
}
3646

3747
await _casePlanCommandRepository.SaveChanges();
48+
await _distributedLock.ReleaseLock(lockId);
3849
}
3950
}
40-
}
51+
}

src/CaseManagement.CMMN/CasePlanInstance/CasePlanInstanceService.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -400,34 +400,11 @@ private static JObject ToDto(CaseInstanceExecutionContext context)
400400

401401
private static FindWorkflowInstanceParameter ExtractFindParameter(IEnumerable<KeyValuePair<string, string>> query)
402402
{
403-
int startIndex;
404-
int count;
405-
string orderBy;
406-
FindOrders findOrder;
407403
string casePlanId;
408404
string owner;
409405
bool takeLatest;
410406
var parameter = new FindWorkflowInstanceParameter();
411-
if (query.TryGet("start_index", out startIndex))
412-
{
413-
parameter.StartIndex = startIndex;
414-
}
415-
416-
if (query.TryGet("count", out count))
417-
{
418-
parameter.Count = count;
419-
}
420-
421-
if (query.TryGet("order_by", out orderBy))
422-
{
423-
parameter.OrderBy = orderBy;
424-
}
425-
426-
if (query.TryGet("order", out findOrder))
427-
{
428-
parameter.Order = findOrder;
429-
}
430-
407+
parameter.ExtractFindParameter(query);
431408
if (query.TryGet("case_plan_id", out casePlanId))
432409
{
433410
parameter.CasePlanId = casePlanId;

src/CaseManagement.CMMN/CasePlanInstance/CommandHandlers/ActivateCommandHandler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using CaseManagement.CMMN.CaseWorkerTask;
44
using CaseManagement.CMMN.CaseWorkerTask.Commands;
55
using CaseManagement.CMMN.Domains;
6-
using CaseManagement.CMMN.Infrastructures;
76
using CaseManagement.CMMN.Infrastructures.Bus;
87
using CaseManagement.CMMN.Infrastructures.EvtStore;
98
using CaseManagement.Workflow.Infrastructure.Bus;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using CaseManagement.CMMN.Infrastructures;
2+
3+
namespace CaseManagement.CMMN.Domains.Role.Events
4+
{
5+
public class RoleDeletedEvent : DomainEvent
6+
{
7+
public RoleDeletedEvent(string id, string aggregateId, int version) : base(id, aggregateId, version)
8+
{
9+
}
10+
}
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using CaseManagement.CMMN.Infrastructures;
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace CaseManagement.CMMN.Domains.Role.Events
6+
{
7+
public class RoleUpdatedEvent : DomainEvent
8+
{
9+
public RoleUpdatedEvent(string id, string aggregateId, int version, ICollection<string> users, DateTime updateDateTime) : base(id, aggregateId, version)
10+
{
11+
Users = users;
12+
UpdateDateTime = updateDateTime;
13+
}
14+
15+
public ICollection<string> Users { get; set; }
16+
public DateTime UpdateDateTime { get; set; }
17+
}
18+
}

0 commit comments

Comments
 (0)