Пример #1
0
        public async Task <IActionResult> GetFilters(string app, string schema)
        {
            var components = await appProvider.GetComponentsAsync(Schema, HttpContext.RequestAborted);

            var filters = ContentQueryModel.Build(Schema.SchemaDef, App.PartitionResolver(), components).Flatten();

            return(Ok(filters));
        }
Пример #2
0
        private async Task <ClrQuery> ParseClrQueryAsync(Context context, Q q, ISchemaEntity?schema)
        {
            var components = ResolvedComponents.Empty;

            if (schema != null)
            {
                components = await appprovider.GetComponentsAsync(schema);
            }

            var query = q.Query;

            if (!string.IsNullOrWhiteSpace(q.QueryAsJson))
            {
                query = ParseJson(context, schema, q.QueryAsJson, components);
            }
            else if (q?.JsonQuery != null)
            {
                query = ParseJson(context, schema, q.JsonQuery, components);
            }
            else if (!string.IsNullOrWhiteSpace(q?.QueryAsOdata))
            {
                query = ParseOData(context, schema, q.QueryAsOdata, components);
            }

            return(query);
        }
Пример #3
0
        public async Task Should_do_nothing_if_no_component_found()
        {
            var schema = Mocks.Schema(appId, schemaId);

            var components = await appProvider.GetComponentsAsync(schema);

            Assert.Empty(components);

            A.CallTo(() => appProvider.GetSchemaAsync(A <DomainId> ._, A <DomainId> ._, false, A <CancellationToken> ._))
            .MustNotHaveHappened();
        }
Пример #4
0
        public async Task <OpenApiDocument> GenerateAsync(HttpContext httpContext, IAppEntity app, IEnumerable <ISchemaEntity> schemas, bool flat)
        {
            var document = CreateApiDocument(httpContext, app);

            var schemaResolver = new OpenApiSchemaResolver(document, schemaSettings);

            requestCache.AddDependency(app.UniqueId, app.Version);

            foreach (var schema in schemas)
            {
                requestCache.AddDependency(schema.UniqueId, schema.Version);
            }

            var builder = new Builder(app, document, schemaResolver, schemaGenerator);

            var validSchemas =
                schemas.Where(x =>
                              x.SchemaDef.IsPublished &&
                              x.SchemaDef.Type != SchemaDefType.Component &&
                              x.SchemaDef.Fields.Count > 0);

            var partitionResolver = app.PartitionResolver();

            foreach (var schema in validSchemas)
            {
                var components = await appProvider.GetComponentsAsync(schema, httpContext.RequestAborted);

                GenerateSchemaOperations(builder.Schema(schema.SchemaDef, partitionResolver, components, flat));
            }

            GenerateSharedOperations(builder.Shared());

            var context =
                new DocumentProcessorContext(document,
                                             Enumerable.Empty <Type>(),
                                             Enumerable.Empty <Type>(),
                                             schemaResolver,
                                             schemaGenerator,
                                             schemaSettings);

            foreach (var processor in schemaSettings.DocumentProcessors)
            {
                processor.Process(context);
            }

            return(document);
        }
Пример #5
0
        private async Task <IReadOnlyList <IEnrichedContentEntity> > EnrichInternalAsync(IEnumerable <IContentEntity> contents, bool cloneData, Context context,
                                                                                         CancellationToken ct)
        {
            using (Telemetry.Activities.StartActivity("ContentEnricher/EnrichInternalAsync"))
            {
                var results = new List <ContentEntity>();

                if (context.App != null)
                {
                    foreach (var step in steps)
                    {
                        await step.EnrichAsync(context, ct);
                    }
                }

                if (contents.Any())
                {
                    foreach (var content in contents)
                    {
                        var result = SimpleMapper.Map(content, new ContentEntity());

                        if (cloneData)
                        {
                            result.Data = result.Data.Clone();
                        }

                        results.Add(result);
                    }

                    if (context.App != null)
                    {
                        var schemaCache = new Dictionary <DomainId, Task <(ISchemaEntity, ResolvedComponents)> >();

                        Task <(ISchemaEntity, ResolvedComponents)> GetSchema(DomainId id)
                        {
                            return(schemaCache.GetOrAdd(id, async x =>
                            {
                                var schema = await appProvider.GetSchemaAsync(context.App.Id, x, false, ct);

                                if (schema == null)
                                {
                                    throw new DomainObjectNotFoundException(x.ToString());
                                }

                                var components = await appProvider.GetComponentsAsync(schema, ct);

                                return (schema, components);
                            }));
                        }

                        foreach (var step in steps)
                        {
                            ct.ThrowIfCancellationRequested();

                            using (Telemetry.Activities.StartActivity(step.ToString() !))
                            {
                                await step.EnrichAsync(context, results, GetSchema, ct);
                            }
                        }
                    }
                }

                return(results);
            }
        }