/// <summary> /// Initializes a new instance of the <see cref="DataParseMetadata"/> class. /// </summary> /// <param name="sourceData"> /// The readable data location /// </param> /// <param name="outPutStream"> /// The output stream /// </param> /// <param name="outputSchemaVersion"> /// The output schema version /// </param> /// <param name="keyFamily"> /// The key family /// </param> public DataParseMetadata(IReadableDataLocation sourceData, Stream outPutStream, SdmxSchema outputSchemaVersion, IDataStructureObject keyFamily) { this._sourceData = sourceData; this._outPutStream = outPutStream; this._dataStructure = keyFamily; this._outputSchemaVersion = outputSchemaVersion; }
/// <summary> /// Submits the specified structural meta-data . /// </summary> /// <param name="dataLocation">The data location pointing to the structural meta-data.</param> /// <returns>The imported objects</returns> /// <exception cref="Estat.Sri.Ws.SubmitStructure.SubmitStructureException">An error occurred while importing structural meta-data.</exception> public ISdmxObjects Submit(IReadableDataLocation dataLocation, SubmitStructureConstant.ActionType actionType = SubmitStructureConstant.ActionType.Replace) { // Parse structures IStructureParsingManager is an instance field. IStructureWorkspace structureWorkspace = this._parsingManager.ParseStructures(dataLocation); // Get immutable objects from workspace ISdmxObjects objects = structureWorkspace.GetStructureObjects(false); // create a new instance of the MappingStoreManager class which implements the IStructurePersistenceManager IList<ArtefactImportStatus> importStatus = new List<ArtefactImportStatus>(); IStructurePersistenceManager persistenceManager = new MappingStoreManager(this._connectionStringSettings, importStatus); switch (actionType) { case SubmitStructureConstant.ActionType.Append: break; case SubmitStructureConstant.ActionType.Replace: // Save the structure to the mapping store database. persistenceManager.SaveStructures(objects); // Validate objects. ValidateImport(importStatus); break; case SubmitStructureConstant.ActionType.Delete: // Delete the structure to the mapping store database. persistenceManager.DeleteStructures(objects); break; default: break; } // Return the immutable object container. return objects; }
/// <summary> /// Gets the root node of the XML file.. /// </summary> /// <param name="sourceData">The source data.</param> /// <returns>The root node</returns> public static string GetRootNode(IReadableDataLocation sourceData) { try { var xmlReaderSettings = new XmlReaderSettings { IgnoreComments = true, IgnoreProcessingInstructions = true, IgnoreWhitespace = true }; using (var stream = sourceData.InputStream) using (var parser = XmlReader.Create(stream, xmlReaderSettings)) { while (parser.Read()) { switch (parser.NodeType) { case XmlNodeType.Element: { return parser.LocalName; } } } } return null; } catch (XmlException e) { throw new SdmxSyntaxException(e, ExceptionCode.XmlParseException); } }
/// <summary> /// Parse request from <paramref name="input"/> /// </summary> /// <param name="input"> /// The reader for the SDMX-ML or REST request /// </param> /// <returns> /// The <see cref="IStreamController{TWriter}"/>. /// </returns> public IStreamController <TWriter> ParseRequest(XmlNode input) { using (IReadableDataLocation xmlReadable = input.GetReadableDataLocation()) { return(this.ParseRequest(xmlReadable)); } }
/// <summary> /// Process a SMDX document to retrieve the Subscriptions, these are expected to be in a SubmitSubscriptionRequest message /// </summary> /// <param name="dataLocation"> /// The location of the SDMX document /// </param> /// <returns> /// The Subscriptions from <paramref name="dataLocation"/> /// </returns> public virtual IList<ISubscriptionObject> ParseSubscriptionXML(IReadableDataLocation dataLocation) { SdmxSchemaEnumType schemaVersion = this.GetSchemaVersion(dataLocation); //// XMLParser.ValidateXml(dataLocation, schemaVersion); using (Stream stream = dataLocation.InputStream) { using (XmlReader reader = XMLParser.CreateSdmxMlReader(stream, schemaVersion)) { IList<ISubscriptionObject> returnList = new List<ISubscriptionObject>(); switch (schemaVersion) { case SdmxSchemaEnumType.VersionTwoPointOne: RegistryInterface rid = MessageFactory.Load<RegistryInterface, RegistryInterfaceType>( reader); SubmitSubscriptionsRequestType submitSubscriptionsRequestType = rid.Content.SubmitSubscriptionsRequest; if (submitSubscriptionsRequestType != null && submitSubscriptionsRequestType.SubscriptionRequest != null) { SubmitSubscriptionsRequestType subscritpionRequestType = submitSubscriptionsRequestType; returnList = this._subscriptionObjectsBuilder.Build(subscritpionRequestType); } break; default: throw new SdmxNotImplementedException( ExceptionCode.Unsupported, "Subscription in version : " + schemaVersion.ToString()); } return returnList; } } }
public static void ParseSdmxErrorMessage(IReadableDataLocation dataLocation) { using (var stream = dataLocation.InputStream) { using (XmlReader reader = XmlReader.Create(stream)) { SdmxErrorCode errorCode = null; string code = null; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: string nodeName = reader.LocalName; if (nodeName.Equals("ErrorMessage")) { code = reader.GetAttribute("code"); errorCode = SdmxErrorCode.ParseClientCode(int.Parse(code)); } else if (nodeName.Equals("Text")) { if (errorCode == null) { errorCode = SdmxErrorCode.GetFromEnum(SdmxErrorCodeEnumType.InternalServerError); } switch (errorCode.EnumType) { case SdmxErrorCodeEnumType.NoResultsFound: throw new SdmxNoResultsException(reader.Value); case SdmxErrorCodeEnumType.NotImplemented: throw new SdmxNotImplementedException(reader.Value); case SdmxErrorCodeEnumType.SemanticError: throw new SdmxSemmanticException(reader.Value); case SdmxErrorCodeEnumType.Unauthorised: throw new SdmxUnauthorisedException(reader.Value); case SdmxErrorCodeEnumType.ServiceUnavailable: throw new SdmxServiceUnavailableException(reader.Value); case SdmxErrorCodeEnumType.SyntaxError: throw new SdmxSyntaxException(reader.Value); case SdmxErrorCodeEnumType.ResponseSizeExceedsServiceLimit: throw new SdmxResponseSizeExceedsLimitException(reader.Value); case SdmxErrorCodeEnumType.ResponseTooLarge: throw new SdmxResponseTooLargeException(reader.Value); case SdmxErrorCodeEnumType.InternalServerError: throw new SdmxInternalServerException(reader.Value); default: throw new SdmxException(reader.Value, errorCode); } } break; } } } } }
/// <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> /// Builds a <see cref="IDataQuery"/> list from a message that contains one or more data queries /// </summary> /// <param name="dataQueryLocation"> /// The data location /// </param> /// <param name="beanRetrievalManager"> /// optional, if given will retrieve the key family bean the query is for /// </param> /// <returns> /// a <see cref="IDataQuery"/> list /// </returns> public IList<IDataQuery> BuildDataQuery( IReadableDataLocation dataQueryLocation, ISdmxObjectRetrievalManager beanRetrievalManager) { this._log.Debug("DataParseManagerImpl.buildDataQuery"); using (ISdmxXmlStream xmlStream = new SdmxXmlStream(dataQueryLocation)) { LoggingUtil.Debug(this._log, "Schema Version Determined to be : " + xmlStream.SdmxVersion); return this.BuildDataQuery(xmlStream, beanRetrievalManager); } }
/// <summary> /// Parse request from <paramref name="input"/> /// </summary> /// <param name="input"> /// The reader for the SDMX-ML or REST request /// </param> /// <returns> /// The <see cref="IStreamController{TWriter}"/>. /// </returns> public IStreamController <TWriter> ParseRequest(IReadableDataLocation input) { IDataQueryParseManager dataQueryParseManager = new DataQueryParseManager(SdmxSchemaEnumType.VersionTwoPointOne); var dataQuery = dataQueryParseManager.BuildComplexDataQuery(input, this._sdmxRetrievalManager).FirstOrDefault(); if (dataQuery == null) { throw new SdmxSemmanticException(Resources.ErrorOperationNotAccepted); } return(this.ParseRequest(dataQuery)); }
/// <summary> /// Gets the data query from stream. /// </summary> /// <param name="input"> /// The input. /// </param> /// <exception cref="Org.Sdmxsource.Sdmx.Api.Exception.SdmxSemmanticException"> /// Operation not accepted /// </exception> /// <returns> /// The <see cref="IDataQuery"/>. /// </returns> protected IDataQuery GetDataQueryFromStream(IReadableDataLocation input) { IDataQueryParseManager dataQueryParseManager = new DataQueryParseManager(SdmxSchemaEnumType.VersionTwo); var dataQuery = dataQueryParseManager.BuildDataQuery(input, this._sdmxRetrievalManager).FirstOrDefault(); if (dataQuery == null) { throw new SdmxSemmanticException(Resources.ErrorOperationNotAccepted); } return(dataQuery); }
/// <summary> /// Initializes a new instance of the <see cref="SdmxDataModelProvider"/> class. /// </summary> /// <param name="rootModel">The root data model.</param> /// <param name="namespaceName">The namespace name.</param> /// <param name="strUrl">The URL path to a SMDX file.</param> public SdmxDataModelProvider(IDataModelProvider rootModel, string namespaceName, string strUrl) : this(rootModel, namespaceName) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl); HttpClient.DefaultProxy.Credentials = CredentialCache.DefaultNetworkCredentials; request.Method = "GET"; request.Accept = "application/xml"; WebResponse response = request.GetResponse(); this._readableDataLocation = this._dataLocationFactory.GetReadableDataLocation(response.GetResponseStream()); }
/// <summary> /// Parse request from <paramref name="input"/> /// </summary> /// <param name="input"> /// The reader for the SDMX-ML or REST request /// </param> /// <returns> /// The <see cref="IStreamController{TWriter}"/>. /// </returns> public IStreamController <TWriter> ParseRequest(Message input) { if (input == null) { throw new SdmxSemmanticException(Resources.ErrorOperationNotAccepted); } using (IReadableDataLocation xmlReadable = input.GetReadableDataLocation(new XmlQualifiedName(SdmxConstants.RegistryInterfaceRootNode, SdmxConstants.MessageNs20))) { return(this.ParseRequest(xmlReadable)); } }
/// <summary> /// Parse request from <paramref name="input"/> /// </summary> /// <param name="input"> /// The reader for the SDMX-ML or REST request /// </param> /// <returns> /// The <see cref="IStreamController{TWriter}"/>. /// </returns> public IStreamController <TWriter> ParseRequest(XElement input) { if (input == null) { throw new SdmxSemmanticException(Resources.ErrorOperationNotAccepted); } using (IReadableDataLocation xmlReadable = input.GetReadableDataLocation()) { return(this.ParseRequest(xmlReadable)); } }
/// <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"); }
// TODO Test that there is a notification event in this message! #region Public Methods and Operators /// <summary> /// Parses the XML that is retrieved from the URI to create a notification event. /// Makes sure the notification event is valid /// </summary> /// <param name="dataLocation"> /// The data location of the SDMX XML file /// </param> /// <returns> /// The <see cref="INotificationEvent"/>. /// </returns> public virtual INotificationEvent CreateNotificationEvent(IReadableDataLocation dataLocation) { LoggingUtil.Debug(_log, "Parse Structure request, for xml at location: " + dataLocation); INotificationEvent notificationEvent; SdmxSchemaEnumType schemaVersion = this.GetSchemaVersion(dataLocation); LoggingUtil.Debug(_log, "Schema Version Determined to be : " + schemaVersion); ////XMLParser.ValidateXml(dataLocation, schemaVersion); LoggingUtil.Debug(_log, "XML VALID"); using (Stream stream = dataLocation.InputStream) { using (XmlReader reader = XMLParser.CreateSdmxMlReader(stream, schemaVersion)) { switch (schemaVersion) { case SdmxSchemaEnumType.VersionTwo: RegistryInterface rid = RegistryInterface.Load(reader); if (rid.NotifyRegistryEvent == null) { throw new ArgumentException( "Can not parse message as NotifyRegistryEvent, as there are no NotifyRegistryEvent in message"); } notificationEvent = new NotificationEventCore(rid.NotifyRegistryEvent); break; case SdmxSchemaEnumType.VersionTwoPointOne: Org.Sdmx.Resources.SdmxMl.Schemas.V21.Message.RegistryInterface rid21 = Org.Sdmx.Resources.SdmxMl.Schemas.V21.Message.RegistryInterface.Load(reader); NotifyRegistryEventType notifyRegistryEventType = rid21.Content.NotifyRegistryEvent; if (notifyRegistryEventType == null) { throw new ArgumentException( "Can not parse message as NotifyRegistryEvent, as there are no NotifyRegistryEvent in message"); } notificationEvent = new NotificationEventCore(notifyRegistryEventType); break; default: throw new SdmxNotImplementedException( ExceptionCode.Unsupported, "Parse NotificationEvent at version: " + schemaVersion); } } } // TODO Validation return notificationEvent; }
/// <summary> /// Gets Maintainable SDMX objects from workspace. /// </summary> /// <returns>Maintainable SDMX objects.</returns> private ISet <IMaintainableObject> GetMaintainableObjects() { IStructureWorkspace workspace; using (IReadableDataLocation rdl = this._readableDataLocation) { workspace = this._structureParsingManager.ParseStructures(rdl); } ISdmxObjects sdmxObjects = workspace.GetStructureObjects(false); ISet <IMaintainableObject> maintainable = sdmxObjects.GetAllMaintainables(); return(maintainable); }
/// <summary> /// Gets the mutable objects V20. /// </summary> /// <param name="input"> /// The input. /// </param> /// <param name="dataflowPrincipal"> /// The dataflow principal. /// </param> /// <returns> /// The <see cref="IMutableObjects"/>. /// </returns> /// <exception cref="SdmxSemmanticException"> /// Operation not accepted /// </exception> private IMutableObjects GetMutableObjectsV21(IReadableDataLocation input, DataflowPrincipal dataflowPrincipal) { IQueryWorkspace queryWorkspace = this._manager.ParseQueries(input); if (queryWorkspace == null) { // throw new SdmxSemmanticException(Properties.Resources.MissingRegistryOrInvalidSoap); throw new SdmxSemmanticException(Resources.ErrorOperationNotAccepted); } IMutableObjects mutableObjects = dataflowPrincipal != null ? this._authStructureSearchManager.GetMaintainables(queryWorkspace.ComplexStructureQuery, dataflowPrincipal.AllowedDataflows.ToList()) : this._structureSearchManager.GetMaintainables(queryWorkspace.ComplexStructureQuery); return(mutableObjects); }
/// <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"); } }
/// <summary> /// First Parse Message arrived from external process for SDMX 2.0 /// </summary> /// <param name="manager">data parsed from DataQueryParseManager (Sdmx CommonAPI)</param> /// <param name="location">Arrived Message converted to IReadableDataLocation</param> public void ParseQueryMessage20(IDataQueryParseManager manager, IReadableDataLocation location) { HaveError = false; ErrorMessage = null; try { RetrievalManagerObject = new RetrievalManager(DataFlowElementId, SdmxSchemaEnumType.VersionTwo); //RetrievalManagerObject. IList <IDataQuery> WhereStatement20 = manager.BuildDataQuery(location, (ISdmxObjectRetrievalManager)RetrievalManagerObject); WhereStatement = new DataWhereStatment(WhereStatement20); } catch (SdmxException sdmxerr) { HaveError = true; ErrorMessage = sdmxerr; } catch (Exception err) { HaveError = true; ErrorMessage = new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.ParsingQueryError, err); } }
/// <summary> /// Submits the specified structural meta-data . /// </summary> /// <param name="dataLocation">The data location pointing to the structural meta-data.</param> /// <returns>The imported objects</returns> /// <exception cref="Estat.Sri.Ws.SubmitStructure.SubmitStructureException">An error occurred while importing structural meta-data.</exception> public ISdmxObjects Submit(IReadableDataLocation dataLocation, SubmitStructureConstant.ActionType actionType = SubmitStructureConstant.ActionType.Replace) { // Parse structures IStructureParsingManager is an instance field. IStructureWorkspace structureWorkspace = this._parsingManager.ParseStructures(dataLocation); // Get immutable objects from workspace ISdmxObjects objects = structureWorkspace.GetStructureObjects(false); // create a new instance of the MappingStoreManager class which implements the IStructurePersistenceManager IList <ArtefactImportStatus> importStatus = new List <ArtefactImportStatus>(); IStructurePersistenceManager persistenceManager = new MappingStoreManager(this._connectionStringSettings, importStatus); switch (actionType) { case SubmitStructureConstant.ActionType.Append: break; case SubmitStructureConstant.ActionType.Replace: // Save the structure to the mapping store database. persistenceManager.SaveStructures(objects); // Validate objects. ValidateImport(importStatus); break; case SubmitStructureConstant.ActionType.Delete: // Delete the structure to the mapping store database. persistenceManager.DeleteStructures(objects); break; default: break; } // Return the immutable object container. return(objects); }
/// <summary> /// Processes the SDMX at the given URI and returns a workspace containing the information on what was being queried. /// <p/> /// The Query parsing manager processes queries that are in a RegistryInterface document, this includes queries for /// Provisions, Registrations and Structures. It also processes Queries that are in a QueryMessage document /// </summary> /// <param name="dataLocation"> /// The data location of the query /// </param> /// <returns> /// The <see cref="IQueryWorkspace"/> from <paramref name="dataLocation"/>. /// </returns> public virtual IQueryWorkspace ParseQueries(IReadableDataLocation dataLocation) { LoggingUtil.Debug(_log, "Parse Structure request, for xml at location: " + dataLocation); using (ISdmxXmlStream xmlStream = new SdmxXmlStream(dataLocation)) { return this.ParseQueries(xmlStream); } }
/// <summary> /// Validates the Edi is valid and returns metadata about the parsed Edi file /// </summary> /// <param name="ediMessageLocation"> /// The EDI message location. /// </param> /// <returns> /// The <see cref="IEdiMetadata"/>. /// </returns> public IEdiMetadata ParseEDIMessage(IReadableDataLocation ediMessageLocation) { var parserEngine = new EDIStructureParserEngine(ediMessageLocation); return parserEngine.ProcessMessage(); }
/// <summary> /// Parse request from <paramref name="input"/> /// </summary> /// <param name="input"> /// The reader for the SDMX-ML request /// </param> /// <returns> /// The <see cref="IStreamController{TWriter}"/>. /// </returns> public IStreamController <TWriter> ParseRequest(IReadableDataLocation input) { return(this.ParseRequestPrivate(principal => this.GetMutableObjectsV20(input, principal))); }
/// <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) { }
/// <summary> /// Gets message type, if set from the constructor otherwise from the <paramref name="dataLocation"/> /// </summary> /// <param name="dataLocation"> /// The data location. /// </param> /// <returns> /// The <see cref="MessageEnumType"/>. /// </returns> protected virtual MessageEnumType GetMessageType(IReadableDataLocation dataLocation) { SdmxSchemaEnumType sdmxSchemaEnumType = this.GetSchemaVersion(dataLocation); bool readDataLocation = this._messageType == MessageEnumType.Null && sdmxSchemaEnumType != SdmxSchemaEnumType.Edi; MessageEnumType messageType = readDataLocation ? SdmxMessageUtil.GetMessageType(dataLocation) : this._messageType; if (readDataLocation) { LoggingUtil.Debug(_log, "Message Type Determined to be : " + messageType); } else { LoggingUtil.Debug(_log, "Message Type specified on CTOR : " + messageType); } return messageType; }
/// <summary> /// Initializes a new instance of the <see cref="EdiReader"/> class. /// </summary> /// <param name="dataFile"> /// The data file. /// </param> public EdiReader(IReadableDataLocation dataFile) : base(dataFile, EdiConstants.EndOfLineRegEx, EdiConstants.CharsetEncoding) { // End of line terminator is any ' char that is not immediately preceded by a ? }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="managed"> /// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only /// unmanaged resources. /// </param> protected virtual void Dispose(bool managed) { if (!this._disposed) { return; } if (managed) { this.CloseStreams(); if (this._dataLocation != null) { this._dataLocation.Close(); this._dataLocation = null; } } this._disposed = true; }
/// <summary> /// Gets the message group data format. /// </summary> /// <param name="sourceData"> /// The source data. /// </param> /// <returns> /// The <see cref="BaseDataFormatEnumType"/>. /// </returns> private BaseDataFormatEnumType GetMessageGroupDataFormat(IReadableDataLocation sourceData) { using (var stream = sourceData.InputStream) using (var parser = this._xmlReaderBuilder.Build(stream)) { while (parser.Read()) { switch (parser.NodeType) { case XmlNodeType.Element: { string rootNode = parser.LocalName; if (ElementNameTable.DataSet.Is(rootNode)) { string namespaceUri = parser.NamespaceURI; if (SdmxConstants.GenericNs10.Equals(namespaceUri) || SdmxConstants.GenericNs20.Equals(namespaceUri)) { return BaseDataFormatEnumType.Generic; } if (SdmxConstants.UtilityNs10.Equals(namespaceUri) || SdmxConstants.UtilityNs20.Equals(namespaceUri)) { return BaseDataFormatEnumType.Utility; } if (SdmxConstants.CompactNs10.Equals(namespaceUri) || SdmxConstants.CompactNs20.Equals(namespaceUri) || namespaceUri.StartsWith("urn")) { return BaseDataFormatEnumType.Compact; } } } break; } } } return BaseDataFormatEnumType.Null; }
/// <summary> /// Returns the target namespace of the dataset /// </summary> /// <param name="sourceData"> /// The readable data location /// </param> /// <returns> /// The target namespace of the dataset /// </returns> public string GetTargetNamepace(IReadableDataLocation sourceData) { using (var stream = sourceData.InputStream) { return this.JumpToNode(stream, ElementNameTable.DataSet, null, true).NamespaceURI; } }
/// <summary> /// Returns the data type for the sourceData /// </summary> /// <param name="sourceData"> /// The readable data location /// </param> /// <returns> /// The data type for the sourceData /// </returns> public IDataFormat GetDataType(IReadableDataLocation sourceData) { MessageEnumType messageEnumType = SdmxMessageUtil.GetMessageType(sourceData); if (messageEnumType == MessageEnumType.SdmxEdi) { return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.EdiTs)); } if (messageEnumType == MessageEnumType.Error) { SdmxMessageUtil.ParseSdmxErrorMessage(sourceData); } // .NET implementation note. There is no XmlReader.GetNamespaceUri(int) in .NET // Also the Java code seems to repeat code already in SdmxMessageUtil. // So the .NET implementation is re-using SdmxMessageUtil to determine the data format and SDMX version. var sdmxVersion = SdmxMessageUtil.GetSchemaVersion(sourceData); switch (sdmxVersion) { case SdmxSchemaEnumType.VersionOne: switch (messageEnumType) { case MessageEnumType.GenericData: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.Generic10)); case MessageEnumType.UtilityData: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.Utility10)); case MessageEnumType.CompactData: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.Compact10)); case MessageEnumType.CrossSectionalData: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.CrossSectional10)); case MessageEnumType.MessageGroup: BaseDataFormatEnumType dataFormat = this.GetMessageGroupDataFormat(sourceData); switch (dataFormat) { case BaseDataFormatEnumType.Compact: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.MessageGroup10Compact)); case BaseDataFormatEnumType.Generic: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.MessageGroup10Generic)); case BaseDataFormatEnumType.Utility: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.MessageGroup10Utility)); } throw new SdmxSyntaxException("Unknown Message Group Format"); } break; case SdmxSchemaEnumType.VersionTwo: switch (messageEnumType) { case MessageEnumType.GenericData: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.Generic20)); case MessageEnumType.UtilityData: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.Utility20)); case MessageEnumType.CompactData: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.Compact20)); case MessageEnumType.CrossSectionalData: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.CrossSectional20)); case MessageEnumType.MessageGroup: BaseDataFormatEnumType dataFormat = this.GetMessageGroupDataFormat(sourceData); switch (dataFormat) { case BaseDataFormatEnumType.Compact: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.MessageGroup20Compact)); case BaseDataFormatEnumType.Generic: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.MessageGroup20Generic)); case BaseDataFormatEnumType.Utility: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.MessageGroup20Utility)); } throw new SdmxSyntaxException("Unknown Message Group Format"); } break; case SdmxSchemaEnumType.VersionTwoPointOne: switch (messageEnumType) { case MessageEnumType.GenericData: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.Generic21)); case MessageEnumType.CompactData: return new SdmxDataFormatCore(DataType.GetFromEnum(DataEnumType.Compact21)); } break; default: throw new SdmxSyntaxException(ExceptionCode.XmlParseException, "Can not determine data type unknown namespaces defined"); } string rootNode = XmlUtil.GetRootNode(sourceData); throw new SdmxSyntaxException("Unexpected root node '" + rootNode + "'"); }
/// <summary> /// Processes an EDI message and returns a workspace containing the SDMX structures and data that were contained in the /// message /// </summary> /// <param name="ediMessageLocation"> /// The EDI message location. /// </param> /// <returns> /// The <see cref="IEdiWorkspace"/>. /// </returns> public IEdiWorkspace ParseEdiMessage(IReadableDataLocation ediMessageLocation) { return new EdiWorkspace(ediMessageLocation, this._writeableDataLocationFactory, this._ediParseEngine); }
/// <summary> /// Initializes a new instance of the <see cref="SdmxDataModelProvider"/> class. /// </summary> /// <param name="rootModel">The root data model.</param> /// <param name="namespaceName">The namespace name.</param> /// <param name="bytes">The SDMX loaded file as a byte array.</param> public SdmxDataModelProvider(IDataModelProvider rootModel, string namespaceName, byte[] bytes) : this(rootModel, namespaceName) { this._readableDataLocation = this._dataLocationFactory.GetReadableDataLocation(bytes); }
/// <summary> /// Parse request from <paramref name="input"/> /// </summary> /// <param name="input"> /// The reader for the SDMX-ML or REST request /// </param> /// <returns> /// The <see cref="IStreamController{TWriter}"/>. /// </returns> public IStreamController <TWriter> ParseRequest(IReadableDataLocation input) { var dataQuery = this.GetDataQueryFromStream(input); return(this.ParseRequest(dataQuery)); }
/// <summary> /// Initializes a new instance of the <see cref="SdmxDataModelProvider"/> class. /// </summary> /// <param name="rootModel">The root data model.</param> /// <param name="namespaceName">The namespace name.</param> /// <param name="structureUri">The SDMX Uri object.</param> public SdmxDataModelProvider(IDataModelProvider rootModel, string namespaceName, Uri structureUri) : this(rootModel, namespaceName) { this._readableDataLocation = this._dataLocationFactory.GetReadableDataLocation(structureUri); }
/// <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> /// 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="EdiAbstractPositionalReader"/> class. /// </summary> /// <param name="dataFile"> /// The data file. /// </param> /// <param name="documentPosition"> /// The document position. /// </param> /// <param name="ediMetadata"> /// The edi metadata. /// </param> public EdiAbstractPositionalReader(IReadableDataLocation dataFile, IEdiDocumentPosition documentPosition, IEdiMetadata ediMetadata) : base(dataFile) { this._ediMetadata = ediMetadata; this._documentPosition = documentPosition; }
/// <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; }
public IList<IComplexDataQuery> BuildComplexDataQuery(IReadableDataLocation dataQueryLocation, ISdmxObjectRetrievalManager beanRetrievalManager) { _log.Debug("DataParseManagerImpl.buildComplexDataQuery"); SdmxSchemaEnumType schemaVersion = SdmxMessageUtil.GetSchemaVersion(dataQueryLocation); LoggingUtil.Debug(_log, "Schema Version Determined to be : " + schemaVersion); XMLParser.ValidateXml(dataQueryLocation, schemaVersion); using (Stream inputStream = dataQueryLocation.InputStream) using (var textReader = new StreamReader(inputStream)) { switch (schemaVersion) { case SdmxSchemaEnumType.VersionOne: throw new ArgumentException("Build Complex Data Query concerns sdmx messages of schema version 2.1 "); case SdmxSchemaEnumType.VersionTwo: throw new ArgumentException("Build Complex Data Query concerns sdmx messages of schema version 2.1 "); case SdmxSchemaEnumType.VersionTwoPointOne: IList<QueryMessageEnumType> queryMessageTypes = SdmxMessageUtil.GetQueryMessageTypes(dataQueryLocation); QueryMessageEnumType queryMessageType = queryMessageTypes[0]; if (queryMessageType.Equals(QueryMessageEnumType.GenericDataQuery)) { GenericDataQuery queryV21 = GenericDataQuery.Load(textReader); return this._dataQueryBuilder.BuildComplexDataQuery(queryV21.Content.BaseDataQueryType, beanRetrievalManager); } else if (queryMessageType.Equals(QueryMessageEnumType.GenericTimeseriesDataQuery)) { GenericTimeSeriesDataQuery queryV21 = GenericTimeSeriesDataQuery.Load(textReader); return this._dataQueryBuilder.BuildComplexDataQuery(queryV21.Content.BaseDataQueryType, beanRetrievalManager); } else if (queryMessageType.Equals(QueryMessageEnumType.StructureSpecificDataQuery)) { StructureSpecificDataQuery queryV21 = StructureSpecificDataQuery.Load(textReader); return this._dataQueryBuilder.BuildComplexDataQuery(queryV21.Content.BaseDataQueryType, beanRetrievalManager); } else //if (queryMessageType.Equals(QueryMessageEnumType.StructureSpecificTimeSeriesDataQuery)) { StructureSpecificTimeSeriesDataQuery queryV21 = StructureSpecificTimeSeriesDataQuery.Load(textReader); return this._dataQueryBuilder.BuildComplexDataQuery(queryV21.Content.BaseDataQueryType, beanRetrievalManager); } default: throw new SdmxNotImplementedException(ExceptionCode.Unsupported, "buildComplexDataQuery in version " + schemaVersion); } } }
/// <summary> /// Initializes a new instance of the <see cref="EdiReader"/> class. /// </summary> /// <param name="dataFile"> /// The data file. /// </param> /// <param name="startindex"> /// The start-index. /// </param> /// <param name="endIndex"> /// The end index. /// </param> public EdiReader(IReadableDataLocation dataFile, int startindex, int endIndex) : base(dataFile, EdiConstants.EndOfLineRegEx, startindex, endIndex, EdiConstants.CharsetEncoding) { }
/// <summary> /// Process a SMDX document to retrieve the Provisions, these can either be in /// a QueryProvisionResponse message or inside a SubmitProvisionRequest message /// </summary> /// <param name="dataLocation"> /// The data location of the SDMX document /// </param> /// <returns> /// The Provisions from <paramref name="dataLocation"/> /// </returns> public virtual IList<IProvisionAgreementObject> ParseXML(IReadableDataLocation dataLocation) { SdmxSchemaEnumType schemaVersion = this.GetSchemaVersion(dataLocation); XMLParser.ValidateXml(dataLocation, schemaVersion); Stream stream = dataLocation.InputStream; XmlReader reader = XMLParser.CreateSdmxMlReader(stream, schemaVersion); IList<IProvisionAgreementObject> returnList = new List<IProvisionAgreementObject>(); switch (schemaVersion) { case SdmxSchemaEnumType.VersionTwo: RegistryInterface rid = RegistryInterface.Load(reader); if (rid.QueryProvisioningResponse != null && rid.QueryProvisioningResponse.ProvisionAgreement != null) { /* foreach */ foreach (ProvisionAgreementType provType in rid.QueryProvisioningResponse.ProvisionAgreement) { returnList.Add(new ProvisionAgreementObjectCore(provType)); } // FUNC Support provisions by these types if (ObjectUtil.ValidCollection(rid.QueryProvisioningResponse.DataflowRef)) { throw new SdmxNotImplementedException(ExceptionCode.Unsupported, "Provision for Dataflow"); } if (ObjectUtil.ValidCollection(rid.QueryProvisioningResponse.MetadataflowRef)) { throw new SdmxNotImplementedException(ExceptionCode.Unsupported, "Provision for Metadataflow"); } if (ObjectUtil.ValidCollection(rid.QueryProvisioningResponse.DataProviderRef)) { throw new SdmxNotImplementedException(ExceptionCode.Unsupported, "Provision for Dataprovider"); } } if (rid.SubmitProvisioningRequest != null && rid.SubmitProvisioningRequest.ProvisionAgreement != null) { /* foreach */ foreach (ProvisionAgreementType provType0 in rid.SubmitProvisioningRequest.ProvisionAgreement) { returnList.Add(new ProvisionAgreementObjectCore(provType0)); } // FUNC Support provisions by these types if (ObjectUtil.ValidCollection(rid.SubmitProvisioningRequest.DataflowRef)) { throw new SdmxNotImplementedException(ExceptionCode.Unsupported, "Submit Provision for Dataflow"); } if (ObjectUtil.ValidCollection(rid.SubmitProvisioningRequest.MetadatataflowRef)) { throw new SdmxNotImplementedException( ExceptionCode.Unsupported, "Submit Provision for Metadataflow"); } if (ObjectUtil.ValidCollection(rid.SubmitProvisioningRequest.DataProviderRef)) { throw new SdmxNotImplementedException( ExceptionCode.Unsupported, "Submit Provision for Dataprovider"); } } break; default: throw new SdmxNotImplementedException(ExceptionCode.Unsupported, schemaVersion); } return returnList; }
/// <summary> /// Gets schema version, if set from the constructor otherwise from the <paramref name="dataLocation"/> /// </summary> /// <param name="dataLocation"> /// The data location. /// </param> /// <returns> /// The <see cref="SdmxSchemaEnumType"/>. /// </returns> protected virtual SdmxSchemaEnumType GetSchemaVersion(IReadableDataLocation dataLocation) { SdmxSchemaEnumType schemaVersion = this._sdmxSchema == SdmxSchemaEnumType.Null ? SdmxMessageUtil.GetSchemaVersion(dataLocation) : this._sdmxSchema; if (this._sdmxSchema == SdmxSchemaEnumType.Null) { LoggingUtil.Debug(_log, "Schema Version Determined to be : " + schemaVersion); } else { LoggingUtil.Debug(_log, "Using Schema Version specified on CTOR : " + schemaVersion); } return schemaVersion; }
/// <summary> /// Initializes a new instance of the <see cref="EDIStructureParserEngine"/> class. /// </summary> /// <param name="sourceData"> /// The source data. /// </param> public EDIStructureParserEngine(IReadableDataLocation sourceData) { this._ediReader = new EdiReader(sourceData); this._twoLetterIsoLanguageName = CultureInfo.GetCultureInfo("en").TwoLetterISOLanguageName; }
/// <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> /// The is edi. /// </summary> /// <param name="sourceData"> /// The source data. /// </param> /// <returns> /// The <see cref="bool"/> . /// </returns> /// <exception cref="ArgumentException">Throws ArgumentException /// </exception> /// <exception cref="Exception">Throws Exception /// </exception> private static bool IsEdi(IReadableDataLocation sourceData) { Stream stream = sourceData.InputStream; try { TextReader br = new StreamReader(stream); var firstPortion = new char[100]; br.Read(firstPortion, 0, 100); var str = new string(firstPortion); return str.ToUpper().StartsWith("UNA"); } catch (IOException e) { throw new ArgumentException("Error while trying to read source:" + sourceData); } finally { if (stream != null) { try { stream.Close(); } catch (IOException e) { throw new Exception(e.Message, e); } } } }