diff --git a/core/interfaces.go b/core/interfaces.go index f33dae02..1e37888d 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -127,7 +127,6 @@ type Storage interface { FindCalendars(id string) (*[]model.UnitCalendar, error) InitializeLegacyLocations() error - //not used FindLegacyLocations() (model.LegacyLocationsListType, error) FindLegacyEventItems(context storage.TransactionContext) ([]model.LegacyEventItem, error) diff --git a/core/logic_events.go b/core/logic_events.go index 9f857952..be41db3b 100644 --- a/core/logic_events.go +++ b/core/logic_events.go @@ -711,6 +711,14 @@ func (e eventsLogic) processLocations(allWebtoolsEvents []model.WebToolsEvent) ( e.logger.Infof("there are %d locations for processing", len(forProcessingLocations)) + //get the locations which are not processed + notProccesed, err := e.getNotProcessedLocations(forProcessingLocations) + if err != nil { + return nil, err + } + + e.logger.Infof("there are %d locations to be processed as not proccesed", len(notProccesed)) + /*locationEventMap := make(map[string]map[string]string) for _, event := range allWebtoolsEvents { @@ -789,6 +797,27 @@ func (e eventsLogic) getLocationsForProcessing(allWebtoolsEvents []model.WebTool return res, nil } +func (e eventsLogic) getNotProcessedLocations(locationsForProcessing []string) ([]string, error) { + allProcessed, err := e.app.storage.FindLegacyLocations() + if err != nil { + return nil, err + } + + processedMap := make(map[string]bool) // map to keep track of processed events + for _, item := range allProcessed { + processedMap[item.Name] = true + } + + var notProcessedEvents []string + for _, loc := range locationsForProcessing { + if _, processed := processedMap[loc]; !processed { + notProcessedEvents = append(notProcessedEvents, loc) + } + } + + return notProcessedEvents, nil +} + func recurenceIDtoInt(s string) (*int, error) { // Parse string to int parsedInt, err := strconv.Atoi(s) diff --git a/driven/storage/adapter_locations.go b/driven/storage/adapter_locations.go index febf9968..22e83ff3 100644 --- a/driven/storage/adapter_locations.go +++ b/driven/storage/adapter_locations.go @@ -38,7 +38,7 @@ func (a *Adapter) InitializeLegacyLocations() error { func (a *Adapter) FindLegacyLocations() (model.LegacyLocationsListType, error) { var list model.LegacyLocationsListType - err := a.db.legacyEvents.FindWithContext(a.context, bson.D{}, &list, options.Find().SetSort(bson.D{{Key: "name", Value: 1}})) + err := a.db.legacyLocations.FindWithContext(a.context, bson.D{}, &list, options.Find().SetSort(bson.D{{Key: "name", Value: 1}})) if err != nil { return nil, errors.WrapErrorAction(logutils.ActionFind, model.TypeEventLocations, nil, err) }