Exemplo n.º 1
0
        /// <summary>
        /// Sélectionne les données modifiables du SelectorInstance.
        /// </summary>
        /// <param name="selectorInstance">SelectorInstance</param>
        /// <param name="wfInstance">WorkflowInstance</param>
        /// <param name="idsDimensionDS">Dictionnaire de DimensionDataSet par Id</param>
        /// <returns>Message de retour</returns>
        public async Task <HttpResponseMessageResult> SetModifyData(SelectorInstance selectorInstance, WorkflowInstance wfInstance, Dictionary <long, DataSetDimension> idsDimensionDS)
        {
            if (selectorInstance == null)
            {
                throw new WrongParameterException($"SelectorInstanceDomain.SetModifyData: SelectorInstance is null.");
            }
            if (selectorInstance.SelectorConfig == null)
            {
                throw new WrongParameterException($"SelectorInstanceDomain.SetModifyData: SelectorConfig is null (Id SelectorInstance : {selectorInstance.Id}).");
            }
            if (selectorInstance.SelectorConfig.ModifyCriterias == null)
            {
                throw new SequenceException($"SelectorInstance.SetModifyData : no ModifyCriterias for values found, error in SelectorConfig. Id SelectorConfig : {selectorInstance.SelectorConfig.Id}");
            }

            HttpResponseMessageResult res = new HttpResponseMessageResult()
            {
                IsSuccess = true
            };

            IEnumerable <IEnumerable <CriteriaValues> > lstCv = await CriteriaDomain.ExtractAllCriteriaValues(selectorInstance.SelectorConfig.ModifyCriterias, wfInstance);

            List <Expression <Func <ValueObject, bool> > > where = new List <Expression <Func <ValueObject, bool> > >();

            res.Append(ValueObjectDomain.BuildFilterRequest(where, lstCv, idsDimensionDS, false));

            if (where.Count > 0)
            {
                IQueryable <ValueObject> dbQuery           = UnitOfWork.GetDbContext().Set <ValueObject>();
                IEnumerable <long>       lstIdsValueObject = await where
                                                             .Aggregate(dbQuery, (current, predicate) => current.Where(predicate))
                                                             .Include(vo => vo.SelectorInstanceValueObject)
                                                             .Where(vo => vo.SelectorInstanceValueObject.Any(sivo => sivo.SelectorInstanceId == selectorInstance.Id))
                                                             .Select(vo => vo.Id)
                                                             .ToAsyncEnumerable()
                                                             .ToList();

                foreach (SelectorInstanceValueObject subSivo in selectorInstance.SelectorInstanceValueObject.Where(sivo => lstIdsValueObject.Contains(sivo.ValueObjectId)))
                {
                    subSivo.IsEditable = true;
                }

                int nbr = await UnitOfWork.GetDbContext().SaveChangesAsync();
            }

            return(res);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Trouve les validateurs et les ajoute dans la liste des utilisateurs en validation.
        /// </summary>
        /// <param name="selectorInstance">SelectorInstance</param>
        /// <param name="wfInstance">WorkflowInstance</param>
        /// <returns>Message de retour</returns>
        public async Task <HttpResponseMessageResult> FindValidators(SelectorInstance selectorInstance, WorkflowInstance wfInstance)
        {
            if (selectorInstance == null)
            {
                throw new WrongParameterException($"SelectorInstanceDomain.FindValidators: SelectorInstance is null.");
            }
            if (selectorInstance.SelectorConfig == null)
            {
                throw new WrongParameterException($"SelectorInstanceDomain.FindValidators: SelectorConfig is null (Id SelectorInstance : {selectorInstance.Id}).");
            }
            if (selectorInstance.SelectorConfig.Validators == null)
            {
                throw new SequenceException($"SelectorInstance.FindValidators: no validator found, error in SelectorConfig (no Validators list). Id SelectorConfig : {selectorInstance.SelectorConfig.Id}");
            }

            HttpResponseMessageResult res = new HttpResponseMessageResult()
            {
                IsSuccess = true
            };
            IEnumerable <IGrouping <int, Criteria> > lstGrp = selectorInstance.SelectorConfig.Validators.GroupBy(c => c.ChainNumber);

            int currentChain = -1;

            if ((lstGrp != null) && (lstGrp.Count() > 0))
            {
                currentChain = lstGrp.Min(g => g.Key);
            }
            IEnumerable <User>        validators = null;
            IEnumerable <UserSetUser> lstUsu     = null;
            IGrouping <int, Criteria> grp        = null;

            // On parcourt les chaines de criteria une à une afin de trouver le modificateur.
            while ((currentChain > -1) && ((validators == null) || (validators.Count() == 0)))
            {
                grp = lstGrp.Where(g => g.Key == currentChain).FirstOrDefault();
                if (grp == null)
                {
                    throw new SequenceException($"SelectorInstance.FindValidators: no validator found, error in SelectorConfig (no group). Id SelectorConfig : {selectorInstance.SelectorConfig.Id}");
                }

                IEnumerable <IEnumerable <CriteriaValues> > lstCv = await CriteriaDomain.ExtractAllCriteriaValues(grp, wfInstance);

                lstUsu = await UserSetDomain.GetUsersByRight(lstCv, wfInstance.DataSetId, RightEnum.Validation);

                validators = lstUsu.Select(usu => usu.User).Distinct(new UserComparer((x, y) => x.Id == y.Id));

                // Gestion des cas des modificateurs
                if ((validators == null) || (validators.Count() == 0))
                {
                    IEnumerable <int> lstNumber = lstGrp.Select(g => g.Key).Where(i => i > currentChain);
                    if (lstNumber.Count() > 0)
                    {
                        currentChain = lstNumber.OrderBy(i => i).First();
                    }
                    else
                    {
                        throw new ConfigurationException("SelectorInstanceDomain.FindValidators: no validator was found.");
                    }
                }
            }

            if (validators != null)
            {
                foreach (User val in validators)
                {
                    SelectorInstanceUser siu = new SelectorInstanceUser()
                    {
                        SelectorInstance = selectorInstance,
                        User             = val,
                        Right            = RightEnum.Validation
                    };
                    UnitOfWork.SelectorInstanceUserRepository.PrepareAddForObject(siu);
                    siu.InitDatesAndUser("");

                    selectorInstance.SelectorInstanceUser.Add(siu);
                    val.SelectorInstanceUser.Add(siu);
                }
            }

            return(res);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Recherche du modificateur pour le SelectorInstance donné en paramétre.
        /// </summary>
        /// <param name="selectorInstance">SelectorInstance</param>
        /// <param name="wfInstance">WorkflowInstance</param>
        /// <returns>Message de retour</returns>
        public async Task <HttpResponseMessageResult> FindModificator(SelectorInstance selectorInstance, WorkflowInstance wfInstance)
        {
            if (selectorInstance == null)
            {
                throw new WrongParameterException($"SelectorInstanceDomain.FindModificator: SelectorInstance is null.");
            }
            if (selectorInstance.SelectorConfig == null)
            {
                throw new WrongParameterException($"SelectorInstanceDomain.FindModificator: SelectorConfig is null (Id SelectorInstance : {selectorInstance.Id}).");
            }
            if (selectorInstance.SelectorConfig.Modifiers == null)
            {
                throw new SequenceException($"SelectorInstance.FindModificator : no modificator found, error in SelectorConfig (no Modifiers list). Id SelectorConfig : {selectorInstance.SelectorConfig.Id}");
            }

            HttpResponseMessageResult res = new HttpResponseMessageResult()
            {
                IsSuccess = true
            };
            IEnumerable <IGrouping <int, Criteria> > lstGrp = selectorInstance.SelectorConfig.Modifiers.GroupBy(c => c.ChainNumber);

            int currentChain = -1;

            if ((lstGrp != null) && (lstGrp.Count() > 0))
            {
                currentChain = lstGrp.Min(g => g.Key);
            }
            User modificator = null;
            IEnumerable <UserSetUser> lstUsu = null;
            IGrouping <int, Criteria> grp    = null;

            // On parcourt les chaines de criteria une à une afin de trouver le modificateur.
            while ((currentChain > -1) && (modificator == null))
            {
                grp = lstGrp.Where(g => g.Key == currentChain).FirstOrDefault();
                if (grp == null)
                {
                    throw new SequenceException($"SelectorInstance.FindModificator : no modificator found, error in SelectorConfig (no group). Id SelectorConfig : {selectorInstance.SelectorConfig.Id}");
                }

                IEnumerable <IEnumerable <CriteriaValues> > lstCv = await CriteriaDomain.ExtractAllCriteriaValues(grp, wfInstance);

                lstUsu = await UserSetDomain.GetUsersByRight(lstCv, wfInstance.DataSetId, RightEnum.Modification);

                IEnumerable <User> modificators = lstUsu.Select(usu => usu.User).Distinct(new UserComparer((x, y) => x.Id == y.Id));

                // Gestion des cas des modificateurs
                if ((modificators == null) || (modificators.Count() == 0))
                {
                    IEnumerable <int> lstNumber = lstGrp.Select(g => g.Key).Where(i => i > currentChain);
                    if (lstNumber.Count() > 0)
                    {
                        currentChain = lstNumber.OrderBy(i => i).First();
                    }
                    else
                    {
                        throw new ConfigurationException("SelectorInstanceDomain.FindModificator : no modificator was found.");
                    }
                }
                if (modificators.Count() > 1)
                {
                    throw new ConfigurationException("SelectorInstanceDomain.FindModificator : more than one modificator was found.");
                }
                if (modificators.Count() == 1)
                {
                    modificator = modificators.ElementAt(0);
                }
            }

            if (modificator == null)
            {
                throw new DataLoadingException($"SelectorInstanceDomain.FindModificator : No modificator found for SelectorInstance (Id : {selectorInstance.Id}).");
            }

            // Régler le SelectorInstance avec l'id de l'utilisateur trouvé.
            selectorInstance.ChainNumberModifyer = currentChain;
            selectorInstance.ModifyerId          = modificator.Id;
            UserSetUser usuDistinct = lstUsu.FirstOrDefault();

            if (usuDistinct == null)
            {
                throw new DataLoadingException("SelectorInstanceDomain.FindModificator : a problem with loading UserSetUser must stop this finding.");
            }

            Dictionary <long, DataSetDimension> dimIds = await DataSetDimensionDomain.GetDimensionColumns(wfInstance.DataSetId);

            foreach (Criteria crit in grp)
            {
                string         dimName = dimIds.Values.Where(v => v.Dimension.Id == crit.Dimension.Id).Select(v => v.ColumnName).FirstOrDefault();
                string         value   = GetValueFromDimension(usuDistinct, dimName);
                CriteriaValues cv      = new CriteriaValues()
                {
                    Criteria = crit, SelectorInstanceModifier = selectorInstance, Value = value
                };
                selectorInstance.ModifyCriteriasValues.Add(cv);
            }

            return(res);
        }
        /// <summary>
        /// Duplicate un SelectorConfig pour l'instance d'un WorkflowConfig.
        /// </summary>
        /// <param name="selectorConfig">SelectorConfig original</param>
        /// <returns>Duplicat du SelectorConfig original</returns>
        public async Task <SelectorConfig> CopyForStatic(SelectorConfig selectorConfig)
        {
            if (selectorConfig == null)
            {
                throw new WrongParameterException("SelectorConfigDomain.CopyForStatic: SelectorConfig source is null!");
            }

            int    lastNumber = 1;
            string name       = selectorConfig.Name;
            Match  m          = _regexSubStringName.Match(selectorConfig.Name);

            if (m.Success)
            {
                if (Int32.TryParse(m.Groups["number"].Value, out int number))
                {
                    lastNumber = number + 1;
                }
                name = m.Groups["name"].Value;
            }

            SelectorConfig duplicat = new SelectorConfig();

            UnitOfWork.SelectorConfigRepository.PrepareAddForObject(duplicat);

            duplicat.Name = $"{name} ({lastNumber})";
            duplicat.ActionSequenceRef     = selectorConfig.ActionSequenceRef;
            duplicat.ConstraintSequenceRef = selectorConfig.ConstraintSequenceRef;
            duplicat.Description           = selectorConfig.Description;
            // Copies des criteres
            foreach (Criteria c in selectorConfig.Criterias)
            {
                duplicat.Criterias.Add(await CriteriaDomain.CopyForStatic(c));
            }
            foreach (Criteria c in selectorConfig.Modifiers)
            {
                duplicat.Modifiers.Add(await CriteriaDomain.CopyForStatic(c));
            }
            foreach (Criteria c in selectorConfig.Validators)
            {
                duplicat.Validators.Add(await CriteriaDomain.CopyForStatic(c));
            }
            foreach (Criteria c in selectorConfig.ModifyCriterias)
            {
                duplicat.ModifyCriterias.Add(await CriteriaDomain.CopyForStatic(c));
            }

            // Copies des propagates...
            List <SelectorConfig> lstPrev = await UnitOfWork.GetDbContext().SelectorConfig
                                            .Where(sc => sc.Id == selectorConfig.PrevPropagateId && sc.WorkflowConfig != null)
                                            .AsNoTracking()
                                            .ToAsyncEnumerable()
                                            .ToList();

            SelectorConfig prev = lstPrev.FirstOrDefault();

            if (prev != null)
            {
                SelectorConfig cpyPrev = await CopyForStatic(prev);

                duplicat.PrevPropagateId = cpyPrev.Id;
            }

            List <SelectorConfig> lstProp = await UnitOfWork.GetDbContext().SelectorConfig
                                            .Where(sc => sc.Id == selectorConfig.PropagateId && sc.WorkflowConfig != null)
                                            .AsNoTracking()
                                            .ToAsyncEnumerable()
                                            .ToList();

            SelectorConfig prop = lstProp.FirstOrDefault();

            if (prop != null)
            {
                SelectorConfig cpyProp = await CopyForStatic(prop);

                duplicat.PropagateId = cpyProp.Id;
            }

            List <SelectorConfig> lstFail = await UnitOfWork.GetDbContext().SelectorConfig
                                            .Where(sc => sc.Id == selectorConfig.FailPropagateId && sc.WorkflowConfig != null)
                                            .AsNoTracking()
                                            .ToAsyncEnumerable()
                                            .ToList();

            SelectorConfig fail = lstFail.FirstOrDefault();

            if (fail != null)
            {
                SelectorConfig cpyFail = await CopyForStatic(fail);

                duplicat.PropagateId = cpyFail.Id;
            }

            int nbr = await UnitOfWork.GetDbContext().SaveChangesAsync();

            return(duplicat);
        }