Beispiel #1
0
        public void Write([NotNull] IRow importExceptionRow,
                          DateTime importDate,
                          [NotNull] string originValue,
                          Guid lineageGuid,
                          string versionOriginValue,
                          string statusValue)
        {
            if (_insertCursor == null)
            {
                _insertCursor  = _targetTable.Insert(true);
                _rowBuffer     = _targetTable.CreateRowBuffer();
                _featureBuffer = _rowBuffer as IFeatureBuffer;
            }

            IRowBuffer buffer = Assert.NotNull(_rowBuffer);

            TransferAttributes(importExceptionRow, buffer);

            WriteText(buffer, _originFieldIndex, originValue);
            buffer.Value[_versionBeginDateFieldIndex] = importDate;
            buffer.Value[_versionEndDateFieldIndex]   = DBNull.Value;
            buffer.Value[_versionUuidFieldIndex]      = GetNewVersionUuid();
            WriteText(buffer, _versionOriginFieldIndex, versionOriginValue);
            buffer.Value[_lineageUuidFieldIndex] =
                ExceptionObjectUtils.FormatGuid(lineageGuid);
            buffer.Value[_statusFieldIndex] = statusValue;

            if (_featureBuffer != null)
            {
                _featureBuffer.Shape = ((IFeature)importExceptionRow).ShapeCopy;
            }

            _insertCursor?.InsertRow(buffer);
        }
Beispiel #2
0
        private static object FormatValue(object rawValue)
        {
            if (rawValue == null)
            {
                return(DBNull.Value);
            }

            if (rawValue is Guid)
            {
                return(ExceptionObjectUtils.FormatGuid((Guid)rawValue));
            }

            return(rawValue);
        }
Beispiel #3
0
        public void Write([NotNull] IRow updateExceptionRow,
                          DateTime updateDate,
                          [NotNull] ManagedExceptionVersion managedExceptionVersion,
                          [NotNull] string originValue,
                          [NotNull] string versionOriginValue,
                          [CanBeNull] string versionImportStatus)
        {
            Assert.ArgumentNotNull(updateExceptionRow, nameof(updateExceptionRow));
            Assert.ArgumentNotNull(managedExceptionVersion, nameof(managedExceptionVersion));
            Assert.ArgumentNotNullOrEmpty(originValue, nameof(originValue));
            Assert.ArgumentNotNullOrEmpty(versionOriginValue, nameof(versionOriginValue));

            if (_insertCursor == null)
            {
                _insertCursor  = _targetTable.Insert(true);
                _rowBuffer     = _targetTable.CreateRowBuffer();
                _featureBuffer = _rowBuffer as IFeatureBuffer;
            }

            IRowBuffer buffer = Assert.NotNull(_rowBuffer);

            TransferAttributes(updateExceptionRow, buffer);

            WriteText(buffer, _originFieldIndex, originValue);
            buffer.Value[_versionBeginDateFieldIndex] = updateDate;
            buffer.Value[_versionEndDateFieldIndex]   = DBNull.Value;           // even if 'Inactive'
            buffer.Value[_versionUuidFieldIndex]      = GetNewVersionUuid();
            WriteText(buffer, _versionOriginFieldIndex, versionOriginValue);
            buffer.Value[_lineageUuidFieldIndex] =
                ExceptionObjectUtils.FormatGuid(managedExceptionVersion.LineageUuid);
            WriteText(buffer, _versionImportStatusIndex, versionImportStatus);

            foreach (IssueAttribute attribute in managedExceptionVersion.EditableAttributes)
            {
                WriteValue(managedExceptionVersion, attribute, buffer);
            }

            if (_featureBuffer != null)
            {
                _featureBuffer.Shape = ((IFeature)updateExceptionRow).ShapeCopy;
            }

            _insertCursor?.InsertRow(buffer);
        }
Beispiel #4
0
        public static void Update(
            [CanBeNull] string whereClause,
            [NotNull] IList <IObjectClass> targetExceptionClasses,
            [NotNull] IList <IObjectClass> updateExceptionClasses,
            [NotNull] string updateOriginValue,
            DateTime updateDate,
            bool requireOriginalVersionExists = true)
        {
            IIssueTableFields updateFields = GetUpdateFields(updateExceptionClasses);
            IIssueTableFields targetFields = GetTargetFields(targetExceptionClasses);

            var editableAttributes = new[]
            {
                IssueAttribute.ExceptionStatus,
                IssueAttribute.ExceptionCategory,
                IssueAttribute.ExceptionNotes,
                IssueAttribute.ExceptionOrigin,
                IssueAttribute.ExceptionDefinitionDate,
                IssueAttribute.ExceptionLastRevisionDate,
                IssueAttribute.ExceptionRetirementDate,
                IssueAttribute.IssueAssignment
            };

            using (_msg.IncrementIndentation(
                       "Updating exceptions based on exported exception datasets..."))
            {
                foreach (ITable updateTable in updateExceptionClasses.Cast <ITable>())
                {
                    using (_msg.IncrementIndentation("from {0}...",
                                                     DatasetUtils.GetName(updateTable)))
                    {
                        ITable targetTable = GetTargetTable(updateTable, targetExceptionClasses);
                        if (targetTable == null)
                        {
                            _msg.Warn(
                                "No matching table in target workspace, ignoring import table");
                            continue;
                        }

                        var targetExceptionFactory = new ManagedExceptionVersionFactory(
                            targetTable, targetFields, editableAttributes);
                        var updateExceptionFactory = new ManagedExceptionVersionFactory(
                            updateTable, updateFields, editableAttributes);

                        ExceptionUpdateDetector updateDetector = GetUpdateDetector(
                            targetTable,
                            targetExceptionFactory,
                            editableAttributes);

                        var replacedOids = new HashSet <int>();

                        var updatedRowsCount       = 0;
                        var rowsWithConflictsCount = 0;

                        using (var exceptionWriter = new ExceptionWriter(updateTable, updateFields,
                                                                         targetTable, targetFields))
                        {
                            foreach (IRow updateRow in GdbQueryUtils.GetRows(
                                         updateTable, GetQueryFilter(whereClause), recycle: true))
                            {
                                ManagedExceptionVersion updateExceptionVersion =
                                    updateExceptionFactory.CreateExceptionVersion(updateRow);

                                ManagedExceptionVersion            mergedException;
                                ManagedExceptionVersion            replacedExceptionVersion;
                                IList <ExceptionAttributeConflict> conflicts;

                                if (updateDetector.HasChange(updateExceptionVersion,
                                                             out mergedException,
                                                             out replacedExceptionVersion,
                                                             out conflicts))
                                {
                                    if (replacedExceptionVersion == null)
                                    {
                                        string message = string.Format(
                                            "Exception version {0} not found in lineage {1} (target table: {2})",
                                            ExceptionObjectUtils.FormatGuid(
                                                updateExceptionVersion.VersionUuid),
                                            ExceptionObjectUtils.FormatGuid(
                                                updateExceptionVersion.LineageUuid),
                                            DatasetUtils.GetName(targetTable));

                                        if (requireOriginalVersionExists)
                                        {
                                            throw new InvalidDataException(message);
                                        }

                                        _msg.WarnFormat(
                                            "{0}. Creating new version with attributes from update row.",
                                            message);
                                    }

                                    updatedRowsCount++;

                                    string versionImportStatus;
                                    if (conflicts.Count == 0)
                                    {
                                        versionImportStatus = null;
                                    }
                                    else
                                    {
                                        versionImportStatus =
                                            FormatConflicts(conflicts, targetFields);

                                        rowsWithConflictsCount++;

                                        LogConflicts(conflicts, targetFields);
                                    }

                                    exceptionWriter.Write(updateRow, updateDate, mergedException,
                                                          FormatOriginValue(updateOriginValue,
                                                                            replacedExceptionVersion),
                                                          updateOriginValue, versionImportStatus);

                                    if (replacedExceptionVersion != null)
                                    {
                                        replacedOids.Add(replacedExceptionVersion.ObjectID);
                                    }
                                }
                            }
                        }

                        _msg.InfoFormat("{0:N0} exception(s) updated", updatedRowsCount);
                        if (rowsWithConflictsCount > 0)
                        {
                            _msg.WarnFormat("{0:N0} exception(s) with conflicts",
                                            rowsWithConflictsCount);
                        }

                        if (replacedOids.Count > 0)
                        {
                            int fixedStatusCount;
                            int updateCount = ProcessReplacedExceptions(targetTable, targetFields,
                                                                        updateDate, replacedOids,
                                                                        out fixedStatusCount);

                            _msg.DebugFormat("{0:N0} replaced exception version(s) updated",
                                             updateCount);
                            if (fixedStatusCount > 0)
                            {
                                _msg.WarnFormat(
                                    "Status value of {0:N0} old exception version(s) fixed",
                                    fixedStatusCount);
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        private bool HasChange([NotNull] ManagedExceptionVersion update,
                               [NotNull] ManagedExceptionVersion current,
                               [NotNull] ManagedExceptionVersion original,
                               [NotNull] out ManagedExceptionVersion merged,
                               [NotNull] out IList <ExceptionAttributeConflict> conflicts)
        {
            merged = update.Clone();

            var changedAttributes = new List <IssueAttribute>();

            conflicts = new List <ExceptionAttributeConflict>();

            if (update.Status == ExceptionObjectStatus.Active &&
                current.Status == ExceptionObjectStatus.Active)
            {
                // 1: update: active; current: active --> update of active exception
                // --> update attributes regularly
            }
            else if (update.Status == ExceptionObjectStatus.Inactive &&
                     current.Status == ExceptionObjectStatus.Active)
            {
                // 2: update: inactive; current: active --> "deletion" of active exception
                // --> update attributes regularly
            }
            else if (update.Status == ExceptionObjectStatus.Active &&
                     current.Status == ExceptionObjectStatus.Inactive)
            {
                // 3: update: active; current: inactive
                if (original.Status == ExceptionObjectStatus.Active)
                {
                    // set to inactive by previous import
                    // --> ignore
                    _msg.DebugFormat(
                        "Exception ({0}) was set to inactive by previous update, ignore update (OID: {1})",
                        ExceptionObjectUtils.FormatGuid(current.LineageUuid), update.ObjectID);
                    return(false);
                }

                // resurrection
                return(true);
                // --> ignore, no change
            }
            else if (update.Status == ExceptionObjectStatus.Inactive &&
                     current.Status == ExceptionObjectStatus.Inactive)
            {
                // 4: update: inactive; current: inactive
                // --> update attributes regularly
                _msg.DebugFormat(
                    "Exception ({0}) was set to inactive by previous update, ignore update (OID: {1})",
                    ExceptionObjectUtils.FormatGuid(current.LineageUuid), update.ObjectID);
            }

            foreach (IssueAttribute attribute in _editableAttributes)
            {
                object newValue      = update.GetValue(attribute);
                object currentValue  = current.GetValue(attribute);
                object originalValue = original.GetValue(attribute);

                if (Equals(newValue, originalValue) || Equals(newValue, currentValue))
                {
                    // the value was not changed in the update, or it is equal to the current value
                    merged.SetValue(attribute, currentValue);
                }
                else
                {
                    // different from current, changed in update
                    changedAttributes.Add(attribute);

                    merged.SetValue(attribute, newValue);

                    if (!Equals(currentValue, originalValue))
                    {
                        // also changed in current --> conflict
                        conflicts.Add(CreateConflict(attribute,
                                                     newValue, currentValue, originalValue,
                                                     update.LineageUuid,
                                                     original.VersionUuid));
                    }
                }
            }

            return(changedAttributes.Count > 0);
        }
Beispiel #6
0
 private static string GetNewVersionUuid()
 {
     return(ExceptionObjectUtils.FormatGuid(Guid.NewGuid()));
 }