示例#1
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);
        }
示例#2
0
        private void FetchAsync(SlicedEntityMetadata entityMetadata, EntityAssociation collectionAssociation, IDictionary <string, ApplicationCompositionSchema> compositionSchemas, IEnumerable <AttributeHolder> entitiesList,
                                ContextHolder ctx, Dictionary <string, EntityRepository.SearchEntityResult> results, PaginatedSearchRequestDto paginatedSearch)
        {
            Quartz.Util.LogicalThreadContext.SetData("context", ctx);
            var lookupAttributes             = collectionAssociation.Attributes;
            var collectionEntityMetadata     = MetadataProvider.Entity(collectionAssociation.To);
            var targetCollectionAttribute    = EntityUtil.GetRelationshipName(collectionAssociation.Qualifier);
            var applicationCompositionSchema = compositionSchemas[collectionAssociation.Qualifier] as ApplicationCompositionCollectionSchema;

            if (applicationCompositionSchema == null)
            {
                throw ExceptionUtil.InvalidOperation("collection schema {0} not found", collectionAssociation.Qualifier);
            }


            var lookupattributes      = lookupAttributes as EntityAssociationAttribute[] ?? lookupAttributes.ToArray();
            var attributeHolders      = entitiesList as AttributeHolder[] ?? entitiesList.ToArray();
            var matchingResultWrapper = new CollectionMatchingResultWrapper();

            var searchRequestDto = BuildSearchRequestDto(applicationCompositionSchema, lookupattributes, matchingResultWrapper, attributeHolders, collectionEntityMetadata, paginatedSearch);

            searchRequestDto.QueryAlias = collectionAssociation.To;

            var firstAttributeHolder = attributeHolders.First();

            if (applicationCompositionSchema.PrefilterFunction != null)
            {
                var dataSet = DataSetProvider.GetInstance().LookupDataSet(entityMetadata.ApplicationName);
                //we will call the function passing the first entry, altough this method could have been invoked for a list of items (printing)
                //TODO: think about it
                var preFilterParam = new CompositionPreFilterFunctionParameters(entityMetadata.AppSchema, searchRequestDto, firstAttributeHolder, applicationCompositionSchema);
                searchRequestDto = PrefilterInvoker.ApplyPreFilterFunction(dataSet, preFilterParam, applicationCompositionSchema.PrefilterFunction);
            }



            EntityRepository.SearchEntityResult queryResult = null;

            if (paginatedSearch == null)
            {
                //if there´s no pagination needed we can just do one thread-query
                queryResult = EntityRepository.GetAsRawDictionary(collectionEntityMetadata, searchRequestDto);
            }
            else
            {
                var tasks = new Task[2];
                tasks[0] = Task.Factory.NewThread(() => {
                    queryResult = EntityRepository.GetAsRawDictionary(collectionEntityMetadata, searchRequestDto);
                });
                // one thread to count results for paginations
                tasks[1] = Task.Factory.NewThread(() => {
                    paginatedSearch.TotalCount = EntityRepository.Count(collectionEntityMetadata, searchRequestDto);
                });
                Task.WaitAll(tasks);
                // add paginationData to result

                // creating a new pagination data in order to have everything calculated correctly
                queryResult.PaginationData = new PaginatedSearchRequestDto(
                    paginatedSearch.TotalCount,
                    paginatedSearch.PageNumber,
                    paginatedSearch.PageSize,
                    paginatedSearch.SearchValues,
                    paginatedSearch.PaginationOptions
                    );
            }
            // one thread to fetch results

            results.Add(collectionAssociation.Qualifier, queryResult);

            if (attributeHolders.Length == 1)
            {
                //default scenario, we have just one entity here
                firstAttributeHolder.Attributes.Add(targetCollectionAttribute, queryResult.ResultList);
                return;
            }
            MatchResults(queryResult, matchingResultWrapper, targetCollectionAttribute);
        }