private List <ICodelistMutableObject> MergeCodelist(List <ICodelistMutableObject> cl1, List <ICodelistMutableObject> cl2) { if (cl2 == null || cl2.Count == 0) { return(cl1); } List <ICodelistMutableObject> basecl = cl1; foreach (var cod in cl2) { ICodelistMutableObject presenteCodelist = basecl.Find(c => cod.Id == c.Id); if (presenteCodelist == null) { basecl.Add(cod); continue; } foreach (ICodeMutableObject obj in cod.Items) { if (presenteCodelist.Items.Count(o => o.Id == obj.Id) == 0) { presenteCodelist.Items.Add(obj); } } } return(basecl); }
/// <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> /// Handles the CodeList element child elements /// </summary> /// <param name="parent"> /// The parent ICodelistMutableObject object /// </param> /// <param name="localName"> /// The name of the current xml element /// </param> /// <returns> /// The <see cref="StructureReaderBaseV20.ElementActions"/>. /// </returns> private ElementActions HandleChildElements(ICodelistMutableObject parent, object localName) { ElementActions actions = null; if (NameTableCache.IsElement(localName, ElementNameTable.Code)) { var code = new CodeMutableCore(); code.Id = Helper.TrySetFromAttribute(this.Attributes, AttributeNameTable.value, code.Id); code.ParentCode = Helper.TrySetFromAttribute( this.Attributes, AttributeNameTable.parentCode, code.ParentCode); code.Urn = Helper.TrySetFromAttribute(this.Attributes, AttributeNameTable.urn, code.Urn); parent.AddItem(code); actions = this.BuildElementActions(code, this.HandleAnnotableChildElements, this.HandleTextChildElement); } return actions; }
/// <summary> /// Add item to codelist whitout generate a duplicate items /// </summary> /// <param name="codelist">codelist from which to copy the items</param> public void AddItemto(ICodelistMutableObject codelist) { try { List <string> Idduples = new List <string>(); try {//ci sono i duplicati ID sotto padri diversi e SDMX scoppia.... if (CodesObjects != null) { Idduples = (from c in CodesObjects where CodesObjects.Count(comp => comp.Id == c.Id) > 1 select c.Id).Distinct().ToList(); } } catch (Exception) { //Errore nella ricerca dei duplicati ma non fa niente } if (!this.ParsingObject.ReturnStub) { foreach (ICodeMutableObject cl in CodesObjects) { if (!Idduples.Contains(cl.Id) && codelist.Items.Count(presentCode => presentCode.Id == cl.Id) == 0) { codelist.AddItem(cl); } } codelist.FinalStructure = TertiaryBool.ParseBoolean(true); } if (this.ParsingObject.isReferenceOf || this.ParsingObject.ReturnStub) { codelist.ExternalReference = TertiaryBool.ParseBoolean(true); codelist.StructureURL = RetreivalStructureUrl.Get(this, codelist.Id, codelist.AgencyId, codelist.Version); } } catch (SdmxException) { throw; } catch (Exception ex) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex); } }
/// <summary> /// Setup a CodelistBean object as a TimeDimension codelist containing two codes, startTime and endTime and using as codelist id the <see cref="CustomCodelistConstants.TimePeriodCodeList"/> . /// </summary> /// <param name="startCode"> /// The code that will contain the start Time period /// </param> /// <param name="endCode"> /// The code that will contain the end Time period /// </param> /// <param name="timeCodeList"> /// The codelist to setup /// </param> public static void SetupTimeCodelist(ICodeMutableObject startCode, ICodeMutableObject endCode, ICodelistMutableObject timeCodeList) { timeCodeList.Id = CustomCodelistConstants.TimePeriodCodeList; timeCodeList.AgencyId = CustomCodelistConstants.Agency; timeCodeList.Version = CustomCodelistConstants.Version; timeCodeList.Names.Add( new TextTypeWrapperMutableCore { Locale = CustomCodelistConstants.Lang, Value = CustomCodelistConstants.TimePeriodCodeListName }); startCode.Names.Add( new TextTypeWrapperMutableCore { Locale = CustomCodelistConstants.Lang, Value = CustomCodelistConstants.TimePeriodStartDescription }); timeCodeList.AddItem(startCode); if (endCode != null) { endCode.Names.Add( new TextTypeWrapperMutableCore { Locale = CustomCodelistConstants.Lang, Value = CustomCodelistConstants.TimePeriodEndDescription }); timeCodeList.AddItem(endCode); } }
/// <summary> /// Get the Codes /// </summary> /// <param name="itemScheme"> /// The parent <see cref="ICodelistMutableObject"/> /// </param> /// <param name="parentSysId"> /// The parent ItemScheme primary key in Mapping Store /// </param> /// <param name="dataflowRef"> /// The dataflow Ref. /// </param> /// <param name="conceptId"> /// The concept Id. /// </param> /// <param name="isTranscoded"> /// Set to true if component is transcoded; otherwise false /// </param> /// <param name="allowedDataflows">The allowed dataflows.</param> /// <returns> /// The <see cref="ICodelistMutableObject"/>. /// </returns> private ICodelistMutableObject FillCodes(ICodelistMutableObject itemScheme, long parentSysId, IMaintainableRefObject dataflowRef, string conceptId, bool isTranscoded, IList <IMaintainableRefObject> allowedDataflows) { var allItems = new Dictionary <long, ICodeMutableObject>(); var orderedItems = new List <KeyValuePair <long, ICodeMutableObject> >(); var childItems = new Dictionary <long, long>(); var sqlQuery = new PartialCodesSqlQuery(isTranscoded ? CodeListConstant.TranscodedSqlQueryInfo : CodeListConstant.LocalCodeSqlQueryInfo, parentSysId) { ConceptId = conceptId, DataflowReference = dataflowRef }; using (DbCommand command = this._partialCodesCommandBuilder.Build(sqlQuery, allowedDataflows)) { this.ReadItems(allItems, orderedItems, command, childItems); } this.FillParentItems(itemScheme, childItems, allItems, orderedItems); this.IdentifiableAnnotationRetrieverEngine.RetrieveAnnotations(parentSysId, allItems); return(itemScheme); }
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 bool SaveInMemory(ICodelistMutableObject cl) { if (cl == null) return false; Session[KEY_PAGE_SESSION] = cl; return true; }
private ICodelistMutableObject InsertCodeInCodelist(ICodelistMutableObject cl) { if (cl == null) return null; ICodeMutableObject code = new CodeMutableCore(); string code_id = txt_id_new.Text.Trim(); IList<ITextTypeWrapperMutableObject> code_names = AddTextName_new.TextObjectList; IList<ITextTypeWrapperMutableObject> code_descs = AddTextDescription_new.TextObjectList; string code_parent_id = txt_parentid_new.Text.Trim(); string code_order_str = txt_order_new.Text.Trim(); #region CODE ID if ( ValidationUtils.CheckIdFormat( code_id ) ) { code.Id = code_id; } else { lblErrorOnNewInsert.Text = Resources.Messages.err_id_format; Utils.AppendScript( "openPopUp('df-Dimension', 600);" ); Utils.AppendScript("location.href= '#codes';"); return null; } IEnumerable<ICodeMutableObject> codes = (from c in cl.Items where c.Id == code_id select c).OfType<ICodeMutableObject>(); if (codes.Count() > 0) { lblErrorOnNewInsert.Text = Resources.Messages.err_id_exist; Utils.AppendScript( "openPopUp('df-Dimension', 600);" ); Utils.AppendScript("location.href= '#codes';"); return null; } #endregion #region CODE NAMES if (code_names != null) { foreach (var tmpName in code_names) { code.AddName(tmpName.Locale, tmpName.Value); } } else { lblErrorOnNewInsert.Text = Resources.Messages.err_list_name_format; Utils.AppendScript( "openPopUp('df-Dimension', 600);" ); Utils.AppendScript("location.href= '#codes';"); return null; } #endregion #region CODE DESCRIPTIONS if (code_descs != null) { foreach (var tmpDescription in code_descs) { code.AddDescription(tmpDescription.Locale, tmpDescription.Value); } } #endregion #region PARANT ID if ( code_id.Equals( code_parent_id ) ) { lblErrorOnNewInsert.Text = Resources.Messages.err_parent_id_same_value; Utils.AppendScript( "openPopUp('df-Dimension-update', 600 );" ); Utils.AppendScript("location.href= '#codes';"); return null; } if (!code_parent_id.Equals(string.Empty) && ValidationUtils.CheckIdFormat(code_id)) { IEnumerable<ICodeMutableObject> parentCode = (from c in cl.Items where c.Id == code_parent_id select c).OfType<ICodeMutableObject>(); if (parentCode.Count() > 0) code.ParentCode = code_parent_id; else { lblErrorOnNewInsert.Text = Resources.Messages.err_parent_id_not_found; Utils.AppendScript( "openPopUp('df-Dimension', 600);" ); Utils.AppendScript("location.href= '#codes';"); return null; } } #endregion #region CODE ORDER int tmpOrder = 0; if (!code_order_str.Equals(string.Empty) && !int.TryParse( code_order_str, out tmpOrder ) ) { lblErrorOnNewInsert.Text = Resources.Messages.err_order_format_invalid; Utils.AppendScript( "openPopUp('df-Dimension', 600);" ); Utils.AppendScript("location.href= '#codes';"); return null; } else { if ( tmpOrder < 0 ) { lblErrorOnNewInsert.Text = Resources.Messages.err_order_less_than_zero; Utils.AppendScript( "openPopUp('df-Dimension', 600);" ); Utils.AppendScript("location.href= '#codes';"); return null; } } #endregion int indexOrder; if (!int.TryParse(code_order_str, out indexOrder)) indexOrder = cl.Items.Count + 1; else { indexOrder--; } if (indexOrder < 0 || indexOrder > cl.Items.Count) indexOrder = cl.Items.Count; cl.Items.Insert(indexOrder, code); try { // Ultimo controllo se ottengo Immutable istanze validazione completa var canRead = cl.ImmutableInstance; } catch (Exception ex) { cl.Items.RemoveAt(indexOrder); return null; } return cl; }
private ICodelistMutableObject GetCodelistForm(ICodelistMutableObject cl) { if (cl == null) return GetCodelistForm(); bool isInError = false; // Indicatore di errore string messagesGroup = string.Empty; // Stringa di raggruppamento errori int errorCounter = 1; // Contatore errori #region CODELIST ID if (!ValidationUtils.CheckIdFormat(txt_id.Text.Trim())) { messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_id_format + "<br /><br />"; errorCounter++; isInError = true; } #endregion #region CODELIST AGENCY if ( cmb_agencies.Text.Trim().Equals( string.Empty ) ) { messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_agency_missing + "<br /><br />"; errorCounter++; isInError = true; } #endregion #region CODELIST VERSION if (!ValidationUtils.CheckVersionFormat(txt_version.Text.Trim())) { messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_version_format + "<br /><br />"; errorCounter++; isInError = true; } #endregion /* URI NOT REQUIRED */ #region CODELIST URI if ((txt_uri.Text != string.Empty) && !ValidationUtils.CheckUriFormat(txt_uri.Text)) { messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_uri_format + "<br /><br />"; errorCounter++; isInError = true; } #endregion #region CODELIST NAMES if (AddTextName.TextObjectList == null || AddTextName.TextObjectList.Count == 0) { messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_list_name_format + "<br /><br />"; errorCounter++; isInError = true; } #endregion #region CODELIST START END DATE bool checkForDatesCombination = true; if (!txt_valid_from.Text.Trim().Equals(string.Empty) && !ValidationUtils.CheckDateFormat(txt_valid_from.Text)) { messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_date_from_format + "<br /><br />"; errorCounter++; checkForDatesCombination = false; isInError = true; } if (!txt_valid_to.Text.Trim().Equals(string.Empty) && !ValidationUtils.CheckDateFormat(txt_valid_to.Text)) { messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_date_to_format + "<br /><br />"; errorCounter++; checkForDatesCombination = false; isInError = true; } if (!txt_valid_from.Text.Trim().Equals(string.Empty) && !txt_valid_to.Text.Trim().Equals(string.Empty)) { // Controllo congruenza date if (checkForDatesCombination) { if (!ValidationUtils.CheckDates(txt_valid_from.Text, txt_valid_to.Text)) { messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_date_diff + "<br /><br />"; errorCounter++; isInError = true; } } } #endregion if (isInError) { Utils.ShowDialog(messagesGroup, 300); return null; } #region CREATE CODELIST FROM FORM cl.AgencyId = GetAgencyValue(); cl.Id = txt_id.Text; cl.Version = txt_version.Text; cl.FinalStructure = TertiaryBool.ParseBoolean(chk_isFinal.Checked); cl.Uri = (!txt_uri.Text.Trim().Equals( string.Empty ) && ValidationUtils.CheckUriFormat(txt_uri.Text)) ? new Uri(txt_uri.Text) : null; if (!txt_valid_from.Text.Trim().Equals(string.Empty)) { cl.StartDate = DateTime.ParseExact(txt_valid_from.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); } if (!txt_valid_to.Text.Trim().Equals(string.Empty)) { cl.EndDate = DateTime.ParseExact(txt_valid_to.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); } if (cl.Names.Count != 0) { cl.Names.Clear(); } foreach (var tmpName in AddTextName.TextObjectList) { cl.AddName(tmpName.Locale, tmpName.Value); } if (cl.Descriptions.Count != 0) { cl.Descriptions.Clear(); } if (AddTextDescription.TextObjectList != null) foreach (var tmpDescription in AddTextDescription.TextObjectList) { cl.AddDescription(tmpDescription.Locale, tmpDescription.Value); } if (cl.Annotations.Count != 0) { cl.Annotations.Clear(); } if (AnnotationGeneralControl.AnnotationObjectList != null) foreach (var annotation in AnnotationGeneralControl.AnnotationObjectList) { cl.AddAnnotation(annotation); } #endregion return cl; }
/// <summary> /// Get the Codes /// </summary> /// <param name="itemScheme"> /// The parent <see cref="ICodelistMutableObject"/> /// </param> /// <param name="parentSysId"> /// The parent ItemScheme primary key in Mapping Store /// </param> /// <param name="dataflowRef"> /// The dataflow Ref. /// </param> /// <param name="conceptId"> /// The concept Id. /// </param> /// <param name="isTranscoded"> /// Set to true if component is transcoded; otherwise false /// </param> /// <param name="allowedDataflows">The allowed dataflows.</param> /// <returns> /// The <see cref="ICodelistMutableObject"/>. /// </returns> private ICodelistMutableObject FillCodes(ICodelistMutableObject itemScheme, long parentSysId, IMaintainableRefObject dataflowRef, string conceptId, bool isTranscoded, IList<IMaintainableRefObject> allowedDataflows) { var allItems = new Dictionary<long, ICodeMutableObject>(); var orderedItems = new List<KeyValuePair<long, ICodeMutableObject>>(); var childItems = new Dictionary<long, long>(); var sqlQuery = new PartialCodesSqlQuery(isTranscoded ? CodeListConstant.TranscodedSqlQueryInfo : CodeListConstant.LocalCodeSqlQueryInfo, parentSysId) { ConceptId = conceptId, DataflowReference = dataflowRef }; using (DbCommand command = this._partialCodesCommandBuilder.Build(sqlQuery, allowedDataflows)) { this.ReadItems(allItems, orderedItems, command, childItems); } this.FillParentItems(itemScheme, childItems, allItems, orderedItems); return itemScheme; }
/// <summary> /// Get the Codes /// </summary> /// <param name="itemScheme"> /// 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 FillCodes(ICodelistMutableObject itemScheme, long parentSysId, ICollection <string> subset) { var allItems = new Dictionary <long, ICodeMutableObject>(); var orderedItems = new List <KeyValuePair <long, ICodeMutableObject> >(); var childItems = new Dictionary <long, long>(); var sql = new StringBuilder(this.ItemSqlQueryInfo.QueryFormat); SqlHelper.AddWhereClause(sql, WhereState.And, " I.ID IN ("); int position = sql.Length; int maxParameters = Math.Min(this._maxSqlParameters, subset.Count); var parameters = new DbParameter[maxParameters]; var parameterNames = new string[maxParameters]; var orderBy = this.ItemSqlQueryInfo.OrderBy; if (string.IsNullOrWhiteSpace(orderBy)) { orderBy = string.Empty; } var stack = new Stack <string>(subset); using (DbConnection connection = this.MappingStoreDb.CreateConnection()) { connection.Open(); using (DbCommand command = connection.CreateCommand()) { var codelistParameter = command.CreateParameter(); codelistParameter.DbType = DbType.Int64; codelistParameter.ParameterName = ParameterNameConstants.IdParameter; codelistParameter.Value = parentSysId; for (int i = 0; i < parameters.Length; i++) { var dbParameter = command.CreateParameter(); dbParameter.DbType = DbType.String; string parameterName = string.Format(CultureInfo.InvariantCulture, "{0}{1}", ParameterNameConstants.CodeParameterName, i); dbParameter.ParameterName = parameterName; parameters[i] = dbParameter; parameterNames[i] = this.MappingStoreDb.BuildParameterName(parameterName); } while (stack.Count > 0) { sql.Length = position; maxParameters = Math.Min(stack.Count, this._maxSqlParameters); for (int i = 0; i < maxParameters; i++) { sql.AppendFormat(CultureInfo.InvariantCulture, "{0},", parameterNames[i]); } sql.Length--; sql.Append(")"); sql.AppendFormat(" {0}", orderBy); command.Parameters.Clear(); command.CommandText = sql.ToString(); command.Parameters.Add(codelistParameter); for (int i = 0; i < maxParameters; i++) { parameters[i].Value = stack.Pop(); command.Parameters.Add(parameters[i]); } this.ReadItems(allItems, orderedItems, command, childItems); } } } this.FillParentItems(itemScheme, childItems, allItems, orderedItems); this.IdentifiableAnnotationRetrieverEngine.RetrieveAnnotations(parentSysId, allItems); return(itemScheme); }
private DataStructureObjectImpl BuildDataStructure(string _foundedDataflowId) { try { string ConceptSchemeId = string.Format(FlyConfiguration.ConceptSchemeFormat, _foundedDataflowId); List <IComponentMutableObject> components = new List <IComponentMutableObject>(); if (!this.ReferencesObject.Concepts.ContainsKey(ConceptSchemeId)) { ConceptSchemeManager gdf = new ConceptSchemeManager((ISdmxParsingObject)this.parsingObject.Clone(), this.versionTypeResp); ReferencesObject.Concepts.Add(string.Format(FlyConfiguration.ConceptSchemeFormat, _foundedDataflowId), gdf.GetConceptList(_foundedDataflowId)); } if (!this.ReferencesObject.Concepts.ContainsKey(ConceptSchemeId)) { throw new Exception("ConceptScheme not found"); } List <IConceptObjectImpl> conceptsObject = this.ReferencesObject.Concepts[ConceptSchemeId]; if (!this.parsingObject.ReturnStub) { foreach (IConceptObjectImpl _concept in conceptsObject) { //Cerco la giusta Codelist ICodelistMutableObject _CodelistAssociata = null; if (this.ReferencesObject.Codelists != null) { _CodelistAssociata = this.ReferencesObject.Codelists.Find(cl => cl.Id.ToUpper() == _concept.CodelistCode); } // CodelistBuilder _CodelistAssociata = this._Codelists.Find(cl => cl.Concept.ConceptObjectCode == _concept.ConceptObjectCode); //Capire se è un attribute/Dimension if (_CodelistAssociata == null) { CodelistManager cm = new CodelistManager((ISdmxParsingObject)this.parsingObject.Clone(), this.versionTypeResp); if (!String.IsNullOrEmpty(_concept.CodelistCode)) { cm.parsingObject.MaintainableId = string.Format(FlyConfiguration.CodelistFormat, _concept.CodelistCode.Substring(3)); } else { cm.parsingObject.MaintainableId = null; } cm.parsingObject.QueryDetail = StructureQueryDetailEnumType.AllStubs; cm.BuildCodelist(_foundedDataflowId, _concept); if (cm.ReferencesObject.Codelists != null && cm.ReferencesObject.Codelists.Count > 0) { _CodelistAssociata = cm.ReferencesObject.Codelists[0]; } } if (_CodelistAssociata != null) { _concept.ConceptDSDInfo = new ConceptDSDInfoObject() { CodelistId = _CodelistAssociata.Id, CodelistAgency = _CodelistAssociata.AgencyId, CodelistVersion = _CodelistAssociata.Version }; } switch (_concept.ConceptType) { case ConceptTypeEnum.Dimension: //Se è una Dimension Capire che tipologia di Dimension è Frequency/Time switch (((IDimensionConcept)_concept).DimensionType) { case DimensionTypeEnum.Dimension: DimensionMutableCore dim = new DimensionMutableCore(); dim.ConceptRef = ReferenceBuilder.CreateConceptReference(ConceptSchemeId, _concept.Id); dim.Id = _concept.Id; if (_CodelistAssociata != null) { dim.Representation = new RepresentationMutableCore() { Representation = ReferenceBuilder.CreateCodelistReference(_CodelistAssociata.Id), }; } components.Add(dim); break; case DimensionTypeEnum.Time: DimensionMutableCore TimeDim = new DimensionMutableCore(); TimeDim.ConceptRef = ReferenceBuilder.CreateConceptReference(ConceptSchemeId, _concept.ConceptObjectCode); TimeDim.Id = _concept.ConceptObjectCode; TimeDim.TimeDimension = true; components.Add(TimeDim); break; case DimensionTypeEnum.Frequency: DimensionMutableCore FreqDim = new DimensionMutableCore(); FreqDim.ConceptRef = ReferenceBuilder.CreateConceptReference(ConceptSchemeId, _concept.ConceptObjectCode); if (_CodelistAssociata != null) { FreqDim.Representation = new RepresentationMutableCore() { ////Si da per scontato che la frequency la codelist ce l'abbia Representation = ReferenceBuilder.CreateCodelistReference(_CodelistAssociata.Id), }; } FreqDim.Id = _concept.ConceptObjectCode; FreqDim.FrequencyDimension = true; if (FreqDim.ConceptRole != null) { FreqDim.ConceptRole.Add(new StructureReferenceImpl("ESTAT", "ESTAT_CONCEPT_ROLES_SCHEME", "0.1", SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Concept), new List <string> { "FREQUENCY" })); } components.Add(FreqDim); break; default: break; } break; case ConceptTypeEnum.Attribute: AttributeMutableCore attr = new AttributeMutableCore(); attr.ConceptRef = ReferenceBuilder.CreateConceptReference(ConceptSchemeId, _concept.ConceptObjectCode); if (_CodelistAssociata != null) { IRepresentationMutableObject representation = new RepresentationMutableCore(); representation.Representation = ReferenceBuilder.CreateCodelistReference(_CodelistAssociata.Id); attr.Representation = representation; } //Aggiungo attributi all'attribute AssignmentStatus e AttachmentLevel attr.AssignmentStatus = ((IAttributeConcept)_concept).AssignmentStatusType.ToString(); attr.AttachmentLevel = ((IAttributeConcept)_concept).AttributeAttachmentLevelType; if (attr.AttachmentLevel == AttributeAttachmentLevel.DimensionGroup) { foreach (var dimref in ((IAttributeConcept)_concept).GetDimensionsReference(ReferencesObject.Concepts[ConceptSchemeId])) { attr.DimensionReferences.Add(dimref); } } if (attr.AttachmentLevel == AttributeAttachmentLevel.Group) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.AttributeErrorAttachmentGroup); } //if (_CodelistAssociata.CodesObjects == null || _CodelistAssociata.CodesObjects.Count == 0) //{//levo dall'attribute la referenza alla codelist // attr.Representation = null; //} if (((IAttributeConcept)_concept).IsValueAttribute) { PrimaryMeasureMutableCore PrimaryMeasure = new PrimaryMeasureMutableCore(); //SdmxStructureType.GetFromEnum(SdmxStructureEnumType.PrimaryMeasure)); PrimaryMeasure.ConceptRef = ReferenceBuilder.CreateConceptReference(ConceptSchemeId, _concept.ConceptObjectCode); components.Add(PrimaryMeasure); } else { components.Add(attr); } break; } } } this.ReferencesObject.Codelists = null; DataStructureBuilder _DataStructureBuilder = new DataStructureBuilder(conceptsObject, this.parsingObject, this.versionTypeResp); _DataStructureBuilder.Code = string.Format(FlyConfiguration.DsdFormat, _foundedDataflowId); _DataStructureBuilder.Names = new List <SdmxObjectNameDescription>(); foreach (var nome in ReferencesObject.FoundedDataflows.Find(df => df.Id == _foundedDataflowId).Names) { _DataStructureBuilder.Names.Add(new SdmxObjectNameDescription() { Lingua = nome.Locale, Name = nome.Value }); } return(_DataStructureBuilder.BuildDataStructure(components, null, FlyConfiguration.MainAgencyId, FlyConfiguration.Version)); } catch (SdmxException) { throw; } catch (Exception ex) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex); } }
/// <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); return itemSchemeBean; }
/// <summary> /// Get the Codes /// </summary> /// <param name="itemScheme"> /// 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 FillCodes(ICodelistMutableObject itemScheme, long parentSysId, ICollection<string> subset) { var allItems = new Dictionary<long, ICodeMutableObject>(); var orderedItems = new List<KeyValuePair<long, ICodeMutableObject>>(); var childItems = new Dictionary<long, long>(); var sql = new StringBuilder(this.ItemSqlQueryInfo.QueryFormat); SqlHelper.AddWhereClause(sql, WhereState.And, " I.ID IN ("); int position = sql.Length; int maxParameters = Math.Min(this._maxSqlParameters, subset.Count); var parameters = new DbParameter[maxParameters]; var parameterNames = new string[maxParameters]; var orderBy = this.ItemSqlQueryInfo.OrderBy; if (string.IsNullOrWhiteSpace(orderBy)) { orderBy = string.Empty; } var stack = new Stack<string>(subset); using (DbConnection connection = this.MappingStoreDb.CreateConnection()) { connection.Open(); using (DbCommand command = connection.CreateCommand()) { var codelistParameter = command.CreateParameter(); codelistParameter.DbType = DbType.Int64; codelistParameter.ParameterName = ParameterNameConstants.IdParameter; codelistParameter.Value = parentSysId; for (int i = 0; i < parameters.Length; i++) { var dbParameter = command.CreateParameter(); dbParameter.DbType = DbType.String; string parameterName = string.Format(CultureInfo.InvariantCulture, "{0}{1}", ParameterNameConstants.CodeParameterName, i); dbParameter.ParameterName = parameterName; parameters[i] = dbParameter; parameterNames[i] = this.MappingStoreDb.BuildParameterName(parameterName); } while (stack.Count > 0) { sql.Length = position; maxParameters = Math.Min(stack.Count, this._maxSqlParameters); for (int i = 0; i < maxParameters; i++) { sql.AppendFormat(CultureInfo.InvariantCulture, "{0},", parameterNames[i]); } sql.Length--; sql.Append(")"); sql.AppendFormat(" {0}", orderBy); command.Parameters.Clear(); command.CommandText = sql.ToString(); command.Parameters.Add(codelistParameter); for (int i = 0; i < maxParameters; i++) { parameters[i].Value = stack.Pop(); command.Parameters.Add(parameters[i]); } this.ReadItems(allItems, orderedItems, command, childItems); } } } this.FillParentItems(itemScheme, childItems, allItems, orderedItems); return itemScheme; }