/// <summary> /// Retrieve Codelist /// </summary> /// <param name="info"> /// The current StructureRetrieval state /// </param> /// <returns> /// A <see cref="ICodelistMutableObject"/> /// </returns> public ICodelistMutableObject GetCodeList(StructureRetrievalInfo info) { var codelist = new CodelistMutableCore(); var name = new TextTypeWrapperMutableCore { Locale = CustomCodelistConstants.Lang, Value = CustomCodelistConstants.CountCodeListName, }; codelist.Names.Add(name); codelist.Id = CustomCodelistConstants.CountCodeList; codelist.AgencyId = CustomCodelistConstants.Agency; codelist.Version = CustomCodelistConstants.Version; int xsMeasureMult = 1; if (info.MeasureComponent != null) { info.Logger.Info("|-- Get XS Measure count"); xsMeasureMult = GetXsMeasureCount(info); } object value = ExecuteSql(info); // setup count codelist var countCode = new CodeMutableCore(); var text = new TextTypeWrapperMutableCore { Locale = CustomCodelistConstants.Lang, Value = CustomCodelistConstants.CountCodeDescription, }; countCode.Names.Add(text); // normally count(*) should always return a number. Checking just in case I missed something. if (value != null && !Convert.IsDBNull(value)) { // in .net, oracle will return 128bit decimal, sql server 32bit int, while mysql & sqlite 64bit long. long count = Convert.ToInt64(value, CultureInfo.InvariantCulture); // check if there are XS measure mappings. In this case there could be multiple measures/obs per row. // even if they are not, then will be static mappings count *= xsMeasureMult; countCode.Id = count.ToString(CultureInfo.InvariantCulture); codelist.AddItem(countCode); } else { countCode.Id = CustomCodelistConstants.CountCodeDefault; } return codelist; }
public NameableMutableObjectBaseCore(INameableObjectBase identifiable) : base(identifiable) { this._descriptions = new List<ITextTypeWrapperMutableObject>(); this.names = new List<ITextTypeWrapperMutableObject>(); //HACK This is a hack if (identifiable.Descriptions != null) { foreach (CultureInfo locale in identifiable.Descriptions.Keys) { ITextTypeWrapperMutableObject Im = new TextTypeWrapperMutableCore(); Im.Locale = locale.TwoLetterISOLanguageName; Im.Locale = identifiable.Descriptions[locale]; _descriptions.Add(Im); } } if (identifiable.Names != null) { /* foreach */ foreach (CultureInfo locale in identifiable.Names.Keys) { ITextTypeWrapperMutableObject mBean1 = new TextTypeWrapperMutableCore(); mBean1.Locale = locale.TwoLetterISOLanguageName; mBean1.Value = identifiable.Names[locale]; names.Add(mBean1); } } }
/// <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; } }
private bool SendQuerySubmit(ICodelistMutableObject cl) { try { ISdmxObjects sdmxObjects = new SdmxObjectsImpl(); int indexOrder = 1; foreach (ICodeMutableObject code in cl.Items) { IEnumerable<IAnnotationMutableObject> annotations = (from a in code.Annotations where a.Type == "@ORDER@" select a).OfType<IAnnotationMutableObject>(); if (annotations.Count() > 0) { IAnnotationMutableObject annotation = annotations.First(); ITextTypeWrapperMutableObject iText = new TextTypeWrapperMutableCore(); iText.Value = (indexOrder++).ToString(); iText.Locale = "en"; annotation.Text.Clear(); annotation.Text.Add(iText); } else { code.AddAnnotation(GetAnnotationOrder(indexOrder++)); } lblCodeListDetail.Text = code.Names[0].Value ; } sdmxObjects.AddCodelist(cl.ImmutableInstance); WSModel modelCodeList = new WSModel(); XmlDocument result = modelCodeList.SubmitStructure(sdmxObjects); Utils.GetXMLResponseError(result); return true; } catch (Exception ex) { return false; } }
private IAnnotationMutableObject GetAnnotationOrder(int index) { IAnnotationMutableObject annotation = new AnnotationMutableCore(); ITextTypeWrapperMutableObject iText = new TextTypeWrapperMutableCore(); iText.Value = index.ToString(); iText.Locale = "en"; annotation.AddText(iText); annotation.Type = "@ORDER@"; return annotation; }
/// <summary> /// The add name. /// </summary> /// <param name="locale"> /// The locale. /// </param> /// <param name="name"> /// The name 0. /// </param> public virtual void AddName(string locale, string name) { foreach (ITextTypeWrapperMutableObject textType in this._names) { if (textType.Locale.Equals(locale)) { textType.Value = name; return; } } ITextTypeWrapperMutableObject tt = new TextTypeWrapperMutableCore(); tt.Locale = locale; tt.Value = name; this._names.Add(tt); }
/// <summary> /// The add textValue. /// </summary> /// <param name="locale"> /// The locale. /// </param> /// <param name="textValue"> /// The textValue 0. /// </param> public virtual void AddText(string locale, string textValue) { ITextTypeWrapperMutableObject tt = new TextTypeWrapperMutableCore(); tt.Locale = locale; tt.Value = textValue; this._text.Add(tt); }
/// <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> /// 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); } } } } } }