Exemplo n.º 1
0
        public void ShouldConvertQueryFromText()
        {
            const string query = "query";

            const int projectId = 4;

            var queryModel = new DslDataQuery();

            _queryTranslator.Setup(_ => _.ToQuery(query)).Returns(queryModel);

            _queryModelAccessValidator.Setup(_ => _.Validate(queryModel, projectId, false));

            var result = _target.FromText(query, projectId, false);

            result.ShouldBeEquivalentTo(queryModel);
        }
Exemplo n.º 2
0
        public void Update(
            long queryId,
            string textQuery,
            string name,
            string comment,
            QueryPrivacyType privacyType,
            QueryVisibilityType visibilityType)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            using (var telemetryScope = _telemetryScopeProvider.Create <Queries>(TelemetryOperationNames.Query.Update))
            {
                try
                {
                    var query = _queryRepository.GetById(queryId);

                    if (query == null)
                    {
                        throw new QueryDoesNotExistsException(queryId);
                    }

                    telemetryScope.SetEntity(query);

                    var canEditQuery = _queryAccessValidator.IsCanEdit(query, _userPrincipal.Info.Id);

                    if (!canEditQuery)
                    {
                        throw new UnauthorizedAccessException();
                    }

                    if (!string.IsNullOrEmpty(textQuery))
                    {
                        var queryModel = _queryModelProcessor.FromText(textQuery, query.ProjectId, query.IsSystem);

                        _queryModelValidator.Validate(queryModel);

                        query.JsonQuery = queryModel.ToJson();
                    }
                    else
                    {
                        query.JsonQuery = null;
                    }

                    query.Comment     = comment;
                    query.ModifiedUtc = _timeService.GetUtc();
                    query.Name        = name;
                    query.Privacy     = (int)privacyType;
                    query.Query       = textQuery;
                    query.Visibility  = (int)visibilityType;

                    _queryRepository.Save();

                    telemetryScope.WriteSuccess();
                }
                catch (Exception ex)
                {
                    telemetryScope.WriteException(ex);

                    throw;
                }
            }
        }