Commit acabc2b4 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

adding ProductOffering events

parent cd43309d
Loading
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -39,6 +39,10 @@ import org.etsi.osl.tmf.pcm620.model.CategoryCreateNotification;
import org.etsi.osl.tmf.pcm620.model.CategoryDeleteNotification;
import org.etsi.osl.tmf.pcm620.model.ProductSpecificationCreateNotification;
import org.etsi.osl.tmf.pcm620.model.ProductSpecificationDeleteNotification;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingCreateNotification;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingDeleteNotification;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingAttributeValueChangeNotification;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingStateChangeNotification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@@ -69,6 +73,18 @@ public class ProductCatalogApiRouteBuilderEvents extends RouteBuilder {
	@Value("${EVENT_PRODUCT_SPECIFICATION_DELETE}")
	private String EVENT_PRODUCT_SPECIFICATION_DELETE = "direct:EVENT_PRODUCT_SPECIFICATION_DELETE";
	
	@Value("${EVENT_PRODUCT_OFFERING_CREATE}")
	private String EVENT_PRODUCT_OFFERING_CREATE = "direct:EVENT_PRODUCT_OFFERING_CREATE";
	
	@Value("${EVENT_PRODUCT_OFFERING_DELETE}")
	private String EVENT_PRODUCT_OFFERING_DELETE = "direct:EVENT_PRODUCT_OFFERING_DELETE";
	
	@Value("${EVENT_PRODUCT_OFFERING_ATTRIBUTE_VALUE_CHANGE}")
	private String EVENT_PRODUCT_OFFERING_ATTRIBUTE_VALUE_CHANGE = "direct:EVENT_PRODUCT_OFFERING_ATTRIBUTE_VALUE_CHANGE";
	
	@Value("${EVENT_PRODUCT_OFFERING_STATE_CHANGE}")
	private String EVENT_PRODUCT_OFFERING_STATE_CHANGE = "direct:EVENT_PRODUCT_OFFERING_STATE_CHANGE";

	@Value("${spring.application.name}")
	private String compname;
	
@@ -107,6 +123,14 @@ public class ProductCatalogApiRouteBuilderEvents extends RouteBuilder {
				 msgtopic = EVENT_PRODUCT_SPECIFICATION_CREATE;
			} else if (n instanceof ProductSpecificationDeleteNotification) {
				 msgtopic = EVENT_PRODUCT_SPECIFICATION_DELETE;
			} else if (n instanceof ProductOfferingCreateNotification) {
				 msgtopic = EVENT_PRODUCT_OFFERING_CREATE;
			} else if (n instanceof ProductOfferingDeleteNotification) {
				 msgtopic = EVENT_PRODUCT_OFFERING_DELETE;
			} else if (n instanceof ProductOfferingAttributeValueChangeNotification) {
				 msgtopic = EVENT_PRODUCT_OFFERING_ATTRIBUTE_VALUE_CHANGE;
			} else if (n instanceof ProductOfferingStateChangeNotification) {
				 msgtopic = EVENT_PRODUCT_OFFERING_STATE_CHANGE;				
			}
			
			Map<String, Object> map = new HashMap<>();
+238 −0
Original line number Diff line number Diff line
/*-
 * ========================LICENSE_START=================================
 * org.etsi.osl.tmf.api
 * %%
 * Copyright (C) 2019 - 2021 openslice.io
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =========================LICENSE_END==================================
 */
package org.etsi.osl.tmf.pcm620.reposervices;

import java.util.List;

import org.etsi.osl.tmf.pcm620.model.ProductOfferingCreateEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingDeleteEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingAttributeValueChangeEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingStateChangeEvent;
import org.etsi.osl.tmf.pcm620.model.EventSubscription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class ProductOfferingCallbackService {

    private static final Logger logger = LoggerFactory.getLogger(ProductOfferingCallbackService.class);

    @Autowired
    private EventSubscriptionRepoService eventSubscriptionRepoService;

    @Autowired
    private RestTemplate restTemplate;

    /**
     * Send product offering create event to all registered callback URLs
     * @param productOfferingCreateEvent The product offering create event to send
     */
    public void sendProductOfferingCreateCallback(ProductOfferingCreateEvent productOfferingCreateEvent) {
        List<EventSubscription> subscriptions = eventSubscriptionRepoService.findAll();
        
        for (EventSubscription subscription : subscriptions) {
            if (shouldNotifySubscription(subscription, "productOfferingCreateEvent")) {
                sendProductOfferingCreateEventToCallback(subscription.getCallback(), productOfferingCreateEvent);
            }
        }
    }

    /**
     * Send product offering delete event to all registered callback URLs
     * @param productOfferingDeleteEvent The product offering delete event to send
     */
    public void sendProductOfferingDeleteCallback(ProductOfferingDeleteEvent productOfferingDeleteEvent) {
        List<EventSubscription> subscriptions = eventSubscriptionRepoService.findAll();
        
        for (EventSubscription subscription : subscriptions) {
            if (shouldNotifySubscription(subscription, "productOfferingDeleteEvent")) {
                sendProductOfferingDeleteEventToCallback(subscription.getCallback(), productOfferingDeleteEvent);
            }
        }
    }

    /**
     * Send product offering attribute value change event to all registered callback URLs
     * @param productOfferingAttributeValueChangeEvent The product offering attribute value change event to send
     */
    public void sendProductOfferingAttributeValueChangeCallback(ProductOfferingAttributeValueChangeEvent productOfferingAttributeValueChangeEvent) {
        List<EventSubscription> subscriptions = eventSubscriptionRepoService.findAll();
        
        for (EventSubscription subscription : subscriptions) {
            if (shouldNotifySubscription(subscription, "productOfferingAttributeValueChangeEvent")) {
                sendProductOfferingAttributeValueChangeEventToCallback(subscription.getCallback(), productOfferingAttributeValueChangeEvent);
            }
        }
    }

    /**
     * Send product offering state change event to all registered callback URLs
     * @param productOfferingStateChangeEvent The product offering state change event to send
     */
    public void sendProductOfferingStateChangeCallback(ProductOfferingStateChangeEvent productOfferingStateChangeEvent) {
        List<EventSubscription> subscriptions = eventSubscriptionRepoService.findAll();
        
        for (EventSubscription subscription : subscriptions) {
            if (shouldNotifySubscription(subscription, "productOfferingStateChangeEvent")) {
                sendProductOfferingStateChangeEventToCallback(subscription.getCallback(), productOfferingStateChangeEvent);
            }
        }
    }

    /**
     * Send product offering create event to a specific callback URL
     * @param callbackUrl The callback URL to send to
     * @param event The product offering create event
     */
    private void sendProductOfferingCreateEventToCallback(String callbackUrl, ProductOfferingCreateEvent event) {
        try {
            String url = buildCallbackUrl(callbackUrl, "/listener/productOfferingCreateEvent");
            
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpEntity<ProductOfferingCreateEvent> entity = new HttpEntity<>(event, headers);
            
            ResponseEntity<String> response = restTemplate.exchange(
                url, HttpMethod.POST, entity, String.class);
            
            logger.info("Successfully sent product offering create event to callback URL: {} - Response: {}", 
                url, response.getStatusCode());
            
        } catch (Exception e) {
            logger.error("Failed to send product offering create event to callback URL: {}", callbackUrl, e);
        }
    }

    /**
     * Send product offering delete event to a specific callback URL
     * @param callbackUrl The callback URL to send to
     * @param event The product offering delete event
     */
    private void sendProductOfferingDeleteEventToCallback(String callbackUrl, ProductOfferingDeleteEvent event) {
        try {
            String url = buildCallbackUrl(callbackUrl, "/listener/productOfferingDeleteEvent");
            
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpEntity<ProductOfferingDeleteEvent> entity = new HttpEntity<>(event, headers);
            
            ResponseEntity<String> response = restTemplate.exchange(
                url, HttpMethod.POST, entity, String.class);
            
            logger.info("Successfully sent product offering delete event to callback URL: {} - Response: {}", 
                url, response.getStatusCode());
            
        } catch (Exception e) {
            logger.error("Failed to send product offering delete event to callback URL: {}", callbackUrl, e);
        }
    }

    /**
     * Send product offering attribute value change event to a specific callback URL
     * @param callbackUrl The callback URL to send to
     * @param event The product offering attribute value change event
     */
    private void sendProductOfferingAttributeValueChangeEventToCallback(String callbackUrl, ProductOfferingAttributeValueChangeEvent event) {
        try {
            String url = buildCallbackUrl(callbackUrl, "/listener/productOfferingAttributeValueChangeEvent");
            
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpEntity<ProductOfferingAttributeValueChangeEvent> entity = new HttpEntity<>(event, headers);
            
            ResponseEntity<String> response = restTemplate.exchange(
                url, HttpMethod.POST, entity, String.class);
            
            logger.info("Successfully sent product offering attribute value change event to callback URL: {} - Response: {}", 
                url, response.getStatusCode());
            
        } catch (Exception e) {
            logger.error("Failed to send product offering attribute value change event to callback URL: {}", callbackUrl, e);
        }
    }

    /**
     * Send product offering state change event to a specific callback URL
     * @param callbackUrl The callback URL to send to
     * @param event The product offering state change event
     */
    private void sendProductOfferingStateChangeEventToCallback(String callbackUrl, ProductOfferingStateChangeEvent event) {
        try {
            String url = buildCallbackUrl(callbackUrl, "/listener/productOfferingStateChangeEvent");
            
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpEntity<ProductOfferingStateChangeEvent> entity = new HttpEntity<>(event, headers);
            
            ResponseEntity<String> response = restTemplate.exchange(
                url, HttpMethod.POST, entity, String.class);
            
            logger.info("Successfully sent product offering state change event to callback URL: {} - Response: {}", 
                url, response.getStatusCode());
            
        } catch (Exception e) {
            logger.error("Failed to send product offering state change event to callback URL: {}", callbackUrl, e);
        }
    }

    /**
     * Build the full callback URL with the listener endpoint
     * @param baseUrl The base callback URL
     * @param listenerPath The listener path to append
     * @return The complete callback URL
     */
    private String buildCallbackUrl(String baseUrl, String listenerPath) {
        if (baseUrl.endsWith("/")) {
            return baseUrl.substring(0, baseUrl.length() - 1) + listenerPath;
        } else {
            return baseUrl + listenerPath;
        }
    }

    /**
     * Check if a subscription should be notified for a specific event type
     * @param subscription The event subscription
     * @param eventType The event type to check
     * @return true if the subscription should be notified
     */
    private boolean shouldNotifySubscription(EventSubscription subscription, String eventType) {
        // If no query is specified, notify all events
        if (subscription.getQuery() == null || subscription.getQuery().trim().isEmpty()) {
            return true;
        }
        
        // Check if the query contains the event type
        String query = subscription.getQuery().toLowerCase();
        return query.contains("productoffering") || 
               query.contains(eventType.toLowerCase()) ||
               query.contains("productoffering.create") ||
               query.contains("productoffering.delete") ||
               query.contains("productoffering.attributevaluechange") ||
               query.contains("productoffering.statechange");
    }
}
 No newline at end of file
+257 −0

File added.

Preview size limit exceeded, changes collapsed.

+30 −3
Original line number Diff line number Diff line
@@ -78,6 +78,9 @@ public class ProductOfferingRepoService {
    @Autowired
    ServiceSpecificationRepoService serviceSpecificationRepoService;
    
    @Autowired
    private ProductOfferingNotificationService productOfferingNotificationService;

	private SessionFactory sessionFactory;


@@ -101,8 +104,12 @@ public class ProductOfferingRepoService {
		serviceSpec = this.updateProductOfferingDataFromAPIcall(serviceSpec, serviceProductOffering);
		serviceSpec = this.prodsOfferingRepo.save(serviceSpec);

		// Publish product offering create notification
		if (productOfferingNotificationService != null) {
			productOfferingNotificationService.publishProductOfferingCreateNotification(serviceSpec);
		}
	
		return this.prodsOfferingRepo.save(serviceSpec);
		return serviceSpec;
	}

	public List<ProductOffering> findAll() {
@@ -261,6 +268,12 @@ public class ProductOfferingRepoService {
		 */

		this.prodsOfferingRepo.delete(s);
		
		// Publish product offering delete notification
		if (productOfferingNotificationService != null) {
			productOfferingNotificationService.publishProductOfferingDeleteNotification(s);
		}
		
		return null;
	}
	
@@ -273,14 +286,28 @@ public class ProductOfferingRepoService {
		if (s == null) {
			return null;
		}
		
		// Store original state for comparison
		String originalLifecycleStatus = s.getLifecycleStatus();
		
		ProductOffering prodOff = s;
		prodOff = this.updateProductOfferingDataFromAPIcall(prodOff, aProductOffering);

		prodOff = this.prodsOfferingRepo.save(prodOff);
		
		// Publish notifications
		if (productOfferingNotificationService != null) {
			// Always publish attribute value change notification on update
			productOfferingNotificationService.publishProductOfferingAttributeValueChangeNotification(prodOff);
			
			// Publish state change notification if lifecycle status changed
			if (originalLifecycleStatus != null && prodOff.getLifecycleStatus() != null 
				&& !originalLifecycleStatus.equals(prodOff.getLifecycleStatus())) {
				productOfferingNotificationService.publishProductOfferingStateChangeNotification(prodOff);
			}
		}
		
		return this.prodsOfferingRepo.save(prodOff);
		return prodOff;

	}

+4 −0
Original line number Diff line number Diff line
@@ -191,6 +191,10 @@ EVENT_PRODUCT_CATEGORY_CREATE: "jms:topic:EVENT.PRODUCTCATEGORY.CREATE"
EVENT_PRODUCT_CATEGORY_DELETE: "jms:topic:EVENT.PRODUCTCATEGORY.DELETE"
EVENT_PRODUCT_SPECIFICATION_CREATE: "jms:topic:EVENT.PRODUCTSPECIFICATION.CREATE"
EVENT_PRODUCT_SPECIFICATION_DELETE: "jms:topic:EVENT.PRODUCTSPECIFICATION.DELETE"
EVENT_PRODUCT_OFFERING_CREATE: "jms:topic:EVENT.PRODUCTOFFERING.CREATE"
EVENT_PRODUCT_OFFERING_DELETE: "jms:topic:EVENT.PRODUCTOFFERING.DELETE"
EVENT_PRODUCT_OFFERING_ATTRIBUTE_VALUE_CHANGE: "jms:topic:EVENT.PRODUCTOFFERING.ATTRCHANGED"
EVENT_PRODUCT_OFFERING_STATE_CHANGE: "jms:topic:EVENT.PRODUCTOFFERING.STATECHANGED"

#QUEUE MESSSAGES WITH VNFNSD CATALOG
NFV_CATALOG_GET_NSD_BY_ID: "jms:queue:NFVCATALOG.GET.NSD_BY_ID"
Loading