Beispiel #1
0
        private DuplicatesGroupResponse ConvertServerEntityToClientEntity(EntitySchemaQuery esq,
                                                                          List <EntityDuplicatesGroup> entityGroups)
        {
            DuplicatesGroupResponse result = new DuplicatesGroupResponse()
            {
                Groups = new Collection <EntityClientDuplicatesGroup>()
            };
            Dictionary <string, string> serverToClientColumnNameMap = GetQueryColumns(esq);

            foreach (EntityDuplicatesGroup groupItem in entityGroups)
            {
                EntityCollection convertedEntities =
                    QueryExtension.GetEntityCollection(groupItem.Duplicates,
                                                       serverToClientColumnNameMap);
                EntityClientDuplicatesGroup clientGroup = new EntityClientDuplicatesGroup()
                {
                    GroupId = groupItem.GroupId,
                    Rows    = convertedEntities
                };
                result.Groups.Add(clientGroup);
            }
            if (result.Groups.Any())
            {
                Dictionary <string, object> columnConfig =
                    QueryExtension.GetColumnConfig(esq, serverToClientColumnNameMap);
                result.RowConfig = columnConfig;
            }
            result.Groups.OrderBy(group => group.GroupId);
            return(result);
        }
Beispiel #2
0
 private EntityCollection GetDuplicatesEntityCollection(EntitySchemaQuery esq,
                                                        Dictionary <string, string> serverToClientColumnNameMap, IEnumerable <Guid> entityIds)
 {
     esq.ResetSelectQuery();
     esq.Filters.Clear();
     esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, esq.PrimaryQueryColumn.Path,
                                                    entityIds.Select(id => id.ToString()).Distinct()));
     return(QueryExtension.GetEntityCollection(esq.GetEntityCollection(UserConnection), serverToClientColumnNameMap));
 }
Beispiel #3
0
        private EntityCollection GetDuplicateEntities(EntitySchemaQuery esq,
                                                      Dictionary <string, string> serverToClientColumnNameMap, IList <DuplicateInfo> entities)
        {
            esq.ResetSelectQuery();
            esq.Filters.Clear();
            esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, esq.PrimaryQueryColumn.Path,
                                                           entities.Select(entity => entity.RecordId.ToString()).Distinct()));
            var duplicatesCollection = QueryExtension.GetEntityCollection(esq.GetEntityCollection(UserConnection), serverToClientColumnNameMap);

            foreach (var item in duplicatesCollection)
            {
                item.Add(IsUniqueAttributeName, entities.First(x => x.RecordId == GetRowRecordId(item, esq)).IsUnique);
            }
            return(duplicatesCollection);
        }
        private SelectQueryResponse GetVisaData(Select entitiesSelect)
        {
            Dictionary <string, string> serverToClientColumnNameMap = GetColumnNameMap(entitiesSelect);
            var collection = new EntityCollection(_userConnection, _baseVisaSchema);

            using (DBExecutor dbExecutor = _userConnection.EnsureDBConnection()) {
                using (IDataReader dataReader = entitiesSelect.ExecuteReader(dbExecutor)) {
                    collection.Load(dataReader);
                }
            }
            var convertedEntities = QueryExtension.GetEntityCollection(collection, serverToClientColumnNameMap);
            Dictionary <string, object> config   = QueryExtension.GetColumnConfig(_baseVisaESQ, serverToClientColumnNameMap);
            SelectQueryResponse         response = new SelectQueryResponse {
                Rows         = convertedEntities,
                RowsAffected = convertedEntities.Count,
                RowConfig    = config
            };

            return(response);
        }
        public SelectQueryResponse GetEntities(RequestOptions requestOptions)
        {
            Select selectFromProviders = GetSelectFromProviders();

            if (selectFromProviders == null)
            {
                return(new SelectQueryResponse {
                    Rows = null,
                    RowsAffected = 0,
                    RowConfig = null
                });
            }
            Select entitiesSelect = WrapSelect(selectFromProviders);

            ApplyOptions(ref entitiesSelect, requestOptions);
            Dictionary <string, string> serverToClientColumnNameMap = GetColumnNameMap(entitiesSelect);
            CoreEntitySchema            baseVisaSchema = GetExtendedBaseVisaEntitySchema();
            EntitySchemaQuery           baseVisaESQ    = GetExtendedBaseVisaESQ(baseVisaSchema);

            Terrasoft.Core.Entities.EntityCollection collection =
                new Terrasoft.Core.Entities.EntityCollection(_userConnection, baseVisaSchema);
            using (DBExecutor dbExecutor = _userConnection.EnsureDBConnection()) {
                using (IDataReader dataReader = entitiesSelect.ExecuteReader(dbExecutor)) {
                    collection.Load(dataReader);
                }
            }
            var convertedEntities = QueryExtension.GetEntityCollection(collection, serverToClientColumnNameMap);
            Dictionary <string, object> config   = QueryExtension.GetColumnConfig(baseVisaESQ, serverToClientColumnNameMap);
            SelectQueryResponse         response = new SelectQueryResponse {
                Rows         = convertedEntities,
                RowsAffected = convertedEntities.Count,
                RowConfig    = config
            };

            return(response);
        }
Beispiel #6
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);
        }