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);
        }
        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);
        }
        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;
        }
Ejemplo n.º 4
0
 private void ClearCacheInQueryApi(Query query)
 {
     var webclient = new WebClient();
     webclient.OpenRead(ApiConfiguration.Current.QueryApiUrl + "/Home/ClearCache?queryName=" + query.Alias);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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();
        }
 private void SaveToFile(string name, Query query)
 {
     string json = JsonConvert.SerializeObject(query, Formatting.Indented);
     File.WriteAllText(this.FilenameFromQueryName(name), json);
 }
 public Query Add(Query query)
 {
     return this.Update(query);
 }
        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;
        }
        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;
        }
 public Query Save(Query query)
 {
     return this.Update(query);
 }
        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;
        }
        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;
        }