Skip to content

Commit

Permalink
🐛 Fix BusinessService CSV import (#766)
Browse files Browse the repository at this point in the history
CSV importer code used to set the last existing BussinessService to an
Application, updating businessService variable from Ref to Value to keep
the found BusinessService until it is saved in Application.

Fixes: https://issues.redhat.com/browse/MTA-4257

Signed-off-by: Marek Aufart <maufart@redhat.com>
  • Loading branch information
aufi authored Nov 25, 2024
1 parent c914669 commit fd98244
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions importer/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,22 @@ func (m *Manager) createApplication(imp *model.Import) (ok bool) {
}

// Assign Business Service
businessService := &model.BusinessService{}
businessService := model.BusinessService{}
businessServices := []model.BusinessService{}
m.DB.Find(&businessServices)
normBusinessServiceName := normalizedName(imp.BusinessService)
// Find existing BusinessService
for _, bs := range businessServices {
if normalizedName(bs.Name) == normBusinessServiceName {
businessService = &bs
businessService = bs
}
}
// If not found business service in database and import specifies some non-empty business service, proceeed with create it
if businessService.ID == 0 && normBusinessServiceName != "" {
if imp.ImportSummary.CreateEntities {
// Create a new BusinessService if not existed
businessService.Name = imp.BusinessService
result := m.DB.Create(businessService)
result := m.DB.Create(&businessService)
if result.Error != nil {
imp.ErrorMessage = fmt.Sprintf("BusinessService '%s' cannot be created.", imp.BusinessService)
return
Expand All @@ -193,7 +193,7 @@ func (m *Manager) createApplication(imp *model.Import) (ok bool) {
}
// Assign business service to the application if was specified
if businessService.ID != 0 {
app.BusinessService = businessService
app.BusinessService = &businessService
}

// Process import Tags & TagCategories
Expand Down

0 comments on commit fd98244

Please sign in to comment.