Example #1
0
        /// <summary>
        /// The populate attributes.
        /// </summary>
        /// <param name="parent">
        /// The parent.
        /// </param>
        /// <param name="dataReader">
        /// The data reader.
        /// </param>
        /// <returns>
        /// The <see cref="IComponentMutableObject"/>.
        /// </returns>
        /// <exception cref="SdmxNotImplementedException">
        /// Unsupported attachment level at COMPONENT.ATT_ASS_LEVEL
        /// </exception>
        private static IComponentMutableObject PopulateAttributes(IDataStructureMutableObject parent, IDataRecord dataReader)
        {
            var attribute = new AttributeMutableCore {
                AssignmentStatus = DataReaderHelper.GetString(dataReader, "ATT_STATUS")
            };

            // TODO pending support already in Java
            ////attribute.TimeFormat = DataReaderHelper.GetBoolean(dataReader, "ATT_IS_TIME_FORMAT")
            ////                           ? "true"
            ////                           : "false";
            string attachmentLevel = DataReaderHelper.GetString(dataReader, "ATT_ASS_LEVEL");

            switch (attachmentLevel)
            {
            case AttachmentLevelConstants.DataSet:
                attribute.AttachmentLevel = AttributeAttachmentLevel.DataSet;
                break;

            case AttachmentLevelConstants.Group:
                attribute.AttachmentLevel = AttributeAttachmentLevel.Group;
                break;

            case AttachmentLevelConstants.Observation:
                attribute.AttachmentLevel = AttributeAttachmentLevel.Observation;
                break;

            case AttachmentLevelConstants.Series:
                attribute.AttachmentLevel = AttributeAttachmentLevel.DimensionGroup;

                break;

            default:
                throw new SdmxNotImplementedException(ExceptionCode.Unsupported, "Attachment:" + attachmentLevel);
            }

            IComponentMutableObject component = attribute;

            parent.AddAttribute(attribute);
            return(component);
        }
        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);
            }
        }