/// <summary> /// Validates the SDMX V20. /// </summary> /// <param name="dataQuery"> /// The data query. /// </param> /// <param name="format"> /// The format. /// </param> /// <exception cref="Org.Sdmxsource.Sdmx.Api.Exception.SdmxNoResultsException"> /// This dataflow uses SDMX v2.0 only /// DataStructureDefinition. /// </exception> private static void ValidateSdmxV20(IBaseDataQuery dataQuery, BaseConstantType <BaseDataFormatEnumType> format) { if (!dataQuery.DataStructure.IsCompatible(SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwo))) { // TODO check java message/error in this case throw new SdmxNoResultsException("This dataflow uses SDMX v2.1 only DataStructureDefinition."); } switch (format.EnumType) { case BaseDataFormatEnumType.Null: break; case BaseDataFormatEnumType.Generic: case BaseDataFormatEnumType.Compact: case BaseDataFormatEnumType.Utility: case BaseDataFormatEnumType.Edi: ValidateSdmxV20TimeSeries(dataQuery); break; case BaseDataFormatEnumType.CrossSectional: ValidateErrors(Validator.ValidateForCrossSectional(dataQuery.DataStructure)); break; default: throw new SdmxSemmanticException("SDMX v2.0 Unsupported format " + format); } }
/// <summary> /// Initializes static members of the <see cref="ControllerBuilder" /> class. /// </summary> static ControllerBuilder() { _log = LogManager.GetLogger(typeof(ControllerBuilder)); _compactDataFormat = BaseDataFormat.GetFromEnum(BaseDataFormatEnumType.Compact); _genericDataFormat = BaseDataFormat.GetFromEnum(BaseDataFormatEnumType.Generic); _crossSectional = BaseDataFormat.GetFromEnum(BaseDataFormatEnumType.CrossSectional); _sdmxSchemaV20 = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwo); _sdmxSchemaV21 = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne); }
/// <summary> /// Initializes a new instance of the <see cref="StructureRequestV20Controller{TWriter}"/> class. /// </summary> /// <param name="responseGenerator"> /// The response generator. /// </param> /// <param name="structureSearchManager"> /// The structure search manager. /// </param> /// <param name="authStructureSearchManager"> /// The authentication structure search manager. /// </param> /// <param name="dataflowPrincipal"> /// The dataflow principal. /// </param> /// <exception cref="SdmxSemmanticException"> /// Operation not accepted with query used /// </exception> public StructureRequestV20Controller( IResponseGenerator <TWriter, ISdmxObjects> responseGenerator, IMutableStructureSearchManager structureSearchManager, IAuthMutableStructureSearchManager authStructureSearchManager, DataflowPrincipal dataflowPrincipal) : base(responseGenerator, dataflowPrincipal) { this._structureSearchManager = structureSearchManager; this._authStructureSearchManager = authStructureSearchManager; SdmxSchema sdmxSchemaV20 = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwo); this._manager = new QueryParsingManager(sdmxSchemaV20.EnumType, new QueryBuilder(null, new ConstrainQueryBuilderV2(), null)); }
/// <summary> /// Initializes a new instance of the <see cref="StructureRequestV21AdvancedController{TWriter}"/> class. /// </summary> /// <param name="responseGenerator"> /// The response generator. /// </param> /// <param name="authStructureSearchManager"> /// The authentication structure search manager. /// </param> /// <param name="structureSearchManager"> /// The structure search manager. /// </param> /// <param name="principal"> /// The principal. /// </param> /// <param name="soapOperation"> /// The SOAP operation. /// </param> /// <exception cref="SdmxSemmanticException"> /// Operation not accepted with query used /// </exception> public StructureRequestV21AdvancedController( IResponseGenerator <TWriter, ISdmxObjects> responseGenerator, IAuthAdvancedMutableStructureSearchManager authStructureSearchManager, IAdvancedMutableStructureSearchManager structureSearchManager, DataflowPrincipal principal, SoapOperation soapOperation) : base(responseGenerator, principal) { this._authStructureSearchManager = authStructureSearchManager; this._structureSearchManager = structureSearchManager; SdmxSchema sdmxSchemaV21 = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne); this._manager = new QueryParsingManager(sdmxSchemaV21.EnumType); this._rootNode = soapOperation.GetQueryRootElementV21(); }
/// <summary> /// The get version from media type. /// </summary> /// <param name="selectedMediaTypeWithVersion"> /// The selected media type with version. /// </param> /// <param name="format"> /// The format. /// </param> /// <returns> /// The <see cref="SdmxSchema"/>. /// </returns> private static SdmxSchema GetVersionFromMediaType(ContentType selectedMediaTypeWithVersion, BaseDataFormat format) { SdmxSchema version = null; switch (format.EnumType) { case BaseDataFormatEnumType.Edi: version = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.Edi); break; case BaseDataFormatEnumType.Csv: version = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.Csv); break; default: version = RestUtils.GetVersionFromMediaType(selectedMediaTypeWithVersion); break; } return(version); }
/// <summary> /// The get version from media type. /// </summary> /// <param name="mediaType"> /// The media type. /// </param> /// <returns> /// The <see cref="SdmxSchema"/>. /// </returns> public static SdmxSchema GetVersionFromMediaType(ContentType mediaType) { if (mediaType.Parameters == null) { return(SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne)); } if (!mediaType.Parameters.ContainsKey("version")) { return(SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne)); } if (mediaType.Parameters["version"].Equals("2.1")) { return(SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne)); } if (mediaType.Parameters["version"].Equals("2.0")) { return(SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwo)); } return(null); }
/// <summary> /// Write a DataMessage in XmlWriter calling WriteTimeSeriesData or WriteFlatData or WriteCrossSectional /// </summary> /// <param name="writer">Stream Destination</param> public override void WriteDataMessage(IFlyWriter writer) { try { IDataWriterEngine dataWriterEngine = null; switch (MessageType) { case MessageTypeEnum.GenericData_21: dataWriterEngine = new GenericDataWriterEngine(writer.__SdmxXml, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne)); break; case MessageTypeEnum.GenericTimeSeries_21: dataWriterEngine = new GenericDataWriterEngine(writer.__SdmxXml, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne)); break; case MessageTypeEnum.StructureSpecific_21: dataWriterEngine = new CompactDataWriterEngine(writer.__SdmxXml, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne)); break; case MessageTypeEnum.StructureSpecificTimeSeries_21: dataWriterEngine = new CompactDataWriterEngine(writer.__SdmxXml, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne)); break; } isFlat = false; if (!string.IsNullOrEmpty(this.DimensionAtObservation) && this.DimensionAtObservation == "AllDimensions") { isFlat = true; } //Da capire!!!! perche in teoria le crossSectional dovrebbero essere GenericData_21 e StructureSpecific_21 mentre le atre 2 sono TimeSeries //Ma le CommonApi non supportano le TimeSeries e quelle che in teoria sono Cross in realtà sono TimeSeries //WriteCrossSectional(ref writer); //return; if (dataWriterEngine == null) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.InternalError, new Exception("No Type Message recognized")); } // write header IHeader header = FlyConfiguration.HeaderSettings.GetHeader(); dataWriterEngine.WriteHeader(header); // start dataset DataStructureObjectImpl dsd = _retrievalManager._dsd; dataWriterEngine.StartDataset(null, dsd.Immutated, null); // Aggiungo dataset Title if (FlyConfiguration.DatasetTitle && !string.IsNullOrEmpty(this._retrievalManager.DataFlowTitle)) { dataWriterEngine.WriteAttributeValue("Title", this._retrievalManager.DataFlowTitle); } //GROUPS if (_retrievalManager.Groups != null && _retrievalManager.Groups.Count > 0) { foreach (DataGroupObject group in _retrievalManager.Groups) { dataWriterEngine.StartGroup(group.GroupId); foreach (GroupReferenceObject GroupKey in group.DimensionReferences) { dataWriterEngine.WriteGroupKeyValue(GroupKey.ConceptCode, GroupKey.ConceptValue.ToString()); } foreach (GroupReferenceObject GroupAttribute in group.AttributeReferences) { dataWriterEngine.WriteAttributeValue(GroupAttribute.ConceptCode, GroupAttribute.ConceptValue.ToString()); } } } this.LastSeriesKey = null; if (isFlat) { WriteFlatData(dataWriterEngine); } else { WriteTimeSeriesData(dataWriterEngine); } dataWriterEngine.Close(); writer.__SdmxXml.Flush(); } catch (SdmxException) { throw; } catch (Exception ex) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.ErrorWriteDataMessage, ex); } }
/// <summary> /// Builds the specified writer engine. /// </summary> /// <param name="writer">The writer.</param> /// <param name="actions">The actions.</param> /// <returns> /// The <see cref="ICrossSectionalWriterEngine" />. /// </returns> public ICrossSectionalWriterEngine Build(XmlWriter writer, Queue <Action> actions) { return(new DelayedCrossWriterEngine(actions, new CrossSectionalWriterEngine(writer, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwo)))); }
/// <summary> /// Write a DataMessage in XmlWriter /// </summary> /// <param name="writer">Stream Destination</param> public override void WriteDataMessage(IFlyWriter writer) { try { IDataWriterEngine dataWriterEngine = null; switch (MessageType) { case MessageTypeEnum.Compact_20: dataWriterEngine = new CompactDataWriterEngine(writer.__SdmxXml, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwo)); break; case MessageTypeEnum.Generic_20: dataWriterEngine = new GenericDataWriterEngine(writer.__SdmxXml, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwo)); break; case MessageTypeEnum.CrossSectional_20: break; } if (dataWriterEngine == null) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.InternalError, new Exception("No Type Message recognized")); } // write header dataWriterEngine.WriteHeader(FlyConfiguration.HeaderSettings.GetHeader()); // start dataset DataStructureObjectImpl dsd = _retrievalManager._dsd; dataWriterEngine.StartDataset(null, dsd.Immutated, null); // Aggiungo dataset Title if (FlyConfiguration.DatasetTitle && !string.IsNullOrEmpty(this._retrievalManager.DataFlowTitle)) { dataWriterEngine.WriteAttributeValue("Title", this._retrievalManager.DataFlowTitle); } this.LastSeriesKey = null; List <DataMessageObject> dmo = _tableResponse.GetNext(); if (dmo != null) { //Aggiungo gli Attributi di Dataset foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyDatasetAttribute(att))) { dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString()); } //GROUPS if (_retrievalManager.Groups != null && _retrievalManager.Groups.Count > 0) { foreach (DataGroupObject group in _retrievalManager.Groups) { dataWriterEngine.StartGroup(group.GroupId); foreach (GroupReferenceObject GroupKey in group.DimensionReferences) { dataWriterEngine.WriteGroupKeyValue(GroupKey.ConceptCode, GroupKey.ConceptValue.ToString()); } foreach (GroupReferenceObject GroupAttribute in group.AttributeReferences) { dataWriterEngine.WriteAttributeValue(GroupAttribute.ConceptCode, GroupAttribute.ConceptValue.ToString()); } } } do { if (dmo == null) { break; } //SERIE if (CheckChanged(dmo)) { dataWriterEngine.StartSeries(); foreach (DataMessageObject seriesKey in dmo.FindAll(dim => OnlySeriesKey(dim))) { dataWriterEngine.WriteSeriesKeyValue(seriesKey.ColImpl.ConceptObjectCode, seriesKey.Val.ToString()); } foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlySeriesAttribute(att))) { dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString()); } } //OBSERVATION DataMessageObject val = dmo.Find(dimV => dimV.ColImpl.ConceptType == ConceptTypeEnum.Attribute && ((IAttributeConcept)dimV.ColImpl).IsValueAttribute); DataMessageObject time = dmo.Find(dimT => dimT.ColImpl.ConceptType == ConceptTypeEnum.Dimension && ((IDimensionConcept)dimT.ColImpl).DimensionType == DimensionTypeEnum.Time); dataWriterEngine.WriteObservation(time.Val.ToString(), val.Val.ToString()); foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyObservationAttribute(att))) { if (seriesAttribute.Val.ToString() != String.Empty) { dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString()); } } dmo = _tableResponse.GetNext(); } while (dmo != null); } dataWriterEngine.Close(); writer.__SdmxXml.Flush(); } catch (SdmxException) { throw; } catch (Exception ex) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.ErrorWriteDataMessage, ex); } }