Skip to content

Commit

Permalink
Feature/ Events Search (#3809)
Browse files Browse the repository at this point in the history
Co-authored-by: David Deal <ddeal@linuxfoundation.org>
  • Loading branch information
nickmango and dealako authored Feb 24, 2023
1 parent 64c80ed commit 70445af
Showing 6 changed files with 46 additions and 45 deletions.
12 changes: 6 additions & 6 deletions cla-backend-go/events/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cla-backend-go/events/mockrepo.go
Original file line number Diff line number Diff line change
@@ -24,11 +24,11 @@ func (repo *mockRepository) AddDataToEvent(eventID, foundationSFID, projectSFID,
panic("implement me")
}

func (repo *mockRepository) GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
func (repo *mockRepository) GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, searchterm *string, all bool) (*models.EventList, error) {
panic("implement me")
}

func (repo *mockRepository) GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
func (repo *mockRepository) GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, searchTerm *string, all bool) (*models.EventList, error) {
panic("implement me")
}

58 changes: 29 additions & 29 deletions cla-backend-go/events/repository.go
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ const (
EventFoundationSFIDEpochIndex = "event-foundation-sfid-event-time-epoch-index"
EventProjectIDEpochIndex = "event-project-id-event-time-epoch-index"
EventCLAGroupIDEpochIndex = "event-cla-group-id-event-time-epoch-index"
EventCompanySFIDEventDataLowerIndex = "event-company-sfid-event-data-lower-index"
)

// constants
@@ -60,8 +61,8 @@ type Repository interface {
SearchEvents(params *eventOps.SearchEventsParams, pageSize int64) (*models.EventList, error)
GetRecentEvents(pageSize int64) (*models.EventList, error)

GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, searchTerm *string, all bool) (*models.EventList, error)
GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, searchTerm *string, all bool) (*models.EventList, error)
GetCompanyEvents(companyID, eventType string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetFoundationEvents(foundationSFID string, nextKey *string, paramPageSize *int64, all bool, searchTerm *string) (*models.EventList, error)
GetClaGroupEvents(claGroupID string, nextKey *string, paramPageSize *int64, all bool, searchTerm *string) (*models.EventList, error)
@@ -373,24 +374,6 @@ func (repo *repository) queryEventsTable(indexName string, condition expression.
log.WithFields(f).Debug("querying events table...")
builder := expression.NewBuilder().WithKeyCondition(condition)

// If we have a search term...
if searchTerm != nil {
log.WithFields(f).Debugf("adding searchTerm: %s", *searchTerm)
eventLowerFilter := expression.Name("event_data_lower").Contains(strings.ToLower(*searchTerm))
if filter == nil {
// Create a new filter
filter = &eventLowerFilter
} else {
// Add to existing filter
filter.And(eventLowerFilter)
}
}

// Add the filter to the builder
if filter != nil {
builder = builder.WithFilter(*filter)
}

// Use the nice builder to create the expression
expr, err := builder.Build()
if err != nil {
@@ -456,8 +439,14 @@ func (repo *repository) queryEventsTable(indexName string, condition expression.
return nil, modelErr
}

// Trim to how many the caller asked for - just in case we go over
events = append(events, eventsList...)
// Add search term filtering
if len(events) > 0 && searchTerm != nil {
log.WithFields(f).Debugf("filtering events by search term: %s", *searchTerm)
events = filterEventsBySearchTerm(events, *searchTerm)
}

// Trim to how many the caller asked for - just in case we go over
if int64(len(events)) > maxResults {
events = events[:maxResults]
}
@@ -502,6 +491,17 @@ func (repo *repository) queryEventsTable(indexName string, condition expression.
}, nil
}

func filterEventsBySearchTerm(events []*models.Event, s string) []*models.Event {
var filteredEvents []*models.Event
for _, event := range events {
log.Debugf("checking event: %s", event.EventData)
if strings.Contains(strings.ToLower(event.EventData), strings.ToLower(s)) {
filteredEvents = append(filteredEvents, event)
}
}
return filteredEvents
}

func buildNextKey(indexName string, event *models.Event) (string, error) {
nextKey := make(map[string]*dynamodb.AttributeValue)
nextKey["event_id"] = &dynamodb.AttributeValue{S: aws.String(event.EventID)}
@@ -534,7 +534,7 @@ func buildNextKey(indexName string, event *models.Event) (string, error) {
}

// GetCompanyFoundationEvents returns the list of events for foundation and company
func (repo *repository) GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
func (repo *repository) GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, searchTerm *string, all bool) (*models.EventList, error) {
f := logrus.Fields{
"functionName": "v1.events.repository.GetCompanyFoundationEvents",
"companySFID": companySFID,
@@ -544,16 +544,16 @@ func (repo *repository) GetCompanyFoundationEvents(companySFID, companyID, found
"paramPageSize": utils.Int64Value(paramPageSize),
"loadAll": all,
}
log.WithFields(f).Debugf("adding key condition of 'event_parent_project_sfid = %s'", foundationSFID)
keyCondition := expression.Key("event_parent_project_sfid").Equal(expression.Value(foundationSFID))
log.WithFields(f).Debugf("adding key condition of 'event_company_sfid_sfid = %s'", companySFID)
keyCondition := expression.Key("event_company_sfid").Equal(expression.Value(companySFID))
var filter expression.ConditionBuilder
log.WithFields(f).Debugf("adding filter condition of 'event_company_sfid = %s'", companySFID)
filter = expression.Name("event_company_sfid").Equal(expression.Value(companySFID))
return repo.queryEventsTable(EventFoundationSFIDEpochIndex, keyCondition, &filter, nextKey, paramPageSize, all, nil)
log.WithFields(f).Debugf("adding filter condition of 'event_parent_project_sfid = %s'", foundationSFID)
filter = expression.Name("event_parent_project_sfid").Equal(expression.Value(foundationSFID))
return repo.queryEventsTable(EventCompanySFIDEventDataLowerIndex, keyCondition, &filter, nextKey, paramPageSize, all, searchTerm)
}

// GetCompanyClaGroupEvents returns the list of events for cla group and the company
func (repo *repository) GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
func (repo *repository) GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, searchTerm *string, all bool) (*models.EventList, error) {
f := logrus.Fields{
"functionName": "v1.events.repository.GetCompanyClaGroupEvents",
"companySFID": companySFID,
@@ -568,7 +568,7 @@ func (repo *repository) GetCompanyClaGroupEvents(companySFID, companyID, claGrou
var filter expression.ConditionBuilder
log.WithFields(f).Debugf("adding filter condition of 'event_company_sfid = %s'", companySFID)
filter = expression.Name("event_company_sfid").Equal(expression.Value(companySFID))
return repo.queryEventsTable(EventCLAGroupIDEpochIndex, keyCondition, &filter, nextKey, paramPageSize, all, nil)
return repo.queryEventsTable(EventCLAGroupIDEpochIndex, keyCondition, &filter, nextKey, paramPageSize, all, searchTerm)
}

// GetCompanyEvents returns the list of events for given company id and event types
12 changes: 6 additions & 6 deletions cla-backend-go/events/service.go
Original file line number Diff line number Diff line change
@@ -39,8 +39,8 @@ type Service interface {

GetFoundationEvents(foundationSFID string, nextKey *string, paramPageSize *int64, all bool, searchTerm *string) (*models.EventList, error)
GetClaGroupEvents(claGroupID string, nextKey *string, paramPageSize *int64, all bool, searchTerm *string) (*models.EventList, error)
GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, searchTerm *string, all bool) (*models.EventList, error)
GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, searchTerm *string, all bool) (*models.EventList, error)
GetCompanyEvents(companyID, eventType string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
}

@@ -101,13 +101,13 @@ func (s *service) GetClaGroupEvents(projectSFDC string, nextKey *string, paramPa
}

// GetCompanyFoundationEvents returns list of events for company and foundation
func (s *service) GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
return s.repo.GetCompanyFoundationEvents(companySFID, companyID, foundationSFID, nextKey, paramPageSize, all)
func (s *service) GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, searchTerm *string, all bool) (*models.EventList, error) {
return s.repo.GetCompanyFoundationEvents(companySFID, companyID, foundationSFID, nextKey, paramPageSize, searchTerm, all)
}

// GetCompanyClaGroupEvents returns list of events for company and cla group
func (s *service) GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
return s.repo.GetCompanyClaGroupEvents(companySFID, companyID, claGroupID, nextKey, paramPageSize, all)
func (s *service) GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, searchTerm *string, all bool) (*models.EventList, error) {
return s.repo.GetCompanyClaGroupEvents(companySFID, companyID, claGroupID, nextKey, paramPageSize, searchTerm, all)
}

func (s *service) GetCompanyEvents(companyID, eventType string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
1 change: 1 addition & 0 deletions cla-backend-go/swagger/cla.v2.yaml
Original file line number Diff line number Diff line change
@@ -1078,6 +1078,7 @@ paths:
- $ref: '#/parameters/path-projectSFID'
- $ref: '#/parameters/path-companyID'
- $ref: '#/parameters/nextKey'
- $ref: '#/parameters/searchTerm'
- $ref: '#/parameters/returnAllEvents'
produces:
- application/json
4 changes: 2 additions & 2 deletions cla-backend-go/v2/events/handlers.go
Original file line number Diff line number Diff line change
@@ -310,7 +310,7 @@ func Configure(api *operations.EasyclaAPI, service v1Events.Service, v1CompanyRe
var result *v1Models.EventList
if utils.IsProjectHasRootParent(projectDetails) {
log.WithFields(f).Debugf("loading foundation level events for projectSFID: %s...", params.ProjectSFID)
result, err = service.GetCompanyFoundationEvents(v1Company.CompanyExternalID, "", params.ProjectSFID, params.NextKey, params.PageSize, aws.BoolValue(params.ReturnAllEvents))
result, err = service.GetCompanyFoundationEvents(v1Company.CompanyExternalID, "", params.ProjectSFID, params.NextKey, params.PageSize, params.SearchTerm, aws.BoolValue(params.ReturnAllEvents))
} else {
log.WithFields(f).Debugf("loading project level events for projectSFID :%s...", params.ProjectSFID)
pm, perr := projectsClaGroupsRepo.GetClaGroupIDForProject(ctx, params.ProjectSFID)
@@ -325,7 +325,7 @@ func Configure(api *operations.EasyclaAPI, service v1Events.Service, v1CompanyRe
log.WithFields(f).WithError(perr).Warnf("problem determining CLA Group for project SFID: %s", params.ProjectSFID)
return events.NewGetCompanyProjectEventsInternalServerError().WithPayload(errorResponse(reqID, perr))
}
result, err = service.GetCompanyClaGroupEvents(v1Company.CompanyExternalID, params.CompanyID, pm.ClaGroupID, params.NextKey, params.PageSize, aws.BoolValue(params.ReturnAllEvents))
result, err = service.GetCompanyClaGroupEvents(v1Company.CompanyExternalID, params.CompanyID, pm.ClaGroupID, params.NextKey, params.PageSize, params.SearchTerm, aws.BoolValue(params.ReturnAllEvents))
}
if err != nil {
log.WithFields(f).WithError(err).Warn("problem loading events")

0 comments on commit 70445af

Please sign in to comment.