/// <summary> /// Initializes a new instance of the <see cref="ControllerBuilder"/> class. /// </summary> /// <param name="mappingStoreConnectionSettings"> /// The mapping store connection settings. /// </param> /// <param name="defaultHeader"> /// The default header. /// </param> public ControllerBuilder(ConnectionStringSettings mappingStoreConnectionSettings, IHeader defaultHeader) { if (mappingStoreConnectionSettings == null) { _log.Error("No connection string defined. Please check the web.config."); throw new ArgumentNullException("mappingStoreConnectionSettings"); } var dataRetrieverCore = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwo); var dataRetrieverV21 = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwoPointOne); this._retrievalWithCrossWriter = dataRetrieverCore; this._retrievalWithWriter = dataRetrieverCore; this._retrievalWithWriterv21 = dataRetrieverV21; this._advancedRetrievalWithWriter = dataRetrieverV21; // structure search factories IStructureSearchManagerFactory <IAdvancedMutableStructureSearchManager> advancedFactory = new AdvancedMutableStructureSearchManagerFactory(); IStructureSearchManagerFactory <IAuthAdvancedMutableStructureSearchManager> autAdvancedFactory = new AuthAdvancedMutableStructureSearchManagerFactory(); IStructureSearchManagerFactory <IMutableStructureSearchManager> structureSearchManager = new MutableStructureSearchManagerFactory(); IStructureSearchManagerFactory <IAuthMutableStructureSearchManager> autFactory = new AuthMutableStructureSearchManagerFactory(); // advanced structure search managers this._advancedMutableStructureSearchManager = advancedFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21); this._authAdvancedMutableStructureSearchManager = autAdvancedFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21); // simple structure search managers this._mutableStructureSearchManagerV20 = structureSearchManager.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV20); this._authMutableStructureSearchManagerV20 = autFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV20); this._mutableStructureSearchManagerV21 = structureSearchManager.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21); this._authMutableStructureSearchManagerV21 = autFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21); this._mappingStoreSdmxObjectRetrievalManager = new MappingStoreSdmxObjectRetrievalManager(mappingStoreConnectionSettings); }
/// <summary> /// Initializes a new instance of the <see cref="StructureRequestRestController{TWriter}"/> class. /// </summary> /// <param name="responseGenerator"> /// The response generator. /// </param> /// <param name="structureSearchManager"> /// The structure Search Manager. /// </param> /// <param name="authStructureSearchManager"> /// The AUTH Structure Search Manager. /// </param> /// <param name="dataflowPrincipal"> /// The dataflow principal. /// </param> /// <exception cref="SdmxSemmanticException"> /// Operation not accepted with query used /// </exception> public StructureRequestRestController( IResponseGenerator <TWriter, ISdmxObjects> responseGenerator, IMutableStructureSearchManager structureSearchManager, IAuthMutableStructureSearchManager authStructureSearchManager, DataflowPrincipal dataflowPrincipal) : base(responseGenerator, dataflowPrincipal) { this._structureSearchManager = structureSearchManager; this._authStructureSearchManager = authStructureSearchManager; }
/// <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)); }
public ISet<ICodelistObject> GetCodelistStruc() { WebOperationContext ctx = WebOperationContext.Current; IRestStructureQuery input = BuildRestQueryBean(structure, agencyID, resourceID, version, ctx.IncomingRequest.UriTemplateMatch.QueryParameters); CodelistXmlBuilder codelistXmlBuilderBean = new CodelistXmlBuilder(); var codelistsType = new CodelistsType(); var structures = new StructuresType(); structures.Codelists = codelistsType; IMutableStructureSearchManager mutableStructureSearchManagerV21; IStructureSearchManagerFactory<IMutableStructureSearchManager> structureSearchManager = new MutableStructureSearchManagerFactory(); var sdmxSchemaV21 = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne); mutableStructureSearchManagerV21 = structureSearchManager.GetStructureSearchManager(SettingsManager.MappingStoreConnectionSettings, sdmxSchemaV21); this._structureSearchManager = mutableStructureSearchManagerV21; ; IMutableObjects mutableObjects = this._structureSearchManager.GetMaintainables(input); var immutableObj = mutableObjects.ImmutableObjects; immutableObj.Header = SettingsManager.Header; ISet<ICodelistObject> codelists = immutableObj.Codelists; return codelists; }
/// <summary> /// Initializes a new instance of the <see cref="ControllerBuilder"/> class. /// </summary> /// <param name="mappingStoreConnectionSettings"> /// The mapping store connection settings. /// </param> /// <param name="defaultHeader"> /// The default header. /// </param> public CsvZipControllerBuilder(ConnectionStringSettings mappingStoreConnectionSettings, IHeader defaultHeader) { if (mappingStoreConnectionSettings == null) { _log.Error("No connection string defined. Please check the web.config."); throw new ArgumentNullException("mappingStoreConnectionSettings"); } var dataRetrieverCore = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwo); var dataRetrieverV21 = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwoPointOne); var dataRetrieverCsvZip = new CsvZipDataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwoPointOne); this._retrievalWithCrossWriter = dataRetrieverCore; this._retrievalWithWriter = dataRetrieverCore; this._retrievalWithWriterv21 = dataRetrieverCsvZip; this._advancedRetrievalWithWriter = dataRetrieverV21; //andrea this._retrievalTabular = dataRetrieverCore; // structure search factories IStructureSearchManagerFactory<IAdvancedMutableStructureSearchManager> advancedFactory = new AdvancedMutableStructureSearchManagerFactory(); IStructureSearchManagerFactory<IAuthAdvancedMutableStructureSearchManager> autAdvancedFactory = new AuthAdvancedMutableStructureSearchManagerFactory(); IStructureSearchManagerFactory<IMutableStructureSearchManager> structureSearchManager = new MutableStructureSearchManagerFactory(); IStructureSearchManagerFactory<IAuthMutableStructureSearchManager> autFactory = new AuthMutableStructureSearchManagerFactory(); // advanced structure search managers this._advancedMutableStructureSearchManager = advancedFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21); this._authAdvancedMutableStructureSearchManager = autAdvancedFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21); // simple structure search managers this._mutableStructureSearchManagerV20 = structureSearchManager.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV20); this._authMutableStructureSearchManagerV20 = autFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV20); this._mutableStructureSearchManagerV21 = structureSearchManager.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21); this._authMutableStructureSearchManagerV21 = autFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21); }
/// <summary> /// Gets the mutable container object. /// </summary> /// <param name="mutableSearchManager"> /// The mutable search manager. /// </param> /// <param name="mockQuery"> /// The mock query. /// </param> /// <param name="maintainableMutableObject"> /// The maintainable mutable object. /// </param> /// <returns> /// The mutable object container. /// </returns> private static IMutableObjects GetMutables(IMutableStructureSearchManager mutableSearchManager, IRestStructureQuery mockQuery, IMaintainableMutableObject maintainableMutableObject) { var mutableObject = mutableSearchManager.GetMaintainables(mockQuery); Assert.IsNotNull(mutableObject, _fromMutable.Build(maintainableMutableObject).ToString()); Assert.IsNotEmpty(mutableObject.AllMaintainables, _fromMutable.Build(maintainableMutableObject).ToString()); return mutableObject; }
public StringWriter StructureResponse(string structure, string agencyId, string resourceId, string version, StringWriter sw) { StringWriter jsonres= null; /* var structure = "codelist"; var agencyId = agenzia; // "IT1"; var resourceId = codelist; // "CL_REFAREA"; var version = versione; // "1.4"; */ System.ServiceModel.Web.WebOperationContext ctx = System.ServiceModel.Web.WebOperationContext.Current; Org.Sdmxsource.Sdmx.Api.Model.Query.IRestStructureQuery input = BuildRestQueryBean(structure, agencyId, resourceId, version, ctx.IncomingRequest.UriTemplateMatch.QueryParameters); /* object tipo; */ //var codelistsType = new Org.Sdmx.Resources.SdmxMl.Schemas.V21.Structure.CodelistsType(); // var structures = new Org.Sdmx.Resources.SdmxMl.Schemas.V21.Structure.StructuresType(); // structures.Codelists = codelistsType; IMutableStructureSearchManager mutableStructureSearchManagerV21; /**/ //var wx = new Org.Sdmx.Resources.SdmxMl.Schemas.V21.Structure.DataflowsType(); //structures.Dataflows = wx; /**/ Estat.Nsi.StructureRetriever.Factory.IStructureSearchManagerFactory<IMutableStructureSearchManager> structureSearchManager = new MutableStructureSearchManagerFactory(); var sdmxSchemaV21 = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne); mutableStructureSearchManagerV21 = structureSearchManager.GetStructureSearchManager(SettingsManager.MappingStoreConnectionSettings, sdmxSchemaV21); this._structureSearchManager = mutableStructureSearchManagerV21; ; Org.Sdmxsource.Sdmx.Api.Model.Mutable.IMutableObjects mutableObjects = this._structureSearchManager.GetMaintainables(input); var immutableObj = mutableObjects.ImmutableObjects; immutableObj.Header = Estat.Sri.Ws.Controllers.Manager.SettingsManager.Header; switch (structure) { case "codelist": ISet<ICodelistObject> codelists = immutableObj.Codelists; jsonres = WriteCodelist(codelists, resourceId, sw); break; case "datastructure": ISet<IDataStructureObject> datastructure = immutableObj.DataStructures; jsonres = WriteDatastructure(datastructure, resourceId, sw); break; case "dataflow": ISet<IDataflowObject> dataflow = immutableObj.Dataflows; jsonres = WriteDataflow(dataflow, resourceId, sw); break; case "agencyscheme": ISet<IAgencyScheme> agencies = immutableObj.AgenciesSchemes; jsonres = WriteAgenciesScheme(agencies, resourceId, sw); break; case "categorisation": ISet<ICategorisationObject> categorisations = immutableObj.Categorisations; jsonres = WriteCategorisation(categorisations, resourceId, sw); break; case "dataproviderscheme": ISet<IDataProviderScheme> dataproviderscheme = immutableObj.DataProviderSchemes; jsonres = WriteDataProviderScheme(dataproviderscheme, resourceId, sw); break; case "dataconsumerscheme": ISet<IDataConsumerScheme> dataconsumerscheme = immutableObj.DataConsumerSchemes; break; case "contentconstraint": ISet<IContentConstraintObject> contentconstraint = immutableObj.ContentConstraintObjects; break; case "categoryscheme": ISet<ICategorySchemeObject> categoryscheme = immutableObj.CategorySchemes; jsonres = WriteCategoryScheme(categoryscheme, resourceId, sw); break; case "conceptscheme": ISet<IConceptSchemeObject> conceptscheme = immutableObj.ConceptSchemes; jsonres = WriteConceptScheme(conceptscheme, resourceId, sw); break; case "provisionagreement": ISet<IProvisionAgreementObject> provisionagreement = immutableObj.ProvisionAgreements; break; case "organisationunitscheme": ISet<IOrganisationUnitSchemeObject> organisationunitscheme = immutableObj.OrganisationUnitSchemes; break; case "metadatastructure": ISet<IMetadataStructureDefinitionObject> metadatastructure = immutableObj.MetadataStructures; break; case "metadataflow": ISet<IMetadataFlow> metadataflow = immutableObj.Metadataflows; break; case "hierarchicalcodelist": ISet<IHierarchicalCodelistObject> hierarchicalcodelist = immutableObj.HierarchicalCodelists; break; } return jsonres; }
/// <summary> /// Initializes a new instance of the <see cref="SampleAdvancedMutableStructureSearchManager"/> class. /// </summary> /// <param name="mutableStructureSearchManager">The mutable structure search manager.</param> public SampleAdvancedMutableStructureSearchManager(IMutableStructureSearchManager mutableStructureSearchManager) { this._mutableStructureSearchManager = mutableStructureSearchManager; }
/// <summary> /// Requests the partial codelist. /// </summary> /// <param name="dataflow">The dataflow.</param> /// <param name="firstDsd">The first DSD.</param> /// <param name="mutableSearchManager">The mutable search manager.</param> /// <returns>The criteria used.</returns> private static IEnumerable<IKeyValuesMutable> RequestPartialCodelist(IDataflowMutableObject dataflow, IDataStructureMutableObject firstDsd, IMutableStructureSearchManager mutableSearchManager) { var currentDataflowReference = _fromMutableBuilder.Build(dataflow); var previousMembers = new List<IKeyValuesMutable>(); foreach (var dimension in firstDsd.Dimensions) { var representation = dimension.GetEnumeratedRepresentation(firstDsd); if (representation != null) { IStructureReference codelistRef = new StructureReferenceImpl(representation.MaintainableReference, SdmxStructureEnumType.CodeList); var id = dimension.Id; var agencyId = firstDsd.AgencyId; var version = firstDsd.Version; var name = dimension.ConceptRef.ChildReference.Id; var specialRequest = BuildConstrainableStructureReference(id, agencyId, version, name, previousMembers, currentDataflowReference); var queries = new[] { specialRequest, codelistRef }; var objects = mutableSearchManager.RetrieveStructures(queries, false, false); var message = string.Format("DataflowRef : {0}, CodelistRef : {1}", specialRequest, codelistRef); Assert.IsNotNull(objects, message); Assert.IsNotEmpty(objects.Codelists, message); Assert.AreEqual(1, objects.Codelists.Count, message); var codeIds = objects.Codelists.First().Items.TakeWhile(o => _random.Next() % 2 == 0).Select(o => o.Id).ToArray(); if (codeIds.Length > 0) { var criteria = new KeyValuesMutableImpl { Id = id }; criteria.KeyValues.AddAll(codeIds); previousMembers.Add(criteria); } } else if (dimension.TimeDimension) { var id = dimension.Id; var agencyId = firstDsd.AgencyId; var version = firstDsd.Version; var name = dimension.ConceptRef.ChildReference.Id; IStructureReference specialRequest = BuildConstrainableStructureReference(id, agencyId, version, name, previousMembers, currentDataflowReference); IStructureReference timeCodelistReference = new StructureReferenceImpl( CustomCodelistConstants.Agency, CustomCodelistConstants.TimePeriodCodeList, CustomCodelistConstants.Version, SdmxStructureEnumType.CodeList); var queries = new[] { specialRequest, timeCodelistReference }; var objects = mutableSearchManager.RetrieveStructures(queries, false, false); var message = string.Format("DataflowRef : {0}, CodelistRef : {1}", specialRequest, timeCodelistReference); Assert.IsNotNull(objects); Assert.IsNotEmpty(objects.Codelists, message); Assert.AreEqual(1, objects.Codelists.Count, message); var timeCodelist = objects.Codelists.First(); Assert.GreaterOrEqual(timeCodelist.Items.Count, 1, message); Assert.LessOrEqual(timeCodelist.Items.Count, 2, message); foreach (var item in timeCodelist.Items) { DateTime date; Assert.IsTrue(DateTime.TryParseExact(item.Id, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out date), "Invalid date : '{0}' for {1}", item.Id, specialRequest); } if (timeCodelist.Items.Count > 0) { var criteria = new KeyValuesMutableImpl { Id = id }; criteria.KeyValues.AddAll(timeCodelist.Items.Select(o => o.Id)); previousMembers.Add(criteria); } } } return previousMembers; }
/// <summary> /// Requests the count. /// </summary> /// <param name="dataflowRef">The dataflow preference.</param> /// <param name="structureSearch">The structure search.</param> private static void RequestCount(IStructureReference dataflowRef, IMutableStructureSearchManager structureSearch) { var countRef = new StructureReferenceImpl(CustomCodelistConstants.Agency, CustomCodelistConstants.CountCodeList, CustomCodelistConstants.Version, SdmxStructureEnumType.CodeList); var queries = new[] { dataflowRef, countRef }; var countResponse = structureSearch.RetrieveStructures(queries, false, false); Assert.IsNotNull(countResponse); Assert.IsNotEmpty(countResponse.Codelists); var countCodelist = countResponse.Codelists.First(); Assert.AreEqual(CustomCodelistConstants.CountCodeList, countCodelist.Id); Assert.AreEqual(1, countCodelist.Items.Count); int count; Assert.IsTrue(int.TryParse(countCodelist.Items.First().Id, NumberStyles.Integer, CultureInfo.InvariantCulture, out count), "Dataflow {0}", dataflowRef); Assert.IsTrue(count > 0, "Dataflow {0}", ExtractInfo(dataflowRef)); }
/// <summary> /// Requests the count. /// </summary> /// <param name="dataflow">The dataflow.</param> /// <param name="structureSearch">The structure search.</param> /// <param name="previousMembers">The previous members.</param> private static void RequestCount(IDataflowMutableObject dataflow, IMutableStructureSearchManager structureSearch, IEnumerable<IKeyValuesMutable> previousMembers = null) { var currentDataflowReference = _fromMutableBuilder.Build(dataflow); var specialRequest = BuildConstrainableStructureReference("PAOK", "SR", "1.1.1", "PAOK OLE", previousMembers, currentDataflowReference); RequestCount(specialRequest, structureSearch); }
/// <summary> /// Initializes a new instance of the <see cref="SriRetrieverFactory" /> class. /// </summary> /// <exception cref="StructureRetrieverException">Could not establish a connection to the mapping store DB /// <see cref="P:Estat.Nsi.StructureRetriever.StructureRetrieverException.ErrorType" /> /// is set to <see cref="F:Estat.Nsi.StructureRetriever.StructureRetrieverErrorTypes.MappingStoreConnectionError" /></exception> public SriRetrieverFactory() { var defaultHeader = SettingsManager.Header; var settingsManager = new MappingStoreSettingsManager(); var mappingStoreConnectionSettings = settingsManager.MappingStoreConnectionSettings; if (mappingStoreConnectionSettings != null) { // Data Retriever initialization var dataRetrieverSdmxv20Behaviour = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwo); var dataRetrieverSdmxV21Behaviour = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwoPointOne); // SDMX v2.0 WS Soap for SDMX v2.0 CrossSectional data (does not throw No Results when no data is found). this._sdmxv20XSDataRetrievalForWs20 = dataRetrieverSdmxv20Behaviour; // SDMX v2.1 WS REST for SDMX v2.0 CrossSectional data (throws No Results when no data is found). this._sdmxV20XSDataRetrieverForRest = dataRetrieverSdmxV21Behaviour; this._dataRetrievalForWs20 = dataRetrieverSdmxv20Behaviour; this._dataRetrievalForRest = dataRetrieverSdmxV21Behaviour; this._dataRetrieverForWs21 = dataRetrieverSdmxV21Behaviour; // advanced structure search managers (SDMX v2.1 SOAP) SdmxSchema sdmxSchemaV21 = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne); this._structureRetrievalForWs21 = new Estat.Nsi.StructureRetriever.Manager.AdvancedStructureRetriever(mappingStoreConnectionSettings); this._authStructureRetrievalForWs21 = new AuthAdvancedStructureRetriever(mappingStoreConnectionSettings); // simple structure search managers (SDMX v2.0 SOAP) SdmxSchema sdmxSchemaV20 = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwo); this._structureRetrievalForWs20 = new StructureRetrieverAvailableData(mappingStoreConnectionSettings, sdmxSchemaV20); this._authStructureRetrievalForWs20 = new AuthStructureRetrieverAvailableData(mappingStoreConnectionSettings, sdmxSchemaV20); // structure search manager (SDMX v2.1 REST) this._structureRetrievalForRest = new StructureRetrieverAvailableData(mappingStoreConnectionSettings, sdmxSchemaV21); this._authStructureRetrievalForRest = new AuthStructureRetrieverAvailableData(mappingStoreConnectionSettings, sdmxSchemaV21); this._mappingStoreSdmxObjectRetrievalManager = new MappingStoreSdmxObjectRetrievalManager(mappingStoreConnectionSettings); } }