/// <summary>
        /// Populate DataStructure (KeyFamyly for SDMX 2.0, Structure for SDMX 2.1)
        /// property of SDMXObjectBuilder for insert this elements in DataStructure response
        /// </summary>
        public DataStructureObjectImpl BuildDSD(IDataflowObject _foundedDataflow)
        {
            try
            {
                if (!this.parsingObject.ReturnStub)
                {
                    if (!ReferencesObject.Concepts.ContainsKey(string.Format(FlyConfiguration.ConceptSchemeFormat, _foundedDataflow.Id)))
                    {
                        ConceptSchemeManager gdf = new ConceptSchemeManager((ISdmxParsingObject)this.parsingObject.Clone(), this.versionTypeResp);
                        ReferencesObject.Concepts.Add(string.Format(FlyConfiguration.ConceptSchemeFormat, _foundedDataflow.Id), gdf.GetConceptList(_foundedDataflow.Id));
                    }

                    //CodelistManager cm = new CodelistManager((ISdmxParsingObject)this.parsingObject.Clone(), this.versionTypeResp);
                    //cm.parsingObject.QueryDetail = StructureQueryDetailEnumType.AllStubs;
                    //cm.BuildCodelist(_foundedDataflow.Id);
                    //if (ReferencesObject.Codelists == null) ReferencesObject.Codelists = new List<ICodelistMutableObject>();
                    //ReferencesObject.Codelists.AddRange(cm.ReferencesObject.Codelists);
                }


                return(BuildDataStructure(_foundedDataflow.Id));
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.BuildDSD, ex);
            }
        }
Example #2
0
        /// <summary>
        /// Populate a list of Codelist property of SDMXObjectBuilder for insert this in DataStructure response
        /// Whitout Call all Dataflows
        /// </summary>
        public void BuildCodelist(string DataFlowCode)
        {
            List <IConceptObjectImpl> concepts = new ConceptSchemeManager(this.parsingObject, this.versionTypeResp).GetConceptList(DataFlowCode);

            foreach (IConceptObjectImpl concept in concepts)
            {
                BuildCodelist(DataFlowCode, concept);
            }
        }
Example #3
0
        /// <summary>
        /// retrieves the codelist Contrain from database
        /// </summary>
        /// <param name="refObj">Referenced Objects</param>
        /// <returns>list of Mutable Code Object</returns>
        public List <ICodelistMutableObject> GetCodelistReferences(IReferencesObject refObj)
        {
            if (refObj.FoundedDataflows == null)
            {
                return(new List <ICodelistMutableObject>());
            }

            if (refObj.Concepts != null)
            {
                foreach (var df in refObj.FoundedDataflows)
                {
                    List <IConceptObjectImpl> concepts = new ConceptSchemeManager(this.parsingObject, this.versionTypeResp).GetConceptList(df.Id);
                    foreach (var Concept in concepts)
                    {
                        BuildCodelist(df.Id, Concept);
                    }
                }
            }
            else
            {
                foreach (var df in refObj.FoundedDataflows)
                {
                    string cs = string.Format(FlyConfiguration.ConceptSchemeFormat, df.Id);
                    if (refObj.Concepts.ContainsKey(cs))
                    {
                        foreach (var Concept in refObj.Concepts[cs])
                        {
                            BuildCodelist(df.Id, Concept);
                        }
                    }
                    else
                    {
                        BuildCodelist(df.Id);
                    }
                    foreach (List <IConceptObjectImpl> Concepts in refObj.Concepts.Values)
                    {
                        foreach (var Concept in Concepts)
                        {
                            BuildCodelist(df.Id, Concept);
                        }
                    }
                }
            }

            return(ReferencesObject.Codelists);
        }
Example #4
0
        /// <summary>
        /// retrieves the codelist Contrain  from database
        /// </summary>
        /// <returns>list of Mutable Code Object</returns>
        public List <ICodelistMutableObject> GetCodelistConstrain()
        {
            if (ReferencesObject == null)
            {
                ReferencesObject = new IReferencesObject();
            }

            if (ReferencesObject.FoundedDataflows == null || ReferencesObject.FoundedDataflows.Count == 0)
            {
                IDataflowsManager gdf = new MetadataFactory().InstanceDataflowsManager((ISdmxParsingObject)this.parsingObject.Clone(), this.versionTypeResp);
                gdf.parsingObject.MaintainableId  = null;
                ReferencesObject.FoundedDataflows = gdf.GetDataFlows();
            }

            if (ReferencesObject.FoundedDataflows == null || ReferencesObject.FoundedDataflows.Count == 0)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.DataflowNotFound, new Exception(this.parsingObject.ConstrainDataFlow));
            }

            if (ReferencesObject.Concepts == null)
            {
                ReferencesObject.Concepts = new Dictionary <string, List <IConceptObjectImpl> >();
            }

            IConceptObjectImpl Concept = null;
            SpecialTypeEnum    specType;

            if (!string.IsNullOrEmpty(this.parsingObject.MaintainableId) &&
                Enum.TryParse <SpecialTypeEnum>(this.parsingObject.MaintainableId.Trim().ToUpper(), out specType) &&
                this.parsingObject.AgencyId == "MA")
            {
                if (!string.IsNullOrEmpty(this.parsingObject.ConstrainConcept))
                {
                    Concept = new SpecialConcept(this.parsingObject.ConstrainConcept, specType);
                }
                else
                {
                    Concept = new SpecialConcept(specType.ToString(), specType);
                }
                Concept.CodelistCode = this.parsingObject.MaintainableId;
            }
            else
            {
                List <IConceptObjectImpl> concepts = new ConceptSchemeManager(this.parsingObject, this.versionTypeResp).GetConceptList(this.parsingObject.ConstrainDataFlow);
                ReferencesObject.Concepts.Add(string.Format(FlyConfiguration.ConceptSchemeFormat, this.parsingObject.ConstrainDataFlow), concepts);
                Concept = concepts.Find(c => c.ConceptObjectCode.Trim().ToLower() == this.parsingObject.ConstrainConcept.Trim().ToLower());
                if (Concept == null)
                {
                    throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CodelistInvalid, new Exception(string.Format("Concept {0} Not Found in Dataflow {1}", this.parsingObject.ConstrainConcept, this.parsingObject.ConstrainDataFlow)));
                }

                if (this.parsingObject.ContrainConceptREF != null && this.parsingObject.ContrainConceptREF.Keys.Count > 0)
                {
                    ISpecialConcept sc = new SpecialConcept(Concept.Id, SpecialTypeEnum.CL_CONTRAINED);
                    sc.CodelistCode = Concept.CodelistCode;
                    sc.SetNames(Concept.ConceptObjectNames);
                    sc.TimeDimensionRef   = concepts.Find(c => c.ConceptType == ConceptTypeEnum.Dimension && ((IDimensionConcept)c).DimensionType == DimensionTypeEnum.Time);
                    sc.ContrainConceptREF = this.parsingObject.ContrainConceptREF;
                    Concept = sc;
                }
            }

            BuildCodelist(this.parsingObject.ConstrainDataFlow, Concept);
            return(ReferencesObject.Codelists);
        }
Example #5
0
        /// <summary>
        /// retrieves the codelist Contrain from database
        /// </summary>
        /// <returns>list of Mutable Code Object</returns>
        public List <ICodelistMutableObject> GetCodelistNoConstrain()
        {
            if (ReferencesObject == null)
            {
                ReferencesObject = new IReferencesObject();
            }


            if (ReferencesObject.FoundedDataflows == null || ReferencesObject.FoundedDataflows.Count == 0)
            {
                IDataflowsManager gdf = new MetadataFactory().InstanceDataflowsManager((ISdmxParsingObject)this.parsingObject.Clone(), this.versionTypeResp);
                gdf.parsingObject.MaintainableId  = null;
                ReferencesObject.FoundedDataflows = gdf.GetDataFlows();
            }

            if (ReferencesObject.FoundedDataflows == null || ReferencesObject.FoundedDataflows.Count == 0)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.DataflowNotFound, new Exception(this.parsingObject.ConstrainDataFlow));
            }

            if (ReferencesObject.Concepts == null)
            {
                ReferencesObject.Concepts = new Dictionary <string, List <IConceptObjectImpl> >();
            }
            foreach (var df in ReferencesObject.FoundedDataflows)
            {
                List <IConceptObjectImpl> concepts = new ConceptSchemeManager(this.parsingObject, this.versionTypeResp).GetConceptList(df.Id);
                ReferencesObject.Concepts.Add(string.Format(FlyConfiguration.ConceptSchemeFormat, df.Id), concepts);
                if (!string.IsNullOrEmpty(this.parsingObject.MaintainableId))
                {
                    string PossibleDimTable = this.parsingObject.MaintainableId.Trim().ToUpper();
                    string PossibleAttTable = this.parsingObject.MaintainableId.Trim().ToUpper();
                    if (PossibleDimTable.StartsWith(FlyConfiguration.CodelistFormat.ToUpper().Replace("{0}", "")))
                    {
                        PossibleDimTable = string.Format("DIM{0}", PossibleDimTable.Substring(FlyConfiguration.CodelistFormat.ToUpper().Replace("{0}", "").Length));
                        PossibleAttTable = string.Format("ATT{0}", PossibleDimTable.Substring(FlyConfiguration.CodelistFormat.ToUpper().Replace("{0}", "").Length));
                    }
                    else if (PossibleDimTable.EndsWith(FlyConfiguration.CodelistFormat.ToUpper().Replace("{0}", "")))
                    {
                        PossibleDimTable = string.Format("DIM{0}", PossibleDimTable.Substring(0, PossibleDimTable.Length - FlyConfiguration.CodelistFormat.ToUpper().Replace("{0}", "").Length));
                        PossibleAttTable = string.Format("ATT{0}", PossibleDimTable.Substring(0, PossibleDimTable.Length - FlyConfiguration.CodelistFormat.ToUpper().Replace("{0}", "").Length));
                    }
                    IConceptObjectImpl Concept = concepts.Find(c => !string.IsNullOrEmpty(c.CodelistCode) && (c.CodelistCode.Trim().ToUpper() == PossibleDimTable || c.CodelistCode.Trim().ToUpper() == PossibleAttTable));
                    if (Concept == null)
                    {
                        continue;
                    }

                    BuildCodelist(null, Concept);
                    break;
                }
                else
                {
                    foreach (var Concept in concepts)
                    {
                        BuildCodelist(null, Concept);
                    }
                }
            }
            return(ReferencesObject.Codelists);
        }
        private DataStructureObjectImpl BuildDataStructure(string _foundedDataflowId)
        {
            try
            {
                string ConceptSchemeId = string.Format(FlyConfiguration.ConceptSchemeFormat, _foundedDataflowId);
                List <IComponentMutableObject> components = new List <IComponentMutableObject>();

                if (!this.ReferencesObject.Concepts.ContainsKey(ConceptSchemeId))
                {
                    ConceptSchemeManager gdf = new ConceptSchemeManager((ISdmxParsingObject)this.parsingObject.Clone(), this.versionTypeResp);
                    ReferencesObject.Concepts.Add(string.Format(FlyConfiguration.ConceptSchemeFormat, _foundedDataflowId), gdf.GetConceptList(_foundedDataflowId));
                }
                if (!this.ReferencesObject.Concepts.ContainsKey(ConceptSchemeId))
                {
                    throw new Exception("ConceptScheme not found");
                }

                List <IConceptObjectImpl> conceptsObject = this.ReferencesObject.Concepts[ConceptSchemeId];
                if (!this.parsingObject.ReturnStub)
                {
                    foreach (IConceptObjectImpl _concept in conceptsObject)
                    {
                        //Cerco la giusta Codelist
                        ICodelistMutableObject _CodelistAssociata = null;
                        if (this.ReferencesObject.Codelists != null)
                        {
                            _CodelistAssociata = this.ReferencesObject.Codelists.Find(cl => cl.Id.ToUpper() == _concept.CodelistCode);
                        }
                        // CodelistBuilder _CodelistAssociata = this._Codelists.Find(cl => cl.Concept.ConceptObjectCode == _concept.ConceptObjectCode);
                        //Capire se è un attribute/Dimension
                        if (_CodelistAssociata == null)
                        {
                            CodelistManager cm = new CodelistManager((ISdmxParsingObject)this.parsingObject.Clone(), this.versionTypeResp);
                            if (!String.IsNullOrEmpty(_concept.CodelistCode))
                            {
                                cm.parsingObject.MaintainableId = string.Format(FlyConfiguration.CodelistFormat, _concept.CodelistCode.Substring(3));
                            }
                            else
                            {
                                cm.parsingObject.MaintainableId = null;
                            }
                            cm.parsingObject.QueryDetail = StructureQueryDetailEnumType.AllStubs;
                            cm.BuildCodelist(_foundedDataflowId, _concept);
                            if (cm.ReferencesObject.Codelists != null && cm.ReferencesObject.Codelists.Count > 0)
                            {
                                _CodelistAssociata = cm.ReferencesObject.Codelists[0];
                            }
                        }

                        if (_CodelistAssociata != null)
                        {
                            _concept.ConceptDSDInfo = new ConceptDSDInfoObject()
                            {
                                CodelistId      = _CodelistAssociata.Id,
                                CodelistAgency  = _CodelistAssociata.AgencyId,
                                CodelistVersion = _CodelistAssociata.Version
                            };
                        }

                        switch (_concept.ConceptType)
                        {
                        case ConceptTypeEnum.Dimension:
                            //Se è una Dimension Capire che tipologia di Dimension è Frequency/Time
                            switch (((IDimensionConcept)_concept).DimensionType)
                            {
                            case DimensionTypeEnum.Dimension:
                                DimensionMutableCore dim = new DimensionMutableCore();
                                dim.ConceptRef = ReferenceBuilder.CreateConceptReference(ConceptSchemeId, _concept.Id);
                                dim.Id         = _concept.Id;
                                if (_CodelistAssociata != null)
                                {
                                    dim.Representation = new RepresentationMutableCore()
                                    {
                                        Representation = ReferenceBuilder.CreateCodelistReference(_CodelistAssociata.Id),
                                    };
                                }
                                components.Add(dim);
                                break;

                            case DimensionTypeEnum.Time:
                                DimensionMutableCore TimeDim = new DimensionMutableCore();
                                TimeDim.ConceptRef    = ReferenceBuilder.CreateConceptReference(ConceptSchemeId, _concept.ConceptObjectCode);
                                TimeDim.Id            = _concept.ConceptObjectCode;
                                TimeDim.TimeDimension = true;
                                components.Add(TimeDim);

                                break;

                            case DimensionTypeEnum.Frequency:
                                DimensionMutableCore FreqDim = new DimensionMutableCore();
                                FreqDim.ConceptRef = ReferenceBuilder.CreateConceptReference(ConceptSchemeId, _concept.ConceptObjectCode);
                                if (_CodelistAssociata != null)
                                {
                                    FreqDim.Representation = new RepresentationMutableCore()
                                    {          ////Si da per scontato che la frequency la codelist ce l'abbia
                                        Representation = ReferenceBuilder.CreateCodelistReference(_CodelistAssociata.Id),
                                    };
                                }
                                FreqDim.Id = _concept.ConceptObjectCode;
                                FreqDim.FrequencyDimension = true;

                                if (FreqDim.ConceptRole != null)
                                {
                                    FreqDim.ConceptRole.Add(new StructureReferenceImpl("ESTAT", "ESTAT_CONCEPT_ROLES_SCHEME", "0.1", SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Concept), new List <string> {
                                        "FREQUENCY"
                                    }));
                                }

                                components.Add(FreqDim);
                                break;

                            default:
                                break;
                            }

                            break;

                        case ConceptTypeEnum.Attribute:

                            AttributeMutableCore attr = new AttributeMutableCore();
                            attr.ConceptRef = ReferenceBuilder.CreateConceptReference(ConceptSchemeId, _concept.ConceptObjectCode);
                            if (_CodelistAssociata != null)
                            {
                                IRepresentationMutableObject representation = new RepresentationMutableCore();
                                representation.Representation = ReferenceBuilder.CreateCodelistReference(_CodelistAssociata.Id);
                                attr.Representation           = representation;
                            }
                            //Aggiungo attributi all'attribute AssignmentStatus e AttachmentLevel
                            attr.AssignmentStatus = ((IAttributeConcept)_concept).AssignmentStatusType.ToString();
                            attr.AttachmentLevel  = ((IAttributeConcept)_concept).AttributeAttachmentLevelType;
                            if (attr.AttachmentLevel == AttributeAttachmentLevel.DimensionGroup)
                            {
                                foreach (var dimref in ((IAttributeConcept)_concept).GetDimensionsReference(ReferencesObject.Concepts[ConceptSchemeId]))
                                {
                                    attr.DimensionReferences.Add(dimref);
                                }
                            }
                            if (attr.AttachmentLevel == AttributeAttachmentLevel.Group)
                            {
                                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.AttributeErrorAttachmentGroup);
                            }

                            //if (_CodelistAssociata.CodesObjects == null || _CodelistAssociata.CodesObjects.Count == 0)
                            //{//levo dall'attribute la referenza alla codelist
                            //    attr.Representation = null;
                            //}

                            if (((IAttributeConcept)_concept).IsValueAttribute)
                            {
                                PrimaryMeasureMutableCore PrimaryMeasure = new PrimaryMeasureMutableCore();    //SdmxStructureType.GetFromEnum(SdmxStructureEnumType.PrimaryMeasure));
                                PrimaryMeasure.ConceptRef = ReferenceBuilder.CreateConceptReference(ConceptSchemeId, _concept.ConceptObjectCode);
                                components.Add(PrimaryMeasure);
                            }
                            else
                            {
                                components.Add(attr);
                            }
                            break;
                        }
                    }
                }
                this.ReferencesObject.Codelists = null;
                DataStructureBuilder _DataStructureBuilder = new DataStructureBuilder(conceptsObject, this.parsingObject, this.versionTypeResp);
                _DataStructureBuilder.Code  = string.Format(FlyConfiguration.DsdFormat, _foundedDataflowId);
                _DataStructureBuilder.Names = new List <SdmxObjectNameDescription>();
                foreach (var nome in ReferencesObject.FoundedDataflows.Find(df => df.Id == _foundedDataflowId).Names)
                {
                    _DataStructureBuilder.Names.Add(new SdmxObjectNameDescription()
                    {
                        Lingua = nome.Locale, Name = nome.Value
                    });
                }

                return(_DataStructureBuilder.BuildDataStructure(components, null, FlyConfiguration.MainAgencyId, FlyConfiguration.Version));
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex);
            }
        }