Beispiel #1
0
        private static List <ColumnAndField> MatchingColumnsFromUserQuery(string className, List <ColumnAndField> columns, JObject clientPayload,
                                                                          MatchingOptions options, string tableName, string primaryKey)
        {
            var matchingColumns = new List <ColumnAndField> ();

            foreach (var col in columns)
            {
                var columnName = (!string.IsNullOrEmpty(col.ClientName)) ? col.ClientName + "." + col.FieldName : col.FieldName;
                var matching   = clientPayload[columnName];
                //need to add broadcast filed to another two fields (ex password to passwordsalt and passwordhash)
                //need to add broadcast filed to another two fields (ex #ENTCAST)
                //simple matching...
                if (matching == null)
                {
                    continue;
                }
                if (options != null && options.AddValueFromPayload)
                {
                    col.Value = matching.ToObject <dynamic> ();
                }
                matchingColumns.Add(col);


                //need to change password
                //itemName
                //entcast
                //if (matching != null)
                //{
                //    col.Value = col.Value == "#ENTCAST" ? iMetadataManager.GetEntityContextByEntityName(matching.ToObject<dynamic>()) : matching.ToObject<dynamic>();
                //    matchingColumns.Add(col);
                //}
                //else if (col.Value != null && col.TableName.Equals(tableName) && col.EntityFullName.ToLower().Equals(className.ToLower()))
                //{
                //    matchingColumns.Add(col);
                //}
            }

            return(matchingColumns);
        }
Beispiel #2
0
        // List<GroupedColumns> IEntityQueryManagerV1.MatchTest (Guid tenantId, string entityName, JObject payload, string subtype, Guid userId)
        // {
        //     return GetMatchingColumns(tenantId, entityName, payload, subtype, userId);
        // }

        private List <GroupedColumns> GetMatchingColumns(Guid primaryId, Guid tenantId, string entityName, JObject payload, string subtype, Guid userId)
        {
            IMetadataManager iMetadataManager = new MetadataManager.Contracts.MetadataManager();
            var entityColumns = iMetadataManager.GetColumnNameByEntityName(entityName, null);
            var context       = iMetadataManager.GetEntityContextByEntityName(entityName);

            if (entityColumns == null)
            {
                throw new FieldAccessException("Column not found.");
            }
            var matchingOptions = new MatchingOptions
            {
                PrimaryId           = primaryId,
                TenantId            = tenantId,
                AddValueFromPayload = true,
                Context             = context,
                UserId        = userId,
                EntitySubType = subtype,
            };
            IMatcher iMatcher = new Matcher();

            return(iMatcher.GetMatchingColumnsForInsertQuery(entityName, entityColumns, payload, matchingOptions));
        }
Beispiel #3
0
        private List <ColumnAndField> GetMatchingFields(string className, List <ColumnAndField> columns, JObject clientPayload, MatchingOptions options)
        {
            IMetadataManager iMetadataManager = new MetadataManager.Contracts.MetadataManager();
            var tableName    = iMetadataManager.GetTableNameByEntityname(className);
            var primaryKey   = iMetadataManager.GetPrimaryKeyByEntityname(className);
            var classColumns = MatchingColumnsFromUserQuery(className, columns, clientPayload, options, tableName, primaryKey);

            //add internalid and tenant id from rest table

            var consolidatedChildren =
                from c in classColumns
                group c by new {
                c.EntityFullName,
                c.ClientName
            }
            into gcs
                select new GroupedColumns()
            {
                EntityFullName = gcs.Key.EntityFullName,
                ClientName     = gcs.Key.ClientName,
                Columns        = gcs.ToList(),
            };

            //add primary column and tenant columns
            foreach (var item in consolidatedChildren)
            {
                var tableName1  = item.Columns[0].TableName;
                var primaryKey1 = item.Columns[0].PrimaryKey;
                var tablePrefix = item.Columns[0].EntityPrefix;
                var itemId      = (item.EntityFullName.ToLower().Equals(className.ToLower()))?options.PrimaryId:Guid.NewGuid();
                AddBusinessColumn(columns, classColumns, primaryKey1, tableName1, tablePrefix, itemId);
                AddBusinessColumn(columns, classColumns, BusinessConstant.TenantId, tableName1, tablePrefix, options.TenantId);

                //------------------- new logic for product
                var exceptionalColumns = columns.Where(t => t.ReferenceColumnName.ToLower().Equals(primaryKey1.ToLower()) && t.ReferenceTableName.ToLower().Equals(tableName1.ToLower())).ToList();
                if (exceptionalColumns.Any())
                {
                    foreach (var col in exceptionalColumns)
                    {
                        col.Value = itemId;
                        classColumns.Add(col);
                    }
                }
                //-------------------
            }
            //
            var entityIsAnItem = iMetadataManager.EntityIsAnItem(className, false);

            if (!entityIsAnItem)
            {
                return(classColumns);
            }

            var itemFields         = ItemHelper.GetItemSelectDetails(Guid.Empty, "not-required", 0);
            var itemMatchingFields = MatchingColumnsFromUserQuery(itemFields[0].EntityFullName, itemFields, clientPayload, options, ItemHelper.ItemTableName, ItemHelper.ItemTablePrimarykey);

            var mergeColumns = classColumns.Concat(itemMatchingFields).ToList();

            //add rest item if table is item
            AddRestItemColumns(itemFields, mergeColumns, options, clientPayload);
            return(mergeColumns);
        }
Beispiel #4
0
        public List <GroupedColumns> GetMatchingColumnsForInsertQuery(string className, List <ColumnAndField> columns, JObject clientPayload, MatchingOptions options)
        {
            var matchingColumns = GetMatchingFields(className, columns, clientPayload, options);

            return(SplitTableMatching(columns, matchingColumns));
        }
Beispiel #5
0
        private void AddRestItemColumns(List <ColumnAndField> whichFields, List <ColumnAndField> whereToAdd, MatchingOptions options, JObject clientPayload)
        {
            foreach (var item in whichFields)
            {
                var isAdded = whereToAdd.Where(t =>
                                               t.ColumnName.ToLower().Equals(item.ColumnName.ToLower()) &&
                                               t.TableName.ToLower().Equals(item.TableName.ToLower()) &&
                                               t.EntityFullName.ToLower().Equals(item.EntityFullName.ToLower()) &&
                                               t.EntityPrefix.ToLower().Equals(item.EntityPrefix.ToLower())
                                               ).ToList();

                if (isAdded.Any())
                {
                    continue;
                }

                if (item.ColumnName.Equals(BusinessConstant.UpdatedBy))
                {
                    item.Value = options.UserId;
                }
                if (item.ColumnName.Equals(BusinessConstant.UpdatedDate))
                {
                    item.Value = HelperUtility.GetCurrentUTCDate();
                }
                if (item.ColumnName.Equals(BusinessConstant.EntityCode))
                {
                    item.Value = options.Context;
                }

                if (item.ColumnName.Equals(BusinessConstant.EntitySubtype))
                {
                    item.Value = options.EntitySubType;
                }
                if (item.ColumnName.Equals(BusinessConstant.Active))
                {
                    item.Value = 1;
                }
                if (item.ColumnName.Equals(BusinessConstant.Name))
                {
                    item.Value = "NotImplemented";
                }
                if (item.ColumnName.Equals(ItemHelper.ItemTablePrimarykey))
                {
                    item.Value = options.PrimaryId;
                }
                if (item.ColumnName.Equals(BusinessConstant.TenantId))
                {
                    item.Value = options.TenantId;
                }
                if (item.ColumnName.Equals(BusinessConstant.AutogeneratedCode))
                {
                    item.Value = CodeGenerationHelper.Generate(ItemHelper.ItemClassName, clientPayload);
                }
                whereToAdd.Add(item);
            }
        }