X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Feventservice%2Feventservice.go;h=0f7a8e8c0f1915fc73e047a95183e9cc32797242;hb=refs%2Fchanges%2F25%2F10125%2F1;hp=1bc910b9867f02ce159b4e379659c5d0475f89e6;hpb=19a22c671e873b438cc7ad005bab386674af7bd2;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/eventservice/eventservice.go b/capifcore/internal/eventservice/eventservice.go index 1bc910b..0f7a8e8 100644 --- a/capifcore/internal/eventservice/eventservice.go +++ b/capifcore/internal/eventservice/eventservice.go @@ -33,6 +33,7 @@ import ( "k8s.io/utils/strings/slices" "oransc.org/nonrtric/capifcore/internal/common29122" "oransc.org/nonrtric/capifcore/internal/eventsapi" + "oransc.org/nonrtric/capifcore/internal/publishserviceapi" "oransc.org/nonrtric/capifcore/internal/restclient" ) @@ -132,9 +133,9 @@ func (es *EventService) getMatchingSubs(event eventsapi.EventNotification) []str subscription := es.subscriptions[subId] if subscription.EventFilters == nil || event.EventDetail == nil { matchingSubs = append(matchingSubs, subId) - break - } - if matchesApiIds(*event.EventDetail.ApiIds, *subscription.EventFilters) { + } else if matchesFilters(event.EventDetail.ApiIds, *subscription.EventFilters, getApiIdsFromFilter) && + matchesFilters(event.EventDetail.ApiInvokerIds, *subscription.EventFilters, getInvokerIdsFromFilter) && + matchesFilters(getAefIdsFromEvent(event.EventDetail.ServiceAPIDescriptions), *subscription.EventFilters, getAefIdsFromFilter) { matchingSubs = append(matchingSubs, subId) } } @@ -152,20 +153,49 @@ func (es *EventService) filterOnEventType(event eventsapi.EventNotification) []s return matchingSubs } -func matchesApiIds(eventIds []string, filters []eventsapi.CAPIFEventFilter) bool { - if len(filters) == 0 { +func matchesFilters(eventIds *[]string, filters []eventsapi.CAPIFEventFilter, getIds func(eventsapi.CAPIFEventFilter) *[]string) bool { + if len(filters) == 0 || eventIds == nil { return true } - for _, apiId := range eventIds { + for _, id := range *eventIds { filter := filters[0] - if filter.ApiIds == nil { - return true && matchesApiIds(eventIds, filters[1:]) + filterIds := getIds(filter) + if filterIds == nil || len(*filterIds) == 0 { + return matchesFilters(eventIds, filters[1:], getIds) } - return slices.Contains(*filter.ApiIds, apiId) && matchesApiIds(eventIds, filters[1:]) + return slices.Contains(*getIds(filter), id) && matchesFilters(eventIds, filters[1:], getIds) } return true } +func getApiIdsFromFilter(filter eventsapi.CAPIFEventFilter) *[]string { + return filter.ApiIds +} + +func getInvokerIdsFromFilter(filter eventsapi.CAPIFEventFilter) *[]string { + return filter.ApiInvokerIds +} + +func getAefIdsFromEvent(serviceAPIDescriptions *[]publishserviceapi.ServiceAPIDescription) *[]string { + aefIds := []string{} + if serviceAPIDescriptions == nil { + return &aefIds + } + for _, serviceDescription := range *serviceAPIDescriptions { + if serviceDescription.AefProfiles == nil { + return &aefIds + } + for _, profile := range *serviceDescription.AefProfiles { + aefIds = append(aefIds, profile.AefId) + } + } + return &aefIds +} + +func getAefIdsFromFilter(filter eventsapi.CAPIFEventFilter) *[]string { + return filter.AefIds +} + func asStrings(events []eventsapi.CAPIFEvent) []string { asStrings := make([]string, len(events)) for i, event := range events {