Exemplo n.º 1
0
        /// <summary>
        /// Returns the artefacts of <typeparamref name="T"/> that match <paramref name="xref"/>
        /// </summary>
        /// <param name="xref">
        /// The maintainable reference. ID, Agency and/or Version can have a value or null. Null is considered a wildcard.
        /// </param>
        /// <param name="returnLatest">
        /// The return Latest.
        /// </param>
        /// <param name="returnStub">
        /// The return Stub.
        /// </param>
        /// <param name="sdmxStructure">
        /// The SDMX structure type.
        /// </param>
        /// <param name="getter">
        /// The getter method to retrieve the artefacts if <see cref="_requestToArtefacts"/> doesn't not contain them.
        /// </param>
        /// <typeparam name="T">
        /// The type of the returned artefacts.
        /// </typeparam>
        /// <returns>
        /// The <see cref="ISet{T}"/>.
        /// </returns>
        private ISet <T> GetArtefacts <T>(IMaintainableRefObject xref, bool returnLatest, bool returnStub, SdmxStructureEnumType sdmxStructure, Func <IMaintainableRefObject, bool, bool, ISet <T> > getter)
            where T : class, IMaintainableMutableObject
        {
            ISet <IMaintainableMutableObject> mutableObjects;
            ISet <T>            retrievedObjects;
            IStructureReference structureReference = new StructureReferenceImpl(xref, sdmxStructure);

            if (!this._requestToArtefacts.TryGetValue(structureReference, out mutableObjects))
            {
                _log.DebugFormat(CultureInfo.InvariantCulture, "Cache miss: {0}", structureReference);
                retrievedObjects = getter(xref, returnLatest, returnStub);
                this._requestToArtefacts.Add(structureReference, new HashSet <IMaintainableMutableObject>(retrievedObjects));
                foreach (T retrievedObject in retrievedObjects)
                {
                    var reference = _fromMutable.Build(retrievedObject);
                    this._requestToArtefacts.AddToSet(reference, retrievedObject);
                }
            }
            else
            {
                retrievedObjects = new HashSet <T>(mutableObjects.Cast <T>());
            }

            return(retrievedObjects);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// The retrieve category reference.
        /// </summary>
        /// <param name="categoryCache">
        /// The category cache.
        /// </param>
        private void RetrieveCategoryReference(IDictionary <long, IStructureReference> categoryCache)
        {
            using (var command = this.MappingStoreDb.GetSqlStringCommand(CategorisationConstant.CategoryRefQueryFormat))
            {
                _log.InfoFormat(CultureInfo.InvariantCulture, "Executing Query: '{0}'", command.CommandText);
                using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command))
                {
                    ////  C.CATN_ID, A.ID, A.VERSION, A.AGENCY, I.ID as CATID
                    int catnIdx    = dataReader.GetOrdinal("CATN_ID");
                    int idIdx      = dataReader.GetOrdinal("ID");
                    int versionIdx = dataReader.GetOrdinal("VERSION");
                    int agencyIdx  = dataReader.GetOrdinal("AGENCY");
                    int catidIdx   = dataReader.GetOrdinal("CATID");

                    while (dataReader.Read())
                    {
                        long   catn    = DataReaderHelper.GetInt64(dataReader, catnIdx);
                        string id      = DataReaderHelper.GetString(dataReader, idIdx);
                        string agency  = DataReaderHelper.GetString(dataReader, agencyIdx);
                        string version = DataReaderHelper.GetString(dataReader, versionIdx);
                        string catid   = DataReaderHelper.GetString(dataReader, catidIdx);

                        var structureReference = new StructureReferenceImpl(agency, id, version, SdmxStructureEnumType.Category, catid);
                        categoryCache.Add(catn, structureReference);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="artefact"></param>
        /// <param name="sysId"></param>
        private void GetCodeListMapCrossReference(IStructureSetMutableObject artefact, ICodelistMapMutableObject clm, long sysId)
        {
            var inParameter = MappingStoreDb.CreateInParameter(ParameterNameConstants.IdParameter, DbType.Int64, sysId);

            using (DbCommand command = MappingStoreDb.GetSqlStringCommandParam(StructureSetConstant.SqlCLMReference, inParameter))
            {
                using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command))
                {
                    if (dataReader.Read())
                    {
                        IStructureReference sourceRef;
                        IStructureReference targetRef;

                        string s_ID, s_Agency, s_Version;
                        string t_ID, t_Agency, t_Version;

                        s_ID      = dataReader["S_ID"].ToString();
                        s_Agency  = dataReader["S_AGENCY"].ToString();
                        s_Version = dataReader["S_Version"].ToString();

                        t_ID      = dataReader["T_ID"].ToString();
                        t_Agency  = dataReader["T_AGENCY"].ToString();
                        t_Version = dataReader["T_Version"].ToString();

                        sourceRef = new StructureReferenceImpl(s_Agency, s_ID, s_Version, SdmxStructureEnumType.CodeList, "");
                        targetRef = new StructureReferenceImpl(t_Agency, t_ID, t_Version, SdmxStructureEnumType.CodeList, "");

                        clm.SourceRef = sourceRef;
                        clm.TargetRef = targetRef;
                    }
                }
            }
        }
Exemplo 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);
        }
Exemplo n.º 6
0
        private void GetCategorisationDataflow()
        {
            _dtCategorisationDataflow = DbAccess.ExecutetoTable(DBOperationEnum.GetCategorisationDataflow, null);

            if (_dtCategorisationDataflow.Rows.Count <= 0)
            {
                return;
            }

            ReferencesObject.Categorisation = new List <ICategorisationObject>();

            string DFID, DFAgency, DFVersion, CSID, CSAgency, CSVersion, CatCode, IDCAT, IDDataFlow;

            DataView  viewCSDF = new DataView(_dtCategorisationDataflow);
            DataTable dtCSDF   = viewCSDF.ToTable(true, "IDDataFlow", "DFID", "DFAgency", "DFVersion", "CSID",
                                                  "CSAgency", "CSVersion", "CatCode", "IDCAT");
            DataTable dtCatNames = viewCSDF.ToTable(true, "IDCAT", "CubeLang", "CubeName", "IDDataFlow");

            ICategorisationMutableObject categorisation;

            foreach (DataRow row in dtCSDF.Rows)
            {
                IDDataFlow = row["IDDataFlow"].ToString();
                DFID       = row["DFID"].ToString();
                DFAgency   = row["DFAgency"].ToString();
                DFVersion  = row["DFVersion"].ToString();
                CSID       = row["CSID"].ToString();
                CSAgency   = row["CSAgency"].ToString();
                CSVersion  = row["CSVersion"].ToString();
                CatCode    = row["CatCode"].ToString();
                IDCAT      = row["IDCAT"].ToString();

                categorisation = new CategorisationMutableCore()
                {
                    Id             = DFID,
                    AgencyId       = DFAgency,
                    Version        = DFVersion,
                    FinalStructure = TertiaryBool.ParseBoolean(true),
                };

                IStructureReference structureRef = new StructureReferenceImpl(DFAgency, DFID, DFVersion,
                                                                              SdmxStructureEnumType.Dataflow);
                IStructureReference categoryRef = new StructureReferenceImpl(CSAgency, CSID, CSVersion,
                                                                             SdmxStructureEnumType.Category, CatCode);

                categorisation.StructureReference = structureRef;
                categorisation.CategoryReference  = categoryRef;

                SetNames(dtCatNames.Select("IDCat = " + IDCAT + " AND IDDataFlow = " + IDDataFlow), categorisation);

                ReferencesObject.Categorisation.Add(categorisation.ImmutableInstance);
            }
        }
Exemplo 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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Retrieve the component representation reference.
        /// </summary>
        /// <param name="dataReader">
        /// The data reader.
        /// </param>
        /// <param name="component">
        /// The component.
        /// </param>
        /// <returns>
        /// The <see cref="IStructureReference"/> of the representation.
        /// </returns>
        private static IStructureReference RetrieveRepresentationReference(IDataRecord dataReader, IComponentMutableObject component)
        {
            IStructureReference measureCodelistRepresentation = null;
            string codelist = DataReaderHelper.GetString(dataReader, "CODELIST_ID");

            if (!string.IsNullOrWhiteSpace(codelist))
            {
                string codelistAgency         = DataReaderHelper.GetString(dataReader, "CODELIST_AGENCY");
                string codelistVersion        = DataReaderHelper.GetString(dataReader, "CODELIST_VERSION");
                var    codelistRepresentation = new StructureReferenceImpl(codelistAgency, codelist, codelistVersion, SdmxStructureEnumType.CodeList);
                component.Representation = new RepresentationMutableCore {
                    Representation = codelistRepresentation
                };
            }

            // Important. Concept scheme must be checked *after* codelist.
            var conceptSchemeRepresentation = DataReaderHelper.GetString(dataReader, "REP_CS_ID");

            if (!string.IsNullOrWhiteSpace(conceptSchemeRepresentation))
            {
                var measureDimension = component as IDimensionMutableObject;
                if (measureDimension != null && measureDimension.MeasureDimension)
                {
                    string agency  = DataReaderHelper.GetString(dataReader, "REP_CS_AGENCY");
                    string version = DataReaderHelper.GetString(dataReader, "REP_CS_VERSION");
                    if (component.Representation != null)
                    {
                        measureCodelistRepresentation = component.Representation.Representation;
                    }

                    measureDimension.Representation = new RepresentationMutableCore
                    {
                        Representation =
                            new StructureReferenceImpl(
                                agency,
                                conceptSchemeRepresentation,
                                version,
                                SdmxStructureEnumType.ConceptScheme)
                    };
                }
            }

            return(measureCodelistRepresentation);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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));
        }
Exemplo n.º 17
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);
         }
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// Return the latest artefact of type <typeparamref name="T" /> that matches the <paramref name="xref" />.
        /// </summary>
        /// <typeparam name="T">The type of the requested artefact</typeparam>
        /// <param name="xref">The maintainable reference. The version must be null.</param>
        /// <param name="returnLatest">if set to <c>true</c> [return latest].</param>
        /// <param name="returnStub">The return Stub.</param>
        /// <param name="sdmxStructure">The SDMX structure type.</param>
        /// <param name="getter">The getter method to retrieve the artefact if <see cref="_requestToLatestArtefacts" /> doesn't not contain it.</param>
        /// <returns>
        /// The <see cref="IMaintainableMutableObject" /> of type <typeparamref name="T" />; otherwise null
        /// </returns>
        private T GetLatest <T>(IMaintainableRefObject xref, bool returnLatest, bool returnStub, SdmxStructureEnumType sdmxStructure, Func <IMaintainableRefObject, bool, bool, T> getter)
            where T : class, IMaintainableMutableObject
        {
            IMaintainableMutableObject mutableObject;
            IStructureReference        structureReference = new StructureReferenceImpl(xref, sdmxStructure);

            if (!this._requestToLatestArtefacts.TryGetValue(structureReference, out mutableObject))
            {
                _log.DebugFormat(CultureInfo.InvariantCulture, "Cache miss: {0}", structureReference);
                T retrievedObject = getter(xref, returnLatest, returnStub);
                if (retrievedObject != null)
                {
                    this._requestToLatestArtefacts.Add(structureReference, retrievedObject);
                    this._requestToArtefacts.AddToSet(_fromMutable.Build(retrievedObject), retrievedObject);
                    return(retrievedObject);
                }

                return(null);
            }

            return(mutableObject as T);
        }
Exemplo n.º 19
0
        /// <summary>
        /// The retrieve artefact reference.
        /// </summary>
        /// <param name="artefactCache">
        /// The artefact cache.
        /// </param>
        /// <param name="allowedDataflows">
        /// The allowed dataflows.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// There is an error in the SQL Query in <see cref="CategorisationConstant.ArtefactRefQueryFormat"/>
        /// </exception>
        private void RetrieveArtefactReference(IDictionary <long, IStructureReference> artefactCache, IList <IMaintainableRefObject> allowedDataflows)
        {
            using (var command = this._authReferenceCommandBuilder.Build(new ReferenceSqlQuery(CategorisationConstant.ArtefactReference), allowedDataflows))
            {
                _log.InfoFormat(CultureInfo.InvariantCulture, "Executing Query: '{0}'", command.CommandText);
                using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command))
                {
                    //// A.ID, A.VERSION, A.AGENCY, T.STYPE
                    int catnIdx    = dataReader.GetOrdinal("CATN_ID");
                    int idIdx      = dataReader.GetOrdinal("ID");
                    int versionIdx = dataReader.GetOrdinal("VERSION");
                    int agencyIdx  = dataReader.GetOrdinal("AGENCY");
                    int stypeIdx   = dataReader.GetOrdinal("STYPE");

                    while (dataReader.Read())
                    {
                        long   catn    = DataReaderHelper.GetInt64(dataReader, catnIdx);
                        string id      = DataReaderHelper.GetString(dataReader, idIdx);
                        string agency  = DataReaderHelper.GetString(dataReader, agencyIdx);
                        string version = DataReaderHelper.GetString(dataReader, versionIdx);
                        string stype   = DataReaderHelper.GetString(dataReader, stypeIdx);
                        SdmxStructureEnumType structureType;
                        if (Enum.TryParse(stype, true, out structureType))
                        {
                            var structureReference = new StructureReferenceImpl(agency, id, version, structureType);
                            artefactCache.Add(catn, structureReference);
                        }
                        else
                        {
                            var message = string.Format(CultureInfo.InvariantCulture, "Error could not convert {0} to SdmxStructureEnumType", stype);
                            _log.Error(message);
                            throw new InvalidOperationException(message);
                        }
                    }
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Writes the item maps.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="schemaMap">
        /// The schema map.
        /// </param>
        /// <param name="primaryKey">
        /// The primary key.
        /// </param>
        protected override void WriteItemMaps(DbTransactionState state, TSchemaMap schemaMap, long primaryKey)
        {
            var cache               = new StructureCache();
            var mapProcedure        = new TMapItemProc();
            var sourceItemSchemeRef = schemaMap.SourceRef;
            var targetItemSchemeRef = schemaMap.TargetRef;

            using (var command = mapProcedure.CreateCommandWithDefaults(state))
            {
                mapProcedure.CreateParentIdParameter(command).Value = primaryKey;
                foreach (var itemMap in schemaMap.Items)
                {
                    var sourceRef       = new StructureReferenceImpl(sourceItemSchemeRef.AgencyId, sourceItemSchemeRef.MaintainableId, sourceItemSchemeRef.Version, this._childType, itemMap.SourceId);
                    var sourceRefStatus = this.GetReferenceStatus(state, sourceRef, cache);
                    mapProcedure.CreateSourceIdParameter(command).Value = sourceRefStatus.ItemIdMap[itemMap.SourceId].SysID;

                    var targetRef       = new StructureReferenceImpl(targetItemSchemeRef.AgencyId, targetItemSchemeRef.MaintainableId, targetItemSchemeRef.Version, this._childType, itemMap.TargetId);
                    var targetRefStatus = this.GetReferenceStatus(state, targetRef, cache);
                    mapProcedure.CreateTargetIdParameter(command).Value = targetRefStatus.ItemIdMap[itemMap.TargetId].SysID;

                    command.ExecuteNonQuery();
                }
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Get the CodelistRef(s) for the given HCL sys id.
        /// </summary>
        /// <param name="sysId">
        /// The HCL primary key value in Mapping Store
        /// </param>
        /// <param name="codelistRefs">
        /// The collection of <see cref="ICodelistRefMutableObject"/> to add the codelist references
        /// </param>
        private void GetCodelistRefs(long sysId, ICollection <ICodelistRefMutableObject> codelistRefs)
        {
            using (DbCommand command = this._itemCommandBuilder.Build(new ItemSqlQuery(this._codelistRefQueryInfo, sysId)))
                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(_codelistType)
                        {
                            MaintainableId = DataReaderHelper.GetString(dataReader, idField),
                            Version        = DataReaderHelper.GetString(dataReader, versionField),
                            AgencyId       = DataReaderHelper.GetString(dataReader, agencyField)
                        };
                        ICodelistRefMutableObject codelistRef = new CodelistRefMutableCore();
                        codelistRef.CodelistReference = item;
                        codelistRef.Alias             = BuildCodelistRefAlias(item.MaintainableId, item.AgencyId, item.Version);

                        codelistRefs.Add(codelistRef);
                    }
                }
        }
Exemplo n.º 22
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);
        }
        /// <summary>
        ///     An empty Set will be returned if there are no matches to the query
        /// </summary>
        /// <param name="maintainableReference">
        /// Contains the identifiers of the structures to returns, can include widcarded values (null indicates a wildcard).
        /// </param>
        /// <param name="returnStub">
        /// If true then a stub object will be returned
        /// </param>
        /// /// <param name="returnLatest">
        /// If true then the latest version is returned, regardless of whether version information is supplied
        /// </param>
        /// <returns>
        /// The set of <see cref="IMaintainableObject"/> .
        /// </returns>
        public ISet <T> GetMaintainableObjects <T>(IMaintainableRefObject maintainableReference, bool returnStub, bool returnLatest) where T : IMaintainableObject
        {
            ISet <T> returnSet;

            if (returnLatest)
            {
                maintainableReference = new MaintainableRefObjectImpl(maintainableReference.AgencyId, maintainableReference.MaintainableId, null);
            }

            SdmxStructureType   type = SdmxStructureType.ParseClass(typeof(T));
            IStructureReference sRef = new StructureReferenceImpl(maintainableReference, type);

            switch (sRef.TargetReference.EnumType)
            {
            //case SdmxStructureEnumType.AgencyScheme:
            //    returnSet = new HashSet<T>(base.GetAgencySchemeObjects(maintainableReference, returnStub).Cast<T>());
            //    break;
            //case SdmxStructureEnumType.DataConsumerScheme:
            //    returnSet = new HashSet<T>(this.GetDataConsumerSchemeObjects(maintainableReference, returnStub).Cast<T>());
            //    break;
            //case SdmxStructureEnumType.AttachmentConstraint:
            //    returnSet = new HashSet<T>(this.GetAttachmentConstraints(maintainableReference, returnLatest, returnStub).Cast<T>());
            //    break;
            case SdmxStructureEnumType.ContentConstraint:
                returnSet = new HashSet <T>(this.GetContentConstraints(maintainableReference, returnLatest, returnStub).Cast <T>());
                break;

            //case SdmxStructureEnumType.DataProviderScheme:
            //    returnSet = new HashSet<T>(this.GetDataProviderSchemeObjects(maintainableReference, returnStub).Cast<T>());
            //    break;
            case SdmxStructureEnumType.Categorisation:
                returnSet = new HashSet <T>(this.GetCategorisationObjects(maintainableReference, returnStub).Cast <T>());
                break;

            case SdmxStructureEnumType.CategoryScheme:
                returnSet = new HashSet <T>(this.GetCategorySchemeObjects(maintainableReference, returnLatest, returnStub).Cast <T>());
                break;

            case SdmxStructureEnumType.CodeList:
                returnSet = new HashSet <T>(this.GetCodelistObjects(maintainableReference, returnLatest, returnStub).Cast <T>());
                break;

            case SdmxStructureEnumType.ConceptScheme:
                returnSet = new HashSet <T>(this.GetConceptSchemeObjects(maintainableReference, returnLatest, returnStub).Cast <T>());
                break;

            case SdmxStructureEnumType.Dataflow:
                returnSet = new HashSet <T>(this.GetDataflowObjects(maintainableReference, returnLatest, returnStub).Cast <T>());
                break;

            case SdmxStructureEnumType.HierarchicalCodelist:
                returnSet = new HashSet <T>(this.GetHierarchicCodeListObjects(maintainableReference, returnLatest, returnStub).Cast <T>());
                break;

            case SdmxStructureEnumType.Dsd:
                returnSet = new HashSet <T>(this.GetDataStructureObjects(maintainableReference, returnLatest, returnStub).Cast <T>());
                break;

            //case SdmxStructureEnumType.MetadataFlow:
            //    returnSet = new HashSet<T>(this.GetMetadataflowObjects(maintainableReference, returnLatest, returnStub).Cast<T>());
            //    break;
            //case SdmxStructureEnumType.Msd:
            //    returnSet = new HashSet<T>(this.GetMetadataStructureObjects(maintainableReference, returnLatest, returnStub).Cast<T>());
            //    break;
            //case SdmxStructureEnumType.OrganisationUnitScheme:
            //    returnSet = new HashSet<T>(this.GetOrganisationUnitSchemeObjects(maintainableReference, returnLatest, returnStub).Cast<T>());
            //    break;
            //case SdmxStructureEnumType.Process:
            //    returnSet = new HashSet<T>(this.GetProcessObjects(maintainableReference, returnLatest, returnStub).Cast<T>());
            //    break;
            //case SdmxStructureEnumType.ReportingTaxonomy:
            //    returnSet = new HashSet<T>(this.GetReportingTaxonomyObjects(maintainableReference, returnLatest, returnStub).Cast<T>());
            //    break;
            //case SdmxStructureEnumType.StructureSet:
            //    returnSet = new HashSet<T>(this.GetStructureSetObjects(maintainableReference, returnLatest, returnStub).Cast<T>());
            //    break;
            //case SdmxStructureEnumType.ProvisionAgreement:
            //    returnSet = new HashSet<T>(this.GetProvisionAgreementObjects(maintainableReference, returnLatest, returnStub).Cast<T>());
            //    break;
            default:
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.RetrivalParsingError, new Exception(sRef.TargetReference.EnumType.ToString()));
            }

            //if (returnStub && _serviceRetrievalManager != null)
            //{
            //    ISet<T> stubSet = new HashSet<T>();
            //    foreach (T returnItm in returnSet)
            //    {
            //        if (returnItm.IsExternalReference.IsTrue)
            //            stubSet.Add(returnItm);
            //        else
            //            stubSet.Add((T)_serviceRetrievalManager.CreateStub(returnItm));
            //    }
            //    returnSet = stubSet;
            //}
            return(returnSet);
        }
Exemplo n.º 24
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);
        }