+ subsIds := es.getMatchingSubs(event)
+ for _, subId := range subsIds {
+ go es.sendEvent(event, subId)
+ }
+}
+
+func (es *EventService) sendEvent(event eventsapi.EventNotification, subscriptionId string) {
+ event.SubscriptionId = subscriptionId
+ e, _ := json.Marshal(event)
+ if error := restclient.Put(string(es.subscriptions[subscriptionId].NotificationDestination), []byte(e), es.client); error != nil {
+ log.Error("Unable to send event")
+ }
+}
+
+func (es *EventService) getMatchingSubs(event eventsapi.EventNotification) []string {
+ es.lock.Lock()
+ defer es.lock.Unlock()
+ matchingTypeSubs := es.filterOnEventType(event)
+ matchingSubs := []string{}
+ for _, subId := range matchingTypeSubs {
+ subscription := es.subscriptions[subId]
+ if subscription.EventFilters == nil || event.EventDetail == nil {
+ matchingSubs = append(matchingSubs, subId)
+ } 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)
+ }
+ }
+
+ return matchingSubs
+}
+
+func (es *EventService) filterOnEventType(event eventsapi.EventNotification) []string {
+ matchingSubs := []string{}
+ for subId, subInfo := range es.subscriptions {
+ if slices.Contains(asStrings(subInfo.Events), string(event.Events)) {
+ matchingSubs = append(matchingSubs, subId)
+ }
+ }
+ return matchingSubs
+}
+
+func matchesFilters(eventIds *[]string, filters []eventsapi.CAPIFEventFilter, getIds func(eventsapi.CAPIFEventFilter) *[]string) bool {
+ if len(filters) == 0 || eventIds == nil {
+ return true
+ }
+ for _, id := range *eventIds {
+ filter := filters[0]
+ filterIds := getIds(filter)
+ if filterIds == nil || len(*filterIds) == 0 {
+ return matchesFilters(eventIds, filters[1:], getIds)
+ } else {
+ 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)