Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ID-80]Legacy event import issues #81

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Legacy event import issues [#80] (https://github.com/rokwire/gateway-building-block/issues/80)

[2.5.0] - 2024-04-18
### Changed
- Webtools import issues [#77](https://github.com/rokwire/gateway-building-block/issues/77)
Expand Down
66 changes: 65 additions & 1 deletion core/apis_tps.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package core

import (
"application/core/model"
"strings"
)

// appTPS contains BB implementations
Expand All @@ -30,14 +31,77 @@ func (a appTPS) GetExample(orgID string, appID string, id string) (*model.Exampl

// CreateEvents creates events
func (a appTPS) CreateEvents(event []model.LegacyEventItem) ([]model.LegacyEventItem, error) {
return a.app.storage.InsertLegacyEvents(nil, event)
modifiedLegacyEvents, err := a.modifyLegacyEventsList(event)
if err != nil {
a.app.logger.Errorf("error on ignoring legacy events - %s", err)
return nil, err
}
return a.app.storage.InsertLegacyEvents(nil, modifiedLegacyEvents)
}

// DeleteEvents deletes legacy events by ids and creator
func (a appTPS) DeleteEvents(ids []string, accountID string) error {
return a.app.storage.DeleteLegacyEventsByIDsAndCreator(nil, ids, accountID)
}

// ignore or modify legacy events
func (a appTPS) modifyLegacyEventsList(legacyEvents []model.LegacyEventItem) ([]model.LegacyEventItem, error) {
modifiedList := []model.LegacyEventItem{}

ignored := 0
stefanvit marked this conversation as resolved.
Show resolved Hide resolved
modified := 0

//map for category conversions
categoryMap := map[string]string{
"exhibition": "Exhibits",
"festival/celebration": "Festivals and Celebrations",
"film screening": "Film Screenings",
"performance": "Performances",
"lecture": "Speakers and Seminars",
"seminar/symposium": "Speakers and Seminars",
"conference/workshop": "Conferences and Workshops",
"reception/open house": "Receptions and Open House Events",
"social/informal event": "Social and Informal Events",
"professional development": "Career Development",
"health/fitness": "Recreation, Health and Fitness",
"sporting event": "Club Athletics",
"sidearm": "Big 10 Athletics",
}

for _, wte := range legacyEvents {
currentWte := wte
category := currentWte.Item.Category
lowerCategory := strings.ToLower(category)

//ignore some categories
if lowerCategory == "informational" || lowerCategory == "meeting" ||
stefanvit marked this conversation as resolved.
Show resolved Hide resolved
lowerCategory == "community service" || lowerCategory == "ceremony/service" ||
lowerCategory == "other" {

a.app.logger.Infof("skipping event as category is %s", category)
ignored++
continue
}

//modify some categories
if newCategory, ok := categoryMap[lowerCategory]; ok {
currentWte.Item.Category = newCategory
a.app.logger.Infof("modifying event category from %s to %s", category, newCategory)

modified++
}

//add it to the modified list
modifiedList = append(modifiedList, currentWte)
}

a.app.logger.Infof("ignored events count is %d", ignored)
stefanvit marked this conversation as resolved.
Show resolved Hide resolved
a.app.logger.Infof("modified events count is %d", modified)
a.app.logger.Infof("final modified list is %d", len(modifiedList))
stefanvit marked this conversation as resolved.
Show resolved Hide resolved

return modifiedList, nil
}

// newAppTPS creates new appTPS
func newAppTPS(app *Application) appTPS {
return appTPS{app: app}
Expand Down
Loading