Esempio n. 1
0
        private IEnumerable <dynamic> Query(EntityMetadata entityMetadata, BindedEntityQuery query, long rowstamp, SearchRequestDto searchDto)
        {
            var sqlAux = query.Sql.Replace("1=1", RowStampUtil.RowstampWhereCondition(entityMetadata, rowstamp, searchDto));
            var rows   = GetDao(entityMetadata).FindByNativeQuery(sqlAux, query.Parameters, null, searchDto.QueryAlias);

            return(rows);
        }
Esempio n. 2
0
        private void HandleRowStamps(IDictionary <string, object> fields)
        {
            //TODO: handle associations correctly on entitymetadataslicer, rowstamps should not be here!
            var rowstampFields = new Dictionary <string, object>();

            foreach (var pair in fields)
            {
                if (pair.Key == RowStampUtil.RowstampColumnName || pair.Key.Contains("." + RowStampUtil.RowstampColumnName))
                {
                    rowstampFields.Add(pair.Key, RowStampUtil.Convert(pair.Value));
                }
            }
            foreach (var o in rowstampFields)
            {
                fields[o.Key] = o.Value;
            }
        }
Esempio n. 3
0
        public static DataMap Populate(ApplicationMetadata applicationMetadata,
                                       IEnumerable <KeyValuePair <string, object> > row)
        {
            IDictionary <string, object> attributes = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            foreach (var pair in row)
            {
                object value;
                if (pair.Key == RowStampUtil.RowstampColumnName || pair.Key.Contains("." + RowStampUtil.RowstampColumnName))
                {
                    value = RowStampUtil.Convert(pair.Value);
                }
                else
                {
                    value = Convert.ToString(pair.Value);
                }
                attributes[pair.Key] = value;
            }
            //true: avoid double rows interation for rowstamp handling
            return(new DataMap(applicationMetadata.Name, applicationMetadata.IdFieldName, attributes, true));
        }
Esempio n. 4
0
 public EntitySchema(string entityName, IEnumerable <EntityAttribute> attributes, [NotNull] string idAttributeName, Boolean excludeUndeclaredAttributes,
                     Boolean excludeUndeclaredAssociations, string whereClause, string parentEntity, bool includeRowstamp = true)
 {
     if (idAttributeName == null)
     {
         throw new ArgumentNullException("idAttributeName");
     }
     EntityName  = entityName;
     _attributes = attributes == null ? new HashSet <EntityAttribute>() : new HashSet <EntityAttribute>(attributes);
     if (includeRowstamp)
     {
         _rowstampAttribute = RowStampUtil.RowstampEntityAttribute();
         _attributes.Add(_rowstampAttribute);
     }
     _idAttribute = new Lazy <EntityAttribute>(() => FindIdAttribute(_attributes, idAttributeName));
     ExcludeUndeclaredAttributes   = excludeUndeclaredAttributes;
     ExcludeUndeclaredAssociations = excludeUndeclaredAssociations;
     ParentEntity = parentEntity;
     WhereClause  = whereClause;
     if (ParentEntity != null)
     {
     }
 }
Esempio n. 5
0
        //needed to avoid "Fields" nesting in collectionData
        public SearchEntityResult GetAsRawDictionary([NotNull] EntityMetadata entityMetadata, [NotNull] SearchRequestDto searchDto, Boolean fetchMaxRowstamp = false)
        {
            if (entityMetadata == null)
            {
                throw new ArgumentNullException("entityMetadata");
            }
            if (searchDto == null)
            {
                throw new ArgumentNullException("searchDto");
            }
            var query      = new EntityQueryBuilder().AllRows(entityMetadata, searchDto);
            var rows       = Query(entityMetadata, query, searchDto);
            var enumerable = rows as dynamic[] ?? rows.ToArray();

            Log.DebugFormat("returning {0} rows", enumerable.Count());
            long?maxRowstamp = 0;

            IList <Dictionary <string, object> > list = new List <Dictionary <string, object> >();

            foreach (var row in enumerable)
            {
                var dict = (IDictionary <string, object>)row;
                var item = new Dictionary <string, object>();
                if (fetchMaxRowstamp)
                {
                    if (dict.ContainsKey(RowStampUtil.RowstampColumnName))
                    {
                        var rowstamp = RowStampUtil.Convert(dict[RowStampUtil.RowstampColumnName]);
                        if (rowstamp > maxRowstamp)
                        {
                            maxRowstamp = rowstamp;
                        }
                    }
                }

                foreach (var column in dict)
                {
                    item[FixKey(column.Key, entityMetadata)] = column.Value;
                }
                if (entityMetadata.Name == "relatedrecord")
                {
                    item["hmachash"] = AuthUtils.HmacShaEncode(item["relatedreckey"].ToString());
                }
                else if (entityMetadata.Name == "ticket" || entityMetadata.Name == "imac")
                {
                    item["hmachash"] = AuthUtils.HmacShaEncode(item["ticketid"].ToString());
                }
                else if (entityMetadata.IdFieldName != null && item.ContainsKey(entityMetadata.IdFieldName))
                {
                    //for compositions in general
                    item["hmachash"] = AuthUtils.HmacShaEncode(item[entityMetadata.IdFieldName].ToString());
                }

                list.Add(item);
            }

            return(new SearchEntityResult {
                MaxRowstampReturned = maxRowstamp == 0 ? null : maxRowstamp,
                ResultList = list,
                IdFieldName = entityMetadata.IdFieldName
            });
        }