Ejemplo n.º 1
0
        /// <summary>
        /// Retrieves all available dataflows.
        /// </summary>
        private IComplexStructureQuery RetrieveDataflows()
        {
            var dataflowRefBean = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dataflow));
            IRestStructureQuery structureQueryDataflow = new RESTStructureQueryCore(dataflowRefBean);

            IBuilder <IComplexStructureQuery, IRestStructureQuery> transformerDataFlow = new StructureQuery2ComplexQueryBuilder();

            IComplexStructureQuery complexStructureQueryDataflow = transformerDataFlow.Build(structureQueryDataflow);

            IList <SdmxStructureType> specificObjects = new List <SdmxStructureType>();

            specificObjects.Add(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dsd));

            IComplexStructureQueryMetadata complexStructureQueryMetadataWithDsd =
                new ComplexStructureQueryMetadataCore(false,
                                                      ComplexStructureQueryDetail.GetFromEnum(ComplexStructureQueryDetailEnumType.Full),
                                                      ComplexMaintainableQueryDetail.GetFromEnum(ComplexMaintainableQueryDetailEnumType.Full),
                                                      StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.Specific),
                                                      specificObjects);

            IComplexStructureQuery complexStructureQueryTempDataflow = new ComplexStructureQueryCore(
                complexStructureQueryDataflow.StructureReference, complexStructureQueryMetadataWithDsd);

            return(complexStructureQueryTempDataflow);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves all available categorisations and category schemes.
        /// </summary>
        private IComplexStructureQuery RetrieveCategorySchemesAndCategorisations()
        {
            var catSch = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CategoryScheme));
            IRestStructureQuery structureQueryCategoryScheme = new RESTStructureQueryCore(StructureQueryDetail.GetFromEnum(StructureQueryDetailEnumType.Full), StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.Parents), null, catSch, false);
            IBuilder <IComplexStructureQuery, IRestStructureQuery> transformerCategoryScheme = new StructureQuery2ComplexQueryBuilder();

            IComplexStructureQuery complexStructureQueryCategoryScheme = transformerCategoryScheme.Build(structureQueryCategoryScheme);

            return(complexStructureQueryCategoryScheme);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves all available dataflows.
        /// </summary>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string RetrieveDataflows()
        {
            var dataflowRefBean = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dataflow));

            IRestStructureQuery            structureQuery = new RESTStructureQueryCore(StructureQueryDetail.GetFromEnum(StructureQueryDetailEnumType.Full), StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.Specific), SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dsd), dataflowRefBean, true);
            IStructureQueryFactory         factory        = new RestStructureQueryFactory();
            IStructureQueryBuilderManager  structureQueryBuilderManager = new StructureQueryBuilderManager(factory);
            IStructureQueryFormat <string> structureQueryFormat         = new RestQueryFormat();
            string request = structureQueryBuilderManager.BuildStructureQuery(structureQuery, structureQueryFormat);

            return(request);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieves all available categorisations and category schemes.
        /// </summary>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string RetrieveCategorySchemesAndCategorisations()
        {
            var catSch = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CategoryScheme));
            IStructureQueryFormat <string> structureQueryFormat         = new RestQueryFormat();
            IRestStructureQuery            structureQueryCategoryScheme = new RESTStructureQueryCore(StructureQueryDetail.GetFromEnum(StructureQueryDetailEnumType.Full), StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.Parents), null, catSch, false);
            IStructureQueryFactory         factory = new RestStructureQueryFactory();

            IStructureQueryBuilderManager structureQueryBuilderManager = new StructureQueryBuilderManager(factory);
            string request = structureQueryBuilderManager.BuildStructureQuery(structureQueryCategoryScheme, structureQueryFormat);

            return(request);
        }
        /// <summary>
        /// Initialie a new instance of the <see cref="RetrievalManager"/> class.
        /// </summary>
        /// <param name="_dataFlowID">
        /// Dataflow ID
        /// </param>
        /// <param name="_versionType">Sdmx Version</param>
        public RetrievalManager(string _dataFlowID, SdmxSchemaEnumType _versionType)
        {
            try
            {
                this.DataFlowID  = _dataFlowID;
                this.VersionType = _versionType;
                DataStructureEngineObject ds      = new DataStructureEngineObject();
                ISDMXObjectBuilder        Builder = ds.CreateBuilder(new SdmxParsingObject(SdmxStructureEnumType.Dataflow)
                {
                    MaintainableId    = DataFlowID,
                    References        = StructureReferenceDetailEnumType.Specific,
                    SpecificReference = new List <SdmxStructureType>()
                    {
                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dsd),
                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptScheme),
                    },
                    QueryDetail = StructureQueryDetailEnumType.Full,
                }, _versionType);

                Builder.Build();
                Builder.AddReferences();

                if (Builder._KeyFamily == null || Builder._KeyFamily.Count == 0)
                {
                    throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.InternalError, new Exception(string.Format("Dsd Not found for Dataflow code: {0}", DataFlowID)));
                }

                //1DF = 1DSD
                this._dsd = Builder._KeyFamily[0];


                if (Builder._Dataflows.Count > 0)
                {
                    this.DataFlowTitle = Builder._Dataflows[0].Name;
                }
                else
                {
                    throw new Exception("No Dataflow Found");
                }
                this._sdmxObjects = Builder.CreateDSD();


                this.DataFlowID = Builder._Dataflows[0].Id;
                GetGroups();
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.InternalError, ex);
                //non sono riuscito a cambiare il nome che è arrivato dalla query con quello effettivo della dsd
            }
        }
Ejemplo n.º 6
0
        private string RetrieveDataflow(string id, string agency, string version)
        {
            IMaintainableRefObject df = new MaintainableRefObjectImpl(agency, id, version);
            var dataflowRefBean       = new StructureReferenceImpl(df, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dataflow));

            IRestStructureQuery            structureQuery = new RESTStructureQueryCore(StructureQueryDetail.GetFromEnum(StructureQueryDetailEnumType.Full), StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.Specific), SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dsd), dataflowRefBean, true);
            IStructureQueryFactory         factory        = new RestStructureQueryFactory();
            IStructureQueryBuilderManager  structureQueryBuilderManager = new StructureQueryBuilderManager(factory);
            IStructureQueryFormat <string> structureQueryFormat         = new RestQueryFormat();
            string request = structureQueryBuilderManager.BuildStructureQuery(structureQuery, structureQueryFormat);

            return(request);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="artefact"></param>
        /// <param name="sysId"></param>
        private void PopulateConstraintGeneral(IContentConstraintMutableObject artefact, long sysId)
        {
            var inParameter = MappingStoreDb.CreateInParameter(ParameterNameConstants.IdParameter, DbType.Int64, sysId);

            using (DbCommand command = MappingStoreDb.GetSqlStringCommandParam(ContentConstraintConstant.SqlConsInfo, inParameter))
            {
                using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command))
                {
                    bool bGeneral = true;

                    artefact.ReleaseCalendar      = new ReleaseCalendarMutableCore();
                    artefact.ConstraintAttachment = new ContentConstraintAttachmentMutableCore();

                    while (dataReader.Read())
                    {
                        if (bGeneral)
                        {
                            if (dataReader["PERIODICITY"] != DBNull.Value)
                            {
                                artefact.ReleaseCalendar.Periodicity = dataReader["PERIODICITY"].ToString();
                            }

                            if (dataReader["OFFSET"] != DBNull.Value)
                            {
                                artefact.ReleaseCalendar.Offset = dataReader["OFFSET"].ToString();
                            }

                            if (dataReader["TOLERANCE"] != DBNull.Value)
                            {
                                artefact.ReleaseCalendar.Tolerance = dataReader["TOLERANCE"].ToString();
                            }

                            if (String.IsNullOrEmpty(artefact.ReleaseCalendar.Periodicity))
                            {
                                artefact.ReleaseCalendar = null;
                            }

                            bGeneral = false;
                        }


                        IStructureReference structRef = new StructureReferenceImpl(dataReader["AGENCY"].ToString(),
                                                                                   dataReader["ID"].ToString(), dataReader["VERSION"].ToString(),
                                                                                   SdmxStructureType.GetFromEnum((SdmxStructureEnumType)Enum.Parse(typeof(SdmxStructureEnumType), dataReader["ARTEFACT_TYPE"].ToString())),
                                                                                   new string[] { });

                        artefact.ConstraintAttachment.AddStructureReference(structRef);
                    }
                }
            }
        }
        /// <summary>
        /// Build concept scheme requests from the concept scheme references of the specified KeyFamilyBean object
        /// </summary>
        /// <param name="kf">
        /// The KeyFamily to look for concept Scheme references
        /// </param>
        /// <returns>
        /// A list of concept scheme requests
        /// </returns>
        public static IEnumerable <IStructureReference> BuildConceptSchemeRequest(IDataStructureObject kf)
        {
            var conceptSchemeSet = new Dictionary <string, object>();
            var ret      = new List <IStructureReference>();
            var crossDsd = kf as ICrossSectionalDataStructureObject;

            List <IComponent> components = new List <IComponent>();

            components.AddRange(kf.GetDimensions());
            components.AddRange(kf.Attributes);
            if (kf.PrimaryMeasure != null)
            {
                components.Add(kf.PrimaryMeasure);
            }
            if (crossDsd != null)
            {
                components.AddRange(crossDsd.CrossSectionalMeasures);
            }

            ICollection <IComponent> comps = components;

            foreach (IComponent comp in comps)
            {
                string key = Utils.MakeKey(comp.ConceptRef.MaintainableReference.MaintainableId, comp.ConceptRef.MaintainableReference.Version, comp.ConceptRef.MaintainableReference.AgencyId);
                if (!conceptSchemeSet.ContainsKey(key))
                {
                    // create concept ref


                    var conceptSchemeRef = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptScheme))
                    {
                        MaintainableId = comp.ConceptRef.MaintainableReference.MaintainableId,
                        AgencyId       = comp.ConceptRef.MaintainableReference.AgencyId,
                        Version        = comp.ConceptRef.MaintainableReference.Version
                    };

                    // add it to request
                    ret.Add(conceptSchemeRef);

                    // added it to set of visited concept schemes
                    conceptSchemeSet.Add(key, null);
                }
            }

            return(ret);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets a bean with data about the key family for specified dataflow.
        /// </summary>
        /// <param name="dataflow">
        /// The dataflow
        /// </param>
        /// <returns>
        /// a <c>StructureBean</c> instance with requested data; the result is never <c>null</c> or  incomplete, instead an exception is throwed away if something goes wrong and not all required data is successfully retrieved
        /// </returns>
        /// <remarks>
        /// The resulted bean will contain exactly one key family, but also will include any concepts and codelists referenced by the key family.
        /// </remarks>
        public ISdmxObjects GetStructure(IDataflowObject dataflow, ISet <IDataStructureObject> dataStructures, bool resolseRef = false)
        {
            Logger.InfoFormat(
                CultureInfo.InvariantCulture,
                Resources.InfoGettingStructureFormat3,
                dataflow.AgencyId,
                dataflow.Id,
                dataflow.Version);
            ISdmxObjects structure;

            var keyFamilyRefBean = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dsd))
            {
                MaintainableId = dataflow.DataStructureRef.MaintainableReference.MaintainableId,
                AgencyId       = dataflow.DataStructureRef.MaintainableReference.AgencyId,
                Version        = dataflow.DataStructureRef.MaintainableReference.Version
            };

            try
            {
                ISdmxObjects response;

                structure = this.SendQueryStructureRequest(keyFamilyRefBean, false);
                NsiClientValidation.CheckifStructureComplete(structure, dataflow);
                IEnumerable <IStructureReference> conceptRefs = NsiClientHelper.BuildConceptSchemeRequest(structure.DataStructures.First());
                response = this.SendQueryStructureRequest(conceptRefs, false);

                structure.Merge(response);

                NsiClientValidation.CheckConcepts(structure);
                Logger.Info(Resources.InfoSuccess);
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw new NsiClientException(Resources.ExceptionGettingStructure, e);
            }

            return(structure);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Retrieves all available categorisations.
        /// </summary>
        /// <returns>
        ///   a list of &amp;lt;c&amp;gt;ISdmxObjects&amp;lt;/c&amp;gt; instances; the result won&amp;apos;t be &amp;lt;c&amp;gt;null&amp;lt;/c&amp;gt; if there are no
        ///   dataflows, instead an empty list will be returned
        /// </returns>
        public ISdmxObjects RetrieveCategorisations()
        {
            Logger.Info(Resources.InfoGettingCategorySchemes);

            ISdmxObjects response = new SdmxObjectsImpl();

            //get dataflows
            var dataflowRefBean = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dataflow));
            //get category scheme
            var catSch = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CategoryScheme));

            IList <IStructureReference> refs = new List <IStructureReference>();

            refs.Add(catSch);
            refs.Add(dataflowRefBean);
            try
            {
                response = this.SendQueryStructureRequest(refs, false);

                if (response.CategorySchemes != null && response.Dataflows != null)
                {
                    Logger.Info(Resources.InfoSuccess);
                }
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionGettingDataflow);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (DataflowException e)
            {
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionGettingDataflow);
                Logger.Error(e.Message, e);
                throw new NsiClientException(Resources.ExceptionGettingDataflow, e);
            }
            if (response.Dataflows != null && response.Dataflows.Count == 0)
            {
                throw new DataflowException(Resources.NoResultsFound);
            }
            return(response);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets a bean with data about the codelist for specified dataflow and component.
        /// The dataflow can be retrieved from <see cref="RetrieveTree"/> and the component from <see cref="GetStructure"/>
        /// </summary>
        /// <param name="dataflow">
        /// The dataflow
        /// </param>
        /// <param name="component">
        /// The component
        /// </param>
        /// <param name="criteria">
        /// The criteria includes a set of Member and MemberValue(s) for each dimension. The Member has componentRef the dimension conceptRef and the MemberValue(s) specify the selected codes for this dimension.
        /// </param>
        /// <returns>
        /// A <c>CodeListBean</c> with the requested data
        /// </returns>
        public ICodelistObject GetCodelist(
            IDataflowObject dataflow,
            IDataStructureObject dsd,
            IComponent component,
            List <IContentConstraintMutableObject> criterias,
            bool Constrained)
        {
            var codelistRef = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList));
            var dimension   = component as IDimension;

            if (dimension != null && dimension.TimeDimension)
            {
                codelistRef.MaintainableId = CustomCodelistConstants.TimePeriodCodeList;
                codelistRef.AgencyId       = CustomCodelistConstants.Agency;
                codelistRef.Version        = CustomCodelistConstants.Version;
            }
            else if (dimension != null && dimension.MeasureDimension && dsd is ICrossSectionalDataStructureObject)
            {
                var crossDsd = dsd as ICrossSectionalDataStructureObject;
                codelistRef.MaintainableId = crossDsd.GetCodelistForMeasureDimension(dimension.Id).MaintainableReference.MaintainableId;
                codelistRef.AgencyId       = crossDsd.GetCodelistForMeasureDimension(dimension.Id).MaintainableReference.AgencyId;
                codelistRef.Version        = crossDsd.GetCodelistForMeasureDimension(dimension.Id).MaintainableReference.Version;
            }
            else
            {
                if (component.HasCodedRepresentation())
                {
                    codelistRef.MaintainableId = component.Representation.Representation.MaintainableReference.MaintainableId;
                    codelistRef.AgencyId       = component.Representation.Representation.MaintainableReference.AgencyId;
                    codelistRef.Version        = component.Representation.Representation.MaintainableReference.Version;
                }
            }

            string info = string.Format(
                CultureInfo.InvariantCulture,
                Resources.InfoPartialCodelistFormat3,
                Utils.MakeKey(dataflow),
                component.ConceptRef,
                Utils.MakeKey(codelistRef));

            return(this.GetCodelist(dataflow, codelistRef, criterias, info, Constrained));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Get the maximum number of observations that can be retrieved given the specified criteria
        /// </summary>
        /// <param name="dataflow">
        /// The dataflow
        /// </param>
        /// <param name="criteria">
        /// The criteria includes a set of Member and MemberValue(s) for each dimension. Each member should have member values else they shouldn't be included. It can be null
        /// </param>
        /// <returns>
        /// The maximum number of observations or -1 if it can't be parsed or it is not available
        /// </returns>
        /// <exception cref="NsiClientException">
        /// NSI WS communication error or parsing error
        /// </exception>
        public int GetDataflowDataCount(IDataflowObject dataflow, IContentConstraintMutableObject criteria)
        {
            int count;
            List <IContentConstraintMutableObject> criterias = new List <IContentConstraintMutableObject>();

            if (criteria == null)
            {
                criteria = new ContentConstraintMutableCore();
            }

            criteria.Id = CustomCodelistConstants.CountCodeList;
            criteria.AddName("en", "name");
            criteria.AgencyId = "agency";
            criterias.Add(criteria);

            var codelistRef = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList))
            {
                MaintainableId = CustomCodelistConstants.CountCodeList,
                AgencyId       = CustomCodelistConstants.Agency,
                Version        = CustomCodelistConstants.Version
            };
            string info = string.Format(CultureInfo.InvariantCulture, Resources.InfoCountFormat2, Utils.MakeKey(dataflow), Utils.MakeKey(codelistRef));

            try
            {
                ICodelistObject countCodelist = this.GetCodelist(dataflow, codelistRef, criterias, info, true);
                if (!CustomCodelistConstants.IsCountCodeList(countCodelist) ||
                    !int.TryParse(countCodelist.Items[0].Id, out count))
                {
                    Logger.WarnFormat(CultureInfo.InvariantCulture, Resources.ExceptionParsingCountCodelistFormat0, info);

                    throw new NsiClientException("Error parsing the count codelist for " + info);
                }
            }
            catch (NsiClientException ex)
            {
                Logger.Warn(ex.Message, ex);
                count = -1;
            }

            return(count);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Generic method for retrieving <see cref="IStructureReference"/> based objects
 /// </summary>
 /// <param name="outList">
 /// The output list
 /// </param>
 /// <param name="command">
 /// The current <see cref="DbCommand"/>
 /// </param>
 /// <param name="structureType">
 /// The structure Type.
 /// </param>
 protected void RetrieveRef(ICollection <IStructureReference> outList, DbCommand command, SdmxStructureEnumType structureType)
 {
     _log.DebugFormat("RetrieveRef of {0} SQL : {1}", structureType, command.CommandText);
     using (IDataReader dataReader = this._mappingStoreDb.ExecuteReader(command))
     {
         int idField      = dataReader.GetOrdinal("ID");
         int agencyField  = dataReader.GetOrdinal("AGENCY");
         int versionField = dataReader.GetOrdinal("VERSION");
         while (dataReader.Read())
         {
             var item = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(structureType))
             {
                 MaintainableId = DataReaderHelper.GetString(dataReader, idField),
                 Version        = DataReaderHelper.GetString(dataReader, versionField),
                 AgencyId       = DataReaderHelper.GetString(dataReader, agencyField)
             };
             outList.Add(item);
         }
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Returns the referenced from inner joins to use with <see cref="ArtefactParentsSqlBuilder"/>
        /// </summary>
        /// <param name="structureEnumType">
        ///     The structure  type.
        /// </param>
        /// <returns>
        /// The referenced from inner joins
        /// </returns>
        protected override string GetReferencedFromInnerJoins(SdmxStructureEnumType structureEnumType)
        {
            string innerJoin = null;

            switch (structureEnumType)
            {
            case SdmxStructureEnumType.Category:
            case SdmxStructureEnumType.CategoryScheme:
                innerJoin = CategorySchemeConstant.ReferencedByCategorisation;
                break;

            default:
                if (SdmxStructureType.GetFromEnum(structureEnumType).IsMaintainable)
                {
                    innerJoin = CategorisationConstant.ReferencedByCategorisation;
                }

                break;
            }

            return(innerJoin);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Gets a bean with data about the codelist for specified dataflow and codelist ref.
        /// The dataflow can be retrieved from <see cref="RetrieveDataflow"/>
        /// </summary>
        /// <param name="dataflow">
        /// The dataflow
        /// </param>
        /// <param name="codelistRef">
        /// The codelist reference
        /// </param>
        /// <param name="criteria">
        /// The criteria includes a set of Member and MemberValue(s) for each dimension.
        /// </param>
        /// <param name="info">
        /// Some helper information used for logging
        /// </param>
        /// <returns>
        /// The partial codelist.
        /// </returns>
        private ICodelistObject GetCodelist(
            IDataflowObject dataflow,
            IStructureReference codelistRef,
            List <IContentConstraintMutableObject> criterias,
            string info,
            bool Constrained)
        {
            ICodelistObject codelist;

            var refs = new List <IStructureReference>();

            refs.Add(codelistRef);

            if (Constrained)
            {
                var dataflowRef = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dataflow))
                {
                    MaintainableId = dataflow.Id,
                    AgencyId       = dataflow.AgencyId,
                    Version        = dataflow.Version,
                };

                foreach (var criteria in criterias)
                {
                    var dataflowRefBean = new ConstrainableStructureReference(dataflowRef, criteria.ImmutableInstance);

                    Logger.InfoFormat(CultureInfo.InvariantCulture, Resources.InfoGettingCodelistFormat1, info);

                    refs.Add(dataflowRefBean);
                }
            }

            try
            {
                ISdmxObjects response;

                response = this.SendQueryStructureRequest(refs, false);

                if (response.Codelists.Count != 1)
                {
                    string message = string.Format(
                        CultureInfo.InvariantCulture, Resources.ExceptionInvalidNumberOfCodeListsFormat1, info);
                    Logger.Error(message);
                    throw new NsiClientException(message);
                }

                codelist = response.Codelists.First();
                if (codelist.Items.Count == 0)
                {
                    string message = string.Format(
                        CultureInfo.InvariantCulture, Resources.ExceptionZeroCodesFormat1, info);
                    Logger.Error(message);
                    throw new NsiClientException(message);
                }
            }
            catch (NsiClientException e)
            {
                string message = string.Format(
                    CultureInfo.InvariantCulture, Resources.ExceptionGetCodelistFormat2, info, e.Message);
                Logger.Error(message);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (DataflowException e)
            {
                throw;
            }
            catch (Exception e)
            {
                string message = string.Format(
                    CultureInfo.InvariantCulture, Resources.ExceptionGetCodelistFormat2, info, e.Message);
                Logger.Error(message);
                Logger.Error(e.Message, e);
                throw new NsiClientException(message, e);
            }

            return(codelist);
        }
Ejemplo n.º 16
0
        public ISdmxObjects GetStructure(string DataflowId, string DatafloAgency, string DatafloVersion, bool resolseRef = false)
        {
            Logger.InfoFormat(
                CultureInfo.InvariantCulture,
                Resources.InfoGettingStructureFormat3,
                DatafloAgency,
                DataflowId,
                DatafloVersion);

            #region Dataflow
            ISdmxObjects responseDF      = new SdmxObjectsImpl();
            var          dataflowRefBean = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dataflow))
            {
                MaintainableId = DataflowId,
                AgencyId       = DatafloAgency,
                Version        = DatafloVersion
            };
            IList <IStructureReference> refs = new List <IStructureReference>();
            refs.Add(dataflowRefBean);
            responseDF = this.SendQueryStructureRequest(refs, false);
            if (responseDF.Dataflows == null || responseDF.Dataflows.Count == 0)
            {
                throw new Exception("Dataflow not found");
            }
            #endregion
            IDataflowObject dataflow = responseDF.Dataflows.First();

            ISdmxObjects structure;

            var keyFamilyRefBean = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dsd))
            {
                MaintainableId = dataflow.DataStructureRef.MaintainableReference.MaintainableId,
                AgencyId       = dataflow.DataStructureRef.MaintainableReference.AgencyId,
                Version        = dataflow.DataStructureRef.MaintainableReference.Version
            };

            try
            {
                ISdmxObjects response;

                structure = this.SendQueryStructureRequest(keyFamilyRefBean, resolseRef);
                NsiClientValidation.CheckifStructureComplete(structure, dataflow);
                IEnumerable <IStructureReference> conceptRefs = NsiClientHelper.BuildConceptSchemeRequest(structure.DataStructures.First());
                response = this.SendQueryStructureRequest(conceptRefs, resolseRef);

                structure.Merge(responseDF);
                structure.Merge(response);

                NsiClientValidation.CheckConcepts(structure);
                Logger.Info(Resources.InfoSuccess);
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw new NsiClientException(Resources.ExceptionGettingStructure, e);
            }

            return(structure);
        }
        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);
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Check if the specified <paramref name="structureEnumType"/> is in <paramref name="sdmxStructureTypes"/>.
 /// </summary>
 /// <param name="sdmxStructureTypes">
 /// The SDMX structure types.
 /// </param>
 /// <param name="structureEnumType">
 /// The structure type as an ENUM.
 /// </param>
 /// <returns>
 /// True if <paramref name="structureEnumType"/> is in <paramref name="sdmxStructureTypes"/> or if <paramref name="sdmxStructureTypes"/> is empty; otherwise false.
 /// </returns>
 public static bool HasStructure(this ISet <SdmxStructureType> sdmxStructureTypes, SdmxStructureEnumType structureEnumType)
 {
     return(sdmxStructureTypes.Count == 0 || sdmxStructureTypes.Contains(SdmxStructureType.GetFromEnum(structureEnumType)));
 }