Example #1
0
 /// <summary>
 /// This constructor copies the necessary fields off the attribute.
 /// </summary>
 /// <param name="attr"></param>
 /// <param name="legitValues"></param>
 public PdbCriteriaAttributeMetadata(PdbAttribute attr, List <IDictionary <string, object> > legitValues)
 {
     CanQuery      = attr.AllowFiltering;
     CanGroup      = attr.AllowGroupBy;
     Category      = attr.Category;
     CategoryOrder = attr.FilterAttrOrder;
     Desc          = attr.Description;
     Difficulty    = attr.Difficulty == null ? null : attr.Difficulty.ToString();
     UID           = attr.UID;
     Name          = attr.DisplayName;
     if (attr.MaxValue != null)
     {
         Max = attr.MaxValue == null ? null : attr.MaxValue.ToString();
     }
     if (attr.MinValue != null)
     {
         Min = attr.MinValue == null ? null : attr.MinValue.ToString();
     }
     Order          = attr.FilterOrder;
     SubCat         = attr.SubCategory;
     UiType         = attr.UiType == null ? null : attr.UiType.ToString();
     ValType        = attr.ValueType == null ? null : attr.ValueType.ToString();
     Values         = legitValues;
     QueryName      = attr.FilterName;
     CanShowInTable = attr.InPrimaryTable;
 }
Example #2
0
 /// <summary>
 /// This constructor pulls the necessary fields off the attribute object.
 /// </summary>
 /// <param name="attr"></param>
 public PdbResultAttributeMetadata(PdbAttribute attr)
 {
     Name        = attr.DisplayName;
     FilterName  = attr.FilterName;
     Description = attr.Description;
     ValType     = attr.ValueType == null ? null : attr.ValueType.ToString();
     Order       = attr.TableViewOrder;
     LongOrder   = attr.LongViewOrder;
     ShortOrder  = attr.ShortViewOrder;
     OnByDefault = attr.ShowByDefault ?? false;
     NotSortable = !attr.InPrimaryTable;  //This attribute is not sortable if it is not in the primary table
     UID         = attr.UID;
 }
Example #3
0
        private static IList <PdbAttribute> GetAttribRecords(
            DaoCriteria crit, IEnumerable <SecurityRole> userRoles, bool addExtraCols)
        {
            IList <PdbAttribute> retVal = new List <PdbAttribute>();
            // We have to post-process the roles because the required role could be anything
            // but the user role could just be "SysAdmin" so there's no easy way to have the DB
            // filter that for us.
            IList <PdbAttribute> colsForAllRoles = _attrDao.Get(crit);

            foreach (PdbAttribute col in colsForAllRoles)
            {
                // null required role is never shown to anyone.
                if (col.RequiredRole != null)
                {
                    foreach (SecurityRole role in userRoles)
                    {
                        if ((role & col.RequiredRole) != 0 || role == SecurityRole.SysAdmin)
                        {
                            // User can see this one, no need to check the other roles.
                            retVal.Add(col);
                            break;
                        }
                    }
                }
            }

            // Lat/Long/Id should not be in attribute metadata - you cannot search on it.
            if (addExtraCols)
            {
                // Lat, Long and ID need to be in every search, no matter the role.  We are using their
                // ColMapped name, not their table name
                PdbAttribute extra = new PdbAttribute();
                extra.Name = "Lat";
                retVal.Add(extra);

                extra      = new PdbAttribute();
                extra.Name = "Lon";
                retVal.Add(extra);

                extra      = new PdbAttribute();
                extra.Name = "UID";
                retVal.Add(extra);
            }
            return(retVal);
        }
Example #4
0
        /// <summary>
        /// Gets all columns (visible to the user anyway) and includes the allowed
        /// values for columns that have entries in the Attribute_Values table.
        /// </summary>
        /// <param name="entityType">Only Properties is supported.</param>
        /// <param name="userRoles">The roles the current user has.
        ///                         Only attributes they can see will be returned.</param>
        /// <returns>All the attribute metadata for the specified columns.</returns>
        public static IList <PdbCategory> GetAttributesForClient(IEnumerable <SecurityRole> userRoles)
        {
            IDictionary <string, IDictionary <string, IList <PdbAttribute> > > attrsByCatAndSub =
                new CheckedDictionary <string, IDictionary <string, IList <PdbAttribute> > >();
            IDictionary <string, IList <PdbAttribute> > attrsByCat =
                new CheckedDictionary <string, IList <PdbAttribute> >();

            DaoCriteria crit = new DaoCriteria();

            crit.Expressions.Add(new PropertyInListExpression("EntityType", PdbTwoTableHelper.EntityTypes));
            IList <PdbAttribute> attrs = GetAttribRecords(crit, userRoles);

            // Get all the attributes and split 'em up.  Put them either into the single
            // or double-nested dictionary depending on if they have subcategories.
            foreach (PdbAttribute attr in attrs)
            {
                IDictionary <string, IList <PdbAttribute> > catSubCats;
                IList <PdbAttribute> catAttrs;
                if (attrsByCatAndSub.ContainsKey(attr.Category))
                {
                    catSubCats = attrsByCatAndSub[attr.Category];
                    catAttrs   = attrsByCat[attr.Category];
                }
                else
                {
                    catSubCats = new CheckedDictionary <string, IList <PdbAttribute> >();
                    catAttrs   = new List <PdbAttribute>();
                    attrsByCatAndSub[attr.Category] = catSubCats;
                    attrsByCat[attr.Category]       = catAttrs;
                }
                // Now either it has a subcategory, in which case it's filed there, or
                // it doesn't, and it's filed under the category directly.
                if (StringHelper.IsNonBlank(attr.SubCategory))
                {
                    IList <PdbAttribute> subcatList;
                    if (catSubCats.ContainsKey(attr.SubCategory))
                    {
                        subcatList = catSubCats[attr.SubCategory];
                    }
                    else
                    {
                        subcatList = new List <PdbAttribute>();
                        catSubCats[attr.SubCategory] = subcatList;
                    }
                    subcatList.Add(attr);
                }
                else
                {
                    catAttrs.Add(attr);
                }
            }
            // Now they're all split up, create the returnable object types.
            // Remember it is impossible for any of the collections to be empty, since we created
            // them all based on records we had.
            List <PdbCategory> retVal = new List <PdbCategory>();

            foreach (KeyValuePair <string, IDictionary <string, IList <PdbAttribute> > > kvp in attrsByCatAndSub)
            {
                IDictionary <string, IList <PdbAttribute> > subCatLists = kvp.Value;
                List <PdbSubCategory> subCats = new List <PdbSubCategory>();
                PdbAttribute          anAttr  = null;
                foreach (IList <PdbAttribute> subCatList in subCatLists.Values)
                {
                    subCats.Add(new PdbSubCategory(subCatList[0].SubCategory,
                                                   subCatList[0].FilterAttrOrder, SimplifyAndGetValues(subCatList)));
                    // save one indicator for the category info.
                    if (anAttr == null)
                    {
                        anAttr = subCatList[0];
                    }
                }
                if (anAttr == null)
                {
                    // subCatList and attrsByCat can't BOTH be empty or we wouldn't have this category.
                    anAttr = attrsByCat[kvp.Key][0];
                }
                retVal.Add(new PdbCategory(anAttr.Category, anAttr.FilterCatOrder,
                                           SimplifyAndGetValues(attrsByCat[kvp.Key]), subCats));
            }
            retVal.Sort();
            return(retVal);
        }