コード例 #1
0
        public async Task <IHttpActionResult> Post([FromBody] BuildActionModel model, Guid idRepository)
        {
            return(await WebApiHelpers.ActionHelper.TryCatchWithLoggerAsync(async() =>
            {
                UDSRepository repository = _unitOfWork.Repository <UDSRepository>().Find(idRepository);
                if (repository != null && model != null && !string.IsNullOrEmpty(model.Model))
                {
                    UDSRelationModel relationModel = JsonConvert.DeserializeObject <UDSRelationModel>(model.Model);
                    ICollection <UDSRole> rolesToManage = GetEntityRoles(relationModel.Roles, repository);
                    ICollection <UDSUser> usersToManage = GetEntityUsers(relationModel.Users, repository);
                    ICollection <UDSPECMail> pecMailsToManage = GetEntityPECMails(relationModel.PECMails, repository);
                    ICollection <UDSMessage> messagesToManage = GetEntityMessages(relationModel.Messages, repository);
                    ICollection <UDSDocumentUnit> documentUnitsToManage = GetEntityDocumentUnits(relationModel.DocumentUnits, repository);
                    ICollection <UDSContact> contactsToManage = GetEntityContacts(relationModel.Contacts, repository);
                    ICollection <UDSCollaboration> collaborationsToManage = GetEntityCollaborations(relationModel.Collaborations, repository);

                    if (model.BuildType == BuildActionType.Build)
                    {
                        _unitOfWork.BeginTransaction();

                        await BuildUDSRoleAsync(rolesToManage);
                        await BuildUDSUserAsync(usersToManage);
                        await BuildUDSPECMailAsync(pecMailsToManage);
                        await BuildUDSMessageAsync(messagesToManage);
                        await BuildUDSDocumentUnitAsync(documentUnitsToManage);
                        await BuildUDSContactAsync(contactsToManage);
                        await BuildUDSCollaborationAsync(collaborationsToManage);

                        await _unitOfWork.SaveAsync();
                    }

                    if (model.BuildType == BuildActionType.Synchronize)
                    {
                        _unitOfWork.BeginTransaction();

                        await SynchroniseUDSRoleAsync(rolesToManage, model.ReferenceId, repository);
                        await SynchroniseUDSUserAsync(usersToManage, model.ReferenceId, repository);
                        await SynchroniseUDSPECMailAsync(pecMailsToManage, model.ReferenceId, repository);
                        await SynchroniseUDSMessageAsync(messagesToManage, model.ReferenceId, repository);
                        await SynchroniseUDSDocumentUnitAsync(documentUnitsToManage, model.ReferenceId, repository);
                        await SynchroniseUDSContactAsync(contactsToManage, model.ReferenceId, repository);
                        await SynchroniseUDSCollaborationAsync(collaborationsToManage, model.ReferenceId, repository);

                        await _unitOfWork.SaveAsync();
                    }
                }
                return Ok(model);
            }, BadRequest, Content, InternalServerError, _logger, LogCategories));
        }
コード例 #2
0
        private async Task <IHttpActionResult> PostAsync(TEntity entity, Func <TEntity, Task <TEntity> > lambda)
        {
            return(await ActionHelper.TryCatchWithLoggerAsync(async() =>
            {
                _unitOfWork.BeginTransaction(PostIsolationLevel);
                if (entity is IWorkflowContentBase)
                {
                    IWorkflowContentBase workflow = (IWorkflowContentBase)entity;
                    WorkflowActions = workflow.WorkflowActions ?? new List <IWorkflowAction>();
                    WorkflowName = workflow.WorkflowName;
                    IdWorkflowActivity = workflow.IdWorkflowActivity;
                    WorkflowAutoComplete = workflow.WorkflowAutoComplete;
                }
                entity = await lambda(entity);
                bool result = await _unitOfWork.SaveAsync();

                if (result)
                {
                    AfterSave(entity);
                    return Ok(entity);
                }
                return InternalServerError();
            }, BadRequest, Content, InternalServerError, _logger, LogCategories));
        }
コード例 #3
0
        private async Task <WorkflowResult> StartWorkflowJson(WorkflowStart content)
        {
            WorkflowResult validationResult = new WorkflowResult();

            WorkflowRepository workflowRepository = _unitOfWork.Repository <WorkflowRepository>().GetByName(content.WorkflowName);

            if (workflowRepository == null)
            {
                throw new DSWValidationException("Evaluate start workflow validation error",
                                                 new List <ValidationMessageModel>()
                {
                    new ValidationMessageModel
                    {
                        Key     = "WorkflowStart",
                        Message = $"Impossibile avviare il workflow '{content.WorkflowName}' in quanto non esiste nel repositories dei workflow validi."
                    }
                }, null, DSWExceptionCode.VA_RulesetValidation);
            }

            WorkflowInstance workflowInstance = new WorkflowInstance()
            {
                Status             = WorkflowStatus.Todo,
                WorkflowRepository = workflowRepository,
                Json    = workflowRepository.Json,
                Subject = workflowRepository.Name
            };
            WorkflowProperty prop;

            foreach (KeyValuePair <string, WorkflowArgument> item in content.Arguments)
            {
                prop = _workflowArgumentMapper.Map(item.Value, new WorkflowProperty());
                prop.WorkflowType = WorkflowType.Workflow;
                workflowInstance.WorkflowProperties.Add(prop);
            }

            WorkflowProperty _dsw_p_WorkflowStartMotivationRequired = workflowInstance.WorkflowProperties.SingleOrDefault(f => f.Name == WorkflowPropertyHelper.DSW_PROPERTY_WORKFLOW_START_MOTIVATION_REQUIRED);
            WorkflowProperty _dsw_p_InstanceSubject = workflowInstance.WorkflowProperties.SingleOrDefault(f => f.Name == WorkflowPropertyHelper.DSW_PROPERTY_INSTANCE_SUBJECT);
            WorkflowProperty _dsw_v_Workflow_ActiveInstanceSubjectUnique = workflowInstance.WorkflowProperties.SingleOrDefault(f => f.Name == WorkflowPropertyHelper.DSW_VALIDATION_INSTANCE_ACTIVE_SUBJECT_UNIQUE);
            WorkflowProperty _dsw_v_Workflow_StartValidations            = workflowInstance.WorkflowProperties.SingleOrDefault(f => f.Name == WorkflowPropertyHelper.DSW_VALIDATION_WORKFLOW_START);
            WorkflowProperty _dsw_p_ReferenceModel = workflowInstance.WorkflowProperties.SingleOrDefault(f => f.Name == WorkflowPropertyHelper.DSW_PROPERTY_REFERENCE_MODEL);

            if (_dsw_v_Workflow_StartValidations != null && !string.IsNullOrEmpty(_dsw_v_Workflow_StartValidations.ValueString))
            {
                Dictionary <DSWEnvironmentType, WorkflowRuleDefinition> deserializedWorkflowStartValidation = JsonConvert.DeserializeObject <Dictionary <DSWEnvironmentType, WorkflowRuleDefinition> >(_dsw_v_Workflow_StartValidations.ValueString);
                Guid fascicleId = JsonConvert.DeserializeObject <WorkflowReferenceModel>(_dsw_p_ReferenceModel.ValueString).ReferenceId;
                #region Intermediate Validations
                if (!(deserializedWorkflowStartValidation is Dictionary <DSWEnvironmentType, WorkflowRuleDefinition>))
                {
                    throw new DSWValidationException("Evaluate start workflow validation error",
                                                     new List <ValidationMessageModel>()
                    {
                        new ValidationMessageModel
                        {
                            Key     = "WorkflowStart",
                            Message = $"Impossibile avviare il workflow '{content.WorkflowName}' in quanto le definizioni delle regole di avvio non sono valide (struttura non valida)."
                        }
                    }, null, DSWExceptionCode.VA_RulesetValidation);
                }

                if (deserializedWorkflowStartValidation.Keys.FirstOrDefault().ToString() != EnumHelper.GetDescription(DSWEnvironmentType.Fascicle))
                {
                    throw new DSWValidationException("Evaluate start workflow validation error",
                                                     new List <ValidationMessageModel>()
                    {
                        new ValidationMessageModel
                        {
                            Key     = "WorkflowStart",
                            Message = $"Impossibile avviare il workflow '{content.WorkflowName}' in quanto il motore supporta definizioni solo per il modulo Fascicoli (environment non supportato)."
                        }
                    }, null, DSWExceptionCode.VA_RulesetValidation);
                }
                #endregion
                List <ValidationMessageModel> errorResult = new List <ValidationMessageModel>();
                ICollection <WorkflowRule>    deserializedWorkflowRules = deserializedWorkflowStartValidation[DSWEnvironmentType.Fascicle].Rules;

                await ValidateWorkflowRules(fascicleId, errorResult, deserializedWorkflowRules);
            }
            if (_dsw_p_InstanceSubject != null)
            {
                workflowInstance.Subject = _dsw_p_InstanceSubject.ValueString;
                _logger.WriteDebug(new LogMessage($"SET INSTANCE SUBJECT: {workflowInstance.Subject}"), LogCategories);
            }
            if (_dsw_p_WorkflowStartMotivationRequired != null && _dsw_p_WorkflowStartMotivationRequired.ValueBoolean.HasValue && _dsw_p_WorkflowStartMotivationRequired.ValueBoolean.Value)
            {
                WorkflowProperty dsw_p_Subject = workflowInstance.WorkflowProperties.SingleOrDefault(f => f.Name == WorkflowPropertyHelper.DSW_PROPERTY_SUBJECT);
                if (dsw_p_Subject == null || string.IsNullOrEmpty(dsw_p_Subject.ValueString))
                {
                    throw new DSWValidationException("Evaluate start workflow validation error",
                                                     new List <ValidationMessageModel>()
                    {
                        new ValidationMessageModel
                        {
                            Key     = "WorkflowStart",
                            Message = $"Impossibile avviare il flusso di lavoro se non è stata fornita una motivazione"
                        }
                    }, null, DSWExceptionCode.VA_RulesetValidation);
                }
            }
            if (_dsw_v_Workflow_ActiveInstanceSubjectUnique != null && _dsw_v_Workflow_ActiveInstanceSubjectUnique.ValueBoolean.HasValue && _dsw_v_Workflow_ActiveInstanceSubjectUnique.ValueBoolean.Value)
            {
                if (_unitOfWork.Repository <WorkflowInstance>().CountActiveInstances(workflowInstance.WorkflowRepository.UniqueId, workflowInstance.Subject) > 0)
                {
                    throw new DSWValidationException("Evaluate start workflow validation error",
                                                     new List <ValidationMessageModel>()
                    {
                        new ValidationMessageModel
                        {
                            Key     = "WorkflowStart",
                            Message = $"Impossibile avviare un nuovo flusso di lavoro in cui l'oggetto '{workflowInstance.Subject}' è stato come unico attivo. Completare i restanti flussi di lavoro attivi."
                        }
                    }, null, DSWExceptionCode.VA_RulesetValidation);
                }
            }

            _unitOfWork.BeginTransaction();
            Guid instanceId = Guid.NewGuid();
            workflowInstance = await _workflowInstanceService.CreateAsync(workflowInstance);
            await PopulateActivityAsync(workflowInstance, instanceId, workflowInstance.WorkflowRepository,
                                        workflowInstance.WorkflowProperties.Where(f => !f.Name.Equals(WorkflowPropertyHelper.DSW_ACTION_ACTIVITY_MANUAL_COMPLETE)));

            bool result = await _unitOfWork.SaveAsync();

            _unitOfWork.BeginTransaction();
            workflowInstance.Status = WorkflowStatus.Progress;
            if (!workflowInstance.InstanceId.HasValue)
            {
                workflowInstance.InstanceId = instanceId;
            }
            workflowInstance = await _workflowInstanceService.UpdateAsync(workflowInstance);

            result = await _unitOfWork.SaveAsync();

            validationResult.InstanceId = workflowInstance.InstanceId;
            validationResult.IsValid    = true;
            _logger.WriteInfo(new LogMessage($"Assing workflowInstance.InstanceId [{workflowInstance.InstanceId}] for {workflowInstance.WorkflowRepository.Name}"), LogCategories);

            return(validationResult);
        }