/// <summary> /// Populate DataStructure (KeyFamyly for SDMX 2.0, Structure for SDMX 2.1) /// property of SDMXObjectBuilder for insert this elements in DataStructure response /// </summary> public DataStructureObjectImpl BuildDSD(IDataflowObject _foundedDataflow) { try { if (!this.parsingObject.ReturnStub) { if (!ReferencesObject.Concepts.ContainsKey(string.Format(FlyConfiguration.ConceptSchemeFormat, _foundedDataflow.Id))) { ConceptSchemeManager gdf = new ConceptSchemeManager((ISdmxParsingObject)this.parsingObject.Clone(), this.versionTypeResp); ReferencesObject.Concepts.Add(string.Format(FlyConfiguration.ConceptSchemeFormat, _foundedDataflow.Id), gdf.GetConceptList(_foundedDataflow.Id)); } //CodelistManager cm = new CodelistManager((ISdmxParsingObject)this.parsingObject.Clone(), this.versionTypeResp); //cm.parsingObject.QueryDetail = StructureQueryDetailEnumType.AllStubs; //cm.BuildCodelist(_foundedDataflow.Id); //if (ReferencesObject.Codelists == null) ReferencesObject.Codelists = new List<ICodelistMutableObject>(); //ReferencesObject.Codelists.AddRange(cm.ReferencesObject.Codelists); } return(BuildDataStructure(_foundedDataflow.Id)); } catch (SdmxException) { throw; } catch (Exception ex) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.BuildDSD, ex); } }
public static LayoutObj GetDefaultLayout(IDataflowObject df, IDataStructureObject kf) { LayoutObj lay = FindInConfigFile(df, kf); if (lay != null) { return(lay); } lay = new LayoutObj(); foreach (var item in kf.DimensionList.Dimensions) { if (item.TimeDimension) { lay.axis_y.Add(item.Id); } else if (item.FrequencyDimension) { lay.axis_z.Add(item.Id); } else { lay.axis_x.Add(item.Id); } } return(lay); }
/// <summary> /// Create a Dataflow Node /// </summary> /// <param name="dataflow"> /// The SDMX Model Dataflow object /// </param> /// <returns> /// The Dataflow Node /// </returns> private JsTreeNode CreateDataflowNode(IDataflowObject dataflow) { var dataflowNode = new JsTreeNode(); // dataflowNode.data.attributes.rel = MakeKey(dataflow); dataflowNode.SetId(Utils.MakeKey(dataflow).Replace('.', '_').Replace('+', '-')); SetupNode(dataflowNode, dataflow); IDataStructureObject dsd = NsiClientHelper.GetDsdFromDataflow(dataflow, _dataStructure); if (dsd != null && NsiClientHelper.DataflowDsdIsCrossSectional(dsd)) { dataflowNode.SetRel("xs-dataflow"); } else { dataflowNode.SetRel("dataflow"); } dataflowNode.AddClass("dataflow-item"); dataflowNode.SetLeaf(true); // dataflowNode.state = "closed"; dataflowNode.metadata = new JSTreeMetadata { DataflowID = dataflow.Id, DataflowVersion = dataflow.Version, DataflowAgency = dataflow.AgencyId }; // dataflowNode.metadata.dataflow_name = dataflow.PrimaryName; return(dataflowNode); }
/// <summary> /// Setup a <see cref="JsTreeNode"/> from a <c>DataflowBean</c> /// </summary> /// <param name="node"> /// The <see cref="JsTreeNode"/> /// </param> /// <param name="artefact"> /// The <c>DataflowBean</c> /// </param> protected static void SetupNode(JsTreeNode node, IDataflowObject artefact) { string entitle = artefact.Id; string format = string.Format(CultureInfo.InvariantCulture, ArtefactFormat, entitle); SetupNode(node, artefact, entitle, format); }
/// <summary> /// This method queries the mapping store for header information for a specific dataflow /// </summary> /// <param name="dataflow"> /// The <see cref="IDataflowObject"/> object /// </param> /// <param name="beginDate"> /// For ReportingBegin element /// </param> /// <param name="endDate"> /// For ReportingEnd element /// </param> /// <returns> /// A <see cref="IHeader"/> object. Otherwise null /// </returns> public IHeader GetHeader(IDataflowObject dataflow, DateTime?beginDate, DateTime?endDate) { var dataflowId = dataflow.Id; var dataflowVersion = dataflow.Version; var dataflowAgency = dataflow.AgencyId; return(this.GetHeader(beginDate, endDate, new MaintainableRefObjectImpl(dataflowAgency, dataflowId, dataflowVersion))); }
private LayoutObj InitLayout(IDataflowObject df, IDataStructureObject kf) { if (this.DataObj.Layout == null) { return(LayoutWidget.GetDefaultLayout(df, kf)); } return(this.DataObj.Layout); }
/// <summary> /// Obtains a DataReaderEngine that is capable of reading the data which is exposed via the ReadableDataLocation /// </summary> /// <param name="sourceData">The source data, giving access to an InputStream of the data.</param> /// <param name="dsd">The Data Structure Definition, describes the data in terms of the dimensionality.</param> /// <param name="dataflow">The dataflow (optional). Provides further information about the data.</param> /// <returns>The <see cref="IDataReaderEngine"/>; otherwise null if the <paramref name="sourceData"/> cannot be read.</returns> /// <exception cref="ArgumentNullException"><paramref name="sourceData"/> is null -or- <paramref name="dsd"/> is null</exception> public IDataReaderEngine GetDataReaderEngine(IReadableDataLocation sourceData, IDataStructureObject dsd, IDataflowObject dataflow) { _log.Debug("Get DataReader Engine"); if (sourceData == null) { throw new ArgumentNullException("sourceData"); } if (dsd == null) { throw new ArgumentNullException("dsd"); } MessageEnumType messageType; try { messageType = SdmxMessageUtil.GetMessageType(sourceData); } catch (Exception e) { _log.Error("While trying to get the message type.", e); return null; } var dataFormat = this.GetDataFormat(sourceData, messageType); if (dataFormat != null && dataFormat.SdmxDataFormat != null) { switch (dataFormat.SdmxDataFormat.BaseDataFormat.EnumType) { case BaseDataFormatEnumType.Compact: return new CompactDataReaderEngine(sourceData, dataflow, dsd); case BaseDataFormatEnumType.Generic: return new GenericDataReaderEngine(sourceData, dataflow, dsd); case BaseDataFormatEnumType.CrossSectional: var crossDsd = dsd as ICrossSectionalDataStructureObject; if (crossDsd == null) { throw new SdmxNotImplementedException("Not supported. Reading from CrossSectional Data for non cross-sectional dsd."); } return new CrossSectionalDataReaderEngine(sourceData, crossDsd, dataflow); case BaseDataFormatEnumType.Edi: if (this._ediParseManager != null) { return this._ediParseManager.ParseEdiMessage(sourceData).GetDataReader(dsd, dataflow); } break; default: _log.WarnFormat("SdmxDataReaderFactory encountered unsupported SDMX format: {0} ", dataFormat); break; } } return null; }
/// <summary> /// Logs the specified dataflow identifier. /// </summary> /// <param name="dataflow">The dataflow identifier.</param> public void Log(IDataflowObject dataflow) { if (dataflow == null) { throw new ArgumentNullException("dataflow"); } _log.InfoFormat("{0}{1}{2}", dataflow.Id, this._separator, this._dataFormat); }
/// <summary> /// Logs the specified dataflow identifier. /// </summary> /// <param name="dataflow">The dataflow identifier.</param> /// <exception cref="ArgumentNullException"><paramref name="dataflow"/> is <see langword="null" />.</exception> public void Log(IDataflowObject dataflow) { if (dataflow == null) { throw new ArgumentNullException("dataflow"); } _log.InfoFormat("{0}{1}{2}", dataflow.Id, this._separator, this._dataFormat); }
public void StartDataset(IDataflowObject dataflow, IDataStructureObject dsd, IDatasetHeader header, params IAnnotation[] annotations) { this._dimensionAtObservation = this.GetDimensionAtObservation(header); _jsonDataWriter.Formatting = Formatting.None; _jsonDataWriter.WritePropertyName("dataSets"); _jsonDataWriter.WriteStartArray(); _jsonDataWriter.WriteStartObject(); _jsonDataWriter.WritePropertyName("actions"); _jsonDataWriter.WriteValue("Information"); }
internal IDataSetStore FindDataCache(IDataflowObject df, IDataStructureObject kf, List <DataCriteria> Criterias, ref Dictionary <string, List <DataChacheObject> > DataCache, bool useAttr, out string DBFileName) { DataChacheObject findCache = null; Dictionary <string, List <string> > Criteri = new Dictionary <string, List <string> >(); Criterias.ForEach(c => Criteri.Add(c.component, c.values)); DBFileName = null; if (DataCache != null) { string DfID = Utils.MakeKey(df); if (DataCache.ContainsKey(DfID)) { List <DataChacheObject> singleDataCache = DataCache[DfID]; findCache = singleDataCache.Find(dc => DictionaryEqual(dc.Criterias, Criteri)); Dictionary <string, List <string> > CriteriDataCache = new Dictionary <string, List <string> >(); if (singleDataCache.Count > 0) { CriteriDataCache = singleDataCache.FirstOrDefault().Criterias; } bool pippo = false; if (CriteriDataCache.Count > 0) { pippo = DictionaryContain(singleDataCache.FirstOrDefault().Criterias, Criteri); } if (pippo) { findCache = singleDataCache.FirstOrDefault(); } } } if (findCache != null) { if (!string.IsNullOrEmpty(findCache.DBFileName) && File.Exists(findCache.DBFileName)) { #region Connessione e Creazione DB SQLLite string ConnectionString = string.Format(CultureInfo.InvariantCulture, Constants.FileDBSettingsFormat, findCache.DBFileName); var info = new DBInfo(ConnectionString); string tempTable = "table_" + Utils.MakeKey(df).Replace("+", "_").Replace(".", ""); IDataSetStore store = new DataSetStoreDB(info, tempTable, kf, false, useAttr); //DBFileName = findCache.DBFileName; store.SetCriteria(Criterias); return(store); #endregion } return(null); } return(null); }
public static IDataStructureObject GetDsdFromDataflow(IDataflowObject dataflow, ISet <IDataStructureObject> dataStructure) { foreach (var dsd in dataStructure) { if (dataflow.DataStructureRef.Equals(dsd.AsReference)) { return(dsd); } } return(null); }
public DataflowObjectBaseCore(IDataflowObject dataflow, IDataStructureObjectBase keyFamily0) : base(dataflow) { if (keyFamily0 == null) { throw new ValidationException( "DataflowObjectBaseCore requires IKeyFamilyObjectBase"); } this._keyFamily = keyFamily0; this._dataflow = dataflow; //TODO Build KeyFamily Ref once the uniqueness constraints have been implemented on the schemas }
/// <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); }
public SessionImplObject GetLayout(SessionQuery query) { try { //ISdmxObjects structure = GetKeyFamily(); //IDataflowObject df = structure.Dataflows.First(); //IDataStructureObject kf = structure.DataStructures.First(); ISdmxObjects structure = query.Structure; IDataflowObject df = query.Dataflow; IDataStructureObject kf = query.KeyFamily; if (kf == null || df == null) { throw new InvalidOperationException("DataStructure is not set"); } if (this.SessionObj.DafaultLayout == null) { this.SessionObj.DafaultLayout = new Dictionary <string, LayoutObj>(); } if (!this.SessionObj.DafaultLayout.ContainsKey(Utils.MakeKey(df))) { LayoutObj deflay = GetDefaultLayout(df, kf); this.SessionObj.DafaultLayout[Utils.MakeKey(df)] = deflay; } DefaultLayoutResponseObject defaultLayoutResponseObject = new DefaultLayoutResponseObject(); defaultLayoutResponseObject.DefaultLayout = this.SessionObj.DafaultLayout[Utils.MakeKey(df)]; this.SessionObj.SavedDefaultLayout = new JavaScriptSerializer().Serialize(defaultLayoutResponseObject); return(this.SessionObj); } catch (InvalidOperationException ex) { Logger.Warn(Resources.ErrorMaxJsonLength); Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } catch (ArgumentException ex) { Logger.Warn(Resources.ErrorRecursionLimit); Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } catch (Exception ex) { Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } }
/// <summary> /// Reset everything /// </summary> public void Reset() { this._dataflow = null; this._structure = null; this._keyFamily = null; this._dataflowTreeList = null; this._componentIndex.Clear(); this._conceptMap.Clear(); this._criteriaComponentIdx = 0; this._workPageIdx = 0; this.Clear(); this._sessionPrefix = Guid.NewGuid().ToString(); }
/// <summary> /// Try to authorize using the dataflow from <see cref="IDataflowObject"/>. /// It uses and checks the <see cref="_principal"/> if there is an authorized user. /// </summary> /// <param name="dataflow"> /// The dataflow. /// </param> /// <exception cref="SdmxUnauthorisedException"> /// Not authorized /// </exception> protected void Authorize(IDataflowObject dataflow) { if (this._principal != null) { IMaintainableRefObject dataflowRefBean = this._principal.GetAllowedDataflow(dataflow); if (dataflowRefBean == null) { string errorMessage = string.Format(CultureInfo.CurrentCulture, Resources.NoMappingForDataflowFormat1, dataflow.Id); throw new SdmxUnauthorisedException(errorMessage); } } }
/// <summary> /// Obtains a DataReaderEngine that is capable of reading the data which is exposed via the ReadableDataLocation /// </summary> /// <param name="sourceData"> /// SourceData - giving access to an InputStream of the data /// </param> /// <param name="dsd"> /// Describes the data in terms of the dimensionality /// </param> /// <param name="dataflowObject"> /// The data flow object (optional) /// </param> /// <returns> /// The data reader engine /// </returns> /// throws SdmxNotImplementedException if ReadableDataLocation or DataStructureBean is null, also if additioanlInformation is not of the expected type public IDataReaderEngine GetDataReaderEngine(IReadableDataLocation sourceData, IDataStructureObject dsd, IDataflowObject dataflowObject) { foreach (var currentFactory in this._engines) { IDataReaderEngine dre = currentFactory.GetDataReaderEngine(sourceData, dsd, dataflowObject); if (dre != null) { return dre; } } throw new SdmxNotImplementedException("Data format is either not supported, or has an invalid syntax"); }
/// <summary> /// The update references. /// </summary> /// <param name="maintianable"> /// The maintianable. /// </param> /// <param name="updateReferences"> /// The update references. /// </param> /// <param name="newVersionNumber"> /// The new version number. /// </param> /// <returns> /// The <see cref="IDataflowObject"/>. /// </returns> public IDataflowObject UpdateReferences(IDataflowObject maintianable, IDictionary<IStructureReference, IStructureReference> updateReferences, string newVersionNumber) { IDataflowMutableObject df = maintianable.MutableInstance; df.Version = newVersionNumber; IStructureReference newTarget = updateReferences[df.DataStructureRef]; if (newTarget != null) { df.DataStructureRef = newTarget; } return df.ImmutableInstance; }
public IDataQuery Build(IDataStructureObject dsd, IDataflowObject dataflowObject) { IDataQuerySelection dataQuerySelection = new DataQueryDimensionSelectionImpl("FREQ", "M", "A"); IDataQuerySelectionGroup dataQuerySelectionGroup = new DataQuerySelectionGroupImpl(new HashSet<IDataQuerySelection> { dataQuerySelection }, new SdmxDateCore("2000-01"), new SdmxDateCore("2005-03")); return new DataQueryImpl( dataStructure: dsd, lastUpdated: null, dataQueryDetail: DataQueryDetail.GetFromEnum(DataQueryDetailEnumType.Full), firstNObs: null, lastNObs: null, dataProviders: null, dataflow: dataflowObject, dimensionAtObservation: "TIME_PERIOD", selectionGroup: new[] { dataQuerySelectionGroup }); }
/// <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); }
private IDataQuery CreateQueryBean(IDataflowObject df, IDataStructureObject kf) { IDataQuery query; if (DataObjConfiguration._TypeEndpoint == EndpointType.REST) { query = new DataQueryFluentBuilder().Initialize(kf, df).Build(); } else { query = new DataQueryFluentBuilder().Initialize(kf, df). WithOrderAsc(true). WithMaxObservations(MaximumObservations).Build(); } return(query); }
/// <summary> /// Initializes a new instance of the <see cref="TestComplexDataQueryToXDoc"/> class. /// </summary> public TestComplexDataQueryToXDoc() { IStructureParsingManager manager = new StructureParsingManager(); this._dataQueryBuilderManager = new ComplexDataQueryBuilderManager(new ComplexDataQueryFactoryV21()); using (var readable = new FileReadableDataLocation("tests/V21/Structure/test-sdmxv2.1-ESTAT+SSTSCONS_PROD_M+2.0.xml")) { var structureWorkspace = manager.ParseStructures(readable); this._dataflowObject = 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); this._dataStructureObject = structureWorkspace.GetStructureObjects(false).DataStructures.First(); } }
public StreamResponseAction ExportSDMXQuery() { SessionQuery query = SessionQueryManager.GetSessionQuery(Session); //ControllerSupport CS = new ControllerSupport(); //GetCodemapObject PostDataArrived = CS.GetPostData<GetCodemapObject>(this.Request); //PostDataArrived.Configuration.Locale = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName; string request = ""; var xdoc = new XmlDocument(); EndpointSettings DataObjConfiguration = new EndpointSettings(); DataObjConfiguration = query._endpointSettings; //IGetSDMX GetSDMXObject = WebServiceSelector.GetSdmxImplementation(DataObjConfiguration); IGetSDMX GetSDMXObject = (query._IGetSDMX == null) ? WebServiceSelector.GetSdmxImplementation(DataObjConfiguration) : query._IGetSDMX; BaseDataObject BDO = new BaseDataObject(DataObjConfiguration, "appo.xml"); ISdmxObjects structure = query.Structure; IDataflowObject df = structure.Dataflows.First(); IDataStructureObject kf = structure.DataStructures.First(); IDataQuery sdmxQuery = BDO.CreateQueryBean(df, kf, query.GetCriteria()); GetSDMXObject.GetSdmxQuery(sdmxQuery, out request); string filename = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", query.Dataflow.Id, "xml"); this.HttpContext.Response.Clear(); this.HttpContext.Response.ContentType = "text/xml"; this.HttpContext.Response.ContentEncoding = Encoding.UTF8; string contentDisposition = string.Format( CultureInfo.InvariantCulture, Constants.AttachmentFilenameFormat, filename); this.HttpContext.Response.AddHeader(Constants.ContentDispositionHttpHeader, contentDisposition); this.HttpContext.Response.AddHeader("content-disposition", contentDisposition); this.HttpContext.Response.Write(request); this.HttpContext.Response.End(); throw new NotImplementedException(); }
/// <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); }
public void WriteSampleData(IDataStructureObject dsd, IDataflowObject dataflow, IDataWriterEngine dwe) { dwe.StartDataset(dataflow, dsd, null); dwe.StartSeries(); dwe.WriteSeriesKeyValue("COUNTRY", "UK"); dwe.WriteSeriesKeyValue("INDICATOR", "E_P"); dwe.WriteObservation("2000", "18,22"); dwe.WriteObservation("2000-02", "17,63"); dwe.StartSeries(); dwe.WriteSeriesKeyValue("COUNTRY", "FR"); dwe.WriteSeriesKeyValue("INDICATOR", "E_P"); dwe.WriteObservation("2000", "22,22"); dwe.WriteObservation("2000-Q3", "15,63"); dwe.Close(); }
public void writeSampleData(IDataStructureObject dsd, IDataflowObject dataflow, IDataWriterEngine dwe){ //Step 1. Writing sample data. //1) Start the dataset dwe.StartDataset(dataflow, dsd, null); //2) Start the dataset series dwe.StartSeries(); //3) Write dimensions dwe.WriteSeriesKeyValue("FREQ", "Q"); dwe.WriteSeriesKeyValue("REF_AREA","IT"); dwe.WriteSeriesKeyValue("ADJUSTMENT","W"); dwe.WriteSeriesKeyValue("STS_INDICATOR","E_P"); dwe.WriteSeriesKeyValue("STS_ACTIVITY","NS0020"); dwe.WriteSeriesKeyValue("STS_INSTITUTION","1"); dwe.WriteSeriesKeyValue("STS_BASE_YEAR","2000"); //4) Write Attribute at Series Level dwe.WriteAttributeValue("TIME_FORMAT", "P3M"); //5) Write the observations dwe.WriteObservation("2000-Q1", "18,22"); dwe.WriteObservation("2000-Q2", "17,63"); //6) Write Attribute at Observation Level dwe.WriteAttributeValue("OBS_STATUS", "C"); //7) Repeat the steps from 2 to 6 to create another dataset series dwe.StartSeries(); dwe.WriteSeriesKeyValue("FREQ", "M"); dwe.WriteSeriesKeyValue("REF_AREA", "SP"); dwe.WriteSeriesKeyValue("ADJUSTMENT", "N"); dwe.WriteSeriesKeyValue("STS_INDICATOR", "PROD"); dwe.WriteSeriesKeyValue("STS_ACTIVITY", "NS0030"); dwe.WriteSeriesKeyValue("STS_INSTITUTION", "1"); dwe.WriteSeriesKeyValue("STS_BASE_YEAR", "2001"); dwe.WriteAttributeValue("TIME_FORMAT", "P1M"); dwe.WriteObservation("2000-01", "18,22"); dwe.WriteObservation("2000-02", "17,63"); dwe.WriteAttributeValue("OBS_STATUS", "S"); //8) Close the dataset dwe.Close(); }
/// <summary> /// Get the latest allowed dataflow with version and agency (if are either defined) /// </summary> /// <param name="dataflow"> /// The dataflow object /// </param> /// <returns> /// The allowed dataflow with biggest version /// </returns> public IMaintainableRefObject GetAllowedDataflow(IDataflowObject dataflow) { if (dataflow == null) { throw new ArgumentNullException("dataflow"); } IMaintainableRefObject actualDataflow = null; var dataflowRef = dataflow.AsReference.MaintainableReference; if (this._authorizationProvider.AccessControl(this._user, dataflowRef)) { actualDataflow = dataflowRef; } return(actualDataflow); }
public static LayoutObj GetDefaultLayout(IDataflowObject df, IDataStructureObject kf) { LayoutObj lay = FindInConfigFile(df, kf); if (lay != null) return lay; lay = new LayoutObj(); foreach (var item in kf.DimensionList.Dimensions) { if (item.TimeDimension) lay.axis_y.Add(item.Id); else if (item.FrequencyDimension) lay.axis_z.Add(item.Id); else lay.axis_x.Add(item.Id); } return lay; }
/// <summary> /// Checks if a structure is complete according to the requirements of <see cref="GetStructure"/> /// </summary> /// <param name="structure"> /// The StructureBean object to check. /// </param> /// <param name="dataflow"> /// The requested dataflow /// </param> /// <exception cref="NsiClientException"> /// Server response error /// </exception> public static void CheckifStructureComplete(ISdmxObjects structure, IDataflowObject dataflow) { if (structure.DataStructures.Count != 1) { Logger.Error(Resources.ExceptionKeyFamilyCountNot1); throw new NsiClientException(Resources.ExceptionKeyFamilyCountNot1); } IDataStructureObject kf = structure.DataStructures.First(); var keyFamilyRef = dataflow.DataStructureRef; if (kf.Id == null || keyFamilyRef == null || !kf.Id.Equals(keyFamilyRef.MaintainableReference.MaintainableId) || !kf.AgencyId.Equals(keyFamilyRef.MaintainableReference.AgencyId) || !kf.Version.Equals(keyFamilyRef.MaintainableReference.Version)) { Logger.Error(Resources.ExceptionServerResponseInvalidKeyFamily); throw new NsiClientException(Resources.ExceptionServerResponseInvalidKeyFamily); } }
/// <summary> /// Initializes a new instance of the <see cref="AbstractDataSetModel"/> class. /// </summary> /// <param name="structure"> /// The SDMX-ML structure /// </param> /// <param name="store"> /// The <see cref="IDataSetStore"/> containing the dataset data /// </param> protected AbstractDataSetModel(ISdmxObjects structure, IDataSetStore store) { if (structure == null) { throw new ArgumentNullException("structure"); } this._store = store; this._structure = structure; // The structure must define exactly one key family... if ((this._structure.DataStructures == null) || (this._structure.DataStructures.Count != 1)) { throw new Exception( "Invalid structure bean, it does not contain the definition for exactly one key family!"); } this._dataFlow = this._structure.Dataflows.First(); this._keyFamily = this._structure.DataStructures.First(); }
/// <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); }
/// <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)); }
public void StartDataset(string dsdName, IDataflowObject dataflow, IDataStructureObject dsd, IDatasetHeader header, params IAnnotation[] annotations) { string appPath = System.Web.HttpRuntime.AppDomainAppPath; string giorno = System.Web.HttpContext.Current.Timestamp.Day.ToString(); string ora = System.Web.HttpContext.Current.Timestamp.Hour.ToString(); string min = System.Web.HttpContext.Current.Timestamp.Minute.ToString(); string secondi = System.Web.HttpContext.Current.Timestamp.Second.ToString(); string ms = System.Web.HttpContext.Current.Timestamp.Millisecond.ToString(); string namedir = giorno + ora + min + secondi + ms; dirPath = appPath + namedir; DirectoryInfo MyRoot = new DirectoryInfo(@appPath); MyRoot.CreateSubdirectory(namedir); IList<IDimension> dimensions = dsd.GetDimensions(SdmxStructureEnumType.Dimension); string[] ordinamento1 = new string[dimensions.Count]; string[] ordinamento2 = new string[dsd.Components.Count]; ordine = new string[dimensions.Count]; ordineser = new string[dimensions.Count]; int indord = 0; string valoredati = ""; IList<IDimension> dimensions1 = dsd.GetDimensions(SdmxStructureEnumType.Dimension); foreach (IDimension dim in dimensions1) { _CsvZipDataWriter.WriteValue(dim.Id + "_code,"); valoredati += dim.Id + "_code,"; ordine[indord] = dim.Id; indord++; } valoredati += "VALUE,date"; string newLinedati = string.Format("{0}{1}", valoredati, Environment.NewLine); csvdati.Append(newLinedati); }
private ICodelistObject GenerateTimePeriodCodelist(IDataflowObject DataFlowItem, IDimension timeDimension) { try { Org.Sdmxsource.Sdmx.Api.Model.Mutable.Codelist.ICodelistMutableObject codelist = new Org.Sdmxsource.Sdmx.SdmxObjects.Model.Mutable.Codelist.CodelistMutableCore(); codelist.Id = "CL_TIME_PERIOD"; codelist.AgencyId = DataFlowItem.AgencyId; codelist.Version = "1.0"; codelist.AddName("en", "Time Dimension Start and End periods"); codelist.CreateItem("1950", "Start Time Period"); codelist.CreateItem(DateTime.Now.Year.ToString(), "End Time Period"); return(codelist.ImmutableInstance); } catch (Exception e) { throw new Exception("[GetDataDLL.Model.ApplicationModel.MetadataLoader.extraceStructureArtefact] - " + e.Message); } }
private ISdmxObjects GetKeyFamily() { if (this.SessionObj == null) { this.SessionObj = new SessionImplObject(); this.SessionObj.SdmxObject = new SdmxObjectsImpl(); } // IDataflowObject dataflow = this.SessionObj.SdmxObject.Dataflows.FirstOrDefault(d => d.AgencyId == this.LayObj.Dataflow.agency && d.Id == this.LayObj.Dataflow.id && d.Version == this.LayObj.Dataflow.version); ISdmxObjects Structure = null; /* * if (dataflow != null) * { * Structure = GetSDMXObject.GetStructure(dataflow, this.SessionObj.SdmxObject.DataStructures); * Structure.AddDataflow(dataflow); * } */ if (dataflow != null && this.SessionObj.SdmxObject.HasConceptSchemes) { Structure = this.SessionObj.SdmxObject; } else if (dataflow != null && !this.SessionObj.SdmxObject.HasConceptSchemes) { Structure = GetSDMXObject.GetStructure(dataflow, this.SessionObj.SdmxObject.DataStructures); Structure.AddDataflow(dataflow); } else { Structure = GetSDMXObject.GetStructure(this.LayObj.Dataflow.id, this.LayObj.Dataflow.agency, this.LayObj.Dataflow.version); } this.SessionObj.SdmxObject.Merge(Structure); return(Structure); }
/// <summary> /// Gets a reader based on the specified <paramref name="operation"/> /// </summary> /// <param name="operation"> /// The operation /// </param> /// <param name="keyFamily"> /// The SDMX-ML dataset KeyFamily (i.e. DSD) /// </param> /// <param name="store"> /// The <see cref="IDataSetStore"/> in which the dataset will be stored /// </param> /// <param name="dataflow"> /// The <see cref="IDataflowObject"/> the dataflow /// </param> /// <param name="dataLocation"> /// The <see cref="IReadableDataLocation"/> the data location /// </param> public static void GetReader(SDMXWSFunction operation, IDataStructureObject keyFamily, IDataSetStore store, IDataflowObject dataflow, IReadableDataLocation dataLocation) { switch (operation) { case SDMXWSFunction.GetCompactData: var compact = new CompactDataReaderEngine(dataLocation, dataflow, keyFamily); var readerCompact = new SdmxDataReader(keyFamily, store); readerCompact.ReadData(compact); break; case SDMXWSFunction.GetCrossSectionalData: var dsdCrossSectional = (ICrossSectionalDataStructureObject)keyFamily; var crossSectional = new CrossSectionalDataReaderEngine(dataLocation, dsdCrossSectional, dataflow); var reader = new SdmxDataReader(keyFamily, store); reader.ReadData(crossSectional); break; default: throw new ArgumentException(Resources.ExceptionUnsupported_operation + operation.ToString(), "operation"); } }
public List <DsplStructure.Languages> VerifyNames(IDataflowObject dataflow) { var Languages = new List <DsplStructure.Languages>(); var Lang = new DsplStructure.Languages(); bool exists = new bool(); foreach (var item in dataflow.Names) { foreach (var lang in Languages) { if (lang.lang == item.Locale) { exists = true; } } if (!exists) { Lang.lang = item.Locale; Languages.Add(Lang); } } return(Languages); }
public List<DsplStructure.Languages> VerifyNames(IDataflowObject dataflow) { var Languages = new List<DsplStructure.Languages>(); var Lang = new DsplStructure.Languages(); bool exists = new bool(); foreach (var item in dataflow.Names) { foreach (var lang in Languages) { if (lang.lang == item.Locale) { exists = true; } } if (!exists) { Lang.lang = item.Locale; Languages.Add(Lang); } } return Languages; }
/// <summary> /// Initializes a new instance of the <see cref="KeyableImpl" /> class. /// </summary> /// <param name="dataflowObject">The dataflow object.</param> /// <param name="dataStructureObject">The data structure object.</param> /// <param name="key">The key .</param> /// <param name="attributes">The attributes .</param> /// <param name="groupName">The group name .</param> /// <param name="timeFormat">The time format .</param> /// <param name="annotations">The annotations.</param> /// <exception cref="System.ArgumentException">Data Structure can not be null</exception> public KeyableImpl(IDataflowObject dataflowObject, IDataStructureObject dataStructureObject, IList<IKeyValue> key, IList<IKeyValue> attributes, string groupName, TimeFormat timeFormat ,params IAnnotation[] annotations) { this._dataStructure = dataStructureObject; this._dataflow = dataflowObject; this._attributes = new List<IKeyValue>(); this._key = new List<IKeyValue>(); this._attributeMap = new Dictionary<string, IKeyValue>(); this._keyMap = new Dictionary<string, string>(); this._annotations = new List<IAnnotation>(); this._isTimeSeries = true; if (_dataStructure == null) { throw new ArgumentException("Data Structure can not be null"); } this._series = string.IsNullOrWhiteSpace(groupName); if (attributes != null) { this._attributes = new List<IKeyValue>(attributes); foreach (IKeyValue currentKv in attributes) { this._attributeMap.Add(currentKv.Concept, currentKv); } } if (key != null) { this._key = new List<IKeyValue>(key); foreach (IKeyValue currentKv4 in key) { this._keyMap.Add(currentKv4.Concept, currentKv4.Code); } } if(annotations != null) { foreach(IAnnotation currentAnnotation in annotations) { this._annotations.Add(currentAnnotation); } } this._groupName = groupName; this._timeFormat = timeFormat; }
/// <summary> /// Initializes a new instance of the <see cref="KeyableImpl" /> class. /// </summary> /// <param name="dataflowObject">The dataflow object.</param> /// <param name="dataStructureObject">The data structure object.</param> /// <param name="key">The key .</param> /// <param name="attributes">The attributes.</param> /// <exception cref="System.ArgumentException">Data Structure can not be null</exception> public KeyableImpl(IDataflowObject dataflowObject, IDataStructureObject dataStructureObject, IList<IKeyValue> key, IList<IKeyValue> attributes) : this(dataflowObject, dataStructureObject, key, attributes: attributes, groupName: null, timeFormat: null) { }
/// <summary> /// Initializes a new instance of the <see cref="KeyableImpl"/> class. /// </summary> /// <param name="key"> /// The key 0. /// </param> /// <param name="attributes"> /// The attributes 1. /// </param> /// <param name="groupName"> /// The group name 2. /// </param> public KeyableImpl(IDataflowObject dataflowObject, IDataStructureObject dataStructureObject, IList<IKeyValue> key, IList<IKeyValue> attributes, string groupName ,params IAnnotation[] annotations) : this(dataflowObject, dataStructureObject, key, attributes, groupName, default(TimeFormat), annotations) { }
/// <summary> /// Initializes a new instance of the <see cref="KeyableImpl"/> class. /// </summary> /// <param name="key"> /// The key 0. /// </param> /// <param name="attributes"> /// The attributes 1. /// </param> /// <param name="timeFormat"> /// The time format 2. /// </param> public KeyableImpl(IDataflowObject dataflowObject, IDataStructureObject dataStructureObject, IList<IKeyValue> key, IList<IKeyValue> attributes, TimeFormat timeFormat ,params IAnnotation[] annotations) : this(dataflowObject, dataStructureObject, key, attributes, null, timeFormat, annotations) { }
private string _uniqueId; // Generated on equals/hashcode #endregion #region Constructors and Destructors /// <summary> /// Initializes a new instance of the <see cref="KeyableImpl"/> class. /// </summary> /// <param name="key"> /// The key 0. /// </param> /// <param name="attributes"> /// The attributes 1. /// </param> /// <param name="timeFormat"> /// The time format 2. /// </param> /// <param name="crossSectionConcept"> /// The cross section concept 3. /// </param> /// <param name="obsTime"> /// The obs time 4. /// </param> /// <exception cref="SdmxSemmanticException"> /// Throws Validate exception. /// </exception> public KeyableImpl( IDataflowObject dataflowObject, IDataStructureObject dataStructureObject, IList<IKeyValue> key, IList<IKeyValue> attributes, TimeFormat timeFormat, string crossSectionConcept, string obsTime, params IAnnotation[] annotations) : this(dataflowObject, dataStructureObject, key, attributes, null, timeFormat, annotations) { this._isTimeSeries = false; this._crossSectionConcept = crossSectionConcept; this._obsTime = obsTime; if (obsTime == null) { throw new SdmxSemmanticException("Cross sectional dataset missing time value for key : " + this); } }
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> /// Sets the current dataflow. /// </summary> /// <param name="currentDataflow"> /// The current dataflow. /// </param> private void SetCurrentDataflow(IDataflowObject currentDataflow) { this._currentDataflow = currentDataflow; // If the current dataset header does not reference a Dataflow then amend it if (this._datasetHeader == null) { this._datasetHeader = new DatasetHeaderCore(Guid.NewGuid().ToString(), DatasetActionEnumType.Information, new DatasetStructureReferenceCore(currentDataflow.AsReference)); } else if (this._datasetHeader.DataProviderReference == null) { IDatasetStructureReference datasetStructureReference = new DatasetStructureReferenceCore(currentDataflow.AsReference); this._datasetHeader = this._datasetHeader.ModifyDataStructureReference(datasetStructureReference); } if (this._defaultDsd != null && this._defaultDsd.Urn.Equals(currentDataflow.DataStructureRef.TargetUrn)) { this.SetCurrentDsd(this._defaultDsd); } else if (this._objectRetrieval != null) { this.SetCurrentDsd(this._objectRetrieval.GetMaintainableObject<IDataStructureObject>(currentDataflow.DataStructureRef.MaintainableReference) as ICrossSectionalDataStructureObject); } }
public IDataQueryFluentBuilder Initialize(IDataStructureObject dataStructure, IDataflowObject dataflow) { this._dataStructure = dataStructure; this._dataflow = dataflow; return this; }
/// <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) { return(_nsiClientWs.GetDataflowDataCount(dataflow, criteria)); }
/// <summary> /// Initializes a new instance of the <see cref="CompactDataReaderEngine"/> class. /// </summary> /// <param name="dataLocation"> /// The data Location. /// </param> /// <param name="defaultDataflow"> /// The default Dataflow. (Optional) /// </param> /// <param name="defaultDsd"> /// The default DSD. The default DSD to use if the /// <paramref> /// <name>objectRetrieval</name> /// </paramref> /// is null, or /// if the bean retrieval does not return the DSD for the given dataset. /// </param> /// <exception cref="System.ArgumentException"> /// AbstractDataReaderEngine expects either a ISdmxObjectRetrievalManager or a /// IDataStructureObject to be able to interpret the structures /// </exception> public CompactDataReaderEngine(IReadableDataLocation dataLocation, IDataflowObject defaultDataflow, IDataStructureObject defaultDsd) : this(dataLocation, null, defaultDataflow, defaultDsd) { }
public virtual ISet<IProvisionAgreementObject> GetProvisions(IDataflowObject dataflow) { return GetByReference(dataflow); }
/// <summary> /// Starts a dataset with the data conforming to the DSD /// </summary> /// <param name="dataflow">Optional. The dataflow can be provided to give extra information about the dataset.</param> /// <param name="dsd">The <see cref="IDataStructureObject" /> for which the dataset will be created</param> /// <param name="header">The <see cref="IHeader" /> of the dataset</param> /// <param name="annotations">Any additional annotations that are attached to the dataset, can be null if no annotations exist</param> /// <exception cref="System.ArgumentNullException">if the <paramref name="dsd" /> is null</exception> public override void StartDataset(IDataflowObject dataflow, IDataStructureObject dsd, IDatasetHeader header, params IAnnotation[] annotations) { base.StartDataset(dataflow, dsd, header, annotations); this._primaryMeasureConcept = this.GetComponentId(dsd.PrimaryMeasure); this._compactNs = this.TargetSchema.EnumType != SdmxSchemaEnumType.VersionTwoPointOne ? this.Namespaces.DataSetStructureSpecific : NamespacePrefixPair.Empty; this._obsConcept = this.IsTwoPointOne ? this.DimensionAtObservation : ConceptRefUtil.GetConceptId(this.KeyFamily.TimeDimension.ConceptRef); if (this.IsTwoPointOne) { this.WriteAnnotations(ElementNameTable.AnnotationType, annotations); } else { this._datasetAnnotations = annotations; } }
/// <summary> /// Initializes a new instance of the <see cref="AbstractSdmxDataReaderEngine"/> class. /// </summary> /// <param name="dataLocation"> /// The data Location. /// </param> /// <param name="objectRetrieval"> /// The SDMX Object Retrieval. giving the ability to retrieve DSDs for the datasets this /// reader engine is reading. This can be null if there is only one relevant DSD - in which case the /// <paramref name="defaultDsd"/> should be provided. /// </param> /// <param name="defaultDataflow"> /// The default Dataflow. (Optional) /// </param> /// <param name="defaultDsd"> /// The default DSD. The default DSD to use if the <paramref name="objectRetrieval"/> is null, or /// if the bean retrieval does not return the DSD for the given dataset. /// </param> /// <exception cref="System.ArgumentException"> /// AbstractDataReaderEngine expects either a ISdmxObjectRetrievalManager or a /// IDataStructureObject to be able to interpret the structures /// </exception> protected AbstractSdmxDataReaderEngine(IReadableDataLocation dataLocation, ISdmxObjectRetrievalManager objectRetrieval, IDataflowObject defaultDataflow, IDataStructureObject defaultDsd) : base(dataLocation, objectRetrieval, defaultDataflow, defaultDsd) { this._isTwoPointOne = SdmxMessageUtil.GetSchemaVersion(dataLocation) == SdmxSchemaEnumType.VersionTwoPointOne; }
/// <summary> /// Build <see cref="DataflowType"/> from <paramref name="buildFrom"/>. /// </summary> /// <param name="buildFrom"> /// The build from. /// </param> /// <param name="categorisations"> /// The categorisations /// </param> /// <returns> /// The <see cref="DataflowType"/> from <paramref name="buildFrom"/> . /// </returns> public DataflowType Build(IDataflowObject buildFrom, ISet<ICategorisationObject> categorisations) { var builtObj = new DataflowType(); string value = buildFrom.AgencyId; if (!string.IsNullOrWhiteSpace(value)) { builtObj.agencyID = buildFrom.AgencyId; } string value1 = buildFrom.Id; if (!string.IsNullOrWhiteSpace(value1)) { builtObj.id = buildFrom.Id; } if (buildFrom.Uri != null) { builtObj.uri = buildFrom.Uri; } else if (buildFrom.StructureUrl != null) { builtObj.uri = buildFrom.StructureUrl; } else if (buildFrom.ServiceUrl != null) { builtObj.uri = buildFrom.StructureUrl; } if (ObjectUtil.ValidString(buildFrom.Urn)) { builtObj.urn = buildFrom.Urn; } string value2 = buildFrom.Version; if (!string.IsNullOrWhiteSpace(value2)) { builtObj.version = buildFrom.Version; } if (buildFrom.StartDate != null) { builtObj.validFrom = buildFrom.StartDate.Date; } if (buildFrom.EndDate != null) { builtObj.validTo = buildFrom.EndDate.Date; } IList<ITextTypeWrapper> names = buildFrom.Names; if (ObjectUtil.ValidCollection(names)) { builtObj.Name = this.GetTextType(names); } IList<ITextTypeWrapper> descriptions = buildFrom.Descriptions; if (ObjectUtil.ValidCollection(descriptions)) { builtObj.Description = this.GetTextType(descriptions); } if (this.HasAnnotations(buildFrom)) { builtObj.Annotations = this.GetAnnotationsType(buildFrom); } if (buildFrom.IsExternalReference.IsSet()) { builtObj.isExternalReference = buildFrom.IsExternalReference.IsTrue; } if (buildFrom.IsFinal.IsSet()) { builtObj.isFinal = buildFrom.IsFinal.IsTrue; } if (ObjectUtil.ValidCollection(categorisations)) { /* foreach */ foreach (ICategorisationObject currentCategoryRef in categorisations) { var categoryRefType = new CategoryRefType(); builtObj.CategoryRef.Add(categoryRefType); ICrossReference refBean = currentCategoryRef.CategoryReference; if (refBean != null) { IMaintainableRefObject maintainableReference = refBean.MaintainableReference; string value3 = maintainableReference.AgencyId; if (!string.IsNullOrWhiteSpace(value3)) { categoryRefType.CategorySchemeAgencyID = maintainableReference.AgencyId; } string value4 = maintainableReference.MaintainableId; if (!string.IsNullOrWhiteSpace(value4)) { categoryRefType.CategorySchemeID = maintainableReference.MaintainableId; } string value5 = maintainableReference.Version; if (!string.IsNullOrWhiteSpace(value5)) { categoryRefType.CategorySchemeVersion = maintainableReference.Version; } CategoryIDType idType = null; IIdentifiableRefObject childRef = refBean.ChildReference; int i = 0; while (childRef != null) { if (i == 0 || idType == null) { idType = categoryRefType.CategoryID = new CategoryIDType(); } else { idType = idType.CategoryID = new CategoryIDType(); } idType.ID = childRef.Id; childRef = childRef.ChildReference; i++; } if (ObjectUtil.ValidString(refBean.TargetUrn)) { categoryRefType.URN = refBean.TargetUrn; } } } } if (buildFrom.DataStructureRef != null) { KeyFamilyRefType keyFamilyRefType = builtObj.KeyFamilyRef = new KeyFamilyRefType(); ICrossReference dataStructureRef = buildFrom.DataStructureRef; IMaintainableRefObject refBean0 = dataStructureRef.MaintainableReference; string value3 = refBean0.AgencyId; if (!string.IsNullOrWhiteSpace(value3)) { keyFamilyRefType.KeyFamilyAgencyID = refBean0.AgencyId; } string value4 = refBean0.MaintainableId; if (!string.IsNullOrWhiteSpace(value4)) { keyFamilyRefType.KeyFamilyID = refBean0.MaintainableId; } string value5 = refBean0.Version; if (!string.IsNullOrWhiteSpace(value5)) { keyFamilyRefType.Version = refBean0.Version; } if (ObjectUtil.ValidString(dataStructureRef.TargetUrn)) { keyFamilyRefType.URN = dataStructureRef.TargetUrn; } } return builtObj; }
/// <summary> /// Initializes a new instance of the <see cref="CrossSectionalDataReaderEngine"/> class. /// </summary> /// <param name="dataLocation"> /// The data location. /// </param> /// <param name="dsd"> /// The DSD. giving the ability to retrieve DSDs for the datasets this reader engine is reading. This /// can be null if there is only one relevant DSD - in which case the default DSD should be provided /// </param> /// <param name="dataflow"> /// The dataflow. /// </param> public CrossSectionalDataReaderEngine(IReadableDataLocation dataLocation, ICrossSectionalDataStructureObject dsd, IDataflowObject dataflow) : this(dataLocation, null, dsd, dataflow) { }
/// <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); }
/// <summary> /// Starts a dataset with the data conforming to the DSD /// </summary> /// <param name="dataflow">Optional. The dataflow can be provided to give extra information about the dataset.</param> /// <param name="dsd">The data structure is used to know the dimensionality of the data</param> /// <param name="header">Dataset header containing, amongst others, the dataset action, reporting dates, /// dimension at observation if null then the dimension at observation is assumed to be TIME_PERIOD and the dataset action is assumed to be INFORMATION</param> /// <param name="annotations">Any additional annotations that are attached to the dataset, can be null if no annotations exist</param> /// <exception cref="T:System.ArgumentException">if the DSD is null</exception> public void StartDataset(IDataflowObject dataflow, IDataStructureObject dsd, IDatasetHeader header, params IAnnotation[] annotations) { this._actions.Enqueue(() => this._dataWriterEngine.StartDataset(dataflow, dsd, header, annotations)); }
/// <summary> /// Initializes a new instance of the <see cref="CrossSectionalDataReaderEngine"/> class. /// </summary> /// <param name="dataLocation"> /// The data location. /// </param> /// <param name="objectRetrieval"> /// The object retrieval. /// </param> /// <param name="defaultDsd"> /// The DSD. giving the ability to retrieve DSDs for the datasets this reader engine is reading. This /// can be null if there is only one relevant DSD - in which case the default DSD should be provided /// </param> /// <param name="dataflow"> /// The dataflow. /// </param> public CrossSectionalDataReaderEngine(IReadableDataLocation dataLocation, ISdmxObjectRetrievalManager objectRetrieval, ICrossSectionalDataStructureObject defaultDsd, IDataflowObject dataflow) { this._xmlBuilder = new XmlReaderBuilder(); if (objectRetrieval == null && defaultDsd == null) { throw new ArgumentException("AbstractDataReaderEngine expects either a ISdmxObjectRetrievalManager or a IDataStructureObject to be able to interpret the structures"); } this._objectRetrieval = objectRetrieval; this._dataLocation = dataLocation; this._defaultDsd = defaultDsd; this._dataflow = dataflow; this.Reset(); }
/// <summary> /// Initializes a new instance of the <see cref="CompactDataReaderEngine"/> class. /// Initializes a new instance of the <see cref="AbstractSdmxDataReaderEngine"/> class. /// </summary> /// <param name="dataLocation"> /// The data Location. /// </param> /// <param name="objectRetrieval"> /// The SDMX Object Retrieval. giving the ability to retrieve DSDs for the datasets this /// reader engine is reading. This can be null if there is only one relevant DSD - in which case the /// <paramref name="defaultDsd"/> should be provided. /// </param> /// <param name="defaultDataflow"> /// The default Dataflow. (Optional) /// </param> /// <param name="defaultDsd"> /// The default DSD. The default DSD to use if the <paramref name="objectRetrieval"/> is null, or /// if the bean retrieval does not return the DSD for the given dataset. /// </param> /// <exception cref="System.ArgumentException"> /// AbstractDataReaderEngine expects either a ISdmxObjectRetrievalManager or a /// IDataStructureObject to be able to interpret the structures /// </exception> public CompactDataReaderEngine(IReadableDataLocation dataLocation, ISdmxObjectRetrievalManager objectRetrieval, IDataflowObject defaultDataflow, IDataStructureObject defaultDsd) : base(dataLocation, objectRetrieval, defaultDataflow, defaultDsd) { this.Reset(); }
/// <summary> /// Determines the current data structure. /// </summary> /// <exception cref="SdmxNoResultsException"> /// Could not read dataset, the data set references dataflow '+errorString+' which could not be resolved /// or /// Could not read dataset, the data set references provision '+errorString+' which could not be resolved /// or /// Could not read dataset, the data set references dataflow '+errorString+' which could not be resolved /// or /// Can not read dataset, the data set references the DSD ' + errorString + ' which could not be resolved /// or /// Can not read dataset, the data set does no reference any data structures, and there was no default data structure /// definition provided /// </exception> /// <exception cref="SdmxNotImplementedException">Can not write dataset for structure of type: + sRef</exception> private void DetermineCurrentDataStructure() { // 1. Set the current DSD to null before trying to resolve it this._currentDsd = null; this._currentDataflow = null; IDatasetStructureReference datasetStructureReference = null; if (this._datasetHeader != null) { datasetStructureReference = this._datasetHeader.DataStructureReference; if (datasetStructureReference == null && this._headerObject != null && this._headerObject.Structures.Count == 1) { datasetStructureReference = this._headerObject.Structures[0]; } } if (datasetStructureReference != null) { var structureReference = datasetStructureReference.StructureReference; string errorString = structureReference.MaintainableReference.ToString(); // Provision, Flow, DSD or MSD switch (structureReference.TargetReference.EnumType) { case SdmxStructureEnumType.Dsd: if (this._defaultDsd != null && structureReference.IsMatch(this._defaultDsd)) { this.SetCurrentDsd(this._defaultDsd); } else if (this._objectRetrieval != null) { this.SetCurrentDsd(structureReference.MaintainableReference); } break; case SdmxStructureEnumType.Dataflow: if (this._objectRetrieval != null) { this._currentDataflow = this._objectRetrieval.GetMaintainableObject<IDataflowObject>(structureReference.MaintainableReference); if (this._currentDataflow == null) { throw new SdmxNoResultsException("Could not read dataset, the data set references dataflow '" + errorString + "' which could not be resolved"); } this.SetCurrentDsd(this._currentDataflow.DataStructureRef.MaintainableReference); } else { // Use the "header" values this.SetCurrentDsd(this._defaultDsd); this._currentDataflow = this._dataflow; } break; default: throw new SdmxNotImplementedException("Can not write dataset for structure of type: " + structureReference); } if (this._currentDsd == null) { throw new SdmxNoResultsException("Can not read dataset, the data set references the DSD '" + errorString + "' which could not be resolved"); } } else if (this._defaultDsd == null) { throw new SdmxNoResultsException("Can not read dataset, the data set does no reference any data structures, and there was no default data structure definition provided"); } else { if (this._dataflow != null) { this.SetCurrentDataflow(this._dataflow); } else { this.SetCurrentDsd(this._defaultDsd); } } }