Beispiel #1
0
        /// <summary>
        /// Invokes merge process
        /// </summary>
        /// <param name="schemaName">Schema name.</param>
        /// <param name="groupId">Identifier of the group of search results</param>
        /// <param name="deduplicateRecordIds">Unique identifiers.</param>
        /// <param name="resolvedConflicts">Config for resolving conflicts.</param>
        /// <returns>Instance <see cref="DuplicatesMergeResponse"/> results for merge process execution.</returns>
        public virtual DuplicatesMergeResponse MergeEntityDuplicatesAsync(string schemaName, int groupId,
                                                                          List <Guid> duplicateRecordIds, Dictionary <string, string> resolvedConflicts = null)
        {
            DuplicatesMergeResponse result = new DuplicatesMergeResponse();

            if (!Locker.CanExecute(DeduplicationConsts.SearchOperationId, schemaName))
            {
                return(result);
            }
            ValidateDuplicatesResponse response = MergeHandler.ValidateDuplicates(schemaName, duplicateRecordIds, resolvedConflicts);

            if (response.ConflictsExists)
            {
                result.Conflicts = response.Conflicts;
                return(result);
            }
            MergeHandler.ExcludeSearchResultGroup(schemaName, groupId);
            string jobName    = string.Format(MergeDuplicatesJobNamePattern, schemaName, Guid.NewGuid());
            var    parameters = new Dictionary <string, object>()
            {
                { "SchemaName", schemaName },
                { "OperationId", DeduplicationConsts.MergeOperationId },
                { "DuplicateGroupId", groupId },
                { "DuplicateRecordIds", duplicateRecordIds },
                { "ResolvedConflicts", resolvedConflicts }
            };

            AppScheduler.ScheduleImmediateProcessJob(jobName, "Dedublication", MergeDuplicatesProcessName,
                                                     _userConnection.Workspace.Name, _userConnection.CurrentUser.Name, parameters);
            result.Success = true;
            return(result);
        }
Beispiel #2
0
        /// <summary>
        ///  Validates duplicate entities.
        /// </summary>
        /// <param name="schemaName">Schema name.</param>
        /// <param name="duplicateRecordIds">Collection of identifiers of duplicate entities.</param>
        /// <param name="resolvedConflicts">Config for resolving conflicts.</param>
        /// <returns>Validation result.</returns>
        public ValidateDuplicatesResponse ValidateDuplicates(string schemaName, List <Guid> duplicateRecordIds,
                                                             Dictionary <string, string> resolvedConflicts)
        {
            ValidateDuplicatesResponse response = new ValidateDuplicatesResponse();
            EntitySchema     entitySchema       = UserConnection.EntitySchemaManager.GetInstanceByName(schemaName);
            EntityCollection entityCollection   = GetEntityDublicates(schemaName, duplicateRecordIds);
            Entity           goldenEntity       = entityCollection.FirstOrDefault();

            if (goldenEntity == null)
            {
                return(response);
            }
            entityCollection.RemoveFirst();
            List <string> resolvedColumns = new List <string>();

            if (resolvedConflicts != null)
            {
                resolvedColumns = resolvedConflicts.Keys.ToList();
            }
            List <string> conflictColumns = new List <string>();

            foreach (EntitySchemaColumn column in goldenEntity.Schema.Columns)
            {
                if (IsColumnInIgnoreList(column.Name))
                {
                    continue;
                }
                if (GetIsSystemColumn(entitySchema, column))
                {
                    continue;
                }
                if (resolvedColumns.Contains(column.Name))
                {
                    continue;
                }
                bool isConflictColumn = false;
                EntityColumnValue goldenColumnValue = goldenEntity.FindEntityColumnValue(column.ColumnValueName);
                foreach (Entity entity in entityCollection)
                {
                    EntityColumnValue columnValue = entity.FindEntityColumnValue(column.ColumnValueName);
                    if (DataTypeUtilities.ValueIsNullOrEmpty(goldenColumnValue.Value))
                    {
                        goldenColumnValue = columnValue;
                        continue;
                    }
                    if (DataTypeUtilities.ValueIsNullOrEmpty(columnValue.Value))
                    {
                        continue;
                    }
                    if (IsEquals(goldenColumnValue.Value, columnValue.Value) == false)
                    {
                        isConflictColumn = true;
                        break;
                    }
                }
                if (isConflictColumn)
                {
                    conflictColumns.Add(column.Name);
                }
            }
            if (conflictColumns.Any())
            {
                conflictColumns.AddRange(resolvedColumns);
                EntityCollection              conflicts         = GetEntityDublicates(schemaName, duplicateRecordIds, conflictColumns);
                Dictionary <string, string>   columnMap         = GetQueryColumns(conflicts.Schema.Columns);
                DataContract.EntityCollection convertedEntities =
                    QueryExtension.GetEntityCollection(conflicts, columnMap);
                response.Conflicts = convertedEntities;
            }
            return(response);
        }