public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(ValidationRuleHelper.Validate <InvalidDirectoryAndFileExistValidationRule>(value));
 }
Example #2
0
        public LogicalModel.Validation.ValidationRule GetLogicalRule(Hierarchy <XbrlIdentifiable> hrule, XbrlTaxonomyDocument document)
        {
            this.Document = document;

            var tmp_rule = hrule.Copy();
            //FixRule(tmp_rule);
            var logicalrule    = new LogicalModel.Validation.ValidationRule();
            var valueassertion = tmp_rule.Item as ValueAssertion;

            logicalrule.ID = valueassertion.ID;
            //Utilities.Logger.WriteLine("Getting rule for " + logicalrule.ID);
            logicalrule.LabelID            = valueassertion.LabelID;
            logicalrule.OriginalExpression = valueassertion.Test.Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " ");
            logicalrule.SetTaxonomy(this.Taxonomy);

            var sb = new StringBuilder();

            sb.AppendLine(logicalrule.DisplayText);
            sb.AppendLine(valueassertion.Test);
            var rawval = document.FileName + "\r\n" + document.LocalPath + "\r\n" + logicalrule.DisplayText + "\r\n" + logicalrule.OriginalExpression + "\r\n" + hrule.ToHierarchyString(i => i.ToString()) + "\r\n";

            logicalrule.RawInfo = rawval;
            Utilities.FS.AppendAllText(Taxonomy.TaxonomyValidationFolder + "Validations_XML.txt", rawval);

            if (logicalrule.ID.Contains("1058"))/*,"es_v354"*/
            {
            }

            var factvariables = tmp_rule.Where(i => i.Item is FactVariable);

            foreach (var fv in factvariables)
            {
                tmp_rule.Remove(fv);
            }


            logicalrule.BaseQuery = GetQuery(tmp_rule);

            logicalrule.BaseQuery.GetString(Taxonomy);

            foreach (var fv in factvariables)
            {
                var factvariable = fv.Item as FactVariable;
                var name         = factvariable.Name;
                var parameter    = new LogicalModel.Validation.ValidationParameter(name, logicalrule.ID);
                logicalrule.Parameters.Add(parameter);
                parameter.BindAsSequence = factvariable.BindAsSequence;
                parameter.FallBackValue  = factvariable.FallbackValue;


                parameter.BaseQuery = GetQuery(fv);
                parameter.Concept   = parameter.BaseQuery.GetConcept();
                if (String.IsNullOrEmpty(parameter.Concept))
                {
                    parameter.Concept = logicalrule.BaseQuery.GetConcept();
                }
                if (parameter.BaseQuery.HasDictFilter("find:filingIndicator"))
                {
                    parameter.IsGeneral   = true;
                    parameter.StringValue = "filingindicators";
                }
                ValidationRuleHelper.SetParamerterTypes(Taxonomy, logicalrule);
            }
            var factparameterqueries  = logicalrule.Parameters.Where(i => !i.IsGeneral).Select(i => i.BaseQuery).ToArray();
            var commconparameterquery = FactBaseQuery.GetCommonQuery(factparameterqueries);

            if (commconparameterquery != null && commconparameterquery.HasFilters())
            {
                FactBaseQuery.MergeQueries(logicalrule.BaseQuery, commconparameterquery);
                foreach (var pquery in factparameterqueries)
                {
                    FactBaseQuery.RemoveQuery(pquery, commconparameterquery);
                }
            }
            var sbquery = new StringBuilder();

            if (1 == 1)
            {
                sbquery.AppendLine("RuleQuery: ");
                sbquery.AppendLine(logicalrule.BaseQuery != null? logicalrule.BaseQuery.ToString():"");
                sbquery.AppendLine();
                foreach (var p in logicalrule.Parameters)
                {
                    sbquery.AppendLine(p + " Query: ");
                    if (p.BaseQuery != null)
                    {
                        sbquery.AppendLine(p.BaseQuery != null ? p.BaseQuery.ToString() : "");
                    }
                }
            }
            foreach (var gp in Taxonomy.ValidationParameters)
            {
                if (valueassertion.Test.Contains(gp.Value.XPathName))
                {
                    if (gp.Key == "ReportingLevel")
                    {
                        var p_rl1 = new LogicalModel.Validation.ValidationParameter("ReportingLevel", logicalrule.ID);
                        p_rl1.StringValue = this.Taxonomy.EntryDocument.FileName.Contains("_con") ? "con" : "ind";
                        p_rl1.Type        = LogicalModel.TypeEnum.String;
                        p_rl1.IsGeneral   = true;
                        logicalrule.Parameters.Add(p_rl1);
                        continue;
                    }
                    if (gp.Key == "AccountingStandard")
                    {
                        var p_rl2 = new LogicalModel.Validation.ValidationParameter("AccountingStandard", logicalrule.ID);
                        p_rl2.StringValue = this.Taxonomy.EntryDocument.FileName.Contains("GAAP") ? "GAAP" : "IFRS";
                        p_rl2.Type        = LogicalModel.TypeEnum.String;
                        p_rl2.IsGeneral   = true;
                        logicalrule.Parameters.Add(p_rl2);
                        continue;
                    }
                    var p_rl = new LogicalModel.Validation.ValidationParameter(gp.Key, logicalrule.ID);
                    p_rl.StringValue = "Unresolved";
                    p_rl.Type        = LogicalModel.TypeEnum.String;
                    p_rl.IsGeneral   = true;
                    logicalrule.Parameters.Add(p_rl);
                }
            }

            /*
             * if (valueassertion.Test.Contains("$ReportingLevel"))
             * {
             *  var p_rl1 = new LogicalModel.Validation.ValidationParameter("ReportingLevel", logicalrule.ID);
             *  p_rl1.StringValue = this.Taxonomy.EntryDocument.FileName.Contains("_con") ? "con" : "ind";
             *  p_rl1.Type = LogicalModel.TypeEnum.String;
             *  p_rl1.IsGeneral = true;
             *  logicalrule.Parameters.Add(p_rl1);
             * }
             * if (valueassertion.Test.Contains("$AccountingStandard"))
             * {
             *  var p_rl2 = new LogicalModel.Validation.ValidationParameter("AccountingStandard", logicalrule.ID);
             *  p_rl2.StringValue = this.Taxonomy.EntryDocument.FileName.Contains("GAAP") ? "GAAP" : "IFRS";
             *  p_rl2.Type = LogicalModel.TypeEnum.String;
             *  p_rl2.IsGeneral = true;
             *  logicalrule.Parameters.Add(p_rl2);
             * }
             */
            logicalrule.SetTaxonomy(this.Taxonomy);
            ValidationRuleHelper.ExecuteExplicitFiltering(this.Taxonomy, logicalrule);
            ValidationRuleHelper.ExecuteImplicitFiltering(this.Taxonomy, logicalrule);
            ValidationRuleHelper.ExecuteMatching(this.Taxonomy, logicalrule);
            ValidationRuleHelper.CheckConsistency(this.Taxonomy, logicalrule);

            //SetFacts(logicalrule);

            return(logicalrule);
        }
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            string[] paramlist = ((string)parameter).Split('|');
            if (paramlist == null || paramlist.Length <= 0)
            {
                throw new ArgumentNullException("parameter");
            }
            int length = paramlist.Length;

            IList <bool> boollist = new List <bool>();

            for (int i = 0; i < paramlist.Length; i++)
            {
                switch (paramlist[i].ToLowerInvariant())
                {
                case "checknameexisted":
                    boollist.Add(ValidationRuleHelper.Validate <InvalidCheckNameExistedValidationRule>(values[i]));
                    break;

                case "checkportavailable":
                    boollist.Add(ValidationRuleHelper.Validate <InvalidCheckPortAvailableValidationRule>(values[i]));
                    break;

                case "directoryandfileexist":
                    boollist.Add(ValidationRuleHelper.Validate <InvalidDirectoryAndFileExistValidationRule>(values[i]));
                    break;

                case "greaterthanzerointeger":
                    boollist.Add(ValidationRuleHelper.Validate <InvalidGreaterThanZeroIntegerValidationRule>(values[i]));
                    break;

                case "numericnull":
                    boollist.Add(ValidationRuleHelper.Validate <InvalidNumericNullValidationRule>(values[i]));
                    break;

                case "stringlength":
                    boollist.Add(ValidationRuleHelper.Validate <InvalidStringLengthValidationRule>(values[i]));
                    break;

                case "stringnullorempty":
                    boollist.Add(ValidationRuleHelper.Validate <InvalidStringNullOrEmptyValidationRule>(values[i]));
                    break;

                case "ipaddress":
                    boollist.Add(ValidationRuleHelper.Validate <InvalidIPAddressValidationRule>(values[i]));
                    break;

                case "objectnull":
                default:
                    boollist.Add(ValidationRuleHelper.Validate <InvalidObjectNullValidationRule>(values[i]));
                    break;
                }
            }

            bool result = boollist[0];

            for (int i = 1; i < boollist.Count; i++)
            {
                result = result & boollist[i];
            }

            return(result);
        }
Example #4
0
        public void SetFacts(LogicalModel.Validation.ValidationRule rule)
        {
            if (rule.ID.Contains("0147"))
            {
            }
            var         tables           = rule.Tables.Select(i => Taxonomy.Tables.FirstOrDefault(t => t.ID == i)).ToList();
            IList <int> tableintevallist = null;

            foreach (var table in tables)
            {
                tableintevallist = tableintevallist == null ? new IntervalList() : tableintevallist;
                tableintevallist = Utilities.Objects.MergeSorted(tableintevallist, table.FactindexList, null);
            }
            var         hastableinfo        = tableintevallist != null ? tableintevallist.Count > 0 : false;
            IList <int> allfactsintevallist = new IntervalList(0, Taxonomy.FactsManager.FactsOfPages.Count);

            if (hastableinfo)
            {
                allfactsintevallist = tableintevallist;
            }
            var ruletypeddimension = rule.BaseQuery.DictFilterIndexes.Where(i => Taxonomy.IsTyped(i));

            foreach (var parameter in rule.Parameters)
            {
                parameter.TaxFacts.Clear();
                IList <int> sdata = tableintevallist;
                if (!parameter.IsGeneral)
                {
                    if (parameter.BaseQuery.DictFilterIndexes.Count == 0)
                    {
                        sdata = allfactsintevallist;
                    }
                    parameter.Data            = parameter.BaseQuery.ToIntervalList(this.Taxonomy.FactsOfParts, sdata);
                    parameter.TypedDimensions = parameter.BaseQuery.DictFilterIndexes.Where(i => Taxonomy.IsTyped(i)).ToList();
                    parameter.TypedDimensions = parameter.TypedDimensions.Concat(ruletypeddimension).Distinct().ToList();
                    parameter.CoveredParts    = parameter.BaseQuery.GetAspects(this.Taxonomy);
                    if (parameter.FallBackValue == "()"
                        /*&& parameter.TypedDimensions.Count>0 */
                        && !parameter.BindAsSequence)
                    {
                        parameter.BindAsSequence = true;
                    }
                }
            }
            bool        hasfacts = false;
            var         ix       = 0;
            IList <int> data     = tableintevallist;

            if (rule.BaseQuery.DictFilterIndexes.Count == 0)
            {
                // && rule.BaseQuery.Pools.Count == 0
                //var interval = allfactsinteval;
                //var intervallist = new IntervalList();
                //intervallist.AddInterval(interval);
                data = allfactsintevallist;
            }
            rule.TypedDimensions = rule.BaseQuery.DictFilterIndexes.Where(i => Taxonomy.IsTyped(i)).ToList();
            rule.CoveredParts    = rule.BaseQuery.GetAspects(this.Taxonomy);
            var singlefactparameters = rule.Parameters.Where(i => !i.IsGeneral && !i.BindAsSequence).ToList();
            var multifactparameters  = rule.Parameters.Where(i => !i.IsGeneral && i.BindAsSequence).ToList();
            var mffnspissue          = false;

            LogicalModel.Validation.ValidationParameter p_mffnspissue = null;
            //Utilities.Logger.WriteToFile(String.Format("EnumerateIntervals {0} on {1}", rule.BaseQuery, data));

            foreach (var group in rule.BaseQuery.EnumerateIntervals(this.Taxonomy.FactsOfParts, 0, data, false))
            {
                //Utilities.Logger.WriteToFile("Joining rule with parameters...");

                foreach (var parameter in rule.Parameters)
                {
                    if (!parameter.IsGeneral)
                    {
                        var factsq = Utilities.Objects.IntersectSorted(parameter.Data, group, null);

                        //var facts = factsq.ToList();
                        var facts = factsq;

                        if (!parameter.BindAsSequence && facts.Count > 1)
                        {
                            mffnspissue   = true;
                            p_mffnspissue = parameter;
                        }
                        if (facts.Count > 0)
                        {
                            hasfacts = true;
                        }
                        parameter.AddTaxFacts(facts);
                    }
                }
                if (mffnspissue)
                {
                    var factcounts         = singlefactparameters.Select(i => new Utilities.KeyValue <int, LogicalModel.Validation.ValidationParameter>(i.TaxFacts.LastOrDefault().Count, i)).OrderByDescending(i => i.Key).ToList();
                    var distinctfactcounts = factcounts.Distinct().ToList();
                    if (singlefactparameters.Count == 1)
                    {
                        mffnspissue = false;
                        var p           = singlefactparameters.FirstOrDefault();
                        var lasttaxfact = p.TaxFacts.LastOrDefault();
                        p.TaxFacts.Remove(lasttaxfact);
                        foreach (var fact in lasttaxfact.AsEnumerable())
                        {
                            p.AddTaxFacts(new List <int>()
                            {
                                fact
                            });
                        }
                    }
                    if ((distinctfactcounts.Count == 2 && distinctfactcounts[1].Key == 1))
                    {
                        mffnspissue = false;
                        var theparameter         = factcounts[0].Value;
                        var parameterstocomplete = factcounts.Where(i => i.Key < factcounts[0].Key).Select(i => i.Value);

                        var facts = theparameter.TaxFacts.LastOrDefault();
                        theparameter.TaxFacts.Clear();
                        var run = 0;
                        foreach (var fact in facts.AsEnumerable())
                        {
                            theparameter.AddTaxFacts(new List <int>()
                            {
                                fact
                            });

                            foreach (var p in parameterstocomplete)
                            {
                                var firsttaxfact = p.TaxFacts.FirstOrDefault();
                                if (run > 0)
                                {
                                    p.TaxFacts.Add(firsttaxfact);
                                }
                            }
                            run++;
                        }
                    }
                    if (distinctfactcounts.Count == 1 /*&& multifactparameters.Count==0*/)
                    {
                        mffnspissue = false;
                        foreach (var p in singlefactparameters)
                        {
                            var lasttaxfact = p.TaxFacts.LastOrDefault();
                            p.TaxFacts.Remove(lasttaxfact);
                            foreach (var fact in lasttaxfact.AsEnumerable())
                            {
                                p.AddTaxFacts(new List <int>()
                                {
                                    fact
                                });
                            }
                        }
                    }
                }
                if (mffnspissue)
                {
                    Utilities.Logger.WriteLine(String.Format("{0}: Multiple facts found for Non Sequenced parameter {1}", rule.ID, p_mffnspissue.Name));
                }
                ix++;
                //Utilities.Logger.WriteToFile("End joining rule with parameters");
            }
            ValidationRuleHelper.SetParamerterTypes(Taxonomy, rule);
            if (!hasfacts)
            {
                Utilities.Logger.WriteLine(String.Format("{0}: Rule has no facts!", rule.ID));
            }
            var parameterswithissues = singlefactparameters.Where(i => i.TaxFacts.Any(f => f.Count > 1)).ToList();

            if (parameterswithissues.Count > 0)
            {
                Utilities.Logger.WriteLine(String.Format("{0}: Rule single factrule has multiple facts!", rule.ID));
            }
        }
Example #5
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(ValidationRuleHelper.Validate <InvalidGreaterThanZeroIntegerValidationRule>(value));
 }