public void Build <T>(QueryBuilderContext <T> ctx) where T : class, new() { var softDeletesQuery = ctx.GetSourceAs <ISoftDeletesQuery>(); if (softDeletesQuery == null || softDeletesQuery.IncludeSoftDeletes) { return; } var idsQuery = ctx.GetSourceAs <IIdentityQuery>(); var opt = ctx.GetOptionsAs <IElasticQueryOptions>(); if (opt == null || !opt.SupportsSoftDeletes || (idsQuery != null && idsQuery.Ids.Count > 0)) { return; } var missingFilter = new MissingFilter { Field = Deleted }; var termFilter = new TermFilter { Field = Deleted, Value = softDeletesQuery.IncludeSoftDeletes }; ctx.Filter &= (new FilterContainer(missingFilter) || new FilterContainer(termFilter)); }
public void Build <T>(QueryBuilderContext <T> ctx) where T : class, new() { var organizationIdQuery = ctx.GetSourceAs <IOrganizationIdQuery>(); if (organizationIdQuery?.OrganizationIds == null || organizationIdQuery.OrganizationIds.Count <= 0) { return; } ctx.Filter &= new TermsFilter { Terms = organizationIdQuery.OrganizationIds, Field = "organization" }; }
public void Build <T>(QueryBuilderContext <T> ctx) where T : class, new() { var sfq = ctx.GetSourceAs <IExceptionlessSystemFilterQuery>(); if (sfq == null) { return; } var allowedOrganizations = sfq.Organizations.Where(o => o.HasPremiumFeatures || (!o.HasPremiumFeatures && !sfq.UsesPremiumFeatures)).ToList(); if (allowedOrganizations.Count == 0) { ctx.Filter &= Filter <T> .Term("organization", "none"); return; } string field = GetDateField(ctx.GetOptionsAs <IElasticQueryOptions>()); if (sfq.Stack != null) { var organization = sfq.Organizations.Single(o => o.Id == sfq.Stack.OrganizationId); ctx.Filter &= (Filter <T> .Term("stack", sfq.Stack.Id) && GetRetentionFilter <T>(field, organization.RetentionDays)); return; } FilterContainer container = null; if (sfq.Projects?.Count > 0) { foreach (var project in sfq.Projects) { var organization = sfq.Organizations.Single(o => o.Id == project.OrganizationId); container |= (Filter <T> .Term("project", project.Id) && GetRetentionFilter <T>(field, organization.RetentionDays)); } ctx.Filter &= container; return; } if (sfq.Organizations?.Count > 0) { foreach (var organization in sfq.Organizations) { container |= (Filter <T> .Term("organization", organization.Id) && GetRetentionFilter <T>(field, organization.RetentionDays)); } ctx.Filter &= container; } }
public void Build <T>(QueryBuilderContext <T> ctx) where T : class, new() { var projectIdQuery = ctx.GetSourceAs <IProjectIdQuery>(); if (projectIdQuery?.ProjectIds == null || projectIdQuery.ProjectIds.Count <= 0) { return; } if (projectIdQuery.ProjectIds.Count == 1) { ctx.Filter &= Filter <T> .Term("project", projectIdQuery.ProjectIds.First()); } else { ctx.Filter &= Filter <T> .Terms("project", projectIdQuery.ProjectIds.ToArray()); } }
public void Build <T>(QueryBuilderContext <T> ctx) where T : class, new() { var stackIdQuery = ctx.GetSourceAs <IStackIdQuery>(); if (stackIdQuery?.StackIds == null || stackIdQuery.StackIds.Count <= 0) { return; } if (stackIdQuery.StackIds.Count == 1) { ctx.Filter &= Filter <T> .Term("stack", stackIdQuery.StackIds.First()); } else { ctx.Filter &= Filter <T> .Terms("stack", stackIdQuery.StackIds.ToArray()); } }
public void Build <T>(QueryBuilderContext <T> ctx) where T : class, new() { var organizationIdQuery = ctx.GetSourceAs <IOrganizationIdQuery>(); if (organizationIdQuery?.OrganizationIds == null || organizationIdQuery.OrganizationIds.Count <= 0) { return; } if (organizationIdQuery.OrganizationIds.Count == 1) { ctx.Filter &= Filter <T> .Term("organization", organizationIdQuery.OrganizationIds.First()); } else { ctx.Filter &= Filter <T> .Terms("organization", organizationIdQuery.OrganizationIds.ToArray()); } }
public Task BuildAsync <T>(QueryBuilderContext <T> ctx) where T : class, new() { var stackIdQuery = ctx.GetSourceAs <IStackIdQuery>(); if (stackIdQuery?.StackIds == null || stackIdQuery.StackIds.Count <= 0) { return(Task.CompletedTask); } if (stackIdQuery.StackIds.Count == 1) { ctx.Query &= Query <T> .Term(_stackIdFieldName, stackIdQuery.StackIds.First()); } else { ctx.Query &= Query <T> .Terms(t => t.Field(_stackIdFieldName).Terms(stackIdQuery.StackIds)); } return(Task.CompletedTask); }
public Task BuildAsync <T>(QueryBuilderContext <T> ctx) where T : class, new() { var companyQuery = ctx.GetSourceAs <ICompanyQuery>(); if (companyQuery?.Companies == null || companyQuery.Companies.Count <= 0) { return(Task.CompletedTask); } if (companyQuery.Companies.Count == 1) { ctx.Filter &= Filter <T> .Term(EmployeeType.Fields.CompanyId, companyQuery.Companies.First()); } else { ctx.Filter &= Filter <T> .Terms(EmployeeType.Fields.CompanyId, companyQuery.Companies.Select(a => a.ToString())); } return(Task.CompletedTask); }
public Task BuildAsync <T>(QueryBuilderContext <T> ctx) where T : class, new() { if (ctx.Type != ContextType.SystemFilter) { return(Task.CompletedTask); } var sfq = ctx.GetSourceAs <IExceptionlessSystemFilterQuery>() ?? ctx.GetSourceAs <ISystemFilterQuery>()?.SystemFilter as IExceptionlessSystemFilterQuery; if (sfq == null) { return(Task.CompletedTask); } var allowedOrganizations = sfq.Organizations.Where(o => o.HasPremiumFeatures || (!o.HasPremiumFeatures && !sfq.UsesPremiumFeatures)).ToList(); if (allowedOrganizations.Count == 0) { ctx.Filter &= Query <T> .Term(_organizationIdFieldName, "none"); return(Task.CompletedTask); } string field = GetDateField(ctx.GetOptionsAs <IElasticQueryOptions>()); if (sfq.Stack != null) { var organization = allowedOrganizations.SingleOrDefault(o => o.Id == sfq.Stack.OrganizationId); if (organization != null) { ctx.Filter &= (Query <T> .Term(_stackIdFieldName, sfq.Stack.Id) && GetRetentionFilter <T>(field, organization, sfq.Stack.FirstOccurrence)); } else { ctx.Filter &= Query <T> .Term(_stackIdFieldName, "none"); } return(Task.CompletedTask); } QueryContainer container = null; if (sfq.Projects?.Count > 0) { var allowedProjects = sfq.Projects.ToDictionary(p => p, p => allowedOrganizations.SingleOrDefault(o => o.Id == p.OrganizationId)).Where(kvp => kvp.Value != null).ToList(); if (allowedProjects.Count > 0) { foreach (var project in allowedProjects) { container |= (Query <T> .Term(_projectIdFieldName, project.Key.Id) && GetRetentionFilter <T>(field, project.Value, project.Key.CreatedUtc.SafeSubtract(TimeSpan.FromDays(3)))); } ctx.Filter &= container; return(Task.CompletedTask); } ctx.Filter &= (Query <T> .Term(_projectIdFieldName, "none")); return(Task.CompletedTask); } foreach (var organization in allowedOrganizations) { container |= (Query <T> .Term(_organizationIdFieldName, organization.Id) && GetRetentionFilter <T>(field, organization)); } ctx.Filter &= container; return(Task.CompletedTask); }