예제 #1
0
        /// <summary>
        /// Insert the specified <paramref name="maintainables"/> to the mapping store.
        /// </summary>
        /// <param name="maintainables">
        /// The maintainable.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{ArtefactImportStatus}"/>.
        /// </returns>
        public new IEnumerable <ArtefactImportStatus> Insert(IEnumerable <ICategorisationObject> maintainables)
        {
            var cache = new StructureCache();

            foreach (var artefact in maintainables)
            {
                using (DbTransactionState state = DbTransactionState.Create(this.Database))
                {
                    ArtefactImportStatus artefactImportStatus;
                    try
                    {
                        artefactImportStatus = this.InsertInternal(state, artefact, cache);
                        state.Commit();
                    }
                    catch (MappingStoreException e)
                    {
                        _log.Error(artefact.Urn.ToString(), e);
                        state.RollBack();
                        artefactImportStatus = new ArtefactImportStatus(-1, artefact.AsReference.GetErrorMessage(e));
                    }
                    catch (DbException e)
                    {
                        _log.Error(artefact.Urn.ToString(), e);
                        state.RollBack();
                        artefactImportStatus = new ArtefactImportStatus(-1, artefact.AsReference.GetErrorMessage(e));
                    }

                    yield return(artefactImportStatus);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Insert or replace artefacts.
        /// </summary>
        /// <param name="maintainables">
        /// The maintainables.
        /// </param>
        /// <typeparam name="T">
        /// The <see cref="IMaintainableObject"/> based interface
        /// </typeparam>
        /// <returns>
        /// The <see cref="IEnumerable{ArtefactImportStatus}"/>.
        /// </returns>
        protected IEnumerable <ArtefactImportStatus> ReplaceOrInsert <T>(IEnumerable <T> maintainables) where T : IMaintainableObject
        {
            foreach (var artefact in maintainables)
            {
                using (DbTransactionState state = DbTransactionState.Create(this._database))
                {
                    ArtefactImportStatus artefactImportStatus;
                    try
                    {
                        artefactImportStatus = this.ReplaceOrInsert(state, artefact);
                        state.Commit();
                    }
                    catch (MappingStoreException e)
                    {
                        _log.Error(artefact.Urn.ToString(), e);
                        state.RollBack();
                        artefactImportStatus = new ArtefactImportStatus(-1, artefact.AsReference.GetErrorMessage(e));
                    }
                    catch (DbException e)
                    {
                        _log.Error(artefact.Urn.ToString(), e);
                        state.RollBack();
                        artefactImportStatus = new ArtefactImportStatus(-1, artefact.AsReference.GetErrorMessage(e));
                    }

                    yield return(artefactImportStatus);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Replace or insert the specified <paramref name="artefact"/> to MAPPING STORE
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="artefact">
        /// The artefact.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="state"/> is null
        ///     -or-
        ///     <paramref name="artefact"/> is null
        /// </exception>
        /// <returns>
        /// The <see cref="ArtefactImportStatus"/>.
        /// </returns>
        protected ArtefactImportStatus ReplaceOrInsert(DbTransactionState state, IMaintainableObject artefact)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            if (artefact == null)
            {
                throw new ArgumentNullException("artefact");
            }

            var structureReference = artefact.AsReference;

            _log.DebugFormat(CultureInfo.InvariantCulture, "Replacing or Insert artefact = {0}", structureReference);
            var finalStatus = GetFinalStatus(state, structureReference);
            ArtefactImportStatus status;

            if (finalStatus == null || finalStatus.PrimaryKey < 0)
            {
                status = this.InsertArtefact(state, artefact);
            }
            else if (!finalStatus.IsFinal)
            {
                this.Delete(state, finalStatus.PrimaryKey);
                status = this.InsertArtefact(state, artefact);
            }
            else
            {
                status = new ArtefactImportStatus(finalStatus.PrimaryKey, this.GetCannotReplaceMessage(structureReference));
            }

            return(status);
        }
예제 #4
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);
        }
예제 #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();
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Inserts the cube region.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <param name="cubeRegion">The cube region.</param>
        /// <param name="artefactStatus">The artefact status.</param>
        /// <param name="isInclude">if set to <c>true</c> [is include].</param>
        private static void InsertCubeRegion(DbTransactionState state, ICubeRegion cubeRegion, ArtefactImportStatus artefactStatus, bool isInclude)
        {
            var  procedure = new InsertCubeRegionProcedure();
            long cubeRegionPrimaryKey;

            using (var command = procedure.CreateCommand(state))
            {
                procedure.CreateContentConstraintIdParameter(command, artefactStatus.PrimaryKeyValue);
                procedure.CreateIncludeParameter(command, isInclude);
                var outputParameter = procedure.CreateOutputParameter(command);
                command.ExecuteNonQuery();
                cubeRegionPrimaryKey = (long)outputParameter.Value;
            }

            // handle dimensions
            var keyValuesWithId = InsertKeyValues(state, isInclude, cubeRegionPrimaryKey, cubeRegion.KeyValues, SdmxComponentType.Dimension);

            InsertValues(state, isInclude, keyValuesWithId);

            // handle attributes
            var attrValuesWithId = InsertKeyValues(state, isInclude, cubeRegionPrimaryKey, cubeRegion.AttributeValues, SdmxComponentType.Attribute);

            InsertValues(state, isInclude, attrValuesWithId);
        }
예제 #7
0
        /// <summary>
        /// Insert the specified <paramref name="maintainable"/> as dataflow if <paramref name="maintainable"/> is final.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="maintainable">
        /// The <see cref="IDataStructureObject"/>.
        /// </param>
        /// <param name="artefactStatus">
        /// The artefact status.
        /// </param>
        /// <remarks>
        /// This method inserts the specified data structure object (DSD) as dataflow. It is not an error.
        /// </remarks>
        private void InsertAsDataflow(DbTransactionState state, IDataStructureObject maintainable, ArtefactImportStatus artefactStatus)
        {
            if (maintainable.IsFinal.IsTrue)
            {
                var dataflowStoredProcedure = new StoredProcedures().InsertDataflow;

                var artefactFinalStatus = GetFinalStatus(state, new StructureReferenceImpl(maintainable.AsReference, SdmxStructureEnumType.Dataflow));
                if (artefactFinalStatus.IsEmpty)
                {
                    this.InsertArtefactInternal(
                        state,
                        maintainable,
                        dataflowStoredProcedure,
                        command =>
                    {
                        dataflowStoredProcedure.CreateDsdIdParameter(command).Value = artefactStatus.PrimaryKeyValue;
                        dataflowStoredProcedure.CreateMapSetIdParameter(command);
                    });
                }
            }
        }