Exemplo n.º 1
0
        /// <summary>
        /// CheckFactsAndDimensionsMatch
        /// </summary>
        /// <param name="totalCells"></param>
        /// <param name="spec"></param>
        /// <param name="language"></param>
        /// <param name="messageFormatter"></param>
        /// <returns></returns>
        private bool CheckFactsAndDimensionsMatch(int totalCells, Matrix.Specification spec, string language, MessageFormatter messageFormatter)
        {
            try
            {
                var cubeSize             = 0;
                var statisticCount       = spec.Statistic.Count;
                var periodCount          = spec.Frequency.Period.Count;
                var variableCombinations = 1;


                foreach (var classification in spec.Classification)
                {
                    variableCombinations = variableCombinations * classification.Variable.Count;
                }

                cubeSize = variableCombinations * periodCount * statisticCount;


                if (cubeSize != totalCells)
                {
                    //TODO: do we need translation here?
                    messageFormatter.AppendArgument("Language", language);
                    messageFormatter.AppendArgument("Expected", cubeSize);
                    messageFormatter.AppendArgument("Found", totalCells);
                    return(false);
                }
                return(true);
            }
            catch (Exception e)
            {
                Log.Instance.ErrorFormat("Error @ CheckFactsAndDimensionsMatch for language = {0}", language);
                Log.Instance.Error(e);
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            var           signature        = Utility.GetMD5(Utility.GetCustomConfig("APP_SALSA") + Utility.JsonSerialize_IgnoreLoopingReference(DTO.GetSignatureDTO()));
            dynamic       validationResult = new ExpandoObject();
            List <string> FrqValues        = new List <string>();

            PxStat.RequestLanguage.LngIsoCode = DTO.LngIsoCode;

            bool isValid = false;


            isValid = Validate();

            // }


            if (isValid)
            {
                validationResult.Signature         = signature;
                validationResult.FrqValueCandidate = FrqValues;
                Response.data = validationResult;



                return(true);
            }
            if (!isValid)
            {
                if (MatrixData != null)
                {
                    if (MatrixData.MainSpec.requiresResponse)
                    {
                        //cancel any validation errors and return an object to enable the user to choose which should be the time dimension
                        Matrix.Specification langSpec = MatrixData.GetSpecFromLanguage(DTO.LngIsoCode);
                        if (langSpec == null)
                        {
                            langSpec = MatrixData.MainSpec;
                        }

                        foreach (var v in langSpec.MainValues)
                        {
                            FrqValues.Add(v.Key);
                        }

                        validationResult.Signature         = null;
                        validationResult.FrqValueCandidate = FrqValues;
                        Response.data = validationResult;
                        return(true);
                    }
                }
                Response.data = validationResult;
                return(false);
            }


            //Response.error = Label.Get("error.validation");
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Check that there are no duplicate dimension codes or names in the Specification
        /// </summary>
        /// <param name="spec"></param>
        /// <returns></returns>
        private bool ValidateSpec(Matrix.Specification spec)
        {
            List <string> comparisons = new List <string>();

            comparisons.Add(spec.ContentVariable.ToUpper());
            comparisons.Add(spec.Frequency.Code.ToUpper());
            foreach (var cls in spec.Classification)
            {
                comparisons.Add(cls.Code.ToUpper());
            }

            if (hasDupes(comparisons))
            {
                return(false);
            }

            comparisons = new List <string>();
            comparisons.Add(spec.ContentVariable.ToUpper());
            comparisons.Add(spec.Frequency.Value.ToUpper());
            foreach (var cls in spec.Classification)
            {
                comparisons.Add(cls.Value.ToUpper());
            }

            //Frequency code must be one of the ones defined in STATIC
            List <string> validCodes = new List <string>();

            foreach (string str in Utility.GetCustomConfig("APP_PX_FREQUENCY_CODES").Split(',').ToList <string>())
            {
                if (str != null)
                {
                    if (str.Contains('/'))
                    {
                        validCodes.Add(str.Split('/')[0]);
                    }
                }
            }

            if (spec.Frequency.Code == null)
            {
                return(false);
            }

            if (!validCodes.Contains(spec.Frequency.Code))
            {
                return(false);
            }

            return(!hasDupes(comparisons));
        }
Exemplo n.º 4
0
        public PxIntegrityValidator(Matrix.Specification spec, string lngIsoCode = null)
        {
            long threshold = Configuration_BSO.GetCustomConfig("dataset.threshold");;

            RuleFor(x => x).Must(PxStat.Build.CustomValidations.BelowLimitDatapoints).WithMessage(lngIsoCode == null ? String.Format(Label.Get("integrity.cell-count"), spec.GetRequiredDatapointCount(), threshold.ToString()) : String.Format(Label.Get("integrity.cell-count", lngIsoCode), spec.GetRequiredDatapointCount(), threshold.ToString()));
            RuleFor(x => x.MainSpec).HaveFactsAndDimensionsMatching().WithMessage(Label.Get("integrity.size"));
            RuleFor(x => x.OtherLanguageSpec).HaveFactsAndDimensionsMatching().When(x => x.OtherLanguageSpec != null && x.OtherLanguageSpec.Count > 0).WithMessage(Label.Get("integrity.size"));
            RuleFor(x => x.Cells).DataIsGood().When(x => x.Cells != null && x.Cells.Count > 0).WithMessage(FormatDataIsGood);
            RuleFor(x => x).Must(NoDuplicateDomains).WithMessage(Label.Get("integrity.codes"));
            RuleFor(x => x).Must(NoDuplicateNames).When(x => spec.Values != null && spec.MainValues != null).WithMessage(Label.Get("integrity.values"));

            RuleFor(x => x).Must(NoDuplicateDomainsLanguageSpec).WithMessage(Label.Get("integrity.codes"));
            RuleFor(x => x).Must(NoDuplicateNamesLanguageSpec).When(x => spec.Values != null && spec.MainValues != null).WithMessage(Label.Get("integrity.values"));
        }
Exemplo n.º 5
0
 private void UpdateExistingSpec(Matrix.Specification theSpec, BuildUpdate_DTO dto)
 {
     if (dto.Map != null)
     {
         foreach (var map in dto.Map)
         {
             ClassificationRecordDTO_Create cls = theSpec.Classification.Where(x => x.Code == map.Key).FirstOrDefault();
             if (cls != null)
             {
                 cls.GeoFlag = map.Value != null;
                 cls.GeoUrl  = map.Value;
             }
         }
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Gets a Matrix_DTO object from a Matrix and Specification
 /// </summary>
 /// <param name="theMatrix"></param>
 /// <param name="spec"></param>
 /// <param name="DTO"></param>
 /// <returns></returns>
 private Matrix_DTO GetMatrixDto(Matrix theMatrix, Matrix.Specification spec, dynamic DTO)
 {
     return(new Matrix_DTO()
     {
         MtrCode = theMatrix.Code,
         FrmType = theMatrix.FormatType,
         FrmVersion = theMatrix.FormatVersion,
         MtrOfficialFlag = theMatrix.IsOfficialStatistic,
         LngIsoCode = spec.Language,
         MtrNote = spec.NotesAsString,
         CprValue = spec.Source,
         MtrTitle = spec.Contents,
         MtrInput = DTO.MtrInput
     });
 }
Exemplo n.º 7
0
        /// <summary>
        /// Creates the metadata for a specific language (px files may contain metadata in more than one language)
        /// </summary>
        /// <param name="releaseId"></param>
        /// <param name="theMatrix"></param>
        /// <param name="languageSpec"></param>
        /// <param name="username"></param>
        /// <param name="DTO"></param>
        private void CreateMatrixForLanguage(int releaseId, Matrix theMatrix, Matrix.Specification languageSpec, string username, dynamic DTO)
        {
            Matrix_ADO matrixAdo       = new Data.Matrix_ADO(Ado);
            var        matrixRecordDTO = GetMatrixDto(theMatrix, languageSpec, DTO);

            languageSpec.MatrixId = matrixAdo.CreateMatrixRecord(matrixRecordDTO, releaseId, username);

            languageSpec.Frequency.FrequencyId = CreateFrequency(languageSpec.Frequency, languageSpec.MatrixId);

            // if I have contvariable I use the content of contvariable to access the values with that value to obtain the names of stat products
            // and I use codes with same name to get the correspondent codes!
            // otherwise

            // if there is only one statistical product we use contents for the title and we set the code at zero 0

            CreateStatisticalProducts(languageSpec.Statistic, languageSpec.MatrixId);

            CreateClassifications(languageSpec.Classification, languageSpec.MatrixId);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            // Init
            List <string> FrqValues        = new List <string>();
            dynamic       validationResult = new ExpandoObject();

            validationResult.Signature         = Utility.GetMD5(Utility.GetCustomConfig("APP_SALSA") + Utility.JsonSerialize_IgnoreLoopingReference(DTO.GetSignatureDTO()));// null;
            validationResult.FrqValueCandidate = FrqValues;

            if (!Validate(validationResult.Signature) && !RequiresResponse)
            {
                return(false);
            }

            if (RequiresResponse)
            {
                //cancel any validation errors and return an object to enable the user to choose which should be the time dimension
                Matrix.Specification langSpec = MatrixData.GetSpecFromLanguage(Configuration_BSO.GetCustomConfig(ConfigType.global, "language.iso.code"));
                if (langSpec == null)
                {
                    langSpec = MatrixData.MainSpec;
                }

                foreach (var v in langSpec.MainValues)
                {
                    FrqValues.Add(v.Key);
                }

                // Set Frequency candidates
                validationResult.FrqValueCandidate = FrqValues;
                validationResult.Signature         = null;
                Response.data = validationResult;
                return(true);
            }

            // Set the Signature
            Response.data = validationResult;
            return(true);
        }
Exemplo n.º 9
0
        private IList <KeyValuePair <string, IList <IPxSingleElement> > > sortMainValuesSpc(Matrix.Specification spec)
        {
            var newValues = new List <object>();


            if (spec.MainValues.Where(x => x.Key == spec.ContentVariable).Count() > 0)
            {
                var val = spec.MainValues.Where(x => x.Key == spec.ContentVariable).FirstOrDefault();
                newValues.Add(val);
            }

            if (spec.MainValues.Where(x => x.Key == spec.Frequency.Value).Count() > 0)
            {
                var val = spec.MainValues.Where(x => x.Key == spec.Frequency.Value).FirstOrDefault();
                newValues.Add(val);
            }

            foreach (var cls in spec.Classification)
            {
                if (spec.MainValues.Where(x => x.Key == cls.Value).Count() > 0)
                {
                    var val = spec.MainValues.Where(x => x.Key == cls.Value).FirstOrDefault();
                    newValues.Add(val);
                }
            }

            spec.MainValues.Clear();
            foreach (var v in newValues)
            {
                spec.MainValues.Add((KeyValuePair <string, IList <PxParser.Resources.Parser.IPxSingleElement> >)v);
            }

            return(spec.MainValues);
        }