Commit 95ce8537 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

adding productofferringPrice events

parent acabc2b4
Loading
Loading
Loading
Loading
Loading
+35 −11
Original line number Diff line number Diff line
@@ -43,6 +43,10 @@ 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.etsi.osl.tmf.pcm620.model.ProductOfferingPriceCreateNotification;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingPriceDeleteNotification;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingPriceAttributeValueChangeNotification;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingPriceStateChangeNotification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@@ -56,34 +60,46 @@ public class ProductCatalogApiRouteBuilderEvents extends RouteBuilder {
	private static final transient Log logger = LogFactory.getLog(ProductCatalogApiRouteBuilderEvents.class.getName());

	@Value("${EVENT_PRODUCT_CATALOG_CREATE}")
	private String EVENT_CATALOG_CREATE = "direct:EVENT_CATALOG_CREATE";
	private String EVENT_CATALOG_CREATE = "";
	
	@Value("${EVENT_PRODUCT_CATALOG_DELETE}")
	private String EVENT_CATALOG_DELETE = "direct:EVENT_CATALOG_DELETE";
	private String EVENT_CATALOG_DELETE = "";
	
	@Value("${EVENT_PRODUCT_CATEGORY_CREATE}")
	private String EVENT_CATEGORY_CREATE = "direct:EVENT_CATEGORY_CREATE";
	private String EVENT_CATEGORY_CREATE = "";
	
	@Value("${EVENT_PRODUCT_CATEGORY_DELETE}")
	private String EVENT_CATEGORY_DELETE = "direct:EVENT_CATEGORY_DELETE";
	private String EVENT_CATEGORY_DELETE = "";
	
	@Value("${EVENT_PRODUCT_SPECIFICATION_CREATE}")
	private String EVENT_PRODUCT_SPECIFICATION_CREATE = "direct:EVENT_PRODUCT_SPECIFICATION_CREATE";
	private String EVENT_PRODUCT_SPECIFICATION_CREATE = "";
	
	@Value("${EVENT_PRODUCT_SPECIFICATION_DELETE}")
	private String EVENT_PRODUCT_SPECIFICATION_DELETE = "direct:EVENT_PRODUCT_SPECIFICATION_DELETE";
	private String EVENT_PRODUCT_SPECIFICATION_DELETE  = "";
	
	@Value("${EVENT_PRODUCT_OFFERING_CREATE}")
	private String EVENT_PRODUCT_OFFERING_CREATE = "direct:EVENT_PRODUCT_OFFERING_CREATE";
	private String EVENT_PRODUCT_OFFERING_CREATE = "";
	
	@Value("${EVENT_PRODUCT_OFFERING_DELETE}")
	private String EVENT_PRODUCT_OFFERING_DELETE = "direct:EVENT_PRODUCT_OFFERING_DELETE";
	private String 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";
	private String 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";
	private String EVENT_PRODUCT_OFFERING_STATE_CHANGE = "";
	
	@Value("${EVENT_PRODUCT_OFFERING_PRICE_CREATE}")
	private String EVENT_PRODUCT_OFFERING_PRICE_CREATE = "";
	
	@Value("${EVENT_PRODUCT_OFFERING_PRICE_DELETE}")
	private String EVENT_PRODUCT_OFFERING_PRICE_DELETE = "";
	
	@Value("${EVENT_PRODUCT_OFFERING_PRICE_ATTRIBUTE_VALUE_CHANGE}")
	private String EVENT_PRODUCT_OFFERING_PRICE_ATTRIBUTE_VALUE_CHANGE = "";
	
	@Value("${EVENT_PRODUCT_OFFERING_PRICE_STATE_CHANGE}")
	private String EVENT_PRODUCT_OFFERING_PRICE_STATE_CHANGE = "";

	@Value("${spring.application.name}")
	private String compname;
@@ -131,6 +147,14 @@ public class ProductCatalogApiRouteBuilderEvents extends RouteBuilder {
				 msgtopic = EVENT_PRODUCT_OFFERING_ATTRIBUTE_VALUE_CHANGE;
			} else if (n instanceof ProductOfferingStateChangeNotification) {
				 msgtopic = EVENT_PRODUCT_OFFERING_STATE_CHANGE;
			} else if (n instanceof ProductOfferingPriceCreateNotification) {
				 msgtopic = EVENT_PRODUCT_OFFERING_PRICE_CREATE;
			} else if (n instanceof ProductOfferingPriceDeleteNotification) {
				 msgtopic = EVENT_PRODUCT_OFFERING_PRICE_DELETE;
			} else if (n instanceof ProductOfferingPriceAttributeValueChangeNotification) {
				 msgtopic = EVENT_PRODUCT_OFFERING_PRICE_ATTRIBUTE_VALUE_CHANGE;
			} else if (n instanceof ProductOfferingPriceStateChangeNotification) {
				 msgtopic = EVENT_PRODUCT_OFFERING_PRICE_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.ProductOfferingPriceCreateEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingPriceDeleteEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingPriceAttributeValueChangeEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingPriceStateChangeEvent;
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 ProductOfferingPriceCallbackService {

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

    @Autowired
    private EventSubscriptionRepoService eventSubscriptionRepoService;

    @Autowired
    private RestTemplate restTemplate;

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

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

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

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

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

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

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

    /**
     * Send product offering price state change event to a specific callback URL
     * @param callbackUrl The callback URL to send to
     * @param event The product offering price state change event
     */
    private void sendProductOfferingPriceStateChangeEventToCallback(String callbackUrl, ProductOfferingPriceStateChangeEvent event) {
        try {
            String url = buildCallbackUrl(callbackUrl, "/listener/productOfferingPriceStateChangeEvent");
            
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpEntity<ProductOfferingPriceStateChangeEvent> entity = new HttpEntity<>(event, headers);
            
            ResponseEntity<String> response = restTemplate.exchange(
                url, HttpMethod.POST, entity, String.class);
            
            logger.info("Successfully sent product offering price state change event to callback URL: {} - Response: {}", 
                url, response.getStatusCode());
            
        } catch (Exception e) {
            logger.error("Failed to send product offering price 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("productofferingprice") || 
               query.contains(eventType.toLowerCase()) ||
               query.contains("productofferingprice.create") ||
               query.contains("productofferingprice.delete") ||
               query.contains("productofferingprice.attributevaluechange") ||
               query.contains("productofferingprice.statechange");
    }
}
 No newline at end of file
+257 −0

File added.

Preview size limit exceeded, changes collapsed.

+26 −1
Original line number Diff line number Diff line
@@ -55,6 +55,9 @@ public class ProductOfferingPriceRepoService {
	@Autowired
	ProductOfferingPriceRepository prodsOfferingRepo;
	
	@Autowired
	ProductOfferingPriceNotificationService productOfferingPriceNotificationService;
	
	

	private SessionFactory sessionFactory;
@@ -80,6 +83,10 @@ public class ProductOfferingPriceRepoService {
		serviceSpec = this.updateProductOfferingPriceDataFromAPIcall(serviceSpec, serviceProductOfferingPrice);
		serviceSpec = this.prodsOfferingRepo.save(serviceSpec);

		// Publish create notification
		if (productOfferingPriceNotificationService != null) {
			productOfferingPriceNotificationService.publishProductOfferingPriceCreateNotification(serviceSpec);
		}
	
		return this.prodsOfferingRepo.save(serviceSpec);
	}
@@ -231,6 +238,11 @@ public class ProductOfferingPriceRepoService {
		 * prior deleting we need to delete other dependency objects
		 */

		// Publish delete notification before actual deletion
		if (productOfferingPriceNotificationService != null) {
			productOfferingPriceNotificationService.publishProductOfferingPriceDeleteNotification(s);
		}
		
		this.prodsOfferingRepo.delete(s);
		return null;
	}
@@ -244,12 +256,25 @@ public class ProductOfferingPriceRepoService {
		if (s == null) {
			return null;
		}
		
		// Store original state for comparison
		String originalLifecycleStatus = s.getLifecycleStatus();
		
		ProductOfferingPrice prodOff = s;
		prodOff = this.updateProductOfferingPriceDataFromAPIcall(prodOff, aProductOfferingPrice);

		prodOff = this.prodsOfferingRepo.save(prodOff);
		
		// Publish notifications
		if (productOfferingPriceNotificationService != null) {
			// Always publish attribute value change notification for updates
			productOfferingPriceNotificationService.publishProductOfferingPriceAttributeValueChangeNotification(prodOff);
			
			// Check for state change and publish state change notification if needed
			if (originalLifecycleStatus != null && !originalLifecycleStatus.equals(prodOff.getLifecycleStatus())) {
				productOfferingPriceNotificationService.publishProductOfferingPriceStateChangeNotification(prodOff);
			}
		}
		
		return this.prodsOfferingRepo.save(prodOff);

+4 −0
Original line number Diff line number Diff line
@@ -195,6 +195,10 @@ 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"
EVENT_PRODUCT_OFFERING_PRICE_CREATE: "jms:topic:EVENT.PRODUCTOFFERINGPRICE.CREATE"
EVENT_PRODUCT_OFFERING_PRICE_DELETE: "jms:topic:EVENT.PRODUCTOFFERINGPRICE.DELETE"
EVENT_PRODUCT_OFFERING_PRICE_ATTRIBUTE_VALUE_CHANGE: "jms:topic:EVENT.PRODUCTOFFERINGPRICE.ATTRCHANGED"
EVENT_PRODUCT_OFFERING_PRICE_STATE_CHANGE: "jms:topic:EVENT.PRODUCTOFFERINGPRICE.STATECHANGED"

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