Esempio n. 1
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);
        }
 public ValidateDuplicatesResponse()
 {
     Conflicts = new DataContract.EntityCollection();
 }