/// <summary> /// Retrieve the Groups from mapping store and populate <paramref name="artefact"/> /// </summary> /// <param name="parentSysId"> /// The DSD primary key in the Mapping Store Database /// </param> /// <param name="artefact"> /// The <see cref="IDataStructureMutableObject"/> to add the groups /// </param> private void PopulateGroups(long parentSysId, IDataStructureMutableObject artefact) { var groupMap = new Dictionary <long, IGroupMutableObject>(); using (DbCommand command = this._commandBuilder.Build(new ItemSqlQuery(this._groupQueryInfo, parentSysId))) { using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command)) { while (dataReader.Read()) { long currGroupId = DataReaderHelper.GetInt64(dataReader, "GR_ID"); IGroupMutableObject group; if (!groupMap.TryGetValue(currGroupId, out group)) { group = new GroupMutableCore { Id = DataReaderHelper.GetString(dataReader, "GROUP_ID") }; artefact.AddGroup(group); groupMap.Add(currGroupId, group); } group.DimensionRef.Add(DataReaderHelper.GetString(dataReader, "DIMENSION_REF")); } } } this._groupAnnotationRetrieverEngine.RetrieveAnnotations(parentSysId, groupMap); }
/// <summary> /// When this method is overridden it is used to retrieve Items of a ItemScheme and populate the output List /// </summary> /// <param name="itemScheme"> /// The <see cref="IItemSchemeMutableObject{T}"/> to fill with <see cref="IItemMutableObject"/> /// </param> /// <param name="parentSysId"> /// The primary key of the Item Scheme from Mapping Store table ARTEFACT.ART_ID field /// </param> protected virtual void FillItems(TMaintaible itemScheme, long parentSysId) { var itemQuery = new ItemSqlQuery(this._itemSqlQueryInfo, parentSysId); var itemMap = new Dictionary <long, TItem>(); using (DbCommand command = this.ItemCommandBuilder.Build(itemQuery)) { using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command)) { int sysIdIdx = dataReader.GetOrdinal("SYSID"); int idIdx = dataReader.GetOrdinal("ID"); int txtIdx = dataReader.GetOrdinal("TEXT"); int langIdx = dataReader.GetOrdinal("LANGUAGE"); int typeIdx = dataReader.GetOrdinal("TYPE"); while (dataReader.Read()) { long sysId = DataReaderHelper.GetInt64(dataReader, sysIdIdx); TItem item; if (!itemMap.TryGetValue(sysId, out item)) { item = this.CreateItem(); // we set them below. item.Id = DataReaderHelper.GetString(dataReader, idIdx); // "ID" itemScheme.AddItem(item); itemMap.Add(sysId, item); } ReadLocalisedString(item, typeIdx, txtIdx, langIdx, dataReader); } } } this.IdentifiableAnnotationRetrieverEngine.RetrieveAnnotations(parentSysId, itemMap); }
/// <summary> /// This method populates the contact details of a <see cref="IContactMutableObject"/> /// </summary> /// <param name="mappingStoreDb"> /// The <see cref="Database"/> instance for Mapping Store database /// </param> /// <param name="contactSysId"> /// The contact system identifier. In the database the column CONTACT.CONTACT_ID /// </param> /// <param name="contact"> /// The <see cref="IContactMutableObject"/> for which the details will be populated /// </param> private static void PopulateContactDetails(Database mappingStoreDb, long contactSysId, IContactMutableObject contact) { string paramId = mappingStoreDb.BuildParameterName(ParameterNameConstants.IdParameter); var sqlCommand = new StringBuilder(); sqlCommand.Append("SELECT CD.CD_ID, CD.CONTACT_ID, CD.TYPE, CD.VALUE "); sqlCommand.Append("FROM CONTACT_DETAIL CD "); sqlCommand.AppendFormat("WHERE CD.CONTACT_ID = {0} ", paramId); using (DbCommand command = mappingStoreDb.GetSqlStringCommand(sqlCommand.ToString())) { mappingStoreDb.AddInParameter(command, ParameterNameConstants.IdParameter, DbType.Int64, contactSysId); using (IDataReader dataReader = mappingStoreDb.ExecuteReader(command)) { while (dataReader.Read()) { string coordinateType = DataReaderHelper.GetString(dataReader, "TYPE"); string coordinateData = DataReaderHelper.GetString(dataReader, "VALUE"); contact.AddCoordinateType(coordinateType, coordinateData); } } } }
/// <summary> /// Retrieves the list of <see cref="LocalisedStringVO"/> for the specified nameable primary key value. /// </summary> /// <param name="nameablePrimaryKeyValue"> /// The nameable primary key value. /// </param> /// <param name="localisedType"> /// Type of the localized. /// </param> /// <param name="isArtefact"> /// Set to <c>true</c> if the foreign key is <c>ART_ID</c>. /// </param> /// <returns> /// The list of <see cref="LocalisedStringVO"/> /// </returns> private IEnumerable <LocalisedStringVO> Retrieve(long nameablePrimaryKeyValue, string localisedType, bool isArtefact) { var typeParameter = this._mappingStoreDatabase.CreateInParameter("p_type", DbType.AnsiString, localisedType); DbParameter artIdParameter; DbParameter itemIdParameter; if (isArtefact) { artIdParameter = this._mappingStoreDatabase.CreateInParameter("p_artid", DbType.Int64, nameablePrimaryKeyValue); itemIdParameter = this._mappingStoreDatabase.CreateInParameter("p_itemId", DbType.Int64, DBNull.Value); } else { artIdParameter = this._mappingStoreDatabase.CreateInParameter("p_artid", DbType.Int64, DBNull.Value); itemIdParameter = this._mappingStoreDatabase.CreateInParameter("p_itemId", DbType.Int64, nameablePrimaryKeyValue); } using (var command = this._mappingStoreDatabase.GetSqlStringCommandFormat(SelectLocalisedStringByForeignKey, typeParameter, artIdParameter, itemIdParameter)) using (var reader = command.ExecuteReader()) { int lsdIdIdx = reader.GetOrdinal("LS_ID"); int textIdx = reader.GetOrdinal("TEXT"); int langIdx = reader.GetOrdinal("LANGUAGE"); while (reader.Read()) { var lsdId = DataReaderHelper.GetInt64(reader, lsdIdIdx); var text = DataReaderHelper.GetString(reader, textIdx); var lang = DataReaderHelper.GetString(reader, langIdx); yield return(new LocalisedStringVO { PrimaryKeyValue = lsdId, TextTypeWrapper = new TextTypeWrapperMutableCore(lang, text) }); } } }
/// <summary> /// The retrieve category reference. /// </summary> /// <param name="categoryCache"> /// The category cache. /// </param> private void RetrieveCategoryReference(IDictionary <long, IStructureReference> categoryCache) { using (var command = this.MappingStoreDb.GetSqlStringCommand(CategorisationConstant.CategoryRefQueryFormat)) { _log.InfoFormat(CultureInfo.InvariantCulture, "Executing Query: '{0}'", command.CommandText); using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command)) { //// C.CATN_ID, A.ID, A.VERSION, A.AGENCY, I.ID as CATID int catnIdx = dataReader.GetOrdinal("CATN_ID"); int idIdx = dataReader.GetOrdinal("ID"); int versionIdx = dataReader.GetOrdinal("VERSION"); int agencyIdx = dataReader.GetOrdinal("AGENCY"); int catidIdx = dataReader.GetOrdinal("CATID"); while (dataReader.Read()) { long catn = DataReaderHelper.GetInt64(dataReader, catnIdx); string id = DataReaderHelper.GetString(dataReader, idIdx); string agency = DataReaderHelper.GetString(dataReader, agencyIdx); string version = DataReaderHelper.GetString(dataReader, versionIdx); string catid = DataReaderHelper.GetString(dataReader, catidIdx); var structureReference = new StructureReferenceImpl(agency, id, version, SdmxStructureEnumType.Category, catid); categoryCache.Add(catn, structureReference); } } } }
/// <summary> /// This method populates the international strings /// </summary> /// <param name="mappingStoreDb"> /// The <see cref="Database"/> instance for Mapping Store database /// </param> /// <param name="partySysId"> /// The party system identifier. In the database the column PARTY.PARTY_ID /// </param> /// <param name="partyNames"> /// The <see cref="ITextTypeWrapper"/>lists to be populated in terms of Names /// </param> private static void PopulatePartyLocalisedStrings(Database mappingStoreDb, long partySysId, ICollection <ITextTypeWrapper> partyNames) { string paramId = mappingStoreDb.BuildParameterName(ParameterNameConstants.IdParameter); var sqlCommand = new StringBuilder(); sqlCommand.Append("SELECT HLS.HLS_ID, HLS.TYPE, HLS.HEADER_ID, HLS.PARTY_ID, HLS.CONTACT_ID, HLS.LANGUAGE, HLS.TEXT "); sqlCommand.Append("FROM HEADER_LOCALISED_STRING HLS "); sqlCommand.AppendFormat("WHERE HLS.PARTY_ID = {0} ", paramId); using (DbCommand command = mappingStoreDb.GetSqlStringCommand(sqlCommand.ToString())) { mappingStoreDb.AddInParameter(command, ParameterNameConstants.IdParameter, DbType.Int64, partySysId); using (IDataReader dataReader = mappingStoreDb.ExecuteReader(command)) { while (dataReader.Read()) { var text = new TextTypeWrapperMutableCore { Locale = DataReaderHelper.GetString(dataReader, "LANGUAGE"), Value = DataReaderHelper.GetString(dataReader, "TEXT") }; string textType = DataReaderHelper.GetString(dataReader, "TYPE"); // is it a sender or a receiver? if (textType.Equals(NameText, StringComparison.OrdinalIgnoreCase)) { partyNames.Add(new TextTypeWrapperImpl(text, null)); } } } } }
/// <summary> /// Read all items with parent item /// </summary> /// <param name="allItems"> /// The all items. /// </param> /// <param name="orderedItems"> /// The ordered items. /// </param> /// <param name="command"> /// The command. /// </param> /// <param name="childItems"> /// The child items. /// </param> protected void ReadItems(IDictionary <long, TItem> allItems, ICollection <KeyValuePair <long, TItem> > orderedItems, DbCommand command, IDictionary <long, long> childItems) { using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command)) { int sysIdIdx = dataReader.GetOrdinal("SYSID"); int idIdx = dataReader.GetOrdinal("ID"); int parentIdx = dataReader.GetOrdinal("PARENT"); int txtIdx = dataReader.GetOrdinal("TEXT"); int langIdx = dataReader.GetOrdinal("LANGUAGE"); int typeIdx = dataReader.GetOrdinal("TYPE"); while (dataReader.Read()) { long sysId = dataReader.GetInt64(sysIdIdx); // not a null. TItem item; if (!allItems.TryGetValue(sysId, out item)) { item = this.CreateItem(); item.Id = DataReaderHelper.GetString(dataReader, idIdx); // "ID" this.HandleItemExtraFields(item, dataReader); orderedItems.Add(new KeyValuePair <long, TItem>(sysId, item)); allItems.Add(sysId, item); long parentItemId = DataReaderHelper.GetInt64(dataReader, parentIdx); if (parentItemId > long.MinValue) { childItems.Add(sysId, parentItemId); } } ReadLocalisedString(item, typeIdx, txtIdx, langIdx, dataReader); } this.MappingStoreDb.CancelSafe(command); } }
/// <summary> /// Retrieve the Dimension references from mapping store /// </summary> /// <param name="parentSysId"> /// The DSD primary key in the Mapping Store Database /// </param> /// <returns> /// The <see cref="IDictionaryOfSets{String, String}"/>. /// </returns> private IDictionaryOfSets <string, string> GetAttributeDimensionRefs(long parentSysId) { IDictionaryOfSets <string, string> mappedAttributes = new DictionaryOfSets <string, string>(StringComparer.Ordinal); using (DbCommand command = this._commandBuilder.Build(new ItemSqlQuery(this._attributeDimensionRefsInfo, parentSysId))) { using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command)) { while (dataReader.Read()) { string currGroupId = DataReaderHelper.GetString(dataReader, "AID"); ISet <string> dimensionList; if (!mappedAttributes.TryGetValue(currGroupId, out dimensionList)) { dimensionList = new HashSet <string>(StringComparer.Ordinal); mappedAttributes.Add(currGroupId, dimensionList); } dimensionList.Add(DataReaderHelper.GetString(dataReader, "DID")); } } } return(mappedAttributes); }
/// <summary> /// Transcodes the time period returned by the local database to SDMX Time period /// </summary> /// <param name="reader"> /// The data reader reading the Dissemination database /// </param> /// <returns> /// The transcoded time period, as in SDMX Time period type /// </returns> public string MapComponent(IDataReader reader) { string ret; this._fieldOrdinals.BuildOrdinal(reader); string yearperiod = DataReaderHelper.GetString(reader, this._fieldOrdinals.YearOrdinal); if (this.Expression.YearStart + this.Expression.YearLength > yearperiod.Length) { return(null); } string year = yearperiod.Substring(this.Expression.YearStart, this.Expression.YearLength); var rowFreq = this.Expression.Freq; if (rowFreq != TimeFormatEnumType.Year) { if (this.Expression.PeriodStart >= yearperiod.Length) { return(null); } string period; if (this.Expression.PeriodLength > 0) { int rowPeriodLen = this.Expression.PeriodLength; if (this.Expression.PeriodLength + this.Expression.PeriodStart > yearperiod.Length) { rowPeriodLen = yearperiod.Length - this.Expression.PeriodStart; } period = yearperiod.Substring(this.Expression.PeriodStart, rowPeriodLen); } else { period = yearperiod.Substring(this.Expression.PeriodStart); } this._periodLocalCode.Clear(); this._periodLocalCode.Add(period); CodeCollection periodDsdCode = this.Expression.TranscodingRules.GetDsdCodes(this._periodLocalCode); if (periodDsdCode == null) { return(null); // MAT-495 // periodDsdCode = periodLocalCode; } ret = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", year, periodDsdCode[0]); } else { ret = year.ToString(FormatProvider); } return(ret); }
/// <summary> /// Get the Codes /// </summary> /// <param name="itemSchemeBean"> /// The parent <see cref="ICodelistMutableObject"/> /// </param> /// <param name="parentSysId"> /// The parent ItemScheme primary key in Mapping Store /// </param> /// <param name="subset"> /// The list of items to retrieve /// </param> /// <returns> /// The <see cref="ICodelistMutableObject"/>. /// </returns> private ICodelistMutableObject FillCodesHash(ICodelistMutableObject itemSchemeBean, long parentSysId, IList <string> subset) { var allItems = new Dictionary <long, ICodeMutableObject>(); var orderedItems = new List <KeyValuePair <long, ICodeMutableObject> >(); var childItems = new Dictionary <long, long>(); // TODO convert to Set<> in .NET 3.5 var subsetSet = new HashSet <string>(StringComparer.Ordinal); for (int i = 0; i < subset.Count; i++) { subsetSet.Add(subset[i]); } using (DbCommand command = this.ItemCommandBuilder.Build(new ItemSqlQuery(this.ItemSqlQueryInfo, parentSysId))) { using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command)) { int sysIdIdx = dataReader.GetOrdinal("SYSID"); int idIdx = dataReader.GetOrdinal("ID"); int parentIdx = dataReader.GetOrdinal("PARENT"); int txtIdx = dataReader.GetOrdinal("TEXT"); int langIdx = dataReader.GetOrdinal("LANGUAGE"); int typeIdx = dataReader.GetOrdinal("TYPE"); while (dataReader.Read()) { string id = DataReaderHelper.GetString(dataReader, idIdx); if (subsetSet.Contains(id)) { long sysId = DataReaderHelper.GetInt64(dataReader, sysIdIdx); ICodeMutableObject item; if (!allItems.TryGetValue(sysId, out item)) { item = new CodeMutableCore { Id = id }; orderedItems.Add(new KeyValuePair <long, ICodeMutableObject>(sysId, item)); allItems.Add(sysId, item); long parentItemId = DataReaderHelper.GetInt64(dataReader, parentIdx); if (parentItemId > long.MinValue) { childItems.Add(sysId, parentItemId); } } ReadLocalisedString(item, typeIdx, txtIdx, langIdx, dataReader); } } } } this.FillParentItems(itemSchemeBean, childItems, allItems, orderedItems); this.IdentifiableAnnotationRetrieverEngine.RetrieveAnnotations(parentSysId, allItems); return(itemSchemeBean); }
/// <summary> /// Retrieve the concept reference. /// </summary> /// <param name="dataReader"> /// The data reader. /// </param> /// <param name="component"> /// The component. /// </param> private static void RetrieveConceptRef(IDataRecord dataReader, IComponentMutableObject component) { //// TODO cache category references string conceptRef = DataReaderHelper.GetString(dataReader, "CONCEPTREF"); string conceptSchemeRef = DataReaderHelper.GetString(dataReader, "CONCEPTSCHEME_ID"); string conceptSchemeVersion = DataReaderHelper.GetString(dataReader, "CONCEPT_VERSION"); string conceptSchemeAgency = DataReaderHelper.GetString(dataReader, "CONCEPT_AGENCY"); component.ConceptRef = new StructureReferenceImpl(conceptSchemeAgency, conceptSchemeRef, conceptSchemeVersion, SdmxStructureEnumType.Concept, conceptRef); }
public void wkfproGetNextTask(DbTransaction tran, int userId, string sessionID, out string entityType, out int entityId, out string functionType, out int lockId, out DateTime lockAcquired, out DateTime lockExpired) { string spName = ""; try { spName = "wkfproGetNextTask"; DbCommand dbCommand = base.DB.GetStoredProcCommand(spName); dbCommand.Parameters.Clear(); base.DB.AddInParameter(dbCommand, "@UserId", DbType.Int64, userId); base.DB.AddInParameter(dbCommand, "@SessionId", DbType.String, sessionID); base.DB.AddOutParameter(dbCommand, "@EntityType", DbType.String, 1); base.DB.AddOutParameter(dbCommand, "@EntityId", DbType.Int64, 0); base.DB.AddOutParameter(dbCommand, "@FunctionType", DbType.String, 1); base.DB.AddOutParameter(dbCommand, "@LockId", DbType.Int64, 0); base.DB.AddOutParameter(dbCommand, "@LockAcquiredDateTime", DbType.DateTime, 0); base.DB.AddOutParameter(dbCommand, "@LockTimeoutDateTime", DbType.DateTime, 0); if (tran != null) { base.DB.ExecuteNonQuery(dbCommand, tran); } else { base.DB.ExecuteNonQuery(dbCommand); } entityType = DataReaderHelper.GetString(base.DB.GetParameterValue(dbCommand, "@EntityType")); entityId = DataReaderHelper.GetInt(base.DB.GetParameterValue(dbCommand, "@EntityId")); functionType = DataReaderHelper.GetString(base.DB.GetParameterValue(dbCommand, "@FunctionType")); lockId = DataReaderHelper.GetInt(base.DB.GetParameterValue(dbCommand, "@LockId")); lockAcquired = DataReaderHelper.GetDateTime(base.DB.GetParameterValue(dbCommand, "@LockAcquiredDateTime")); lockExpired = DataReaderHelper.GetDateTime(base.DB.GetParameterValue(dbCommand, "@LockTimeoutDateTime")); } catch (SqlException ex) { throw new DacSqlException(ex); } catch (Exception ex) { throw ex; } finally { base.ReleaseConnection(); } }
/// <summary> /// Retrieve and populate the <see cref="IHierarchicalCodelistMutableObject.Hierarchies"/> for the HCL with specified Primary KEY /// </summary> /// <param name="hierarchicalCodelistBean"> /// The <see cref="IHierarchicalCodelistMutableObject"/> to populate /// </param> /// <param name="sysId"> /// The HCL Mapping store Primary KEY /// </param> private void FillHierarchy(IHierarchicalCodelistMutableObject hierarchicalCodelistBean, long sysId) { // ReSharper restore SuggestBaseTypeForParameter var sysIdArtefacts = new Dictionary <long, IHierarchyMutableObject>(); var itemSqlQuery = new ItemSqlQuery(this._hierarchyQueryInfo, sysId); using (DbCommand command = this._itemCommandBuilder.Build(itemSqlQuery)) { using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command)) { int sysIdIdx = dataReader.GetOrdinal("SYSID"); int idIdx = dataReader.GetOrdinal("ID"); int txtIdx = dataReader.GetOrdinal("TEXT"); int langIdx = dataReader.GetOrdinal("LANGUAGE"); int typeIdx = dataReader.GetOrdinal("TYPE"); while (dataReader.Read()) { long hierarchySysId = DataReaderHelper.GetInt64(dataReader, sysIdIdx); IHierarchyMutableObject artefact; if (!sysIdArtefacts.TryGetValue(hierarchySysId, out artefact)) { artefact = new HierarchyMutableCore { Id = DataReaderHelper.GetString(dataReader, idIdx) }; sysIdArtefacts.Add(hierarchySysId, artefact); } ReadLocalisedString(artefact, typeIdx, txtIdx, langIdx, dataReader); } } } this._hierarchyAnnotationRetrieverEngine.RetrieveAnnotations(sysId, sysIdArtefacts); foreach (KeyValuePair <long, IHierarchyMutableObject> sysIdArtefact in sysIdArtefacts) { long hid = sysIdArtefact.Key; IHierarchyMutableObject artefact = sysIdArtefact.Value; this.FillLevel(artefact, hid); this.FillCodeRef(artefact, hid); hierarchicalCodelistBean.AddHierarchies(artefact); } }
/// <summary> /// Populates the concept scheme per measure dimension. /// </summary> /// <param name="reader"> /// The reader. /// </param> /// <param name="conceptSchemesPerMeasureDimension"> /// The concept schemes per measure dimension. /// </param> private static void PopulateConceptSchemePerMeasureDimension(IDataReader reader, IDictionary <long, IMaintainableRefObject> conceptSchemesPerMeasureDimension) { int compIdIdx = reader.GetOrdinal("COMP_ID"); int agencyIdx = reader.GetOrdinal("CONCEPTSCHEME_AGENCY"); int idIdx = reader.GetOrdinal("CONCEPTSCHEME_ID"); int versionIdx = reader.GetOrdinal("CONCEPTSCHEME_VERSION"); while (reader.Read()) { var compId = DataReaderHelper.GetInt64(reader, compIdIdx); var agencyId = DataReaderHelper.GetString(reader, agencyIdx); var id = DataReaderHelper.GetString(reader, idIdx); var version = DataReaderHelper.GetString(reader, versionIdx); var conceptSchemeReference = new MaintainableRefObjectImpl(agencyId, id, version); conceptSchemesPerMeasureDimension.Add(compId, conceptSchemeReference); } }
/// <summary> /// Fill the components of a KeyFamilyBean object /// </summary> /// <param name="parent"> /// The KeyFamilyBean to populate /// </param> /// <param name="parentSysId"> /// The DSD.DSD_ID PrimaryKey /// </param> /// <returns> /// The <see cref="IDataStructureMutableObject"/> which will be the same as <paramref name="parent"/> unless the DSD /// is cross sectional. /// </returns> private IDataStructureMutableObject FillComponents(IDataStructureMutableObject parent, long parentSysId) { var crossSectionalMeasures = new List <ICrossSectionalMeasureMutableObject>(); var crossDataSet = new HashSet <string>(); var crossGroup = new HashSet <string>(); var crossSection = new HashSet <string>(); var crossObs = new HashSet <string>(); var componentMap = new Dictionary <long, IComponentMutableObject>(); IStructureReference measureCodelistRepresentation = null; using (DbCommand command = this._commandBuilder.Build(new ItemSqlQuery(this._componentQueryInfo, parentSysId))) using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command)) { var idIdx = dataReader.GetOrdinal("ID"); var compIdIdx = dataReader.GetOrdinal("COMP_ID"); while (dataReader.Read()) { IComponentMutableObject component = RetrieveComponentType(parent, dataReader, crossSectionalMeasures); componentMap.Add(dataReader.GetInt64(compIdIdx), component); component.Id = DataReaderHelper.GetString(dataReader, idIdx); measureCodelistRepresentation = RetrieveRepresentationReference(dataReader, component); RetrieveConceptRef(dataReader, component); RetrieveCrossSectionalAttachments(dataReader, crossDataSet, component.Id, crossGroup, crossSection, crossObs); } } if (parent.AttributeList != null) { this.SetupGroupAttributes(parent, parentSysId); SetupAttributeAttachmentLevel(parent, this.GetAttributeDimensionRefs(parentSysId)); } parent = SetupCrossSectionalDsd(parent, crossDataSet, crossGroup, crossSection, crossObs, crossSectionalMeasures, measureCodelistRepresentation); this.SetupAttributesAttachmentCrossMeasures(parent as ICrossSectionalDataStructureMutableObject, parentSysId); this.GetTextFormatInformation(parentSysId, componentMap); this._componentAnnotationRetrieverEngine.RetrieveAnnotations(parentSysId, componentMap); return(parent); }
/// <summary> /// Retrieve annotations for the specified SDMX <paramref name="annotable"/> object /// </summary> /// <param name="sysId">The artefact primary key value.</param> /// <param name="annotable">The SDMX object.</param> public void RetrieveAnnotations(long sysId, IAnnotableMutableObject annotable) { using (var command = this._annotationCommandBuilder.Build(new PrimaryKeySqlQuery(this._annotationSqlQueryInfo, sysId))) using (var dataReader = this._mappingStoreDb.ExecuteReader(command)) { int annIdIdx = dataReader.GetOrdinal("ANN_ID"); int idIdx = dataReader.GetOrdinal("ID"); int txtIdx = dataReader.GetOrdinal("TEXT"); int langIdx = dataReader.GetOrdinal("LANGUAGE"); int typeIdx = dataReader.GetOrdinal("TYPE"); int titleIdx = dataReader.GetOrdinal("TITLE"); int urlIdx = dataReader.GetOrdinal("URL"); IDictionary <long, IAnnotationMutableObject> annotationMap = new Dictionary <long, IAnnotationMutableObject>(); while (dataReader.Read()) { var annId = dataReader.GetInt64(annIdIdx); IAnnotationMutableObject annotation; if (!annotationMap.TryGetValue(annId, out annotation)) { annotation = new AnnotationMutableCore { Id = DataReaderHelper.GetString(dataReader, idIdx), Title = DataReaderHelper.GetString(dataReader, titleIdx), Type = DataReaderHelper.GetString(dataReader, typeIdx) }; var url = DataReaderHelper.GetString(dataReader, urlIdx); Uri uri; if (!string.IsNullOrWhiteSpace(url) && Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri)) { annotation.Uri = uri; } annotable.AddAnnotation(annotation); } var text = DataReaderHelper.GetString(dataReader, txtIdx); if (!string.IsNullOrWhiteSpace(text)) { annotation.AddText(DataReaderHelper.GetString(dataReader, langIdx), text); } } } }
/// <summary> /// Retrieve the component representation reference. /// </summary> /// <param name="dataReader"> /// The data reader. /// </param> /// <param name="component"> /// The component. /// </param> /// <returns> /// The <see cref="IStructureReference"/> of the representation. /// </returns> private static IStructureReference RetrieveRepresentationReference(IDataRecord dataReader, IComponentMutableObject component) { IStructureReference measureCodelistRepresentation = null; string codelist = DataReaderHelper.GetString(dataReader, "CODELIST_ID"); if (!string.IsNullOrWhiteSpace(codelist)) { string codelistAgency = DataReaderHelper.GetString(dataReader, "CODELIST_AGENCY"); string codelistVersion = DataReaderHelper.GetString(dataReader, "CODELIST_VERSION"); var codelistRepresentation = new StructureReferenceImpl(codelistAgency, codelist, codelistVersion, SdmxStructureEnumType.CodeList); component.Representation = new RepresentationMutableCore { Representation = codelistRepresentation }; } // Important. Concept scheme must be checked *after* codelist. var conceptSchemeRepresentation = DataReaderHelper.GetString(dataReader, "REP_CS_ID"); if (!string.IsNullOrWhiteSpace(conceptSchemeRepresentation)) { var measureDimension = component as IDimensionMutableObject; if (measureDimension != null && measureDimension.MeasureDimension) { string agency = DataReaderHelper.GetString(dataReader, "REP_CS_AGENCY"); string version = DataReaderHelper.GetString(dataReader, "REP_CS_VERSION"); if (component.Representation != null) { measureCodelistRepresentation = component.Representation.Representation; } measureDimension.Representation = new RepresentationMutableCore { Representation = new StructureReferenceImpl( agency, conceptSchemeRepresentation, version, SdmxStructureEnumType.ConceptScheme) }; } } return(measureCodelistRepresentation); }
/// <summary> /// Setups the group attributes. /// </summary> /// <param name="dataStructure">The data structure.</param> /// <param name="dsdId">The DSD identifier.</param> private void SetupAttributesAttachmentCrossMeasures(ICrossSectionalDataStructureMutableObject dataStructure, long dsdId) { if (dataStructure == null || !ObjectUtil.ValidCollection(dataStructure.Attributes) || !ObjectUtil.ValidCollection(dataStructure.CrossSectionalMeasures)) { return; } var idToAttribureMap = dataStructure.Attributes.Where(o => dataStructure.CrossSectionalAttachObservation.Contains(o.Id)).ToDictionary(o => o.Id, StringComparer.Ordinal); if (idToAttribureMap.Count == 0) { return; } using (DbCommand command = this._commandBuilder.Build(new ItemSqlQuery(this._attributeMeasureQueryInfo, dsdId))) { using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command)) { while (dataReader.Read()) { var measureId = DataReaderHelper.GetString(dataReader, "XSM_ID"); var attributeId = DataReaderHelper.GetString(dataReader, "ATTR_ID"); IAttributeMutableObject attribute; if (idToAttribureMap.TryGetValue(attributeId, out attribute)) { Debug.Assert(attribute != null, "BUG. Attribute is null"); IList <string> measures; if (!dataStructure.AttributeToMeasureMap.TryGetValue(attributeId, out measures)) { measures = new List <string>(); dataStructure.AttributeToMeasureMap.Add(attributeId, measures); } measures.Add(measureId); } else { _log.WarnFormat("Attribute with ID {0} of DSD {1} has measure mappings but its attachment level is not observation", attributeId, dataStructure.Id); } } } } }
/// <summary> /// Maps the column of the mapping to the components of this <see cref="ComponentMappingNto1"/> object and transcodes it. /// </summary> /// <param name="reader"> /// The DataReader for retrieving the values of the column. /// </param> /// <returns> /// The value of the component or null if no transcoding rule for the column values is found /// </returns> public string MapComponent(IDataReader reader) { string ret = null; this.BuildOrdinals(reader); ColumnOrdinal column = this.ColumnOrdinals[0]; var resultCodes = new CodeCollection { DataReaderHelper.GetString(reader, column.Value) }; CodeCollection transcodedCodes = this.Mapping.Transcoding.TranscodingRules.GetDsdCodes(resultCodes); if (transcodedCodes != null && this._componentIndex < transcodedCodes.Count) { ret = transcodedCodes[this._componentIndex]; } return(ret); }
/// <summary> /// This method populates the Senders and Receivers of a <see cref="IHeader"/> /// </summary> /// <param name="mappingStoreDb"> /// The <see cref="Database"/> instance for Mapping Store database /// </param> /// <param name="headerSysId"> /// The header system identifier. In the database the column HEADER.HEADER_ID /// </param> /// <param name="header"> /// The <see cref="IHeader"/> to be populated in terms of Senders and Receivers /// </param> private static void PoulateHeaderSendersAndReceivers(Database mappingStoreDb, long headerSysId, IHeader header) { string paramId = mappingStoreDb.BuildParameterName(ParameterNameConstants.IdParameter); var sqlCommand = new StringBuilder(); sqlCommand.Append("SELECT PARTY.PARTY_ID, PARTY.ID, PARTY.HEADER_ID, PARTY.TYPE "); sqlCommand.Append("FROM PARTY "); sqlCommand.AppendFormat("WHERE PARTY.HEADER_ID = {0} ", paramId); using (DbCommand command = mappingStoreDb.GetSqlStringCommand(sqlCommand.ToString())) { mappingStoreDb.AddInParameter(command, ParameterNameConstants.IdParameter, DbType.Int64, headerSysId); using (IDataReader dataReader = mappingStoreDb.ExecuteReader(command)) { while (dataReader.Read()) { var id = DataReaderHelper.GetString(dataReader, "ID"); long partySysId = DataReaderHelper.GetInt64(dataReader, "PARTY_ID"); string partyType = DataReaderHelper.GetString(dataReader, "TYPE"); var names = new List <ITextTypeWrapper>(); PopulatePartyLocalisedStrings(mappingStoreDb, partySysId, names); var contacts = new List <IContact>(); PopulatePartyContacts(mappingStoreDb, partySysId, contacts); var party = new PartyCore(names, id, contacts, null); // is it a sender or a receiver? if (partyType.Equals(SenderText, StringComparison.OrdinalIgnoreCase)) { header.Sender = party; } else if (partyType.Equals(ReceiverText, StringComparison.OrdinalIgnoreCase)) { header.AddReciever(party); } } } } }
/// <summary> /// Maps the column of the mapping to the component of this ComponentMapping1to1T object /// and transcodes it. /// </summary> /// <param name="reader"> /// The DataReader for retrieving the values of the column. /// </param> /// <returns> /// The value of the component or null if no transcoding rule for the column values is found /// </returns> public string MapComponent(IDataReader reader) { var resultCodes = new CodeCollection(); this.BuildOrdinals(reader); var column = this.ColumnOrdinals[0]; string columnValue = DataReaderHelper.GetString(reader, column.Value); resultCodes.Add(columnValue); Collection <string> transcodedCodes = this.Mapping.Transcoding.TranscodingRules.GetDsdCodes(resultCodes); string ret = null; if (transcodedCodes != null && transcodedCodes.Count > 0) { ret = transcodedCodes[0]; } return(ret); }
/// <summary> /// This method populates the Localized Strings (Names, Departments, Roles) /// of a <see cref="IContactMutableObject"/> /// </summary> /// <param name="mappingStoreDb"> /// The <see cref="Database"/> instance for Mapping Store database /// </param> /// <param name="contactSysId"> /// The contact system identifier. In the database the column CONTACT.CONTACT_ID /// </param> /// <param name="contact"> /// The <see cref="IContactMutableObject"/> to be populated in terms of Names, Departments, Roles /// </param> private static void PopulateContactLocalisedStrings(Database mappingStoreDb, long contactSysId, IContactMutableObject contact) { string paramId = mappingStoreDb.BuildParameterName(ParameterNameConstants.IdParameter); var sqlCommand = new StringBuilder(); sqlCommand.Append("SELECT HLS.HLS_ID, HLS.TYPE, HLS.HEADER_ID, HLS.PARTY_ID, HLS.CONTACT_ID, HLS.LANGUAGE, HLS.TEXT "); sqlCommand.Append("FROM HEADER_LOCALISED_STRING HLS "); sqlCommand.AppendFormat("WHERE HLS.CONTACT_ID = {0} ", paramId); using (DbCommand command = mappingStoreDb.GetSqlStringCommand(sqlCommand.ToString())) { mappingStoreDb.AddInParameter(command, ParameterNameConstants.IdParameter, DbType.Int64, contactSysId); using (IDataReader dataReader = mappingStoreDb.ExecuteReader(command)) { while (dataReader.Read()) { var text = new TextTypeWrapperMutableCore { Locale = DataReaderHelper.GetString(dataReader, "LANGUAGE"), Value = DataReaderHelper.GetString(dataReader, "TEXT") }; if (!string.IsNullOrWhiteSpace(text.Value) && !string.IsNullOrWhiteSpace(text.Locale)) { string textType = DataReaderHelper.GetString(dataReader, "TYPE"); if (textType.Equals(NameText, StringComparison.OrdinalIgnoreCase)) { contact.Names.Add(text); } else if (textType.Equals(DepartmentText, StringComparison.OrdinalIgnoreCase)) { contact.Departments.Add(text); } else if (textType.Equals(RoleText, StringComparison.OrdinalIgnoreCase)) { contact.Roles.Add(text); } } } } } }
/// <summary> /// Generic method for retrieving <see cref="IStructureReference"/> based objects /// </summary> /// <param name="outList"> /// The output list /// </param> /// <param name="command"> /// The current <see cref="DbCommand"/> /// </param> /// <param name="structureType"> /// The structure Type. /// </param> protected void RetrieveRef(ICollection <IStructureReference> outList, DbCommand command, SdmxStructureEnumType structureType) { _log.DebugFormat("RetrieveRef of {0} SQL : {1}", structureType, command.CommandText); using (IDataReader dataReader = this._mappingStoreDb.ExecuteReader(command)) { int idField = dataReader.GetOrdinal("ID"); int agencyField = dataReader.GetOrdinal("AGENCY"); int versionField = dataReader.GetOrdinal("VERSION"); while (dataReader.Read()) { var item = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(structureType)) { MaintainableId = DataReaderHelper.GetString(dataReader, idField), Version = DataReaderHelper.GetString(dataReader, versionField), AgencyId = DataReaderHelper.GetString(dataReader, agencyField) }; outList.Add(item); } } }
/// <summary> /// Gets the text format information. /// </summary> /// <param name="parentSysId"> /// The parent system unique identifier. /// </param> /// <param name="componentMap"> /// The component map. /// </param> private void GetTextFormatInformation(long parentSysId, IDictionary <long, IComponentMutableObject> componentMap) { var textFormats = new Dictionary <long, ITextFormatMutableObject>(); using (var command = this.MappingStoreDb.GetSqlStringCommandFormat(DsdConstant.TextFormatQueryFormat, this.MappingStoreDb.CreateInParameter("dsdId", DbType.Int64, parentSysId))) using (var reader = this.MappingStoreDb.ExecuteReader(command)) { var compIdIdx = reader.GetOrdinal("COMP_ID"); var enumNameIdx = reader.GetOrdinal("ENUM_NAME"); var enumValueIdx = reader.GetOrdinal("ENUM_VALUE"); var facetValueIdx = reader.GetOrdinal("FACET_VALUE"); while (reader.Read()) { var compId = reader.GetInt64(compIdIdx); ITextFormatMutableObject textFormat; if (!textFormats.TryGetValue(compId, out textFormat)) { textFormat = new TextFormatMutableCore(); textFormats.Add(compId, textFormat); } var enumName = DataReaderHelper.GetString(reader, enumNameIdx); var enumValue = DataReaderHelper.GetString(reader, enumValueIdx); var facetValue = DataReaderHelper.GetString(reader, facetValueIdx); PopulateTextFormat(enumName, enumValue, textFormat, facetValue); } } foreach (var textFormat in textFormats) { IComponentMutableObject component = componentMap[textFormat.Key]; if (component.Representation == null) { component.Representation = new RepresentationMutableCore(); } component.Representation.TextFormat = textFormat.Value; } }
/// <summary> /// The populate attributes. /// </summary> /// <param name="parent"> /// The parent. /// </param> /// <param name="dataReader"> /// The data reader. /// </param> /// <returns> /// The <see cref="IComponentMutableObject"/>. /// </returns> /// <exception cref="SdmxNotImplementedException"> /// Unsupported attachment level at COMPONENT.ATT_ASS_LEVEL /// </exception> private static IComponentMutableObject PopulateAttributes(IDataStructureMutableObject parent, IDataRecord dataReader) { var attribute = new AttributeMutableCore { AssignmentStatus = DataReaderHelper.GetString(dataReader, "ATT_STATUS") }; // TODO pending support already in Java ////attribute.TimeFormat = DataReaderHelper.GetBoolean(dataReader, "ATT_IS_TIME_FORMAT") //// ? "true" //// : "false"; string attachmentLevel = DataReaderHelper.GetString(dataReader, "ATT_ASS_LEVEL"); switch (attachmentLevel) { case AttachmentLevelConstants.DataSet: attribute.AttachmentLevel = AttributeAttachmentLevel.DataSet; break; case AttachmentLevelConstants.Group: attribute.AttachmentLevel = AttributeAttachmentLevel.Group; break; case AttachmentLevelConstants.Observation: attribute.AttachmentLevel = AttributeAttachmentLevel.Observation; break; case AttachmentLevelConstants.Series: attribute.AttachmentLevel = AttributeAttachmentLevel.DimensionGroup; break; default: throw new SdmxNotImplementedException(ExceptionCode.Unsupported, "Attachment:" + attachmentLevel); } IComponentMutableObject component = attribute; parent.AddAttribute(attribute); return(component); }
/// <summary> /// Read the localized string from <paramref name="dataReader"/> /// </summary> /// <param name="item"> /// The <see cref="INameableMutableObject"/> . /// </param> /// <param name="typeIdx"> /// The <c>LOCALISED_STRING.TYPE</c> ordinal /// </param> /// <param name="txtIdx"> /// The <c>LOCALISED_STRING.TEXT</c> ordinal /// </param> /// <param name="langIdx"> /// The <c>LOCALISED_STRING.LANGUAGE</c> ordinal /// </param> /// <param name="dataReader"> /// The MASTORE DB <see cref="IDataReader"/> /// </param> /// <param name="detail">The Structure Query Detail</param> protected static void ReadLocalisedString(INameableMutableObject item, int typeIdx, int txtIdx, int langIdx, IDataRecord dataReader, ComplexStructureQueryDetailEnumType detail = ComplexStructureQueryDetailEnumType.Full) { //// TODO support SDMX-ML Query detail CompleteStub versus Stub when Common API supports it. //// When it is stub then only name should be returned. //// When it is complete stub both name and description. //// Now we use StructureQueryDetail which is for REST queries only. //// According to the http://sdmx.org/wp-content/uploads/2012/05/SDMX_2_1-SECTION_07_WebServicesGuidelines_May2012.pdf //// page 10, footnotes 10-12 REST AllStubs == SDMX-ML Query Stub so in that case we skip description var value = DataReaderHelper.GetString(dataReader, txtIdx); var locale = DataReaderHelper.GetString(dataReader, langIdx); string type = DataReaderHelper.GetString(dataReader, typeIdx); var textType = new TextTypeWrapperMutableCore { Locale = locale, Value = value }; switch (type) { case LocalisedStringType.Name: item.Names.Add(textType); break; case LocalisedStringType.Desc: if (detail != ComplexStructureQueryDetailEnumType.Stub) { item.Descriptions.Add(textType); } break; default: _log.WarnFormat(CultureInfo.InvariantCulture, "Unknown type at LOCALISATION.TYPE : '{0}', Locale: '{1}', Text:'{2}'", type, locale, value); if (item.Names.Count == 0) { item.AddName(null, !string.IsNullOrWhiteSpace(value) ? value : item.Id); } break; } }
public User GetUsers(string userName, string passWord) { User _user = null; string sqlCommand = "select * from User where Deleted=0 and LoginID=" + userName + " and Password="******"PhoneNumber"); _user.Password = DataReaderHelper.GetString(dr, "Password"); _user.LoginID = DataReaderHelper.GetString(dr, "LoginID"); _user.UserType = DataReaderHelper.GetInt16(dr, "UserType"); _user.Name = DataReaderHelper.GetString(dr, "Name"); _user.Deleted = DataReaderHelper.GetBoolean(dr, "Deleted"); _user.Notification = DataReaderHelper.GetBoolean(dr, "Notification"); _user.NotificationSound = DataReaderHelper.GetBoolean(dr, "NotificationSound"); _user.NotificationVibration = DataReaderHelper.GetBoolean(dr, "NotificationVibration"); _user.CreateTime = DataReaderHelper.GetDateTime(dr, "CreateTime"); _user.UpdateTime = DataReaderHelper.GetDateTime(dr, "UpdateTime"); } return(_user); }
/// <summary> /// Transcodes the time period returned by the local database to SDMX Time period /// </summary> /// <param name="reader"> /// The data reader reading the Dissemination database /// </param> /// <returns> /// The transcoded time period, as in SDMX Time period type /// </returns> public string MapComponent(IDataReader reader) { this._fieldOrdinals.BuildOrdinal(reader); string year = DataReaderHelper.GetString(reader, this._fieldOrdinals.YearOrdinal); if (this.Expression.YearLength > 0) { year = year.Substring(this.Expression.YearStart, this.Expression.YearLength); } string period = DataReaderHelper.GetString(reader, this._fieldOrdinals.PeriodOrdinal); if (this.Expression.PeriodLength > 0) { int rowPeriodLen = this.Expression.PeriodLength; if (this.Expression.PeriodLength + this.Expression.PeriodStart > period.Length) { rowPeriodLen = period.Length - this.Expression.PeriodStart; } period = period.Substring(this.Expression.PeriodStart, rowPeriodLen); } this._periodLocalCode.Clear(); this._periodLocalCode.Add(period); CodeCollection periodDsdCode = this.Expression.TranscodingRules.GetDsdCodes(this._periodLocalCode); if (periodDsdCode == null) { return(null); // MAT-495 // periodDsdCode = periodLocalCode; } string ret = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", year, periodDsdCode[0]); // ret = _timePeriodTranscoding[String.Format(CultureInfo.InvariantCulture,"{0}-{1}", year, period)]; return(ret); }
/// <summary> /// Maps the columns of the mapping to the component of this ComponentMapping1N object /// and transcodes it. /// </summary> /// <param name="reader"> /// The DataReader for retrieving the values of the column. /// </param> /// <returns> /// The value of the component or null if no transcoding rule for the column values is found /// </returns> public string MapComponent(IDataReader reader) { var resultCodes = new string[this.Mapping.Columns.Count]; this.BuildOrdinals(reader); foreach (var column in this.ColumnOrdinals) { resultCodes[column.ColumnPosition] = DataReaderHelper.GetString(reader, column.Value); } Collection <string> transcodedCodes = this.Mapping.Transcoding.TranscodingRules.GetDsdCodes(new CodeCollection(resultCodes)); string ret = null; if (transcodedCodes != null && transcodedCodes.Count > 0) { ret = transcodedCodes[0]; } return(ret); }
/// <summary> /// The retrieve artefact reference. /// </summary> /// <param name="artefactCache"> /// The artefact cache. /// </param> /// <param name="allowedDataflows"> /// The allowed dataflows. /// </param> /// <exception cref="InvalidOperationException"> /// There is an error in the SQL Query in <see cref="CategorisationConstant.ArtefactRefQueryFormat"/> /// </exception> private void RetrieveArtefactReference(IDictionary <long, IStructureReference> artefactCache, IList <IMaintainableRefObject> allowedDataflows) { using (var command = this._authReferenceCommandBuilder.Build(new ReferenceSqlQuery(CategorisationConstant.ArtefactReference), allowedDataflows)) { _log.InfoFormat(CultureInfo.InvariantCulture, "Executing Query: '{0}'", command.CommandText); using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command)) { //// A.ID, A.VERSION, A.AGENCY, T.STYPE int catnIdx = dataReader.GetOrdinal("CATN_ID"); int idIdx = dataReader.GetOrdinal("ID"); int versionIdx = dataReader.GetOrdinal("VERSION"); int agencyIdx = dataReader.GetOrdinal("AGENCY"); int stypeIdx = dataReader.GetOrdinal("STYPE"); while (dataReader.Read()) { long catn = DataReaderHelper.GetInt64(dataReader, catnIdx); string id = DataReaderHelper.GetString(dataReader, idIdx); string agency = DataReaderHelper.GetString(dataReader, agencyIdx); string version = DataReaderHelper.GetString(dataReader, versionIdx); string stype = DataReaderHelper.GetString(dataReader, stypeIdx); SdmxStructureEnumType structureType; if (Enum.TryParse(stype, true, out structureType)) { var structureReference = new StructureReferenceImpl(agency, id, version, structureType); artefactCache.Add(catn, structureReference); } else { var message = string.Format(CultureInfo.InvariantCulture, "Error could not convert {0} to SdmxStructureEnumType", stype); _log.Error(message); throw new InvalidOperationException(message); } } } } }