//
        // Hide this, embarrassing
        //
        // Indemenity clause: database and tableset changes independent of filters hath wreaked havoc in places.
        private questStatus klugieGetFilterItemInfo(FilterItemJoin filterItemJoin, out DatabaseId databaseId, out TablesetId tablesetId)
        {
            // Initialize
            questStatus status = null;

            databaseId = null;
            tablesetId = null;

            FilterItemId     filterItemId     = new FilterItemId(filterItemJoin.FilterItemId);
            FilterItem       filterItem       = null;
            DbFilterItemsMgr dbFilterItemsMgr = new DbFilterItemsMgr(this.UserSession);

            status = dbFilterItemsMgr.Read(filterItemId, out filterItem);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(klugieGetFilterItemInfo(filterItem, out databaseId, out tablesetId));
        }
        public questStatus ApplyFilterToLookResults(LookupRequest lookupRequest, List <OptionValuePair> lookupOptionList, out List <OptionValuePair> filteredLookupOptionList)
        {
            // THIS IS NOW BROKEN THANKS TO IDENTIFIER-BASED REQUIREMENTS.
            // CHANGED THIS TO READ "SHALLOW" COPY OF FILTER ITEM.  HOPE IT WORKS OUT


            // Initialize
            questStatus status = null;

            filteredLookupOptionList = null;


            // Must have a valid filter Id
            if (lookupRequest.FilterItemId == null || lookupRequest.FilterItemId.Id < BaseId.VALID_ID)
            {
                return(new questStatus(Severity.Error, String.Format("Invalid LookupRequest {0} FilterItemId", lookupRequest.LookupId.Id)));
            }


            // Get the filter items
            FilterItem       filterItem       = null;
            DbFilterItemsMgr dbFilterItemsMgr = new DbFilterItemsMgr(this.UserSession);

            status = dbFilterItemsMgr.Read(lookupRequest.FilterItemId, out filterItem);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Accumulate all filter values.
            List <FilterValue> filterValueList = new List <FilterValue>();

            if (filterItem.LookupId == lookupRequest.LookupId.Id)
            {
                foreach (FilterOperation filterOperation in filterItem.OperationList)
                {
                    if (filterOperation.ValueList.Count > 0)
                    {
                        filterValueList.AddRange(filterOperation.ValueList);
                    }
                }
            }

            // If no filter values, return full list.
            if (filterValueList.Count == 0)
            {
                filteredLookupOptionList = lookupOptionList;
                return(new questStatus(Severity.Success));
            }

            // Filter lookup by filter item values.
            filteredLookupOptionList = new List <OptionValuePair>();
            foreach (FilterValue filterValue in filterValueList)
            {
                OptionValuePair optionValuePair = lookupOptionList.Find(delegate(OptionValuePair o) { return(o.Id == filterValue.Value); });
                if (optionValuePair != null)
                {
                    filteredLookupOptionList.Add(optionValuePair);
                }
            }
            return(new questStatus(Severity.Success));
        }