Пример #1
0
        /// <summary>
        /// Gets the CodeList status.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="reference">
        /// The reference.
        /// </param>
        /// <param name="itemScheme">
        /// The item scheme.
        /// </param>
        /// <returns>
        /// The <see cref="ItemSchemeFinalStatus"/>.
        /// </returns>
        public ItemSchemeFinalStatus GetReferenceStatus(DbTransactionState state, IStructureReference reference, StructureCache itemScheme)
        {
            ItemSchemeFinalStatus codelistStatus = itemScheme.GetStructure(state, reference);

            this.ValidateFinalStatus(codelistStatus.FinalStatus, reference);
            return(codelistStatus);
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Insert the specified <paramref name="maintainable"/> to the mapping store with <paramref name="state"/>
        /// </summary>
        /// <param name="state">
        /// The MAPPING STORE connection and transaction state
        /// </param>
        /// <param name="maintainable">
        /// The maintainable.
        /// </param>
        /// <returns>
        /// The <see cref="ArtefactImportStatus"/>.
        /// </returns>
        public override ArtefactImportStatus Insert(DbTransactionState state, IHierarchicalCodelistObject maintainable)
        {
            var codelistCache = new StructureCache();

            foreach (var codelistRef in maintainable.CodelistRef)
            {
                ICrossReference codelistReference = codelistRef.CodelistReference;

                ItemSchemeFinalStatus itemSchemeFinalStatus = codelistCache.GetStructure(state, codelistReference);
                var codelistMaintainableReference           = codelistReference.MaintainableReference;
                if (itemSchemeFinalStatus.FinalStatus.PrimaryKey <= 0)
                {
                    string message = string.Format(
                        "HierarchicalCodeList {0} uses the CodeList:\r\n ID: {1}\r\n VERSION:{2}\r\n AGENCY: {3}\r\n which doesn't exist in the Mapping Store",
                        maintainable.Id,
                        codelistMaintainableReference.MaintainableId,
                        codelistMaintainableReference.Version,
                        codelistMaintainableReference.AgencyId);
                    return(new ArtefactImportStatus(-1, new ImportMessage(ImportMessageStatus.Error, codelistReference, message)));
                }

                if (!itemSchemeFinalStatus.FinalStatus.IsFinal)
                {
                    string message = string.Format(
                        "HierarchicalCodeList {0} uses the CodeList:\r\n ID: {1}\r\n VERSION:{2}\r\n AGENCY: {3}\r\n which is not Final",
                        maintainable.Id,
                        codelistMaintainableReference.MaintainableId,
                        codelistMaintainableReference.Version,
                        codelistMaintainableReference.AgencyId);
                    return(new ArtefactImportStatus(-1, new ImportMessage(ImportMessageStatus.Error, codelistReference, message)));
                }
            }

            _log.DebugFormat(CultureInfo.InvariantCulture, "Importing artefact {0}", maintainable.Urn);
            var artefactStoredProcedure = _storedProcedures.InsertHcl;
            var artefactStatus          = this.InsertArtefactInternal(state, maintainable, artefactStoredProcedure);

            foreach (KeyValuePair <long, IHierarchy> hierarchy in this.InsertHierarchies(state, maintainable.Hierarchies, artefactStatus.PrimaryKeyValue))
            {
                var levelIds = this.InsertLevels(state, hierarchy.Value.Level, hierarchy.Key);
                this.InsertCodeReferences(state, hierarchy.Value.HierarchicalCodeObjects, hierarchy.Key, codelistCache, levelIds);
            }

            return(artefactStatus);
        }
Пример #4
0
        /// <summary>
        /// The validate concept scheme.
        /// </summary>
        /// <param name="conceptSchemeID">
        /// The concept scheme id.
        /// </param>
        /// <param name="reference">
        /// The reference.
        /// </param>
        /// <returns>
        /// The <see cref="ItemStatus"/>.
        /// </returns>
        /// <exception cref="MappingStoreException">
        /// The specified <paramref name="conceptSchemeID"/> is not valid.
        /// </exception>
        private static ItemStatus ValidateConceptScheme(ItemSchemeFinalStatus conceptSchemeID, IStructureReference reference)
        {
            if (conceptSchemeID.FinalStatus.PrimaryKey < 1)
            {
                throw new MappingStoreException(GetError("Concept Scheme {0}, Agency {1}, Version {2} for concept {3} is not available. Cannot import DSD.", reference));
            }

            if (!conceptSchemeID.FinalStatus.IsFinal)
            {
                throw new MappingStoreException(GetError("Referenced Concept Scheme {0}, Agency {1}, Version {2} for concept {3} is not Final. Cannot import DSD.", reference));
            }

            ItemStatus conceptId;

            if (!conceptSchemeID.ItemIdMap.TryGetValue(reference.ChildReference.Id, out conceptId))
            {
                throw new MappingStoreException(GetError("Concept {3} from concept scheme {0}, Agency {1}, Version {2} is not available. Cannot import DSD.", reference));
            }

            return(conceptId);
        }
Пример #5
0
        /// <summary>
        /// Insert a <see cref="IHierarchicalCode"/> to mapping store table <c>HCL_CODE</c>.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="coderef">
        /// The Hierarchical code reference.
        /// </param>
        /// <param name="hierarchyID">
        /// The hierarchy ID.
        /// </param>
        /// <param name="parentID">
        /// The parent id.
        /// </param>
        /// <param name="codelistReferences">
        /// The codelist references.
        /// </param>
        /// <param name="levelIds">
        /// The level Ids.
        /// </param>
        /// <returns>
        /// The primary key of the ne
        /// </returns>
        private long InsertCodeReference(DbTransactionState state, IHierarchicalCode coderef, long hierarchyID, long parentID, StructureCache codelistReferences, IDictionary <string, long> levelIds)
        {
            var  artefactStoredProcedure = _storedProcedures.InsertHclCode;
            long artefactImportStatus;

            using (DbCommand command = artefactStoredProcedure.CreateCommandWithDefaults(state))
            {
                DbParameter parentHcodeIDIdParameter = artefactStoredProcedure.CreateParentHcodeIdParameter(command);
                parentHcodeIDIdParameter.Value = parentID > 0 ? (object)parentID : null;

                DbParameter lcdIddParameter = artefactStoredProcedure.CreateLcdIdParameter(command);

                ItemSchemeFinalStatus itemSchemeFinalStatus = codelistReferences.GetStructure(state, coderef.CodeReference);
                ItemStatus            codeStatus;
                if (itemSchemeFinalStatus.ItemIdMap.TryGetValue(coderef.CodeReference.ChildReference.Id, out codeStatus))
                {
                    lcdIddParameter.Value = codeStatus.SysID;
                }

                DbParameter hierarchyIdParameter = artefactStoredProcedure.CreateHIdParameter(command);
                hierarchyIdParameter.Value = hierarchyID;

                DbParameter  levelIdParameter = artefactStoredProcedure.CreateLevelIdParameter(command);
                ILevelObject levelObject      = coderef.GetLevel(false);
                long         levelPrimaryKey;
                if (levelObject != null && levelIds.TryGetValue(levelObject.Id, out levelPrimaryKey))
                {
                    levelIdParameter.Value = levelPrimaryKey;
                }

                if (coderef.Uri != null)
                {
                    artefactStoredProcedure.CreateUriParameter(command).Value = coderef.Uri.ToString();
                }

                artefactImportStatus = this.RunIdentifiableArterfactCommand(coderef, command, artefactStoredProcedure);
            }

            return(artefactImportStatus);
        }
Пример #6
0
        /// <summary>
        /// Gets the CodeList status.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <param name="component">The component.</param>
        /// <param name="itemScheme">The item scheme.</param>
        /// <returns>
        /// The <see cref="ItemSchemeFinalStatus" />.
        /// </returns>
        private static ItemSchemeFinalStatus GetCodelistStatus(DbTransactionState state, IComponent component, StructureCache itemScheme)
        {
            ItemSchemeFinalStatus codelistStatus = null;

            if (component.HasCodedRepresentation())
            {
                var dimension = component as IDimension;
                var crossDsd  = component.MaintainableParent as ICrossSectionalDataStructureObject;
                IStructureReference reference;
                if (dimension != null && dimension.MeasureDimension && crossDsd != null)
                {
                    reference = crossDsd.GetCodelistForMeasureDimension(dimension.Id);
                }
                else
                {
                    reference = component.Representation.Representation;
                }

                codelistStatus = itemScheme.GetStructure(state, reference);
                ValidateCodelist(codelistStatus.FinalStatus, reference);
            }

            return(codelistStatus);
        }
Пример #7
0
        /// <summary>
        /// Returns the referenced category primary key. If the category does not exist it will be added.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="maintainable">
        /// The maintainable.
        /// </param>
        /// <param name="categoryScheme">
        /// The category scheme.
        /// </param>
        /// <returns>
        /// The <see cref="ItemStatus"/>.
        /// </returns>
        private ItemStatus GetCategoryPrimaryKey(DbTransactionState state, ICategorisationObject maintainable, ItemSchemeFinalStatus categoryScheme)
        {
            ItemStatus categoryPrimaryKey;

            if (!categoryScheme.ItemIdMap.TryGetValue(maintainable.CategoryReference.ChildReference.Id, out categoryPrimaryKey))
            {
                ICategoryObject categoryObject = this._categoryBuilder.Build(maintainable.CategoryReference);
                var             primaryKey     = this._categoryImport.Insert(state, new[] { categoryObject }, categoryScheme.FinalStatus.PrimaryKey).FirstOrDefault();
                categoryPrimaryKey = new ItemStatus(categoryObject.Id, primaryKey);
            }

            return(categoryPrimaryKey);
        }
Пример #8
0
        /// <summary>
        /// Set codelist parameters.
        /// </summary>
        /// <param name="storedProcedure">
        /// The stored procedure.
        /// </param>
        /// <param name="command">
        /// The command.
        /// </param>
        /// <param name="codelistStatus">
        /// The codelist status.
        /// </param>
        /// <param name="component">
        /// The component.
        /// </param>
        private static void SetCodelist(InsertComponent storedProcedure, DbCommand command, ItemSchemeFinalStatus codelistStatus, IComponent component)
        {
            DbParameter clidParameter     = storedProcedure.CreateClIdParameter(command);
            DbParameter conSchIdParameter = storedProcedure.CreateConSchIdParameter(command);

            if (codelistStatus != null && component.HasCodedRepresentation())
            {
                switch (component.Representation.Representation.TargetReference.EnumType)
                {
                case SdmxStructureEnumType.CodeList:
                    clidParameter.Value = codelistStatus.FinalStatus.PrimaryKey;
                    break;

                case SdmxStructureEnumType.ConceptScheme:
                {
                    var crossDsd = component.MaintainableParent as ICrossSectionalDataStructureObject;
                    if (crossDsd != null)
                    {
                        clidParameter.Value = codelistStatus.FinalStatus.PrimaryKey;
                    }
                    else
                    {
                        conSchIdParameter.Value = codelistStatus.FinalStatus.PrimaryKey;
                    }
                }

                break;
                }
            }
        }