Exemplo n.º 1
0
        public IActionResult GetAll()
        {
            var result = _queryCoordinator.Execute(new AllDataCollectors(_database), new PagingInfo());

            if (result.Success)
            {
                return(Ok(result.Items));
            }

            return(new NotFoundResult());
        }
Exemplo n.º 2
0
        private IActionResult GetAllStaffUsers <T>()
            where T : Read.StaffUsers.Models.BaseUser
        {
            var result = _queryCoordinator.Execute(new AllStaffUsers <T>(_database), new PagingInfo());

            if (result.Success)
            {
                return(Ok(result.Items));
            }

            return(new NotFoundResult());
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="queryRequest"></param>
        /// <returns></returns>
        public async Task <QueryResult> Execute(QueryRequest queryRequest)
        {
            QueryResult result = null;

            try
            {
                _executionContextManager.CurrentFor(TenantId.Development, Dolittle.Execution.CorrelationId.New(), ClaimsPrincipal.Current.ToClaims());

                var queryType = _typeFinder.GetQueryTypeByName(queryRequest.GeneratedFrom);
                var query     = _container.Get(queryType) as IQuery;

                PopulateProperties(queryRequest, queryType, query);

                _logger.Trace($"Executing runtime query coordinator");
                result = await _queryCoordinator.Execute(query, new PagingInfo());

                if (result.Success)
                {
                    AddClientTypeInformation(result);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Error executing query : '{queryRequest.NameOfQuery}'");
                result = new QueryResult
                {
                    Exception = ex,
                    QueryName = queryRequest.NameOfQuery
                };
            }

            return(result);
        }
Exemplo n.º 4
0
        public QueryResult Execute(QueryDescriptor descriptor, PagingInfo paging)
        {
            try
            {
                _logger.Information($"Executing query : {descriptor.NameOfQuery}");
                var queryType = _typeDiscoverer.GetQueryTypeByName(descriptor.GeneratedFrom);
                var query     = _container.Get(queryType) as IQuery;

                PopulateProperties(descriptor, queryType, query);

                var result = _queryCoordinator.Execute(query, paging);
                if (result.Success)
                {
                    AddClientTypeInformation(result);
                }
                return(result);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Error executing query : '{descriptor.NameOfQuery}'");
                return(new QueryResult {
                    Exception = ex
                });
            }
        }
Exemplo n.º 5
0
        public ActionResult Handle([FromBody] QueryRequest queryRequest)
        {
            _executionContextConfigurator.ConfigureFor(_tenantResolver.Resolve(HttpContext.Request), Dolittle.Execution.CorrelationId.New(), ClaimsPrincipal.Current.ToClaims());
            QueryResult queryResult = null;

            try
            {
                _logger.Information($"Executing query : {queryRequest.NameOfQuery}");
                var queryType = _typeFinder.GetQueryTypeByName(queryRequest.GeneratedFrom);
                var query     = _container.Get(queryType) as IQuery;

                PopulateProperties(queryRequest, queryType, query);

                queryResult = _queryCoordinator.Execute(query, new PagingInfo());
                if (queryResult.Success)
                {
                    AddClientTypeInformation(queryResult);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Error executing query : '{queryRequest.NameOfQuery}'");
                queryResult = new QueryResult {
                    Exception = ex
                };
            }

            var content = new ContentResult();

            content.Content     = _serializer.ToJson(queryResult, SerializationOptions.CamelCase);
            content.ContentType = "application/json";
            return(content);
        }
Exemplo n.º 6
0
        public IActionResult Execute([FromBody] ExecuteQueryRequest request)
        {
            var type    = _artifactTypeMap.GetTypeFor(request.Artifact);
            var command = _objectFactory.Build(type, request.Query) as IQuery;
            var result  = _coordinator.Execute(request.Tenant, command);

            return(Ok(result));
        }
        /// <inheritdoc/>
        public async Task HandlePostRequest(HttpContext context, IQuery artifact)
        {
            var paging      = new PagingInfo();
            var queryResult = await _queryCoordinator.Execute(artifact, paging).ConfigureAwait(false);

            if (queryResult.Success)
            {
                await context.RespondWithOk($"Query {artifact.GetType()} executed successfully. \nQueryResult: {queryResult}").ConfigureAwait(false);
            }
            else
            {
                await context.RespondWithError($"Query {artifact.GetType()} wasn't executed succesfully. \nQueryResult: {queryResult.Exception}").ConfigureAwait(false);
            }
        }
        public IActionResult Handle([FromRoute] string path)
        {
            if (TryResolveTenantAndArtifact(path, HttpContext.Request.Query.ToDictionary(), out var tenantId, out var query))
            {
                var result = _queryCoordinator.Execute(tenantId, query);
                return(new ContentResult
                {
                    ContentType = "application/json",
                    Content = _serializer.ToJson(result),
                });
            }

            return(new BadRequestResult());
        }
Exemplo n.º 9
0
        public QueryResult Execute(QueryDescriptor descriptor, PagingInfo paging)
        {
            var queryType = _typeDiscoverer.GetQueryTypeByName(descriptor.GeneratedFrom);
            var query     = _container.Get(queryType) as IQuery;

            PopulateProperties(descriptor, queryType, query);

            var result = _queryCoordinator.Execute(query, paging);

            if (result.Success)
            {
                AddClientTypeInformation(result);
            }
            return(result);
        }
        /// <summary>
        /// Handles a <see cref="QueryRequest" /> from the <see cref="HttpRequest.Body" /> and writes the <see cref="QueryResult" /> to the <see cref="HttpResponse" />.
        /// </summary>
        /// <param name="context">The <see cref="HttpContext" />.</param>
        /// <returns>A task representing the asynchronous operation.</returns>
        public async Task Handle(HttpContext context)
        {
            QueryRequest queryRequest = null;

            try
            {
                queryRequest = await context.RequestBodyFromJson <QueryRequest>().ConfigureAwait(false);

                _logger.Information("Executing query : {Query}", queryRequest.NameOfQuery);
                var queryType  = _typeFinder.GetQueryTypeByName(queryRequest.GeneratedFrom);
                var query      = _container.Get(queryType) as IQuery;
                var properties = queryType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty).ToDictionary(p => p.Name.ToLowerInvariant(), p => p);
                CopyPropertiesFromRequestToQuery(queryRequest, query, properties);

                var result = await _queryCoordinator.Execute(query, new PagingInfo()).ConfigureAwait(false);

                if (result.Success)
                {
                    AddClientTypeInformation(result);
                }

                await context.RespondWithStatusCodeAndResult(StatusCodes.Status200OK, result, SerializationOptions.CamelCase).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                var queryName = queryRequest?.NameOfQuery ?? "Could not resolve query name";
                _logger.Error(ex, "Could not handle query request for the '{QueryName}' query", queryName);
                await context.RespondWithStatusCodeAndResult(
                    StatusCodes.Status200OK,
                    new QueryResult
                {
                    Exception = ex,
                    QueryName = queryName
                }).ConfigureAwait(false);
            }
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Handle([FromBody] QueryRequest queryRequest)
        {
            var         content     = new ContentResult();
            QueryResult queryResult = null;

            try
            {
                _executionContextConfigurator.ConfigureFor(_tenantResolver.Resolve(HttpContext.Request), Dolittle.Execution.CorrelationId.New(), ClaimsPrincipal.Current.ToClaims());
                _logger.Information($"Executing query : {queryRequest.NameOfQuery}");
                var queryType = _typeFinder.GetQueryTypeByName(queryRequest.GeneratedFrom);
                var query     = _container.Get(queryType) as IQuery;

                var properties = queryType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty).ToDictionary(p => p.Name.ToLowerInvariant(), p => p);
                CopyPropertiesFromRequestToQuery(queryRequest, query, properties);

                queryResult = await _queryCoordinator.Execute(query, new PagingInfo());

                if (queryResult.Success)
                {
                    AddClientTypeInformation(queryResult);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Error executing query : '{queryRequest.NameOfQuery}'");
                queryResult = new QueryResult
                {
                    Exception = ex,
                    QueryName = queryRequest.NameOfQuery
                };
            }

            content.Content     = _serializer.ToJson(queryResult, SerializationOptions.CamelCase);
            content.ContentType = "application/json";
            return(content);
        }
Exemplo n.º 12
0
        public IActionResult GetAllUsers()
        {
            var res = _queryCoordinator.Execute(
                new AllStaffUsers(_adminRepository, _dataConsumerRepository, _dataCoordinatorRepository,
                                  _dataOwnerRepository, _dataVerifierRepository, _systemConfiguratorRepository), new PagingInfo());

            if (res.Success)
            {
                return(Ok(res.Items));
            }
            return(StatusCode(500));
        }
Exemplo n.º 13
0
        public IActionResult GetAll()
        {
            var result = _queryCoordinator.Execute(new AllDataCollectors(_database), new PagingInfo());

            return(Ok(result.Items));
        }