private bool CheckRoleWorkFlowSecurity(Guid tenantId, TransitionWapper operationWapper, string subTypeCode) { var entityId = iMetadataManager.GetEntityContextByEntityName(operationWapper.EntityName); var validTransitionTypes = _managerWorkFlowStep.GetAssignedWorkFlowStepsOfUser(tenantId, operationWapper.UserId, entityId, subTypeCode); return(validTransitionTypes.Contains(operationWapper.NextTransitionType)); }
private WorkFlowResultMessage <WorkFlowTransition> Transition(Guid tenantId, TransitionWapper operationWapper) { var resM = new WorkFlowResultMessage <WorkFlowTransition>(); //-------Update last active step endtime var transactionHistories = _managerTrasition.GetTransitionHistoryByRefId(tenantId, operationWapper.RefId); if (transactionHistories.Count > 0) { var currentTrasitionTypes = (from transactionHistorie in transactionHistories where transactionHistorie.TransitionType.Id == operationWapper.CurrentTransitionType select transactionHistorie).OrderByDescending(p => p.StartTime).ToList(); if (currentTrasitionTypes.Count > 0) { var transitionLast = new WorkFlowTransition { TransitionHistoryId = currentTrasitionTypes[0].TransitionHistoryId, EndTime = DateTime.UtcNow }; _managerTrasition.UpdateTransitionHistory(tenantId, transitionLast); } dynamic jsonObject = new JObject(); jsonObject.CurrentWorkFlowStep = operationWapper.NextTransitionType; var myObj = new JObject(); myObj.Add(operationWapper.EntityName, jsonObject); IEntityResourceManager _iEntityResourceManager = new VPC.Framework.Business.EntityResourceManager.Contracts.EntityResourceManager(); var resultId = _iEntityResourceManager.UpdateResultWithoutWorkFlow(tenantId, operationWapper.UserId, operationWapper.RefId, operationWapper.EntityName, myObj, operationWapper.SubTypeName); //----- Insert into history table var entityId = iMetadataManager.GetEntityContextByEntityName(operationWapper.EntityName); var subTypeCode = iMetadataManager.GetSubTypeId(operationWapper.EntityName, operationWapper.SubTypeName); var workFlow = _reviewWorkFlow.GetWorkFlow(tenantId, entityId, subTypeCode); if (workFlow == null) { throw new CustomWorkflowException <WorkFlowMessage>(WorkFlowMessage.NoOperationActivity); } var itsCurrentStep = _managerWorkFlowStep.GetWorkFlowSteps(tenantId, workFlow.WorkFlowId).FirstOrDefault(x => x.TransitionType.Id == operationWapper.NextTransitionType); var transitionNew = new WorkFlowTransition(); transitionNew.TransitionHistoryId = Guid.NewGuid(); transitionNew.StartTime = DateTime.UtcNow; transitionNew.WorkFlowStepId = itsCurrentStep.WorkFlowStepId; transitionNew.EntityId = entityId; transitionNew.RefId = operationWapper.RefId; _managerTrasition.CreateTransitionHistory(tenantId, transitionNew); resM.Result = transitionNew; } return(resM); }
public IActionResult Transition([FromBody] TransitionWapper wapper) { try { // var details = iMetadataManager.GetEntitityByName(wapper.EntityName); // if(details!=null && details.VersionControl !=null ) // wapper.EntityName=details.VersionControl.Name; wapper.UserId = UserId; var retVal = _managerWorkFlow.ManageTransition(TenantCode, wapper, IsSuperAdmin); return(Ok(retVal)); } catch (Exception ex) { _log.Error(ExceptionFormatter.SerializeToString(ex)); return(StatusCode((int)HttpStatusCode.InternalServerError, ApiConstant.CustomErrorMessage)); } }
WorkFlowResultMessage <WorkFlowTransition> IManagerWorkFlow.ManageTransition(Guid tenantId, TransitionWapper operationWapper, bool isSuperAdmin) { var resM = new WorkFlowResultMessage <WorkFlowTransition>(); ITransitionFlowEngine transitionEngine = new TransitionFlowEngine(); var subTypeCode = iMetadataManager.GetSubTypeId(operationWapper.EntityName, operationWapper.SubTypeName); if (!isSuperAdmin) { var isValid = CheckRoleWorkFlowSecurity(tenantId, operationWapper, subTypeCode); if (!isValid) { throw new CustomWorkflowException <WorkFlowMessage>(WorkFlowMessage.InValidTransition); } } var properties = new WorkFlowProcessProperties { EntityName = operationWapper.EntityName, SubTypeCode = subTypeCode, UserId = operationWapper.UserId, IsSuperAdmin = isSuperAdmin }; transitionEngine.PreProcess(tenantId, operationWapper); resM = Transition(tenantId, operationWapper); transitionEngine.Process(tenantId, operationWapper); transitionEngine.PostProcess(tenantId, operationWapper); return(resM); }
WorkFlowResultMessage <WorkFlowTransition> IManagerWorkFlow.ManageTransitionFirstStep(Guid tenantId, TransitionWapper operationWapper) { var resM = new WorkFlowResultMessage <WorkFlowTransition>(); IOperationFlowEngine operationEngine = new OperationFlowEngine(); var subTypeCode = iMetadataManager.GetSubTypeId(operationWapper.EntityName, operationWapper.SubTypeName); var properties = new WorkFlowProcessProperties { EntityName = operationWapper.EntityName, SubTypeCode = subTypeCode, UserId = operationWapper.UserId, IsSuperAdmin = false }; operationEngine.PreProcess(tenantId, new OperationWapper { OperationType = WorkFlowOperationType.Create, Data = operationWapper.ObjectData }, properties); resM = Transition(tenantId, operationWapper); operationEngine.Process(tenantId, new OperationWapper { OperationType = WorkFlowOperationType.Create, Data = operationWapper.ObjectData }, properties); operationEngine.FirstOperation(tenantId, properties); operationEngine.PostProcess(tenantId, new OperationWapper { OperationType = WorkFlowOperationType.Create, Data = operationWapper.ObjectData }, properties); return(resM); }
WorkFlowResultMessage <WorkFlowProcessMessage> ITransitionFlowEngine.PostProcess(Guid tenantId, TransitionWapper transitionWapper) { var arrayList = new ArrayList { transitionWapper.ObjectData, tenantId }; var resM = new WorkFlowResultMessage <WorkFlowProcessMessage>(); var itsOperationProcess = WorkFlowCommon(tenantId, transitionWapper.EntityName, transitionWapper.SubTypeName, transitionWapper.StepId); if (itsOperationProcess.Count > 0) { //get its all process task var allTasks = _managerWorkFlowProcessTask.GetWorkFlowProcessTask(tenantId, itsOperationProcess[0].WorkFlowId); var itsPostProcessTasks = new List <WorkFlowProcessTaskInfo>(); foreach (var itsOperationProc in itsOperationProcess) { if (itsOperationProc.ProcessType == (int)WorkFlowProcessType.PostProcess) { itsPostProcessTasks = (from allProcessTask in allTasks where itsOperationProc.WorkFlowProcessId == allProcessTask.WorkFlowProcessId orderby allProcessTask.SequenceCode select allProcessTask).ToList(); } } foreach (var itsPostProcessTask in itsPostProcessTasks) { WorkFlowProcessMessage processResult = _processWorkFlow.TransitionProcess(itsPostProcessTask.ProcessCode, arrayList); if (!processResult.Success) { throw new CustomWorkflowException <WorkFlowMessage>(processResult.ErrorMessage.Code); } resM.Result = processResult; } } var resultArrayList = new ArrayList { transitionWapper }; if (resM.Result != null && resM.Result.Data != null) { resultArrayList.Add(resM.Result.Data); } return(resM); }
BatchTypeReturnMessage IBatchTypes.OnExecute(dynamic obj) { try { var tenantId = (Guid)obj[0]; BatchTypeInfo batchType = (BatchTypeInfo)obj[1]; var result = _iSettingManager.GetSettingsByContext(tenantId, SettingContextTypeEnum.EMAIL); if (result != null) { EmailSenderOptions options = Newtonsoft.Json.JsonConvert.DeserializeObject <EmailSenderOptions>(result.Content); //get mail in draft mode var queryFilter1 = new List <QueryFilter>(); queryFilter1.Add(new QueryFilter { FieldName = "CurrentWorkFlowStep", Operator = "Equal", Value = WorkFlowEngine.Draft.ToString() }); queryFilter1.Add(new QueryFilter { FieldName = "TenantId", Operator = "Equal", Value = tenantId.ToString() }); // queryFilter1.Add(new QueryFilter{FieldName="CurrentWorkFlowStep",Operator="Equal" ,Value= WorkFlowEngine.Fail.ToString()}); var queryContext1 = new QueryContext { Fields = "Date,Recipient,Sender,Subject,Body,CurrentWorkFlowStep", Filters = queryFilter1, PageSize = 100, PageIndex = 1 }; var emails = _iEntityResourceManager.GetResult(tenantId, "email", queryContext1); var emailMapped = EntityMapper <Email> .Mappers(emails); if (emailMapped.Count > 0) { foreach (var emailMap in emailMapped) { var currentWorkFlowId = Guid.Empty; if (emailMap.CurrentWorkFlowStep.Value == "Draft") { currentWorkFlowId = WorkFlowEngine.Draft; } else if (emailMap.CurrentWorkFlowStep.Value == "Send") { currentWorkFlowId = WorkFlowEngine.Sent; } else if (emailMap.CurrentWorkFlowStep.Value == "Failure") { currentWorkFlowId = WorkFlowEngine.Fail; } else if (emailMap.CurrentWorkFlowStep.Value == "Cancel") { currentWorkFlowId = WorkFlowEngine.Cancel; } var nextSteps = _workFlow.GetNextPossibleSteps(tenantId, "email", "Standard", currentWorkFlowId); var nextTransition = (from nextStep in nextSteps where nextStep.TransitionType.Id == WorkFlowEngine.Sent select nextStep).FirstOrDefault(); try { SendEmail(emailMap.Recipient.Value, emailMap.Subject.Value, emailMap.Body.Value, options); } catch (System.Exception ex) { _log.Error("An error has occurred while sending email", ex.Message); nextTransition = (from nextStep in nextSteps where nextStep.TransitionType.Id == WorkFlowEngine.Fail select nextStep).FirstOrDefault(); } var transitionWapper = new TransitionWapper { EntityName = "email", SubTypeName = "Standard", StepId = nextTransition.InnerStepId, RefId = Guid.Parse(emailMap.InternalId.Value), CurrentTransitionType = currentWorkFlowId, NextTransitionType = nextTransition.TransitionType.Id }; _workFlow.ManageTransitionFirstStep(tenantId, transitionWapper); } } } else { _log.Error("Email gateway not configured"); } } catch (System.Exception ex) { _log.Error("Email send failed", ex.Message); } return(new BatchTypeReturnMessage { NoDataFound = true }); }