/// <summary>
        /// Sends the specified <paramref name="references"/> to the Web Service defined by <see cref="_config"/>
        /// </summary>
        /// <param name="references">The <see cref="IStructureReference"/></param>
        /// <param name="resolveReferences">
        /// The resolve references
        /// </param>
        /// <returns>The QueryStructureResponse returned by the Web Service</returns>
        public ISdmxObjects SendQueryStructureRequest(IEnumerable <IStructureReference> references, bool resolveReferences)
        {
            var queryStructureRequestBuilderManager = new QueryStructureRequestBuilderManager();

            IStructureQueryFormat <XDocument> queryFormat = new QueryStructureRequestFormat();
            var wdoc = queryStructureRequestBuilderManager.BuildStructureQuery(references, queryFormat, resolveReferences);

            var doc = new XmlDocument();

            doc.LoadXml(wdoc.ToString());

            string tempFileName = Path.GetTempFileName();

            try
            {
                this.SendRequest(doc, SDMXWSFunction.QueryStructure, tempFileName);

                ISdmxObjects             structureObjects = new SdmxObjectsImpl();
                IStructureParsingManager parsingManager   = new StructureParsingManager(SdmxSchemaEnumType.Null);
                using (var dataLocation = new FileReadableDataLocation(tempFileName))
                {
                    IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(dataLocation);
                    structureObjects = structureWorkspace.GetStructureObjects(false);
                }

                NsiClientValidation.CheckResponse(structureObjects);
                return(structureObjects);
            }
            finally
            {
                //delete the temporary file
                File.Delete(tempFileName);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends the specified <paramref name="request"/> to the Web Service defined by <see cref="_config"/>
        /// </summary>
        /// <param name="request">
        /// The <see cref="IComplexStructureQuery"/>
        /// </param>
        /// <returns>
        /// The ISdmxObjects returned by the Web Service
        /// </returns>
        private ISdmxObjects SendQueryStructureRequest(string request)
        {
            string tempFileName = Path.GetTempFileName();

            try
            {
                this.SendRequest(request, tempFileName, RequestType.Structure);

                ISdmxObjects             structureObjects = new SdmxObjectsImpl();
                IStructureParsingManager parsingManager   = new StructureParsingManager(SdmxSchemaEnumType.Null);
                using (var dataLocation = new FileReadableDataLocation(tempFileName))
                {
                    IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(dataLocation);
                    structureObjects = structureWorkspace.GetStructureObjects(false);
                }

                NsiClientValidation.CheckResponse(structureObjects);
                return(structureObjects);
            }
            finally
            {
                // Delete the temporary file
                File.Delete(tempFileName);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sends the specified <paramref name="complexStructureQuery"/> to the Web Service defined by <see cref="_config"/>
        /// </summary>
        /// <param name="complexStructureQuery">The <see cref="IComplexStructureQuery"/></param>
        /// <returns>The ISdmxObjects returned by the Web Service</returns>
        private ISdmxObjects SendQueryStructureRequest(IComplexStructureQuery complexStructureQuery, SDMXWSFunctionV21 sdmxwsFunctionV21)
        {
            IStructureQueryFormat <XDocument> queryFormat = new ComplexQueryFormatV21();

            IComplexStructureQueryFactory <XDocument>        factory = new ComplexStructureQueryFactoryV21 <XDocument>();
            IComplexStructureQueryBuilderManager <XDocument> complexStructureQueryBuilderManager = new ComplexStructureQueryBuilderManager <XDocument>(factory);
            var wdoc = complexStructureQueryBuilderManager.BuildComplexStructureQuery(complexStructureQuery, queryFormat);
            var doc  = new XmlDocument();

            doc.LoadXml(wdoc.ToString());

            string tempFileName = Path.GetTempFileName();

            try
            {
                this.SendRequest(doc, sdmxwsFunctionV21, tempFileName);

                ISdmxObjects             structureObjects = new SdmxObjectsImpl();
                IStructureParsingManager parsingManager   = new StructureParsingManager(SdmxSchemaEnumType.Null);
                using (var dataLocation = new FileReadableDataLocation(tempFileName))
                {
                    IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(dataLocation);
                    structureObjects = structureWorkspace.GetStructureObjects(false);
                }

                NsiClientValidation.CheckResponse(structureObjects);
                return(structureObjects);
            }
            finally
            {
                //Delete the temporary file
                File.Delete(tempFileName);
            }
        }
        public void ReadingStructures(String structureFile, SdmxSchemaEnumType schema, String output){

            // Step 2. Implementing a helper class that parses DSD, Dataflow and writes datasets.
            //1)	Call the method getXmlWriter
            XmlWriter xmlWriter = this.getXmlWriter(output);

            //2)	Obtain IDataWriterEngine
            IDataWriterEngine compactWriter = new CompactDataWriterEngine(xmlWriter,SdmxSchema.GetFromEnum(schema));

            //3)	Read a structure file from a stream
            this.spm = new StructureParsingManager();
            ISdmxObjects structureObjects = new SdmxObjectsImpl();

            using (FileStream stream = File.Open(structureFile, FileMode.Open, FileAccess.Read))
            {
                using (IReadableDataLocation rdl = new ReadableDataLocationTmp(stream))
                {
                    IStructureWorkspace structureWorkspace = this.spm.ParseStructures(rdl);
                    structureObjects = structureWorkspace.GetStructureObjects(false);
                }
            }

            //4)	The IMaintainableRefObject is used to reference structures that extend the IMaintainableObject Interface.  
            IMaintainableRefObject dsdRef = new MaintainableRefObjectImpl("ESTAT", "STS", "2.2");
            IMaintainableRefObject flowRef = new MaintainableRefObjectImpl("ESTAT", "SSTSCONS_PROD_A", "1.0");

            //5)	Get the DataStructure and the Dataflow
            ISet<IDataStructureObject> dsd = structureObjects.GetDataStructures(dsdRef);
            ISet<IDataflowObject> dataflow = structureObjects.GetDataflows(flowRef);

            //6)	After obtaining our IDataWriterEngine, and the IDataStructureObject that we wish to create data for, we can write the dataset
            SampleDataWriter sampleDataWriter = new SampleDataWriter();
            sampleDataWriter.writeSampleData(dsd.FirstOrDefault(), dataflow.FirstOrDefault(), compactWriter);
            xmlWriter.Close();
        }
		/// <summary>
		/// Returns a set of super beans that match the query parameter
		/// </summary>
		///
		/// <param name="structureQuery"></param>
		/// <returns></returns>
		private IObjectsBase IGetObjectsBase(IStructureReference xref) {
			ISet<IMaintainableObject> maintainables = this.SdmxObjectRetrievalManager
					.GetMaintainableWithReferences(xref);
			ISdmxObjects beans = new SdmxObjectsImpl(null, maintainables);
			if (superBeanBuilder == null) {
				throw new Exception(
						"SuperBeansBuilder not set, ISdmxBaseObjectRetrievalManagerImpl is @Configurable please ensure AspectJ weaving is enabled");
			}
			return superBeanBuilder.Build(beans);
		}
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">
        /// The parameter is not used.
        /// </param>
        public static void Main(string[] args)
        {
            // Steps 1 - 4 are performed in the new class DatabaseRetrievalManager, an implementation of the ISdmxObjectRetrievalManager interface.
            // DatabaseRetrievalManager: Step 1. Creating an implementation of  the ISdmxObjectRetrievalManager interface
            // DatabaseRetrievalManager: Step 2. Implementing ISdmxObjectRetrievalManager GetMaintainableObjects<> method.
            // DatabaseRetrievalManager: Step 3. Retrieving codelists from database. 
            // DatabaseRetrievalManager: Step 4. Retrieving Codes from the database.

            // Step 5. Create a ISdmxObjectRetrievalManager instance
            ISdmxObjectRetrievalManager retrievalManager = new DatabaseRetrievalManager();

            // Step 6. Create an IHeader  instance.
            // Create a new HeaderImpl instance with ID “IDREF0001”, Sender ID “ZZ9” 
            IHeader header = new HeaderImpl("IDREF001", "ZZ9"); // can be an instance or even a static field.

            // Step 7. Create the query
            IMaintainableRefObject query = new MaintainableRefObjectImpl("TEST_AGENCY", "TEST", "1.2");

            // Step 8. Get the codelist objects
            var codelistObjects = retrievalManager.GetMaintainableObjects<ICodelistObject>(query);

            // Step 9. Build the immutable object container.
            // Create an immutable container with the header and the codelist objects.
            // Note that immutable container can be modified.
            ISdmxObjects immutableObjects = new SdmxObjectsImpl(header, codelistObjects);

            // Step 10. Create an instance of the IStructureWriterManager.
            IStructureWriterManager structureWriterManager = new StructureWriterManager(); // can be an instance or even static field.

            // Step 11. Create a SdmxStructureFormat instance with StructureOutputFormat SdmxV21StructureDocument
            // SDMX v2.1. Create a SdmxStructureFormat instance with StructureOutputFormat SdmxV21StructureDocument. It can also be an instance or even a static field.
            IStructureFormat formatV21 = new SdmxStructureFormat(StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV21StructureDocument));

            // Step 12. Create a SdmxStructureFormat instance with StructureOutputFormat SdmxV2StructureDocument
            // SDMX v2.0. Create a SdmxStructureFormat instance with StructureOutputFormat SdmxV2StructureDocument. It can also be an instance or even a static field.
            IStructureFormat formatV20 = new SdmxStructureFormat(StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV2StructureDocument));


            // Step 13. Write to  the SDMX v2.1 structure file.
            using (Stream fileStream = File.Create(@"..\..\Exercise Output\outputv21.xml"))
            {
                // Write the objects in SDMX v2.1 format. Then flush the output.
                structureWriterManager.WriteStructures(immutableObjects, formatV21, fileStream);
                fileStream.Flush();
            }

            // Step 14. Write to  the SDMX v2.0 structure file. 
            using (Stream fileStream = File.Create(@"..\..\Exercise Output\outputv20.xml"))
            {
                // Write the objects in SDMX v2.0 format. Then flush the output.
                structureWriterManager.WriteStructures(immutableObjects, formatV20, fileStream);
                fileStream.Flush();
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// The write structure to file.
        /// </summary>
        /// <param name="outputFormat">
        /// The output format.
        /// </param>
        /// <param name="outputStream">
        /// The output stream.
        /// </param>
        public void writeStructureToFile(IStructureFormat outputFormat, Stream outputStream)
        {
            ISdmxObjects sdmxObjects = new SdmxObjectsImpl();

            sdmxObjects.AddAgencyScheme(this.structuresCreator.BuildAgencyScheme());
            sdmxObjects.AddCodelist(this.structuresCreator.BuildCountryCodelist());
            sdmxObjects.AddCodelist(this.structuresCreator.BuildIndicatorCodelist());
            sdmxObjects.AddConceptScheme(this.structuresCreator.BuildConceptScheme());

            IDataStructureObject dsd = this.structuresCreator.BuildDataStructure();
            sdmxObjects.AddDataStructure(dsd);
            sdmxObjects.AddDataflow(this.structuresCreator.BuildDataflow("DF_WDI", "World Development Indicators", dsd));

            this.swm.WriteStructures(sdmxObjects, outputFormat, outputStream);
        }
Exemplo 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)
        {
            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();

                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 structureQueryConceptScheme = new RESTStructureQueryCore(structureReference);
                    IBuilder <IComplexStructureQuery, IRestStructureQuery> transformerCategoryScheme = new StructureQuery2ComplexQueryBuilder();
                    IComplexStructureQuery complexStructureQueryConceptScheme = transformerCategoryScheme.Build(structureQueryConceptScheme);
                    responseConceptScheme = this.SendQueryStructureRequest(complexStructureQueryConceptScheme, SDMXWSFunctionV21.GetConceptScheme);
                    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);
        }
Exemplo 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);
        }
        private ISdmxObjects GetSdmxOBJ(string FileName)
        {
            ISdmxObjects             structureObjects = new SdmxObjectsImpl();
            IStructureParsingManager parsingManager   = new StructureParsingManager(SdmxSchemaEnumType.VersionTwo);

            string FullNamePath = Path.Combine(Utils.GetTreeCachePath(), FileName);

            if (!File.Exists(FullNamePath))
            {
                return(null);
            }
            using (var dataLocation = new FileReadableDataLocation(FullNamePath))
            {
                IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(dataLocation);
                structureObjects = structureWorkspace.GetStructureObjects(false);
            }

            return(structureObjects);
        }
        public void TestDownload(string dsd, string dataflow, string query)
        {

            IStructureParsingManager parsingManager = new StructureParsingManager();
            ISdmxObjects objects = new SdmxObjectsImpl();
            using (IReadableDataLocation location = new FileReadableDataLocation(dsd))
            {
                objects.Merge(parsingManager.ParseStructures(location).GetStructureObjects(false));
            }

            using (IReadableDataLocation location = new FileReadableDataLocation(dataflow))
            {
                objects.Merge(parsingManager.ParseStructures(location).GetStructureObjects(false));
            }

            ISdmxObjectRetrievalManager retrievalManager = new InMemoryRetrievalManager(objects);
            IList<IDataQuery> buildDataQuery;
            IDataQueryParseManager parseManager = new DataQueryParseManager(SdmxSchemaEnumType.VersionTwo);
            using (IReadableDataLocation readable = new FileReadableDataLocation(query))
            {
                // call BuildDataQuery to process the query.xml and get a list of IDataQuery
                buildDataQuery = parseManager.BuildDataQuery(readable, retrievalManager);
            }
            IList<IDataQuery> buildDataQuery1;
            foreach (var dataQuery in buildDataQuery)
            {
                IDataQueryBuilderManager dataQueryBuilderManager = new DataQueryBuilderManager(new DataQueryFactory());
                var xdoc = dataQueryBuilderManager.BuildDataQuery(dataQuery, new QueryMessageV2Format());
                Assert.IsNotNull(xdoc);
                MemoryStream xmlStream = new MemoryStream();
                xdoc.Save(xmlStream);
                using (IReadableDataLocation readable = new MemoryReadableLocation(xmlStream.ToArray()))
                {
                    // call BuildDataQuery to process the xmlStream and get a list of IDataQuery
                    buildDataQuery1 = parseManager.BuildDataQuery(readable, retrievalManager);
                }
                Assert.AreEqual(dataQuery.ToString(),buildDataQuery1[0].ToString());
                xmlStream.Flush();
            }

        }
        public static void DeleteCubeView(int idSet)
        {
            BuilderProcedure bp = new BuilderProcedure();
            SDMXIdentifier sdmxDSDKey = DataAccess.GetIdentifierFromIDSet(idSet);

            try
            {
                if (sdmxDSDKey != null)
                {
                    ISdmxObjects sdmxObjectDel = new SdmxObjectsImpl();

                    List<SDMXIdentifier> lCatsIdentifiers = DataSDMX.Get_CategorisationIdentifierFromIdFlow(DataAccess.GetDataflowIDFromIDSet(idSet));

                    ICategorisationObject cat = null;

                    foreach (SDMXIdentifier ident in lCatsIdentifiers)
                    {
                        cat = DataSDMX.GetCategorisation(ident, true);
                        if (cat != null)
                            sdmxObjectDel.AddCategorisation(cat);
                    }

                    IDataflowObject df = DataSDMX.GetDataflow(sdmxDSDKey, true);
                    IDataStructureObject dsd = DataSDMX.GetDSD(sdmxDSDKey, true);

                    if (df != null)
                        sdmxObjectDel.AddDataflow(df);

                    if (dsd != null)
                        sdmxObjectDel.AddDataStructure(dsd);

                    DataSDMX.DeleteStructure(sdmxObjectDel);
                }

                bp.Delete_DATASET(idSet);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void TestBuildSuccessResponse(SdmxSchemaEnumType version)
        {
            var responseBuilder = new SubmitStructureResponseBuilder();
            ISdmxObjects sdmxObjects = new SdmxObjectsImpl();
            var codelist = new CodelistMutableCore() { Id = "CL_TEST", Version = "1.0", AgencyId = "TEST" };
            codelist.AddName("en", "Test Codelist");
            for (int i = 0; i < 10; i++)
            {
                ICodeMutableObject item = new CodeMutableCore() { Id = "TEST_" + i.ToString(CultureInfo.InvariantCulture) };
                item.AddName("en", "Name for " + item.Id);
                codelist.AddItem(item);
            }

            sdmxObjects.AddCodelist(codelist.ImmutableInstance);
            var output = responseBuilder.BuildSuccessResponse(sdmxObjects, SdmxSchema.GetFromEnum(version));
            var fileName = "TestBuildSuccessResponse" + version + ".xml";
            output.Untyped.Save(fileName);
            using (IReadableDataLocation dataLocation = new FileReadableDataLocation(fileName))
            {
                XMLParser.ValidateXml(dataLocation, version);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the full structure with codelists
        /// </summary>
        /// <returns>
        /// The full structure with Codelists
        /// </returns>
        public ISdmxObjects GetFullStructure()
        {
            if (this._structure == null)
            {
                return(null);
            }

            var fullStructure = new SdmxObjectsImpl();

            foreach (var structure in this._structure.DataStructures)
            {
                fullStructure.AddDataStructure(structure);
            }
            foreach (var conceptScheme in this._structure.ConceptSchemes)
            {
                fullStructure.AddConceptScheme(conceptScheme);
            }
            foreach (var mergedList in this._codelistCache.GetMergedItemScheme())
            {
                fullStructure.AddCodelist(mergedList);
            }

            return(fullStructure);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Sends the specified <paramref name="request"/> to the Web Service defined by <see cref="_config"/> 
        /// </summary>
        /// <param name="request">
        /// The <see cref="IComplexStructureQuery"/>
        /// </param>
        /// <returns>
        /// The ISdmxObjects returned by the Web Service
        /// </returns>
        private ISdmxObjects SendQueryStructureRequest(string request)
        {
            string tempFileName = Path.GetTempFileName();

            try
            {
                this.SendRequest(request, tempFileName, RequestType.Structure);

                ISdmxObjects structureObjects = new SdmxObjectsImpl();
                IStructureParsingManager parsingManager = new StructureParsingManager(SdmxSchemaEnumType.Null);
                using (var dataLocation = new FileReadableDataLocation(tempFileName))
                {
                    IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(dataLocation);
                    structureObjects = structureWorkspace.GetStructureObjects(false);
                }

                NsiClientValidation.CheckResponse(structureObjects);
                return structureObjects;
            }
            finally
            {
                // Delete the temporary file
                File.Delete(tempFileName);
            }
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="TestWsRetrieverFactory" /> class.
        /// </summary>
        public TestWsRetrieverFactory()
        {
            ISdmxObjects sdmxObjects = new SdmxObjectsImpl();
            using (var stream = GetResource("ESTAT+STS+2.0.xml"))
            {
                Merge(stream, sdmxObjects);
            }

            using (var stream = GetResource("ESTAT+DEMOGRAPHY+2.1.xml"))
            {
                Merge(stream, sdmxObjects);
            }

            var sts = sdmxObjects.GetDataStructures(new MaintainableRefObjectImpl(null, "STS", null)).Select(o => o.AsReference).FirstOrDefault();
            var demo = sdmxObjects.GetDataStructures(new MaintainableRefObjectImpl(null, "DEMOGRAPHY", null)).Select(o => o.AsReference).FirstOrDefault();
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.NoResults, sts));
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.ResponseExceedsLimit, sts));
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.ResponseTooLarge, sts));
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.Semantic, sts));
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.TimeSeries, sts));
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.CrossV20Only, demo));

            InMemoryRetrievalManager retrievalManager = new InMemoryRetrievalManager(sdmxObjects);
            retrievalManager.CrossReferenceRetrievalManager = new CrossReferencedRetrievalManager(retrievalManager);
            this._sdmxObjectRetrievalManager = retrievalManager;
            this._mutableStructureSearchManager = new SampleStructureSearchManager(this._sdmxObjectRetrievalManager);
            this._sampleAdvancedMutableStructureSearchManager = new SampleAdvancedMutableStructureSearchManager(this._mutableStructureSearchManager);
            this._sampleAuthAdvancedStructureSearchManager = new SampleAuthAdvancedStructureSearchManager(this._sampleAdvancedMutableStructureSearchManager);
        }
        protected void btnSaveCategorisation_Click(object sender, EventArgs e)
        {
            // Controllo su selezione categoria
            if (String.IsNullOrEmpty(tvCategory.SelectedValue))
                return;

            // Creo la Categorisation e la salvo

            // Creazione delle info di base della categorisation
            // Recupero della category selezionata

            string catsID = cmbCategorySchemes.SelectedValue.Replace(',', '_').Replace(".", "") + "_" +
                                        tvCategory.SelectedValue + "-" +
                                        ucArtIdentity.ID + "_" +
                                        ucArtIdentity.Agency + "_" +
                                        ucArtIdentity.Version.Replace(".", "");

            ICategorisationMutableObject categorisation = new CategorisationMutableCore();
            categorisation.Id = catsID;
            categorisation.AgencyId = ucArtIdentity.Agency;
            categorisation.Version = ucArtIdentity.Version;
            categorisation.AddName("en", "Categorisation " + ucArtIdentity.ToString());

            IStructureReference structureRef = new StructureReferenceImpl(ucArtIdentity.Agency,
                                                                            ucArtIdentity.ID,
                                                                            ucArtIdentity.Version,
                                                                            GetStructureType());
            categorisation.StructureReference = structureRef;

            ArtefactIdentity artIDCS = Utils.GetArtefactIdentityFromString(cmbCategorySchemes.SelectedValue);

            IStructureReference categoryRef = new StructureReferenceImpl(artIDCS.Agency,
                                                                        artIDCS.ID,
                                                                        artIDCS.Version,
                                                                        SdmxStructureEnumType.Category,
                                                                        tvCategory.SelectedValue);
            categorisation.CategoryReference = categoryRef;

            ISdmxObjects sdmxCategorisationInsert = new SdmxObjectsImpl();

            sdmxCategorisationInsert.AddCategorisation(categorisation.ImmutableInstance);

            _wsModel.SubmitStructure(sdmxCategorisationInsert);

            // Controllo su errore

            // Messaggio di inserimento avvenuto con successo

            // Refresh della Gridview
            PopolateGVCategorisations();
            ResetCatPanel();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Sends the specified <paramref name="references"/> to the Web Service defined by <see cref="_config"/> 
        /// </summary>
        /// <param name="references">The <see cref="IStructureReference"/></param>
        /// <param name="resolveReferences">
        /// The resolve references
        /// </param>
        /// <returns>The QueryStructureResponse returned by the Web Service</returns>
        public ISdmxObjects SendQueryStructureRequest(IEnumerable<IStructureReference> references, bool resolveReferences)
        {
            var queryStructureRequestBuilderManager= new QueryStructureRequestBuilderManager();

            IStructureQueryFormat<XDocument> queryFormat = new QueryStructureRequestFormat();
            var wdoc = queryStructureRequestBuilderManager.BuildStructureQuery(references, queryFormat, resolveReferences);

            var doc = new XmlDocument();
            doc.LoadXml(wdoc.ToString());

            string tempFileName = Path.GetTempFileName();

            try
            {

                this.SendRequest(doc, SDMXWSFunction.QueryStructure, tempFileName);

                ISdmxObjects structureObjects = new SdmxObjectsImpl();
                IStructureParsingManager parsingManager = new StructureParsingManager(SdmxSchemaEnumType.Null);
                using (var dataLocation = new FileReadableDataLocation(tempFileName))
                {
                    IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(dataLocation);
                    structureObjects = structureWorkspace.GetStructureObjects(false);
                }

                NsiClientValidation.CheckResponse(structureObjects);
                return structureObjects;
            }
            finally
            {
                //delete the temporary file
                File.Delete(tempFileName);
            }
        }
Exemplo n.º 20
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);
        }
        public ISdmxObjects CreateDSD(IList<ITextTypeWrapperMutableObject> lNames)
        {
            IDataStructureMutableObject workingDSD;

            try
            {
                workingDSD = GetOriginalDSD(_originalIDSet);
                RestylingDSD(workingDSD, _lCubeColumnsName, _sdmxDFKey);

                // Creo la nuova DSD nel Mapping Store
                ISdmxObjects sdmxObject = new SdmxObjectsImpl();

                workingDSD.Names.Clear();
                foreach (ITextTypeWrapperMutableObject name in lNames)
                {
                    workingDSD.Names.Add(name);
                }

                sdmxObject.AddDataStructure(workingDSD.ImmutableInstance);
                DataSDMX.SubmitStructure(sdmxObject);

                return sdmxObject;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// The get maintainable with references.
        /// </summary>
        /// <param name="query">
        /// The query.
        /// </param>
        /// <param name="structureWriter">
        /// The structure writer.
        /// </param>
        /// <exception cref="ArgumentException">
        /// </exception>
        public virtual void GetMaintainableWithReferences(
            IStructureReference query, IStructureWritingEngine structureWriter)
        {
            if (structureWriter == null)
            {
                throw new ArgumentException("IStructureWritingEngine can not be null");
            }

            ISet<IMaintainableObject> mBeans = this.SdmxObjectRetrievalManager.GetMaintainableWithReferences(query);
            ISdmxObjects beans = new SdmxObjectsImpl(null, mBeans);
            structureWriter.WriteStructures(beans);
        }
        /// <summary>
        /// Gets the SDMX object retrieval manager.
        /// </summary>
        /// <param name="dataflowFile">The dataflow file.</param>
        /// <param name="dsdFile">The DSD file.</param>
        /// <returns>The SDMX Object retrieval manager</returns>
        private ISdmxObjectRetrievalManager GetSdmxObjectRetrievalManager(string dataflowFile, string dsdFile)
        {
            ISdmxObjects objects = new SdmxObjectsImpl();
            using (var fileDataFlowReadableDataLocation = new FileReadableDataLocation(dataflowFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(fileDataFlowReadableDataLocation);
                ISdmxObjects structureBeans = structureWorkspace.GetStructureObjects(false);
                objects.Merge(structureBeans);
                Assert.IsNotEmpty(structureBeans.Dataflows);
            }

            using (var fileKeybeanReadableDataLocation = new FileReadableDataLocation(dsdFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(fileKeybeanReadableDataLocation);
                ISdmxObjects structureBeans = structureWorkspace.GetStructureObjects(false);
                objects.Merge(structureBeans);
                Assert.IsNotEmpty(structureBeans.DataStructures);
            }
            ISdmxObjectRetrievalManager retrievalManager = new InMemoryRetrievalManager(objects);
            return retrievalManager;
        }
        public void TestDataQueryParserManagerV21(string file,string dataflowFile, string dsdFile)
        {
            ISdmxObjects objects = new SdmxObjectsImpl();
            using (IReadableDataLocation readableDataLocation = new FileReadableDataLocation(dataflowFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(readableDataLocation);
                objects.Merge(structureWorkspace.GetStructureObjects(false));
            }
            using (IReadableDataLocation readableDataLocation = new FileReadableDataLocation(dsdFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(readableDataLocation);
                objects.Merge(structureWorkspace.GetStructureObjects(false));
            }

            var retrievalManager = new InMemoryRetrievalManager(objects);
            using (var fileReadableDataLocation = new FileReadableDataLocation(file))
            {
                var dataQuery = this.dataQueryParseManager.BuildComplexDataQuery(fileReadableDataLocation, retrievalManager);
                Assert.IsNotEmpty(dataQuery);
            }
        }
        public void TestBuildErrorResponse(SdmxSchemaEnumType version)
        {
            var responseBuilder = new SubmitStructureResponseBuilder();
            ISdmxObjects sdmxObjects = new SdmxObjectsImpl();
            var codelist = new CodelistMutableCore() { Id = "CL_TEST", Version = "1.0", AgencyId = "TEST"};
            codelist.AddName("en", "Test Codelist");
            for (int i = 0; i < 10; i++)
            {
                ICodeMutableObject item = new CodeMutableCore() { Id = "TEST_" + i.ToString(CultureInfo.InvariantCulture) };
                item.AddName("en", "Name for " + item.Id);
                codelist.AddItem(item);
            }
            
            sdmxObjects.AddCodelist(codelist.ImmutableInstance);
            const string ErrorMessage = "Invalid syntax";
            var output = responseBuilder.BuildErrorResponse(new SdmxSyntaxException(ErrorMessage), new StructureReferenceImpl("TEST", "CL_TEST", "1.0", SdmxStructureEnumType.CodeList), SdmxSchema.GetFromEnum(version));
            var fileName = "TestBuildErrorResponse" + version + ".xml";
            output.Untyped.Save(fileName);
            using (IReadableDataLocation dataLocation = new FileReadableDataLocation(fileName))
            {
                XMLParser.ValidateXml(dataLocation, version);
            }

            Assert.IsTrue(File.ReadAllText(fileName).Contains(ErrorMessage));
        }
        public void TestBuildComplexDataQuery()
        {
            IStructureParsingManager manager = new StructureParsingManager();
            IDataQueryParseManager queryParseManager = new DataQueryParseManager(SdmxSchemaEnumType.VersionTwoPointOne);
            IComplexDataQueryBuilderManager dataQueryBuilderManager = new ComplexDataQueryBuilderManager(new ComplexDataQueryFactoryV21());
            
            IDataflowObject dataFlow;
            IDataStructureObject dsd;
            using (var readable = new FileReadableDataLocation("tests/V21/Structure/test-sdmxv2.1-ESTAT+SSTSCONS_PROD_M+2.0.xml"))
            {
                var structureWorkspace = manager.ParseStructures(readable);
                dataFlow = structureWorkspace.GetStructureObjects(false).Dataflows.First();
            }

            using (var readable = new FileReadableDataLocation("tests/V21/Structure/test-sdmxv2.1-ESTAT+STS+2.0.xml"))
            {
                var structureWorkspace = manager.ParseStructures(readable);
                dsd = structureWorkspace.GetStructureObjects(false).DataStructures.First();
            }

            ISet<IComplexDataQuerySelection> sections = new HashSet<IComplexDataQuerySelection>();
            var freqCriteria = new ComplexDataQuerySelectionImpl("FREQ", new IComplexComponentValue[] { new ComplexComponentValueImpl("M", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.Equal), SdmxStructureEnumType.Dimension), new ComplexComponentValueImpl("A", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.NotEqual), SdmxStructureEnumType.Dimension), new ComplexComponentValueImpl("B", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.Equal), SdmxStructureEnumType.Dimension) });
            sections.Add(freqCriteria);
            var adjustmentCriteria = new ComplexDataQuerySelectionImpl("ADJUSTMENT", new IComplexComponentValue[] { new ComplexComponentValueImpl("01", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.NotEqual), SdmxStructureEnumType.Dimension),  new ComplexComponentValueImpl("S2", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.NotEqual), SdmxStructureEnumType.Dimension) });
            sections.Add(adjustmentCriteria);
            var titleCriteria = new ComplexDataQuerySelectionImpl(
                "TITLE", 
                new IComplexComponentValue[] { new ComplexComponentValueImpl("PAOKARA", TextSearch.GetFromEnum(TextSearchEnumType.Contains), SdmxStructureEnumType.DataAttribute),  new ComplexComponentValueImpl("ARIS", TextSearch.GetFromEnum(TextSearchEnumType.DoesNotContain), SdmxStructureEnumType.DataAttribute) });
            sections.Add(titleCriteria);
            OrderedOperator equalOperator = OrderedOperator.GetFromEnum(OrderedOperatorEnumType.Equal);
            var dateFrom = new SdmxDateCore("2000-01");
            var dateFromOperator = OrderedOperator.GetFromEnum(OrderedOperatorEnumType.GreaterThanOrEqual);
            var primaryMeasureValue = new ComplexComponentValueImpl("200.20", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.GreaterThan), SdmxStructureEnumType.PrimaryMeasure);
            ICollection<IComplexDataQuerySelectionGroup> collection = new[] { new ComplexDataQuerySelectionGroupImpl(sections, dateFrom, dateFromOperator, null, equalOperator, new HashSet<IComplexComponentValue> { primaryMeasureValue }) };

            var complexDataQueryImpl = new ComplexDataQueryImpl(
                null, 
                null, 
                null, 
                dsd, 
                dataFlow, 
                null, 
                null, 
                0, 
                null, 
                false, 
                null, 
                DimensionAtObservation.GetFromEnum(DimensionAtObservationEnumType.Time).Value, 
                false, 
                DataQueryDetail.GetFromEnum(DataQueryDetailEnumType.Full), 
                collection);

            var buildComplexDataQuery = dataQueryBuilderManager.BuildComplexDataQuery(
                complexDataQueryImpl, new StructSpecificDataFormatV21());

            var fileName = string.Format("test-TestBuildComplexDataQuery.xml");
            buildComplexDataQuery.Save(fileName);

            ISdmxObjects objects = new SdmxObjectsImpl();
            objects.AddDataStructure(dsd);
            objects.AddDataflow(dataFlow);
            ISdmxObjectRetrievalManager beanRetrievalManager = new InMemoryRetrievalManager(objects);

            IComplexDataQuery query;
            using (var readable = new FileReadableDataLocation(fileName))
            {
                XMLParser.ValidateXml(readable, SdmxSchemaEnumType.VersionTwoPointOne);

                query = queryParseManager.BuildComplexDataQuery(readable, beanRetrievalManager).First();
            }

            Assert.AreEqual(1, query.SelectionGroups.Count);
            var selectionGroup = query.SelectionGroups.First();
            Assert.AreEqual(dateFrom, selectionGroup.DateFrom);
            Assert.AreEqual(dateFromOperator, selectionGroup.DateFromOperator);
            Assert.IsNull(selectionGroup.DateTo);
            Assert.AreEqual(1, selectionGroup.PrimaryMeasureValue.Count);
            var primaryValue = selectionGroup.PrimaryMeasureValue.First();
            Assert.AreEqual(primaryMeasureValue.Value, primaryValue.Value);
            Assert.AreEqual(primaryMeasureValue.OrderedOperator, primaryValue.OrderedOperator);
            Assert.AreEqual(3, selectionGroup.Selections.Count);

            var gotFreqCriteria = selectionGroup.GetSelectionsForConcept(freqCriteria.ComponentId);
            Assert.AreEqual(gotFreqCriteria, freqCriteria, "FREQ diff");
            
            var gotAdjustmentCriteria = selectionGroup.GetSelectionsForConcept(adjustmentCriteria.ComponentId);
            Assert.AreEqual(gotAdjustmentCriteria, adjustmentCriteria, "ADJ diff");
            Assert.IsTrue(gotAdjustmentCriteria.Values.All(value => value.OrderedOperator.EnumType == OrderedOperatorEnumType.NotEqual));

            var gotTitleCriteria = selectionGroup.GetSelectionsForConcept(titleCriteria.ComponentId);
            Assert.AreEqual(gotTitleCriteria, titleCriteria, "TITLE diff");
        }
        private bool SendQuerySubmit(IDataConsumerSchemeMutableObject dataConsumerScheme)
        {
            try
            {

                ISdmxObjects sdmxObjects = new SdmxObjectsImpl();

                sdmxObjects.AddDataConsumerScheme(dataConsumerScheme.ImmutableInstance);

                WSModel modelDataConsumerScheme = new WSModel();

                XmlDocument result = modelDataConsumerScheme.SubmitStructure(sdmxObjects);

                Utils.GetXMLResponseError(result);

                return true;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
        private ISdmxObjects GetSdmxObjects()
        {
            WSModel wsModel = new WSModel();
            ISdmxObjects sdmxInput;
            ISdmxObjects sdmxFinal;
            IMutableObjects mutableObj = new MutableObjectsImpl();
            LocalizedUtils localizedUtils = new LocalizedUtils(Utils.LocalizedCulture);
            sdmxFinal = new SdmxObjectsImpl();

            try
            {
                sdmxInput = wsModel.GetOrganisationUnitScheme(new ArtefactIdentity(SearchBar1.ucID, SearchBar1.ucAgency, SearchBar1.ucVersion), true,true);

                if (SearchBar1.ucName.Trim() != string.Empty)
                {
                    foreach (IOrganisationUnitSchemeObject ous in sdmxInput.OrganisationUnitSchemes)
                    {
                        if (localizedUtils.GetNameableName(ous).ToUpper().Contains(SearchBar1.ucName.Trim().ToUpper()))
                            mutableObj.AddOrganisationUnitScheme(ous.MutableInstance);
                    }
                    sdmxFinal = mutableObj.ImmutableObjects;
                }
                else
                    sdmxFinal = sdmxInput;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return sdmxFinal;
        }
Exemplo n.º 29
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);

            //Get category schemes and categorisations
            ISdmxObjects           responseCategorySchemes             = new SdmxObjectsImpl();
            IComplexStructureQuery complexStructureQueryCategoryScheme = RetrieveCategorySchemesAndCategorisations();

            //Get dataflows
            ISdmxObjects           responseDataflows             = new SdmxObjectsImpl();
            IComplexStructureQuery complexStructureQueryDataflow = RetrieveDataflows();

            try
            {
                try
                {
                    responseCategorySchemes = this.SendQueryStructureRequest(complexStructureQueryCategoryScheme, SDMXWSFunctionV21.GetCategoryScheme);
                }
                catch (DataflowException ex)
                {
                    //do nothing
                }
                responseDataflows = this.SendQueryStructureRequest(complexStructureQueryDataflow, SDMXWSFunctionV21.GetDataflow);

                //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 = _nsiClientWs.SendQueryStructureRequest(sdmxV20onlyReferences, false);
                    responseDataflows.Merge(responseDSD);
                }

                responseCategorySchemes.Merge(responseDataflows);

                if (responseCategorySchemes.CategorySchemes != null && responseCategorySchemes.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);
            }
            return(responseCategorySchemes);
        }
        /// <summary>
        /// The get structure set beans.
        /// </summary>
        /// <param name="xref">
        /// The xref.
        /// </param>
        /// <param name="structureWriter">
        /// The structure writer.
        /// </param>
        /// <exception cref="ArgumentException">
        /// </exception>
        public virtual void GetStructureSetBeans(IMaintainableRefObject xref, IStructureWritingEngine structureWriter)
        {
            if (structureWriter == null)
            {
                throw new ArgumentException("IStructureWritingEngine can not be null");
            }

            ISet<IStructureSetObject> mBeans = this.SdmxObjectRetrievalManager.GetStructureSetBeans(xref);
            ISdmxObjects beans = new SdmxObjectsImpl(null, mBeans);
            structureWriter.WriteStructures(beans);
        }
Exemplo n.º 31
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);
        }
Exemplo n.º 32
0
        /// <summary>
        /// Saves the maintainable
        /// </summary>
        /// <param name="maintainable">
        /// The <see cref="IMaintainableObject"/>
        /// </param>
        public void SaveStructure(IMaintainableObject maintainable)
        {
            ISdmxObjects objects = new SdmxObjectsImpl(maintainable);

            this.SaveStructures(objects);
        }
        private bool SendQuerySubmit(ICodelistMutableObject cl)
        {
            try
            {
                ISdmxObjects sdmxObjects = new SdmxObjectsImpl();

                int indexOrder = 1;
                foreach (ICodeMutableObject code in cl.Items)
                {
                    IEnumerable<IAnnotationMutableObject> annotations = (from a in code.Annotations where a.Type == "@ORDER@" select a).OfType<IAnnotationMutableObject>();

                    if (annotations.Count() > 0)
                    {
                        IAnnotationMutableObject annotation = annotations.First();

                        ITextTypeWrapperMutableObject iText = new TextTypeWrapperMutableCore();

                        iText.Value = (indexOrder++).ToString();
                        iText.Locale = "en";

                        annotation.Text.Clear();
                        annotation.Text.Add(iText);

                    }
                    else {
                        code.AddAnnotation(GetAnnotationOrder(indexOrder++));
                    }
                    lblCodeListDetail.Text = code.Names[0].Value ;
                }

                sdmxObjects.AddCodelist(cl.ImmutableInstance);
                WSModel modelCodeList = new WSModel();
                XmlDocument result = modelCodeList.SubmitStructure(sdmxObjects);
                Utils.GetXMLResponseError(result);

                return true;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
        private bool SendQuerySubmit(ICategorySchemeMutableObject cs)
        {
            try
            {

                ISdmxObjects sdmxObjects = new SdmxObjectsImpl();

                for (int i = 0; i < cs.Annotations.Count; )
                    if (cs.Annotations[i].Type.Trim() == "CategoryScheme_node_order")
                        cs.Annotations.RemoveAt(i);
                    else i++;

                sdmxObjects.AddCategoryScheme(cs.ImmutableInstance);

                WSModel modelCategoryScheme = new WSModel();

                XmlDocument result = modelCategoryScheme.SubmitStructure(sdmxObjects);

                if (Utils.GetXMLResponseError(result) != "")
                {
                    Utils.ShowDialog(Utils.GetXMLResponseError(result), 350, "Error");
                    return false;
                }

                return true;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 35
0
        public ISdmxObjects GetDsd(string DsdId, string DsdAgency, string DsdVersion, bool resolseRef = false)
        {
            Logger.InfoFormat(
                CultureInfo.InvariantCulture,
                Resources.InfoGettingStructureFormat3,
                DsdAgency,
                DsdId,
                DsdVersion);



            System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
            string path         = System.IO.Path.GetDirectoryName(ass.CodeBase);
            string templateFile = Path.Combine(path, "Model\\XMLQueryTemplate\\DOTSTAT_GetDataStructureDefinition.xml");
            var    doc          = new XmlDocument();

            doc.Load(templateFile);

            var nodesId = doc.GetElementsByTagName("KeyFamily");

            if (nodesId == null || nodesId.Count < 1)
            {
                return(null);
            }
            nodesId[0].InnerText = DsdId;

            var nodeAgency = doc.GetElementsByTagName("Receiver");

            if (nodeAgency == null || nodeAgency.Count < 1)
            {
                return(null);
            }
            nodeAgency[0].Attributes.GetNamedItem("id").Value = DsdAgency;

            string tempFileName = Path.GetTempFileName();

            try
            {
                this.SendRequest(doc, SDMXWSFunction.GetDataStructureDefinition, tempFileName);


                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(tempFileName);


                var codes = xmlDoc.GetElementsByTagName("Code");
                for (int i = 0; i < codes.Count; i++)
                {
                    var val = codes.Item(i).Attributes.GetNamedItem("value");
                    var par = codes.Item(i).Attributes.GetNamedItem("parentCode");
                    if (val != null && par != null && val.Value == par.Value)
                    {
                        codes.Item(i).Attributes.GetNamedItem("parentCode").Value = null;
                    }
                }

                var time_dimensions = xmlDoc.GetElementsByTagName("TimeDimension");
                time_dimensions.Item(0).Attributes.RemoveNamedItem("codelist");

                xmlDoc.Save(tempFileName);

                ISdmxObjects             structureObjects = new SdmxObjectsImpl();
                IStructureParsingManager parsingManager   = new StructureParsingManager(SdmxSchemaEnumType.VersionTwo);

                using (var dataLocation = new FileReadableDataLocation(tempFileName))
                {
                    IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(dataLocation);
                    structureObjects = structureWorkspace.GetStructureObjects(false);
                }

                NsiClientValidation.CheckResponse(structureObjects);
                return(structureObjects);
            }
            finally
            {
                //delete the temporary file
                File.Delete(tempFileName);
            }
        }
Exemplo n.º 36
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;
        }
        private void PopolateGVCategorisations()
        {
            // Prendere solo le Categorisation legate all'artefatto
            if (ucArtIdentity == null || ucArtIdentity.ID == "")
                return;

            ISdmxObjects sdmxCats;

            try
            {
                sdmxCats = _wsModel.GetAllCategorisation(false);
            }
            catch (Exception ex)
            {
                if (ex.Message == "No Results Found")
                    return;
                else
                    throw ex;
            }

            if (sdmxCats.Categorisations == null || sdmxCats.Categorisations.Count <= 0)
                return;

            ISdmxObjects sdmxFiltered = new SdmxObjectsImpl();

            SdmxStructureType st = GetStructureType();

            IEnumerable<ICategorisationObject> lCats = sdmxCats.Categorisations.Where(c => c.StructureReference.MaintainableStructureEnumType == st
                                                            && c.StructureReference.MaintainableId == ucArtIdentity.ID
                                                            && c.StructureReference.AgencyId == ucArtIdentity.Agency
                                                            && c.StructureReference.Version == ucArtIdentity.Version);

            foreach (var cat in lCats)
                sdmxFiltered.AddCategorisation(cat);

            if (sdmxFiltered.Categorisations == null || sdmxFiltered.Categorisations.Count <= 0)
                return;

            List<ISTAT.Entity.Categorization> lCategorisation = _eMapper.GetCategorizationList(sdmxFiltered);

            gvCategorisations.PageSize = Utils.GeneralCategorizationGridNumberRow;

            //            lblNumberOfTotalElements.Text = string.Format(Resources.Messages.lbl_number_of_total_rows, lCategorization.Count.ToString());
            gvCategorisations.DataSource = lCategorisation;
            gvCategorisations.DataBind();

            //if (lCategorisation.Count == 0)
            //{
            //    txtNumberOfRows.Visible = false;
            //    lblNumberOfRows.Visible = false;
            //    btnChangePaging.Visible = false;
            //}
            //else
            //{
            //    txtNumberOfRows.Visible = true;
            //    lblNumberOfRows.Visible = true;
            //    btnChangePaging.Visible = true;
            //}
        }
Exemplo n.º 38
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);

            // Get category schemes and categorisations
            ISdmxObjects responseCategorySchemes = new SdmxObjectsImpl();
            string requestCategoryScheme = this.RetrieveCategorySchemesAndCategorisations();

            // Get dataflows
            ISdmxObjects responseDataflows = new SdmxObjectsImpl();
            string requestDataFlows = this.RetrieveDataflows();

            try
            {
                try
                {
                    responseCategorySchemes = this.SendQueryStructureRequest(requestCategoryScheme);
                }
                catch (DataflowException ex)
                {
                    //do nothing
                }
                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);
                }

                responseCategorySchemes.Merge(responseDataflows);

               if (responseCategorySchemes.CategorySchemes != null && responseCategorySchemes.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);
            }

            return responseCategorySchemes;
        }
        private bool SendQuerySubmit(IOrganisationUnitSchemeMutableObject ous)
        {
            try
            {

                ISdmxObjects sdmxObjects = new SdmxObjectsImpl();

                sdmxObjects.AddOrganisationUnitScheme(ous.ImmutableInstance);

                WSModel modelOrganizationUnitScheme = new WSModel();

                XmlDocument result = modelOrganizationUnitScheme.SubmitStructure(sdmxObjects);

                Utils.GetXMLResponseError(result);

                return true;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public void TestNestedAndInOrV21(string file, string dataflowFile, string dsdFile, int expectedDataSelectionGroup)
        {
            // To be analysed  in SDMXRI-124
            ISdmxObjects objects = new SdmxObjectsImpl();
            using (IReadableDataLocation readableDataLocation = new FileReadableDataLocation(dataflowFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(readableDataLocation);
                objects.Merge(structureWorkspace.GetStructureObjects(false));
            }
            using (IReadableDataLocation readableDataLocation = new FileReadableDataLocation(dsdFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(readableDataLocation);
                objects.Merge(structureWorkspace.GetStructureObjects(false));
            }

            var retrievalManager = new InMemoryRetrievalManager(objects);
            using (var fileReadableDataLocation = new FileReadableDataLocation(file))
            {
                var dataQuery = this.dataQueryParseManager.BuildComplexDataQuery(fileReadableDataLocation, retrievalManager);
                Assert.IsNotEmpty(dataQuery);
                Assert.AreEqual(expectedDataSelectionGroup, dataQuery.First().SelectionGroups.Count);
            }
        }
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        public static void Main(string[] args)
        {
            // 1. initialize the ISdmxObjectRetrievalManager we will use for retrieving Dataflow and DSD. 
            // Depending on the implementation, they could be retrieved from the registry or mapping store.
            // but in this example we used a simple implementation which retrieves them from files.
            IStructureParsingManager parsingManager = new StructureParsingManager();
            ISdmxObjects objects = new SdmxObjectsImpl();
            using (IReadableDataLocation location = new FileReadableDataLocation("ESTAT+STS+2.0.xml"))
            {
                objects.Merge(parsingManager.ParseStructures(location).GetStructureObjects(false));
            }

            using (IReadableDataLocation location = new FileReadableDataLocation("ESTAT+SSTSCONS_PROD_M+2.0.xml"))
            {
                objects.Merge(parsingManager.ParseStructures(location).GetStructureObjects(false));
            }

            ISdmxObjectRetrievalManager retrievalManager = new InMemoryRetrievalManager(objects);

            // 2. initialize the IDataQueryParseManager implementation. 
            IDataQueryParseManager parseManager = new DataQueryParseManager(SdmxSchemaEnumType.VersionTwo);

            // 3. Create a IReadableDataLocation. Since we work with files we use the FileReadableDataLocation implementation.
            IList<IDataQuery> buildDataQuery;
            using (IReadableDataLocation readable = new FileReadableDataLocation("query.xml"))
            {
                // 4. we call BuildDataQuery to process the query.xml and get a list of IDataQuery
                buildDataQuery = parseManager.BuildDataQuery(readable, retrievalManager);
            }

            // below we print to console the contents of each IDataQuery
            foreach (var dataQuery in buildDataQuery)
            {
                Console.WriteLine("Dataflow: {0}", dataQuery.Dataflow.Id);
                Console.WriteLine("DSD: {0}", dataQuery.DataStructure.Id);
                Console.WriteLine("Maximum number of observations (DefaultLimit): {0}", dataQuery.FirstNObservations);
                Console.WriteLine("Has selections: {0}", dataQuery.HasSelections());
                Console.WriteLine("(");
                foreach (var selectionGroup in dataQuery.SelectionGroups)
                {
                    if (selectionGroup.DateFrom != null)
                    {
                        Console.WriteLine("\tPeriod from {0}", selectionGroup.DateFrom);
                        Console.WriteLine(" AND ");
                    }

                    if (selectionGroup.DateTo != null)
                    {
                        Console.WriteLine("\tPeriod to {0}", selectionGroup.DateTo);
                        Console.WriteLine(" AND ");
                    }

                    foreach (var selection in selectionGroup.Selections)
                    {
                        var s = selection.HasMultipleValues ? string.Join(" OR ", selection.Values) : selection.Value;
                        Console.WriteLine("{0} = ( {1} )", selection.ComponentId, s);
                        Console.WriteLine(" AND ");
                    }
                }
            }
        }
        private ISdmxObjects GetSdmxObjects()
        {
            WSModel wsModel = new WSModel();
            ISdmxObjects sdmxInput;
            ISdmxObjects sdmxFinal;
            IMutableObjects mutableObj = new MutableObjectsImpl();
            LocalizedUtils localizedUtils = new LocalizedUtils(Utils.LocalizedCulture);

            sdmxFinal = new SdmxObjectsImpl();

            try
            {
                sdmxInput = wsModel.GetDataFlow(new ArtefactIdentity(SearchBar1.ucID, SearchBar1.ucAgency, SearchBar1.ucVersion, ucIsFinalArtefact), true, true);

                if (SearchBar1.ucName.Trim() != string.Empty)
                {

                    foreach (IDataflowObject df in sdmxInput.Dataflows)
                    {
                        if (localizedUtils.GetNameableName(df).Contains(SearchBar1.ucName.Trim()))
                            mutableObj.AddDataflow(df.MutableInstance);

                    }
                    sdmxFinal = mutableObj.ImmutableObjects;

                }
                else
                    sdmxFinal = sdmxInput;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return sdmxFinal;
        }
Exemplo n.º 43
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;
        }
Exemplo n.º 44
0
        /// <summary>
        /// Create a SdmxObjects from all parameter configured
        /// </summary>
        /// <returns>SdmxObject for write message</returns>
        public ISdmxObjects CreateDSD()
        {
            try
            {
                StringBuilder sdmxObjectDescription = new StringBuilder();
                sdmxObjectDescription.AppendLine();
                ISdmxObjects sdmxObject = new SdmxObjectsImpl();
                sdmxObject.Header = FlyConfiguration.HeaderSettings.GetHeader();
                //sdmxObject.AddRegistration(


                if (_CategorySchemeObject != null)
                {
                    foreach (ICategorySchemeObject CSObj in _CategorySchemeObject)
                    {
                        sdmxObject.AddCategoryScheme(CSObj);
                        sdmxObjectDescription.AppendLine(string.Format("CategoryScheme: {0} category", CSObj.Items == null ? 0 : CSObj.Items.Count));
                    }
                }
                if (_CategorisationObject != null)
                {
                    foreach (var categorisation in _CategorisationObject)
                    {
                        sdmxObject.AddCategorisation(categorisation);
                    }
                    sdmxObjectDescription.AppendLine(string.Format("Categorisation: {0} categorisation", _CategorisationObject.Count));
                }


                if (_AgencyScheme != null)
                {
                    sdmxObject.AddAgencyScheme(_AgencyScheme);
                    sdmxObjectDescription.AppendLine(string.Format("AgencyScheme"));
                }

                if (_Codelists != null)
                {
                    try
                    {
                        int totalcode = 0;
                        _Codelists.ForEach(cl =>
                        {
                            sdmxObject.AddCodelist(cl.ImmutableInstance);
                            totalcode += cl.Items.Count;
                        });
                        sdmxObjectDescription.AppendLine(string.Format("Codelists: {0} codelists, {1} code_objects", _Codelists.Count, totalcode));
                    }
                    catch (SdmxException) { throw; }
                    catch (Exception ex)
                    {
                        throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex);
                    }
                }

                if (_Conceptscheme != null)
                {
                    foreach (var conceptscheme in _Conceptscheme)
                    {
                        sdmxObject.AddConceptScheme(conceptscheme);
                        sdmxObjectDescription.AppendLine(string.Format("Conceptscheme: {0} concepts -> {1}", (conceptscheme.Items == null ? 0 : conceptscheme.Items.Count), conceptscheme.Id));
                    }
                }

                if (_KeyFamily != null)
                {
                    foreach (DataStructureObjectImpl keyFamily in _KeyFamily)
                    {
                        sdmxObject.AddDataStructure(keyFamily.Immutated);
                        sdmxObjectDescription.AppendLine(string.Format("Structure: {0} dimensions, {1} attributes  -> {2}",
                                                                       keyFamily.Immutated.GetDimensions() == null ? 0 : keyFamily.Immutated.GetDimensions().Count,
                                                                       keyFamily.Attributes == null ? 0 : keyFamily.Attributes.Count, keyFamily.Id));
                    }
                }

                if (_Dataflows != null)
                {
                    _Dataflows.ForEach(df => sdmxObject.AddDataflow(df));
                    sdmxObjectDescription.AppendLine(string.Format("Dataflows: {0} dataflows", _Dataflows.Count));
                }

                FlyLog.WriteLog(this, FlyLog.LogTypeEnum.All, @"Writing sdmxObject complete succesfully. the Sdmx Contains: {0}", sdmxObjectDescription.ToString().Trim());


                return(sdmxObject);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateDSDObject, ex);
            }
        }