Example #1
0
        /// <summary>
        /// Gets the structure.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <param name="reference">The reference.</param>
        /// <returns>The <see cref="ItemStatusCollection"/></returns>
        public ItemSchemeFinalStatus GetStructure(DbTransactionState state, IStructureReference reference)
        {
            ItemSchemeFinalStatus returnObjet;

            if (!this._dictionary.TryGetValue(reference, out returnObjet))
            {
                var artefactFinalStatus = ArtefactBaseEngine.GetFinalStatus(state, reference);

                ItemStatusCollection collection = null;
                if (artefactFinalStatus != null && artefactFinalStatus.IsFinal && reference.HasChildReference())
                {
                    switch (reference.TargetReference.EnumType)
                    {
                    case SdmxStructureEnumType.Component:
                    case SdmxStructureEnumType.Dimension:
                    case SdmxStructureEnumType.TimeDimension:
                    case SdmxStructureEnumType.MeasureDimension:
                    case SdmxStructureEnumType.DataAttribute:
                    case SdmxStructureEnumType.PrimaryMeasure:
                    case SdmxStructureEnumType.CrossSectionalMeasure:
                        var map = GetComponentMapIds(state, reference);
                        collection = new ItemStatusCollection(map.Select(pair => new ItemStatus(pair.Key, pair.Value)));
                        break;

                    default:
                        collection = GetId(state, reference.TargetReference.EnumType, artefactFinalStatus.PrimaryKey);
                        break;
                    }
                }

                returnObjet = new ItemSchemeFinalStatus(artefactFinalStatus ?? ArtefactFinalStatus.Empty, collection);
            }

            return(returnObjet);
        }
Example #2
0
        /// <summary>
        /// Converts the concept schemes to code lists.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="conceptSchemesPerMeasureDimension">
        /// The concept schemes per measure dimension.
        /// </param>
        private void ConvertConceptSchemes(DbTransactionState state, IEnumerable <KeyValuePair <long, IMaintainableRefObject> > conceptSchemesPerMeasureDimension)
        {
            var transactionalDatabase         = new Database(this._database, state.Transaction);
            var mutableObjectRetrievalManager = this.GetRetrievalManager(transactionalDatabase);
            var codelistPrimaryKeyCache       = new Dictionary <IMaintainableRefObject, ArtefactFinalStatus>();

            foreach (var keyValuePair in conceptSchemesPerMeasureDimension)
            {
                ArtefactFinalStatus artefactFinalStatus;
                if (!codelistPrimaryKeyCache.TryGetValue(keyValuePair.Value, out artefactFinalStatus))
                {
                    artefactFinalStatus = ArtefactBaseEngine.GetFinalStatus(state, new StructureReferenceImpl(keyValuePair.Value, SdmxStructureEnumType.CodeList));

                    if (artefactFinalStatus.IsEmpty)
                    {
                        var conceptScheme = mutableObjectRetrievalManager.GetMutableConceptScheme(keyValuePair.Value, false, false);
                        var codelist      = conceptScheme.ConvertToCodelist();
                        var importStatus  = this._importEngine.Insert(state, codelist.ImmutableInstance);
                        artefactFinalStatus = new ArtefactFinalStatus(importStatus.PrimaryKeyValue, true);
                    }

                    codelistPrimaryKeyCache.Add(keyValuePair.Value, artefactFinalStatus);
                }

                state.ExecuteNonQueryFormat(
                    UpdateComponentCodelist,
                    transactionalDatabase.CreateInParameter("clId", DbType.Int64, artefactFinalStatus.PrimaryKey),
                    transactionalDatabase.CreateInParameter("compId", DbType.Int64, keyValuePair.Key));
            }
        }