예제 #1
0
        private static void BuildParentQueryConstraint(CollectionMatchingResultWrapper matchingResultWrapper,
                                                       AttributeHolder[] attributeHolders, EntityAssociationAttribute lookupAttribute,
                                                       SearchRequestDto searchRequestDto)
        {
            var searchValues  = new List <string>();
            var enumerable    = attributeHolders as AttributeHolder[] ?? attributeHolders.ToArray();
            var hasMainEntity = enumerable.Any();

            foreach (var entity in attributeHolders)
            {
                var key         = matchingResultWrapper.FetchKey(entity);
                var searchValue = SearchUtils.GetSearchValue(lookupAttribute, entity);
                if (!String.IsNullOrWhiteSpace(searchValue) && lookupAttribute.To != null)
                {
                    searchValues.Add(searchValue);
                    key.AppendEntry(lookupAttribute.To, searchValue);
                }
            }
            if (searchValues.Any())
            {
                searchRequestDto.AppendSearchEntry(lookupAttribute.To, searchValues);
            }
            else if (hasMainEntity && lookupAttribute.Primary)
            {
                //if nothing was provided, it should return nothing, instead of all the values -->
                //if the main entity had a null on a primary element of the composition, nothing should be seen
                searchRequestDto.AppendSearchEntry(lookupAttribute.To, new[] { "-1231231312" });
            }
        }
예제 #2
0
        public IEnumerable <IAssociationOption> ResolveOptions(ApplicationMetadata applicationMetadata,
                                                               AttributeHolder originalEntity, ApplicationAssociationDefinition association, SearchRequestDto associationFilter)
        {
            if (!FullSatisfied(association, originalEntity))
            {
                return(null);
            }

            // Set dependante lookup atributes
            var lookupAttributes = association.LookupAttributes();

            foreach (var lookupAttribute in lookupAttributes)
            {
                var searchValue = SearchUtils.GetSearchValue(lookupAttribute, originalEntity);
                if (!String.IsNullOrEmpty(searchValue))
                {
                    associationFilter.AppendSearchParam(lookupAttribute.To);
                    associationFilter.AppendSearchValue(searchValue);
                }
                else if (lookupAttribute.Query != null)
                {
                    associationFilter.AppendWhereClause(lookupAttribute.GetQueryReplacingMarkers(association.EntityAssociation.To));
                }
            }

            // Set projections and pre filter functions
            var numberOfLabels        = BuildProjections(associationFilter, association);
            var prefilterFunctionName = association.Schema.DataProvider.PreFilterFunctionName;

            if (prefilterFunctionName != null)
            {
                var preFilterParam = new AssociationPreFilterFunctionParameters(applicationMetadata, associationFilter, association, originalEntity);
                associationFilter = PrefilterInvoker.ApplyPreFilterFunction(DataSetProvider.GetInstance().LookupDataSet(applicationMetadata.Name), preFilterParam, prefilterFunctionName);
            }

            var entityMetadata = MetadataProvider.Entity(association.EntityAssociation.To);

            associationFilter.QueryAlias = association.AssociationKey;
            var queryResponse = EntityRepository.Get(entityMetadata, associationFilter);

            if (associationFilter is PaginatedSearchRequestDto)
            {
                var paginatedFilter = (PaginatedSearchRequestDto)associationFilter;
                if (paginatedFilter.NeedsCountUpdate)
                {
                    paginatedFilter.TotalCount = EntityRepository.Count(entityMetadata, associationFilter);
                }
            }

            var    options            = BuildOptions(queryResponse, association, numberOfLabels);
            string filterFunctionName = association.Schema.DataProvider.PostFilterFunctionName;

            return(filterFunctionName != null?ApplyFilters(applicationMetadata.Name, originalEntity, filterFunctionName, options, association) : options);
        }