Ejemplo n.º 1
0
        /// <summary>
        /// Insert the specified <paramref name="maintainable"/> to mapping store <c>CATEGORISATION</c> table
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="maintainable">
        /// The maintainable.
        /// </param>
        /// <param name="cache">
        /// The cached Dataflow and Category Scheme
        /// </param>
        /// <returns>
        /// The <see cref="ArtefactImportStatus"/>.
        /// </returns>
        private ArtefactImportStatus InsertInternal(DbTransactionState state, ICategorisationObject maintainable, StructureCache cache)
        {
            var dataflowStatus = cache.GetStructure(state, maintainable.StructureReference);
            ArtefactImportStatus returnValue;

            if (dataflowStatus.FinalStatus.PrimaryKey > 0)
            {
                var categoryScheme = cache.GetStructure(state, maintainable.CategoryReference);
                if (categoryScheme.FinalStatus.PrimaryKey > 0 && categoryScheme.FinalStatus.IsFinal)
                {
                    var categoryPrimaryKey = this.GetCategoryPrimaryKey(state, maintainable, categoryScheme);
                    if (!ExistsCategorisation(state, dataflowStatus.FinalStatus.PrimaryKey, categoryPrimaryKey.SysID))
                    {
                        var artefactStoredProcedure = _storedProcedures.InsertCategorisation;

                        returnValue = this.InsertArtefactInternal(
                            state,
                            maintainable,
                            artefactStoredProcedure,
                            command =>
                        {
                            artefactStoredProcedure.CreateArtIdParameter(command).Value = dataflowStatus.FinalStatus.PrimaryKey;
                            artefactStoredProcedure.CreateCatIdParameter(command).Value = categoryPrimaryKey.SysID;
                        });

                        string message = string.Format(
                            CultureInfo.InvariantCulture,
                            "Successfully categorized {0} with Category {1} of {2}\n",
                            maintainable.StructureReference.GetAsHumanReadableString(),
                            maintainable.CategoryReference.ChildReference.Id,
                            maintainable.CategoryReference.GetAsHumanReadableString());
                        returnValue = new ArtefactImportStatus(returnValue.PrimaryKeyValue, new ImportMessage(ImportMessageStatus.Success, maintainable.AsReference, message));
                    }
                    else
                    {
                        returnValue = BuildWarningMessage(maintainable, "Warning: Ignoring duplicate categorisation of {0} with {1}\n");
                    }
                }
                else if (!categoryScheme.FinalStatus.IsFinal)
                {
                    returnValue = BuildWarningMessage(maintainable, "Failure: {0} is not Final so it cannot be referenced from {1}\n");
                }
                else
                {
                    returnValue = BuildWarningMessage(maintainable, "Failure: {0} does not exist so it cannot be referenced from {1}\n");
                }
            }
            else
            {
                string message = string.Format(CultureInfo.InvariantCulture, "Failure: Cannot categorize {0}, because it does not exist\n", maintainable.StructureReference.GetAsHumanReadableString());
                returnValue = new ArtefactImportStatus(-1, new ImportMessage(ImportMessageStatus.Warning, maintainable.AsReference, message));
            }

            return(returnValue);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Inserts the content constraint attachment.
        /// </summary>
        /// <param name="state">
        ///     The state.
        /// </param>
        /// <param name="maintainable">
        ///     The maintainable.
        /// </param>
        /// <param name="artefactStatus">
        ///     The artefact status.
        /// </param>
        private void InsertContentConstraintAttachment(DbTransactionState state, IContentConstraintObject maintainable, ArtefactImportStatus artefactStatus)
        {
            if (maintainable.ConstraintAttachment == null)
            {
                return;
            }

            var procedure      = new InsertContentConstraintAttachmentProcedure();
            var structureCache = new StructureCache();

            using (var command = procedure.CreateCommand(state))
            {
                procedure.CreateContentConstraintIdParameter(command, artefactStatus.PrimaryKeyValue);
                foreach (var crossReference in maintainable.ConstraintAttachment.StructureReference)
                {
                    var itemSchemeFinalStatus = structureCache.GetStructure(state, crossReference);
                    this._validateStatusEngine.ValidateFinalStatus(itemSchemeFinalStatus.FinalStatus, crossReference);
                    procedure.CreateArtefactIdParameter(command, itemSchemeFinalStatus.FinalStatus.PrimaryKey);
                    command.ExecuteNonQuery();
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// The insert.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="component">
        /// The component.
        /// </param>
        /// <param name="itemScheme">
        /// The item scheme.
        /// </param>
        /// <param name="parentArtefact">
        /// The parent artefact.
        /// </param>
        /// <returns>
        /// The <see cref="long"/>.
        /// </returns>
        /// <exception cref="MappingStoreException">
        /// THere was a problem with the <paramref name="component"/> references.
        /// </exception>
        private static long Insert(
            DbTransactionState state, IComponent component, StructureCache itemScheme, long parentArtefact)
        {
            var        conceptStatus  = itemScheme.GetStructure(state, component.ConceptRef);
            ItemStatus conceptID      = ValidateConceptScheme(conceptStatus, component.ConceptRef);
            var        codelistStatus = GetCodelistStatus(state, component, itemScheme);

            var  formats = new List <KeyValuePair <long, ITextFormat> >();
            long compID;
            var  attribute       = component as IAttributeObject;
            var  dimension       = component as IDimension;
            var  storedProcedure = _storedProcedures.InsertComponent;

            using (DbCommand command = storedProcedure.CreateCommand(state))
            {
                DbParameter idParameter = storedProcedure.CreateIdParameter(command);
                idParameter.Value = component.Id;

                SetDsd(parentArtefact, storedProcedure, command);

                SetConcept(storedProcedure, command, conceptID);

                SetComponentType(component, storedProcedure, command);

                SetCodelist(storedProcedure, command, codelistStatus, component);

                DbParameter isFreqDimParameter = storedProcedure.CreateIsFreqDimParameter(command);

                DbParameter isMeasureDimParameter = storedProcedure.CreateIsMeasureDimParameter(command);

                DbParameter attAssLevelParameter = storedProcedure.CreateAttAssLevelParameter(command);

                DbParameter attStatusParameter = storedProcedure.CreateAttStatusParameter(command);

                DbParameter attIsTimeFormatParameter = storedProcedure.CreateAttIsTimeFormatParameter(command);

                DbParameter xsMeasureCodeParameter = storedProcedure.CreateXsMeasureCodeParameter(command);

                DbParameter outputParameter = storedProcedure.CreateOutputParameter(command);

                switch (component.StructureType.EnumType)
                {
                case SdmxStructureEnumType.Dimension:
                case SdmxStructureEnumType.MeasureDimension:
                {
                    SetDimensionParameters(dimension, isFreqDimParameter, isMeasureDimParameter);
                }

                break;

                case SdmxStructureEnumType.TimeDimension:
                    break;

                case SdmxStructureEnumType.DataAttribute:
                {
                    SetAttributeParameters(attribute, attAssLevelParameter, attStatusParameter, attIsTimeFormatParameter);
                }

                break;

                case SdmxStructureEnumType.PrimaryMeasure:
                    break;

                case SdmxStructureEnumType.CrossSectionalMeasure:
                {
                    SetCrossSectionalMeasureParameters(component, xsMeasureCodeParameter);
                }

                break;
                }

                SetCrossSectionalLevels(component, storedProcedure, command);

                command.ExecuteNonQuery();

                compID = (long)outputParameter.Value;

                if (component.Representation != null && component.Representation.TextFormat != null)
                {
                    formats.Add(new KeyValuePair <long, ITextFormat>(compID, component.Representation.TextFormat));
                }
            }

            InsertTextFormats(state, formats);
            _annotationInsertEngine.Insert(state, compID, _insertComponentAnnotation, component.Annotations);
            return(compID);
        }
Ejemplo n.º 8
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;
 }