コード例 #1
0
        public void Delete(Query query)
        {
            string filename = this.FilenameFromQueryName(query.Id);

            if (this._queries.Any(q => q.Id == query.Id))
            {
                this._queries.Remove(query);
            }

            File.Delete(filename);
        }
コード例 #2
0
        public override void Delete(Query query)
        {
            var eventStore = new EventStore()
              {
            Date = DateTime.UtcNow,
            EventName = Events.DeleteAccount,
            Payload = query
              };

              this.eventStoreRepository.Add(eventStore);
              this.QueryRepository.Delete(query);
        }
コード例 #3
0
        public override Query Save(Query query)
        {
            var isNewQuery = query.Id == null;

              var queryResult = this.QueryRepository.Save(query);

              var eventStore = new EventStore()
              {
            Date = DateTime.UtcNow,
            EventName = isNewQuery ? Events.CreateAccount : Events.UpdateAccount,
            Payload = queryResult
              };

              if (isNewQuery)
              {
            this.eventStoreRepository.Add(eventStore);
              }
              else
              {
            this.eventStoreRepository.Add(eventStore);
              }

              return queryResult;
        }
コード例 #4
0
 private void ClearCacheInQueryApi(Query query)
 {
     var webclient = new WebClient();
     webclient.OpenRead(ApiConfiguration.Current.QueryApiUrl + "/Home/ClearCache?queryName=" + query.Alias);
 }
コード例 #5
0
 private bool CanEdit(Query query)
 {
     var account = OperatingAccount.Current(this._accountRepository);
       if (
     (query.Authorization.Any(a => a.AccountId == account.Id && a.Operation == AuthorizationOperations.Edit)
       || account.IsAdministrator)) {
     return true;
       }
       return false;
 }
コード例 #6
0
        public dynamic Post(ExtendedQueryModel model)
        {
            if (string.IsNullOrEmpty(model.Alias))
            {
                return BadRequest("Query moet een naam hebben.");
            }

              var account = OperatingAccount.Current(_accountRepository);
              if (!account.IsEditor) {
            return this.Unauthorized();
              }

              if (this._queryRepository.GetByAlias(model.Alias) != null) {
            return BadRequest("Query met dezelfde naam bestaat reeds.");
              }

              var query = new Query();
            model.MapTo(query);

              query.Authorization = new List<AuthorizationSettings> {
            new AuthorizationSettings { AccountId = account.Id, Operation = AuthorizationOperations.Edit }
              };

              this._queryRepository.Save(query);

            this.ClearCacheInQueryApi(query);

            return Ok();
        }
コード例 #7
0
 private void SaveToFile(string name, Query query)
 {
     string json = JsonConvert.SerializeObject(query, Formatting.Indented);
     File.WriteAllText(this.FilenameFromQueryName(name), json);
 }
コード例 #8
0
 public Query Add(Query query)
 {
     return this.Update(query);
 }
コード例 #9
0
        private Query LoadFromFile(string filename)
        {
            string json = File.ReadAllText(filename);

            var item = JsonConvert.DeserializeObject<dynamic>(json);
            var query =
                new Query()
                {
                    Id = item.Id,
                    Alias = item.Id,
                    AllowAnonymous = item.AllowAnonymous,
                    Description = item.Description,
                    Endpoint = item.Endpoint,
                    Group = item.Group,
                    Label = item.Label,
                    SparqlQuery = item.SparqlQuery,
                };

            query.ApiKeys = (item.ApiKeys != null) ? item.ApiKeys.ToObject<List<string>>() : new List<string>();
            query.Notes = (item.Notes != null) ? item.Notes.ToObject<List<Note>>() : new List<Note>();
            query.Parameters = (item.Parameters != null) ? item.Parameters.ToObject<List<QueryParameter>>() : new List<QueryParameter>(); ;

            return query;
        }
コード例 #10
0
        public Query Update(Query query)
        {
            //query.Id = query.ApiKey.AsObjectId().ToString();
              dynamic item =
            new {
              query.Id,
              query.AllowAnonymous,
              query.ApiKeys,
              query.Description,
              query.Endpoint,
              query.Group,
              query.Label,
              query.Notes,
              query.Parameters,
              query.SparqlQuery,
            };

              this.SaveToFile(query.Id, item);
              return query;
        }
コード例 #11
0
 public Query Save(Query query)
 {
     return this.Update(query);
 }
コード例 #12
0
        public void MapFrom(Query query, IEnumerable<Core.Accounts.Account> accounts, IEnumerable<string> groups)
        {
            if (query.Parameters == null)
            {
                query.Parameters = new List<QueryParameter>();
            }

            Id = query.Id;
            Alias = query.Alias;
            Label = (string.IsNullOrEmpty(query.Label)) ? query.Alias : query.Label;
            Description = query.Description;
              Notes = Mapper.Map<IEnumerable<NoteModel>>(query.Notes);
            Group = query.Group;
            Groups = groups;
            SparqlQuery = query.SparqlQuery;
            Link = "/" + query.Alias + "?api_key=$$apikey" + query.Parameters.Aggregate("", (current, queryParameter) => current + ("&" + queryParameter.Name + "=" + (queryParameter.SampleValue ?? "")));
            Parameters =
                query.Parameters.Select(
                    p => new QueryParameterModel()
                        {
                            Name = p.Name,
                            Description = p.Description,
                            SampleValue = p.SampleValue,
                            ValuesQuery = p.ValuesQuery
                        });
            Access =
                accounts.Select(
                    a => new AccessModel
                        {
              Account = Mapper.Map<AccountModel>(a),
                            Name = a.FullName,
                            CanReadSelected = (query.ApiKeys != null && query.ApiKeys.Contains(a.ApiKey)),
              CanEditSelected = (query.Authorization != null && query.Authorization.Any(aus => aus.AccountId == a.Id && aus.Operation == AuthorizationOperations.Edit))
                        });
            Endpoints = ApiConfiguration.Current.SparqlEndpoints
                .Select(e => e.Name);
            Endpoint = query.Endpoint;
            AllowAnonymous = query.AllowAnonymous;
        }
コード例 #13
0
        public void MapTo(Query query)
        {
            query.Id = Id;
            query.Alias = Alias;
            query.Label = Label;
            query.Description = Description;
              query.Notes = Mapper.Map<IList<Note>>(Notes);
              query.Group = Group;
            query.SparqlQuery = SparqlQuery;
            query.Parameters = (Parameters != null)
                                      ? Parameters.Select(p => new QueryParameter()
                                          {
                                              Name = p.Name,
                                              Description = p.Description,
                                              SampleValue = p.SampleValue,
                                                                ValuesQuery = p.ValuesQuery
                                          }).ToList()
                                      : new List<QueryParameter>();
            query.ApiKeys = Access.Where(a => a.CanReadSelected).Select(a => a.Account.ApiKey).ToList();

              query.Authorization = Access.Where(a => a.CanEditSelected).Select(a => new AuthorizationSettings() {
            AccountId = a.Account.Id,
            Operation = a.Account.IsEditor ? AuthorizationOperations.Edit : AuthorizationOperations.Read
              }).ToList();

            query.Endpoint = Endpoint;
            query.AllowAnonymous = AllowAnonymous;
        }