public StructureQueryMetadataCore(
            StructureQueryDetail structureQueryDetail,
            StructureReferenceDetail structureReferenceDetail,
            SdmxStructureType specificStructureReference,
            bool isReturnLatest)
        {
            if (structureReferenceDetail == StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.Specific)
                && specificStructureReference == null)
            {
                throw new SdmxSemmanticException("SpecificStructureReference is null and specific reference detail was requested");
            }

            if (specificStructureReference != null && !specificStructureReference.IsMaintainable)
            {
               throw new SdmxSemmanticException("SpecificStructureReference is not maintainable");
            }

            if (structureQueryDetail != StructureQueryDetail.GetFromEnum(StructureQueryDetailEnumType.Null))
            {
                this.structureQueryDetail = structureQueryDetail;
            }

            if (structureReferenceDetail != null)
            {
                this.structureReferenceDetail = structureReferenceDetail;
            }

            if (specificStructureReference != null)
            {
                this.specificStructureReference = specificStructureReference;
            }

            this.isReturnLatest = isReturnLatest;
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a bean with data about the key family for specified dataflow.
        /// </summary>
        /// <param name="dataflow">
        /// The dataflow
        /// </param>
        /// <param name="dataStructures">
        /// The data Structures.
        /// </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)
        {
            Logger.InfoFormat(
                CultureInfo.InvariantCulture,
                Resources.InfoGettingStructureFormat3,
                dataflow.AgencyId,
                dataflow.Id,
                dataflow.Version);
            ISdmxObjects structure = new SdmxObjectsImpl();

            try
            {
                ISdmxObjects responseConceptScheme = new SdmxObjectsImpl();
                ISdmxObjects response = new SdmxObjectsImpl();

                IStructureQueryFormat <string> structureQueryFormat = new RestQueryFormat();
                IStructureQueryFactory         factory = new RestStructureQueryFactory();
                IStructureQueryBuilderManager  structureQueryBuilderManager = new StructureQueryBuilderManager(factory);

                IDataStructureObject dsd = NsiClientHelper.GetDsdFromDataflow(dataflow, dataStructures);
                structure.AddDataStructure(dsd);

                NsiClientValidation.CheckifStructureComplete(structure, dataflow);
                IEnumerable <IStructureReference> conceptRefs = NsiClientHelper.BuildConceptSchemeRequest(structure.DataStructures.First());
                foreach (var structureReference in conceptRefs)
                {
                    IRestStructureQuery structureQuery = new RESTStructureQueryCore(StructureQueryDetail.GetFromEnum(StructureQueryDetailEnumType.Full), StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.None), null, structureReference, false);
                    string request = structureQueryBuilderManager.BuildStructureQuery(structureQuery, structureQueryFormat);
                    responseConceptScheme = this.SendQueryStructureRequest(request);
                    response.Merge(responseConceptScheme);
                }

                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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RetrievalSettings"/> class. 
 /// </summary>
 /// <param name="queryDetail">
 /// The query Detail. 
 /// </param>
 public RetrievalSettings(StructureQueryDetail queryDetail)
 {
     this.QueryDetail = queryDetail;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="RESTStructureQueryCore"/> class. 
        /// </summary>
        /// <param name="structureQueryDetail">
        /// The structure query detail. 
        /// </param>
        /// <param name="structureReferenceDetail">
        /// The structure reference detail. 
        /// </param>
        /// <param name="specificStructureReference">
        /// The specific structure reference. 
        /// </param>
        /// <param name="structureReference">
        /// The structure reference. 
        /// </param>
        /// <param name="returnLatest">
        /// The return last. 
        /// </param>
	    public RESTStructureQueryCore(StructureQueryDetail structureQueryDetail, StructureReferenceDetail structureReferenceDetail,
			SdmxStructureType specificStructureReference, IStructureReference structureReference, bool returnLatest)
         {
		       this._structureQueryMetadata = new StructureQueryMetadataCore(structureQueryDetail, structureReferenceDetail, specificStructureReference, returnLatest);
		       this._structureReference = structureReference;
	     }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
        private void ParserQueryParameters(IDictionary<string, string> queryParameters)
        {
            if (queryParameters != null)
            {
                foreach (string key in queryParameters.Keys)
                {
                    string value = queryParameters[key];
                    if (key.Equals("detail", StringComparison.OrdinalIgnoreCase))
                    {
                        var structureQueryDetailEnum = StructureQueryDetailEnumType.Full;
                        if (!Enum.TryParse(value, true, out structureQueryDetailEnum))
                        {
                            structureQueryDetail = StructureQueryDetail.GetFromEnum(structureQueryDetailEnum);
                            throw new SdmxSemmanticException("unable to parse value for key " + key);
                        }
                      
                        structureQueryDetail = StructureQueryDetail.GetFromEnum(structureQueryDetailEnum);
                    }
                    else if (key.Equals("references", StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            structureReferenceDetail = StructureReferenceDetail.ParseString(value);

                            if (structureReferenceDetail.EnumType == StructureReferenceDetailEnumType.Specific)
                            {
                                specificStructureReference = SdmxStructureType.ParseClass(value);
                            }
                        }
                        catch (SdmxSemmanticException e)
                        {
                            throw new SdmxSemmanticException("unable to parse value for key " + key, e);
                        }
                    }
                    else
                    {
                        throw new SdmxSemmanticException("Unknown query parameter : " + key);
                    }
                }
            }
        }
Esempio n. 9
0
        public ISdmxObjects GetStructure(string DataflowId, string DatafloAgency, string DatafloVersion, bool resolseRef = false)
        {
            Logger.InfoFormat(
                CultureInfo.InvariantCulture,
                Resources.InfoGettingStructureFormat3,
                DatafloAgency,
                DataflowId,
                DatafloVersion);
            ISdmxObjects structure = new SdmxObjectsImpl();

            #region Dataflow
            // Get dataflows
            ISdmxObjects responseDataflows = new SdmxObjectsImpl();
            string       requestDataFlows  = this.RetrieveDataflow(DataflowId, DatafloAgency, DatafloVersion);
            responseDataflows = this.SendQueryStructureRequest(requestDataFlows);
            // Remove from structure (ISdmxObjects) the DSDS built with SDMX v2.0
            var structureSdmxV20DSD = responseDataflows.DataStructures.Where(o => o.Annotations.Any(a => a.FromAnnotation() == CustomAnnotationType.SDMXv20Only)).ToArray();
            foreach (var sdmxV20Only in structureSdmxV20DSD)
            {
                responseDataflows.RemoveDataStructure(sdmxV20Only);
            }

            // DSDS with annotation
            var sdmxV20onlyReferences = structureSdmxV20DSD.Select(o => o.AsReference).ToArray();

            // Add the DSDS built with Sdmx V2.0
            ISdmxObjects responseDSD = new SdmxObjectsImpl();
            if (sdmxV20onlyReferences.Length > 0)
            {
                responseDSD = this._nsiClientWs.SendQueryStructureRequest(sdmxV20onlyReferences, false);
                responseDataflows.Merge(responseDSD);
            }
            if (responseDataflows.Dataflows == null || responseDataflows.Dataflows.Count == 0)
            {
                throw new Exception("Dataflow not found");
            }
            #endregion

            try
            {
                IDataflowObject dataflow = responseDataflows.Dataflows.First();
                ISdmxObjects    responseConceptScheme = new SdmxObjectsImpl();
                ISdmxObjects    response = new SdmxObjectsImpl();

                IStructureQueryFormat <string> structureQueryFormat = new RestQueryFormat();
                IStructureQueryFactory         factory = new RestStructureQueryFactory();
                IStructureQueryBuilderManager  structureQueryBuilderManager = new StructureQueryBuilderManager(factory);

                IDataStructureObject dsd = NsiClientHelper.GetDsdFromDataflow(dataflow, responseDataflows.DataStructures);
                structure.AddDataStructure(dsd);

                NsiClientValidation.CheckifStructureComplete(structure, dataflow);
                IEnumerable <IStructureReference> conceptRefs = NsiClientHelper.BuildConceptSchemeRequest(structure.DataStructures.First());
                foreach (var structureReference in conceptRefs)
                {
                    IRestStructureQuery structureQuery = new RESTStructureQueryCore(StructureQueryDetail.GetFromEnum(StructureQueryDetailEnumType.Full), StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.None), null, structureReference, false);
                    string request = structureQueryBuilderManager.BuildStructureQuery(structureQuery, structureQueryFormat);
                    responseConceptScheme = this.SendQueryStructureRequest(request);
                    response.Merge(responseConceptScheme);
                }

                structure.Merge(responseDataflows);
                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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RetrievalSettings"/> class.
 /// </summary>
 /// <param name="queryDetail">
 /// The query Detail.
 /// </param>
 public RetrievalSettings(StructureQueryDetail queryDetail)
 {
     this.QueryDetail = queryDetail;
 }
Esempio n. 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RetrievalSettings"/> class.
 /// </summary>
 public RetrievalSettings()
     : this(StructureQueryDetail.GetFromEnum(StructureQueryDetailEnumType.Full))
 {
 }