Exemplo n.º 1
0
        public async Task <IActionResult> Search([FromQuery] WorkflowTransitionSearchRequest requestArgs)
        {
            return(await FunctionWrapper.ExecuteFunction(this, async() =>
            {
                if (string.IsNullOrEmpty(requestArgs.WorkflowId) && string.IsNullOrEmpty(requestArgs.FromNodeId))
                {
                    throw new System.Exception("Valid search criteria not supplied.");
                }

                return await _workflowTransitionRepository.Search(requestArgs);
            }));
        }
Exemplo n.º 2
0
        private async Task <Item> HydrateForGet(Item item, ItemExpansionParams expand)
        {
            try
            {
                item = await HydrateForGetAndSave(item);

                if (expand.LinkedItems)
                {
                    if (item.LinkedItemIds != null && item.LinkedItemIds.Count > 0)
                    {
                        item.LinkedItems = new List <Item>();
                        foreach (ObjectId linkedItemId in item.LinkedItemIds)
                        {
                            if (item.LinkedItems == null)
                            {
                                item.LinkedItems = new List <Item>();
                            }
                            item.LinkedItems.Add(await Get(linkedItemId));
                        }
                    }
                }

                if (expand.Transitions)
                {
                    var funcReg = new FunctionRegistry(this,
                                                       _itemTypeRepository, null, _workflowNodeRepository);

                    var nodeTransitions = await _workflowTransitionRepository
                                          .Search(new WorkflowTransitionSearchRequest()
                    {
                        FromNodeId = item.WorkflowNodeId.ToString()
                    });

                    // Test each transitions conditions for applicability to the item
                    foreach (WorkflowTransition transition in nodeTransitions)
                    {
                        bool anyFailedConditions = false;

                        if (transition.PreConditions == null)
                        {
                            transition.PreConditions = new List <WorkflowTransitionFunction>();
                        }

                        foreach (WorkflowTransitionFunction condition in transition.PreConditions)
                        {
                            var execResult = await funcReg
                                             .ExecuteFunction(condition, item);

                            if (execResult.IsFailure)
                            {
                                anyFailedConditions = true;
                                break;
                            }
                        }

                        if (!anyFailedConditions)
                        {
                            if (item.Transitions == null)
                            {
                                item.Transitions = new List <WorkflowTransition>();
                            }

                            item.Transitions.Add(transition);
                        }
                    }
                }

                return(item);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }