11using CaseManagement . CMMN . CaseInstance . CommandHandlers ;
22using CaseManagement . CMMN . CaseInstance . Commands ;
3- using CaseManagement . CMMN . CaseInstance . Exceptions ;
43using CaseManagement . CMMN . Domains ;
5- using CaseManagement . CMMN . Extensions ;
6- using Microsoft . AspNetCore . Authorization ;
7- using Microsoft . AspNetCore . Http ;
84using Microsoft . AspNetCore . Mvc ;
95using Newtonsoft . Json . Linq ;
106using System ;
11- using System . Collections . Generic ;
12- using System . Linq ;
137using System . Net ;
148using System . Threading . Tasks ;
159
@@ -18,21 +12,13 @@ namespace CaseManagement.CMMN.Apis
1812 [ Route ( CMMNConstants . RouteNames . CaseInstances ) ]
1913 public class CaseInstancesController : Controller
2014 {
15+ private readonly ICreateCaseInstanceCommandHandler _createCaseInstanceCommandHandler ;
2116 private readonly ILaunchCaseInstanceCommandHandler _launchCaseInstanceCommandHandler ;
22- private readonly IConfirmFormCommandHandler _confirmFormCommandHandler ;
23- private readonly IStopCaseInstanceCommandHandler _stopCaseInstanceCommandHandler ;
24- // private readonly IProcessFlowInstanceQueryRepository _processFlowInstanceQueryRepository;
25- private readonly IActivateCommandHandler _activateCommandHandler ;
26- private readonly ITerminateCommandHandler _terminateCommandHandler ;
2717
28- public CaseInstancesController ( ILaunchCaseInstanceCommandHandler launchCaseInstanceCommandHandler , IConfirmFormCommandHandler confirmFormCommandHandler , IStopCaseInstanceCommandHandler stopCaseInstanceCommandHandler , /* IProcessFlowInstanceQueryRepository processFlowInstanceQueryRepository, */ IActivateCommandHandler activateCommandHandler , ITerminateCommandHandler terminateCommandHandler )
18+ public CaseInstancesController ( ICreateCaseInstanceCommandHandler createCaseInstanceCommandHandler , ILaunchCaseInstanceCommandHandler launchCaseInstanceCommandHandler )
2919 {
20+ _createCaseInstanceCommandHandler = createCaseInstanceCommandHandler ;
3021 _launchCaseInstanceCommandHandler = launchCaseInstanceCommandHandler ;
31- _confirmFormCommandHandler = confirmFormCommandHandler ;
32- _stopCaseInstanceCommandHandler = stopCaseInstanceCommandHandler ;
33- // _processFlowInstanceQueryRepository = processFlowInstanceQueryRepository;
34- _activateCommandHandler = activateCommandHandler ;
35- _terminateCommandHandler = terminateCommandHandler ;
3622 }
3723
3824 /*
@@ -43,6 +29,7 @@ public async Task<IActionResult> Search()
4329 var result = await _processFlowInstanceQueryRepository.Find(ExtractFindWorkflowInstanceParameter(query));
4430 return new OkObjectResult(ToDto(result));
4531 }
32+ */
4633
4734 [ HttpPost ]
4835 public async Task < IActionResult > Create ( [ FromBody ] CreateCaseInstanceCommand createCaseInstance )
@@ -62,6 +49,7 @@ public async Task<IActionResult> Launch(string id)
6249 return new OkResult ( ) ;
6350 }
6451
52+ /*
6553 [HttpGet("{id}/stop")]
6654 public async Task<IActionResult> Stop(string id)
6755 {
@@ -256,81 +244,111 @@ private static JObject ToDto(FindResponse<ProcessFlowInstance> resp)
256244 })) }
257245 };
258246 }
247+ */
259248
260- private static JObject ToDto(ProcessFlowInstance flowInstance )
249+ private static JObject ToDto ( CMMNWorkflowInstance workflowInstance )
261250 {
262251 var result = new JObject
263252 {
264- { "id", flowInstance .Id },
265- { "create_datetime", flowInstance .CreateDateTime },
266- { "template_id ", flowInstance.ProcessFlowTemplateId },
267- { "name ", flowInstance.ProcessFlowName },
268- { "context ", ToDto(flowInstance.ExecutionContext) }
253+ { "id" , workflowInstance . Id } ,
254+ { "create_datetime" , workflowInstance . CreateDateTime } ,
255+ { "definition_id " , workflowInstance . WorkflowDefinitionId } ,
256+ { "context " , ToDto ( workflowInstance . ExecutionContext ) } ,
257+ { "state " , workflowInstance . State }
269258 } ;
270- if (flowInstance.Status != null)
259+ var stateHistories = new JArray ( ) ;
260+ var transitionHistories = new JArray ( ) ;
261+ var executionHistories = new JArray ( ) ;
262+ var elts = new JArray ( ) ;
263+ foreach ( var stateHistory in workflowInstance . StateHistories )
271264 {
272- result.Add("status", Enum.GetName(typeof(ProcessFlowInstanceStatus), flowInstance.Status).ToLowerInvariant());
265+ stateHistories . Add ( new JObject
266+ {
267+ { "state" , stateHistory . State } ,
268+ { "datetime" , stateHistory . UpdateDateTime }
269+ } ) ;
273270 }
274271
275- var planItems = new JArray();
276- foreach(var planItem in flowInstance.Elements.Where(e => e is CMMNPlanItemDefinition).Cast<CMMNPlanItemDefinition>())
272+ foreach ( var transitionHistory in workflowInstance . TransitionHistories )
277273 {
278- planItems.Add(ToDto(planItem));
274+ transitionHistories . Add ( new JObject
275+ {
276+ { "transition" , Enum . GetName ( typeof ( CMMNTransitions ) , transitionHistory . Transition ) } ,
277+ { "datetime" , transitionHistory . CreateDateTime }
278+ } ) ;
279279 }
280280
281- var fileItems = new JArray();
282- foreach(var caseFileItem in flowInstance.Elements.Where(e => e is CMMNCaseFileItem).Cast<CMMNCaseFileItem>())
281+ foreach ( var executionHistory in workflowInstance . ExecutionHistories )
283282 {
284- fileItems.Add(ToDto(caseFileItem));
283+ executionHistories . Add ( new JObject
284+ {
285+ { "start_datetime" , executionHistory . StartDateTime } ,
286+ { "end_datetime" , executionHistory . EndDateTime } ,
287+ { "id" , executionHistory . WorkflowElementDefinitionId }
288+ } ) ;
285289 }
286290
287- result.Add("items", planItems);
288- result.Add("fileitems", fileItems);
289- return result;
290- }
291-
292- private static JObject ToDto(CMMNWorkflowInstanceExecutionContext context)
293- {
294- var jObj = new JObject();
295- foreach (var kvp in context.Variables)
291+ foreach ( var elt in workflowInstance . WorkflowElementInstances )
296292 {
297- jObj .Add(kvp.Key, kvp.Value );
293+ elts . Add ( ToDto ( elt ) ) ;
298294 }
299295
300- return jObj;
296+ result . Add ( "state_histories" , stateHistories ) ;
297+ result . Add ( "transition_histories" , transitionHistories ) ;
298+ result . Add ( "execution_histories" , executionHistories ) ;
299+ result . Add ( "elements" , elts ) ;
300+ return result ;
301301 }
302302
303- private static JObject ToDto(CMMNPlanItemDefinition planItem )
303+ private static JObject ToDto ( CMMNWorkflowElementInstance elt )
304304 {
305305 var result = new JObject
306306 {
307- { "id", planItem.Id },
308- { "name", planItem.Name },
309- { "version", planItem.Version }
307+ { "id" , elt . Id } ,
308+ { "version" , elt . Version } ,
309+ { "create_datetime" , elt . CreateDateTime } ,
310+ { "definition_id" , elt . WorkflowElementDefinitionId } ,
311+ { "form_instanceid" , elt . FormInstanceId } ,
312+ { "state" , elt . State }
310313 } ;
314+ var stateHistories = new JArray ( ) ;
311315 var transitionHistories = new JArray ( ) ;
312- if (planItem.TransitionHistories != null )
316+ foreach ( var stateHistory in elt . StateHistories )
313317 {
314- foreach(var transitionHistory in planItem.TransitionHistories)
318+ stateHistories . Add ( new JObject
315319 {
316- transitionHistories.Add(new JObject
317- {
318- { "create_datetime", transitionHistory.CreateDateTime },
319- { "transition", Enum.GetName(typeof(CMMNPlanItemTransitions), transitionHistory.Transition).ToLowerInvariant() },
320- { "version", transitionHistory.Version }
321- });
322- }
320+ { "state" , stateHistory . State } ,
321+ { "datetime" , stateHistory . UpdateDateTime }
322+ } ) ;
323323 }
324324
325- if (planItem.Status != null )
325+ foreach ( var transitionHistory in elt . TransitionHistories )
326326 {
327- result.Add("status", Enum.GetName(typeof(ProcessFlowInstanceElementStatus), planItem.Status).ToLowerInvariant());
327+ transitionHistories . Add ( new JObject
328+ {
329+ { "transition" , Enum . GetName ( typeof ( CMMNTransitions ) , transitionHistory . Transition ) } ,
330+ { "datetime" , transitionHistory . CreateDateTime }
331+ } ) ;
328332 }
329333
330- result.Add("histories", transitionHistories);
334+ result . Add ( "state_histories" , stateHistories ) ;
335+ result . Add ( "transition_histories" , transitionHistories ) ;
331336 return result ;
332337 }
333338
339+ private static JObject ToDto ( CMMNWorkflowInstanceExecutionContext context )
340+ {
341+ var jObj = new JObject ( ) ;
342+ foreach ( var kvp in context . Variables )
343+ {
344+ jObj . Add ( kvp . Key , kvp . Value ) ;
345+ }
346+
347+ return jObj ;
348+ }
349+
350+ /*
351+
334352 private static JObject ToDto(CMMNCaseFileItem fileItem)
335353 {
336354 var result = new JObject();
0 commit comments