Skip to content

Commit 1a27292

Browse files
committed
Initial commit (WIP)
1 parent 5d02001 commit 1a27292

File tree

39 files changed

+1846
-307
lines changed

39 files changed

+1846
-307
lines changed

src/apis/management/Synapse.Apis.Management.Core/Services/ISynapseManagementApi.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,27 @@ public interface ISynapseManagementApi
231231
[OperationContract]
232232
Task<List<V1Correlation>> GetCorrelationsAsync(string? query = null, CancellationToken cancellationToken = default);
233233

234+
/// <summary>
235+
/// Deletes the specified <see cref="V1CorrelationContext"/>
236+
/// </summary>
237+
/// <param name="correlationId">The id of the <see cref="V1Correlation"/> the <see cref="V1CorrelationContext"/> to delete belongs to</param>
238+
/// <param name="contextId">The id of the <see cref="V1CorrelationContext"/> to delete</param>
239+
/// <param name="cancellationToken">A <see cref="CancellationToken"/></param>
240+
/// <returns>A new awaitable <see cref="Task"/></returns>
241+
[OperationContract]
242+
Task DeleteCorrelationContextAsync(string correlationId, string contextId, CancellationToken cancellationToken = default);
243+
244+
/// <summary>
245+
/// Deletes the specified correlated <see cref="V1Event"/>
246+
/// </summary>
247+
/// <param name="correlationId">The id of the <see cref="V1Correlation"/> the correlated <see cref="V1Event"/> to delete belongs to</param>
248+
/// <param name="contextId">The id of the <see cref="V1CorrelationContext"/> the correlated <see cref="V1Event"/> to delete belongs to</param>
249+
/// <param name="eventId">The id of the correlated <see cref="V1Event"/> to delete</param>
250+
/// <param name="cancellationToken">A <see cref="CancellationToken"/></param>
251+
/// <returns>A new awaitable <see cref="Task"/></returns>
252+
[OperationContract]
253+
Task DeleteCorrelationContextEventAsync(string correlationId, string contextId, string eventId, CancellationToken cancellationToken = default);
254+
234255
/// <summary>
235256
/// Deletes the <see cref="V1Correlation"/> with the specified id
236257
/// </summary>

src/apis/management/Synapse.Apis.Management.Http/Controllers/V1CorrelationsController.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,41 @@ public async Task<IActionResult> PatchCorrelation([FromBody] Integration.Command
101101
return this.Process(await this.Mediator.ExecuteAsync(this.Mapper.Map<Application.Commands.Generic.V1PatchCommand<Domain.Models.V1Correlation, Integration.Models.V1Correlation, string >>(command), cancellationToken));
102102
}
103103

104+
/// <summary>
105+
/// Deletes an existing correlation context
106+
/// </summary>
107+
/// <param name="correlationId">The id of the correlation the context to delete belongs to</param>
108+
/// <param name="contextId">The id of the correlation context to delete</param>
109+
/// <param name="cancellationToken">A <see cref="CancellationToken"/></param>
110+
/// <returns>A new <see cref="IActionResult"/></returns>
111+
[HttpDelete("byid/{correlationId}/context/{contextId}")]
112+
[ProducesResponseType((int)HttpStatusCode.NoContent)]
113+
[ProducesResponseType((int)HttpStatusCode.NotFound)]
114+
[ProducesResponseType((int)HttpStatusCode.Unauthorized)]
115+
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
116+
public async Task<IActionResult> DeleteCorrelationContext(string correlationId, string contextId, CancellationToken cancellationToken)
117+
{
118+
return this.Process(await this.Mediator.ExecuteAsync(new Application.Commands.Correlations.V1DeleteCorrelationContextCommand(correlationId, contextId), cancellationToken), (int)HttpStatusCode.NoContent);
119+
}
120+
121+
/// <summary>
122+
/// Deletes a correlated event
123+
/// </summary>
124+
/// <param name="correlationId">The id of the correlation the correlated event to delete belongs to</param>
125+
/// <param name="contextId">The id of the context the correlated event to delete belongs to</param>
126+
/// <param name="eventId">The id of the correlated event to delete</param>
127+
/// <param name="cancellationToken">A <see cref="CancellationToken"/></param>
128+
/// <returns>A new <see cref="IActionResult"/></returns>
129+
[HttpDelete("byid/{correlationId}/context/{contextId}/events/{eventId}")]
130+
[ProducesResponseType((int)HttpStatusCode.NoContent)]
131+
[ProducesResponseType((int)HttpStatusCode.NotFound)]
132+
[ProducesResponseType((int)HttpStatusCode.Unauthorized)]
133+
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
134+
public async Task<IActionResult> DeleteCorrelatedEvent(string correlationId, string contextId, string eventId, CancellationToken cancellationToken)
135+
{
136+
return this.Process(await this.Mediator.ExecuteAsync(new Application.Commands.Correlations.V1DeleteCorrelatedEventCommand(correlationId, contextId, eventId), cancellationToken), (int)HttpStatusCode.NoContent);
137+
}
138+
104139
/// <summary>
105140
/// Deletes an existing correlation
106141
/// </summary>
@@ -114,7 +149,7 @@ public async Task<IActionResult> PatchCorrelation([FromBody] Integration.Command
114149
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
115150
public async Task<IActionResult> DeleteCorrelation(string id, CancellationToken cancellationToken)
116151
{
117-
return this.Process(await this.Mediator.ExecuteAsync(new Application.Commands.Generic.V1DeleteCommand<Domain.Models.V1Correlation, string>(id), cancellationToken), (int)HttpStatusCode.Created);
152+
return this.Process(await this.Mediator.ExecuteAsync(new Application.Commands.Generic.V1DeleteCommand<Domain.Models.V1Correlation, string>(id), cancellationToken), (int)HttpStatusCode.NoContent);
118153
}
119154

120155
}

src/core/Synapse.Application/Commands/Correlations/v1/V1CreateCorrelationCommand.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,28 @@ protected V1CreateCorrelationCommand()
4141
/// <summary>
4242
/// Initializes a new <see cref="V1CreateWorkflowInstanceCommand"/>
4343
/// </summary>
44+
/// <param name="activationType">The activation type of the <see cref="V1Correlation"/> to create</param>
4445
/// <param name="lifetime">The lifetime of the <see cref="V1Correlation"/> to create</param>
4546
/// <param name="conditionType">The type of <see cref="V1CorrelationCondition"/> evaluation the <see cref="V1Correlation"/> should use</param>
4647
/// <param name="conditions">An <see cref="IEnumerable{T}"/> containing all <see cref="V1CorrelationCondition"/>s the <see cref="V1Correlation"/> to create is made out of</param>
4748
/// <param name="outcome">The <see cref="V1CorrelationOutcome"/> of the <see cref="V1Correlation"/> to create</param>
4849
/// <param name="context">The initial <see cref="V1CorrelationContext"/> of the <see cref="V1Correlation"/> to create</param>
49-
public V1CreateCorrelationCommand(V1CorrelationLifetime lifetime, V1CorrelationConditionType conditionType,
50+
public V1CreateCorrelationCommand(V1CorrelationActivationType activationType, V1CorrelationLifetime lifetime, V1CorrelationConditionType conditionType,
5051
IEnumerable<V1CorrelationCondition> conditions, V1CorrelationOutcome outcome, V1CorrelationContext? context)
5152
{
53+
this.ActivationType = activationType;
5254
this.Lifetime = lifetime;
5355
this.ConditionType = conditionType;
5456
this.Conditions = conditions;
5557
this.Outcome = outcome;
5658
this.Context = context;
5759
}
5860

61+
/// <summary>
62+
/// Gets the activation type of the <see cref="V1Correlation"/> to create
63+
/// </summary>
64+
public virtual V1CorrelationActivationType ActivationType { get; protected set; }
65+
5966
/// <summary>
6067
/// Gets the lifetime of the <see cref="V1Correlation"/> to create
6168
/// </summary>
@@ -116,7 +123,7 @@ public V1CreateCorrelationCommandHandler(ILoggerFactory loggerFactory, IMediator
116123
/// <inheritdoc/>
117124
public virtual async Task<IOperationResult<Integration.Models.V1Correlation>> HandleAsync(V1CreateCorrelationCommand command, CancellationToken cancellationToken = default)
118125
{
119-
var correlation = new V1Correlation(command.Lifetime, command.ConditionType, command.Conditions, command.Outcome, command.Context);
126+
var correlation = new V1Correlation(command.ActivationType, command.Lifetime, command.ConditionType, command.Conditions, command.Outcome, command.Context);
120127
correlation = await this.Correlations.AddAsync(correlation, cancellationToken);
121128
await this.Correlations.SaveChangesAsync(cancellationToken);
122129
return this.Ok(this.Mapper.Map<Integration.Models.V1Correlation>(correlation));
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright © 2022-Present The Synapse Authors
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
namespace Synapse.Application.Commands.Correlations
19+
{
20+
/// <summary>
21+
/// Represents the <see cref="ICommand"/> used to delete a correlated <see cref="V1Event"/>
22+
/// </summary>
23+
[DataTransferObjectType(typeof(Integration.Commands.Correlations.V1DeleteCorrelatedEventCommand))]
24+
public class V1DeleteCorrelatedEventCommand
25+
: Command
26+
{
27+
28+
/// <summary>
29+
/// Initializes a new <see cref="V1DeleteCorrelatedEventCommand"/>
30+
/// </summary>
31+
protected V1DeleteCorrelatedEventCommand() { }
32+
33+
/// <summary>
34+
/// Initializes a new <see cref="V1DeleteCorrelatedEventCommand"/>
35+
/// </summary>
36+
/// <param name="correlationId">The id of the <see cref="V1Correlation"/> the <see cref="V1Event"/> to delete belongs to</param>
37+
/// <param name="contextId">The id of the <see cref="V1CorrelationContext"/> the <see cref="V1Event"/> to delete belongs to</param>
38+
/// <param name="eventId">The id of the <see cref="V1Event"/> to delete</param>
39+
public V1DeleteCorrelatedEventCommand(string correlationId, string contextId,string eventId)
40+
{
41+
this.CorrelationId = correlationId;
42+
this.ContextId = contextId;
43+
this.EventId = eventId;
44+
}
45+
46+
/// <summary>
47+
/// Gets the id of the <see cref="V1Correlation"/> the <see cref="V1Event"/> to delete belongs to
48+
/// </summary>
49+
public virtual string CorrelationId { get; protected set; } = null!;
50+
51+
/// <summary>
52+
/// Gets the id of the <see cref="V1CorrelationContext"/> the <see cref="V1Event"/> to delete belongs to
53+
/// </summary>
54+
public virtual string ContextId { get; protected set; } = null!;
55+
56+
/// <summary>
57+
/// Gets the id of the <see cref="V1Event"/> to delete
58+
/// </summary>
59+
public virtual string EventId { get; protected set; } = null!;
60+
61+
}
62+
63+
/// <summary>
64+
/// Represents the service used to handle <see cref="V1DeleteCorrelatedEventCommand"/>s
65+
/// </summary>
66+
public class V1DeleteCorrelatedEventCommandHandler
67+
: CommandHandlerBase,
68+
ICommandHandler<V1DeleteCorrelatedEventCommand>
69+
{
70+
71+
/// <summary>
72+
/// Initializes a new <see cref="V1DeleteCorrelatedEventCommandHandler"/>
73+
/// </summary>
74+
/// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
75+
/// <param name="mediator">The service used to mediate calls</param>
76+
/// <param name="mapper">The service used to map objects</param>
77+
/// <param name="correlations">The <see cref="IRepository"/> used to manage <see cref="V1Correlation"/>s</param>
78+
public V1DeleteCorrelatedEventCommandHandler(ILoggerFactory loggerFactory, IMediator mediator, IMapper mapper, IRepository<V1Correlation, string> correlations)
79+
: base(loggerFactory, mediator, mapper)
80+
{
81+
this.Correlations = correlations;
82+
}
83+
84+
/// <summary>
85+
/// Gets the <see cref="IRepository"/> used to manage <see cref="V1Correlation"/>s
86+
/// </summary>
87+
protected IRepository<V1Correlation, string> Correlations { get; }
88+
89+
/// <inheritdoc/>
90+
public virtual async Task<IOperationResult> HandleAsync(V1DeleteCorrelatedEventCommand command, CancellationToken cancellationToken = default)
91+
{
92+
var correlation = await this.Correlations.FindAsync(command.CorrelationId, cancellationToken);
93+
if (correlation == null) throw DomainException.NullReference(typeof(V1Correlation), command.CorrelationId);
94+
var context = correlation.Contexts?.FirstOrDefault(c => c.Id.Equals(command.ContextId, StringComparison.InvariantCultureIgnoreCase));
95+
if (context == null) throw DomainException.NullReference(typeof(V1CorrelationContext), command.ContextId);
96+
var evt = context.PendingEvents?.FirstOrDefault(e => e.Id.Equals(command.EventId, StringComparison.InvariantCultureIgnoreCase));
97+
if (evt == null) throw DomainException.NullReference(typeof(V1Event), command.EventId);
98+
correlation.ReleaseEvent(context, evt);
99+
await this.Correlations.UpdateAsync(correlation, cancellationToken);
100+
await this.Correlations.SaveChangesAsync(cancellationToken);
101+
return this.Ok();
102+
}
103+
104+
}
105+
106+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright © 2022-Present The Synapse Authors
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
namespace Synapse.Application.Commands.Correlations
19+
{
20+
/// <summary>
21+
/// Represents the <see cref="ICommand"/> used to delete a <see cref="V1Correlation"/>'s <see cref="V1CorrelationContext"/>
22+
/// </summary>
23+
[DataTransferObjectType(typeof(Integration.Commands.Correlations.V1DeleteCorrelationContextCommand))]
24+
public class V1DeleteCorrelationContextCommand
25+
: Command
26+
{
27+
28+
/// <summary>
29+
/// Initializes a new <see cref="V1DeleteCorrelationCommand"/>
30+
/// </summary>
31+
protected V1DeleteCorrelationContextCommand() { }
32+
33+
/// <summary>
34+
/// Initializes a new <see cref="V1DeleteCorrelationCommand"/>
35+
/// </summary>
36+
/// <param name="correlationId">The id of the <see cref="V1Correlation"/> the <see cref="V1CorrelationContext"/> to delete belongs to</param>
37+
/// <param name="contextId">The id of the <see cref="V1CorrelationContext"/> to delete</param>
38+
public V1DeleteCorrelationContextCommand(string correlationId, string contextId)
39+
{
40+
this.CorrelationId = correlationId;
41+
this.ContextId = contextId;
42+
}
43+
44+
/// <summary>
45+
/// Gets the id of the <see cref="V1Correlation"/> the <see cref="V1CorrelationContext"/> to delete belongs to
46+
/// </summary>
47+
public virtual string CorrelationId { get; protected set; } = null!;
48+
49+
/// <summary>
50+
/// Gets the id of the <see cref="V1CorrelationContext"/> to delete
51+
/// </summary>
52+
public virtual string ContextId { get; protected set; } = null!;
53+
54+
}
55+
56+
/// <summary>
57+
/// Represents the service used to handle <see cref="V1DeleteCorrelationContextCommand"/>s
58+
/// </summary>
59+
public class V1DeleteCorrelationContextCommandHandler
60+
: CommandHandlerBase,
61+
ICommandHandler<V1DeleteCorrelationContextCommand>
62+
{
63+
64+
/// <summary>
65+
/// Initializes a new <see cref="V1DeleteCorrelationCommandHandler"/>
66+
/// </summary>
67+
/// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
68+
/// <param name="mediator">The service used to mediate calls</param>
69+
/// <param name="mapper">The service used to map objects</param>
70+
/// <param name="correlations">The <see cref="IRepository"/> used to manage <see cref="V1Correlation"/>s</param>
71+
public V1DeleteCorrelationContextCommandHandler(ILoggerFactory loggerFactory, IMediator mediator, IMapper mapper, IRepository<V1Correlation, string> correlations)
72+
: base(loggerFactory, mediator, mapper)
73+
{
74+
this.Correlations = correlations;
75+
}
76+
77+
/// <summary>
78+
/// Gets the <see cref="IRepository"/> used to manage <see cref="V1Correlation"/>s
79+
/// </summary>
80+
protected IRepository<V1Correlation, string> Correlations { get; }
81+
82+
/// <inheritdoc/>
83+
public virtual async Task<IOperationResult> HandleAsync(V1DeleteCorrelationContextCommand command, CancellationToken cancellationToken = default)
84+
{
85+
var correlation = await this.Correlations.FindAsync(command.CorrelationId, cancellationToken);
86+
if (correlation == null) throw DomainException.NullReference(typeof(V1Correlation), command.CorrelationId);
87+
var context = correlation.Contexts?.FirstOrDefault(c => c.Id.Equals(command.ContextId, StringComparison.InvariantCultureIgnoreCase));
88+
if(context == null) throw DomainException.NullReference(typeof(V1CorrelationContext), command.ContextId);
89+
correlation.ReleaseContext(context);
90+
await this.Correlations.UpdateAsync(correlation, cancellationToken);
91+
await this.Correlations.SaveChangesAsync(cancellationToken);
92+
return this.Ok();
93+
}
94+
95+
}
96+
97+
}

src/core/Synapse.Application/Commands/WorkflowInstances/v1/V1ConsumeOrBeginCorrelateEventCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public V1ConsumeWorkflowInstancePendingEventCommandHandler(ILoggerFactory logger
9999
{
100100
var conditions = new List<V1CorrelationCondition>() { V1CorrelationCondition.Match(command.EventDefinition) };
101101
var outcome = new V1CorrelationOutcome(V1CorrelationOutcomeType.Correlate, command.WorkflowInstanceId);
102-
await this.Mediator.ExecuteAndUnwrapAsync(new V1CreateCorrelationCommand(V1CorrelationLifetime.Singleton, V1CorrelationConditionType.AnyOf, conditions, outcome, workflowInstance.CorrelationContext), cancellationToken);
102+
await this.Mediator.ExecuteAndUnwrapAsync(new V1CreateCorrelationCommand(V1CorrelationActivationType.Implicit, V1CorrelationLifetime.Singleton, V1CorrelationConditionType.AnyOf, conditions, outcome, workflowInstance.CorrelationContext), cancellationToken);
103103
}
104104
else
105105
{

src/core/Synapse.Application/Commands/Workflows/v1/V1CreateWorkflowCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public V1CreateWorkflowCommandHandler(ILoggerFactory loggerFactory, IMediator me
150150
conditions.Add(new(filters.ToArray()));
151151
}
152152
var outcome = new V1CorrelationOutcome(V1CorrelationOutcomeType.Start, workflow.Id);
153-
await this.Mediator.ExecuteAndUnwrapAsync(new V1CreateCorrelationCommand(lifetime, conditionType, conditions, outcome, null), cancellationToken: cancellationToken);
153+
await this.Mediator.ExecuteAndUnwrapAsync(new V1CreateCorrelationCommand(V1CorrelationActivationType.Implicit, lifetime, conditionType, conditions, outcome, null), cancellationToken: cancellationToken);
154154
}
155155
else if (workflow.Definition.Start?.Schedule != null)
156156
{

0 commit comments

Comments
 (0)