Commit 3bbfb4df authored by Christos Tranoris's avatar Christos Tranoris Committed by Kostis Trantzas
Browse files

Resolve "Implement the Listener API for product catalog 620 with just stub code"

parent 144699d7
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -449,6 +449,14 @@
                	<parallel>none</parallel>
                	<runOrder>alphabetical</runOrder>
                	<forkCount>1</forkCount>
                	<reuseForks>false</reuseForks>
                	    <!--
					    <argLine>-Xmx2g -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${project.build.directory}/heap.hprof</argLine>
					    <systemPropertyVariables>
					      <spring.test.context.cache.maxSize>8</spring.test.context.cache.maxSize>
					      <logging.level.org.springframework.test.context.cache>TRACE</logging.level.org.springframework.test.context.cache>
					    </systemPropertyVariables>
          			-->
            	</configuration>
			</plugin>
			<plugin>
+27 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -116,4 +117,30 @@ public interface HubApi {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }

    @Operation(summary = "Get all registered listeners", operationId = "getListeners", description = "Retrieves all registered event subscriptions", tags={ "events subscription", })
    @ApiResponses(value = { 
        @ApiResponse(responseCode = "200", description = "Success" ),
        @ApiResponse(responseCode = "400", description = "Bad Request" ),
        @ApiResponse(responseCode = "401", description = "Unauthorized" ),
        @ApiResponse(responseCode = "403", description = "Forbidden" ),
        @ApiResponse(responseCode = "500", description = "Internal Server Error" ) })
    @RequestMapping(value = "/hub",
        produces = { "application/json;charset=utf-8" },
        method = RequestMethod.GET)
    default ResponseEntity<List<EventSubscription>> getListeners() {
        if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
            if (getAcceptHeader().get().contains("application/json")) {
                try {
                    return new ResponseEntity<>(getObjectMapper().get().readValue("[ {  \"query\" : \"query\",  \"callback\" : \"callback\",  \"id\" : \"id\"} ]", List.class), HttpStatus.NOT_IMPLEMENTED);
                } catch (IOException e) {
                    log.error("Couldn't serialize response for content type application/json", e);
                    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
                }
            }
        } else {
            log.warn("ObjectMapper or HttpServletRequest not configured in default HubApi interface so no example is generated");
        }
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }

}
+20 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
 */
package org.etsi.osl.tmf.pcm620.api;

import java.util.List;
import java.util.Optional;

import com.fasterxml.jackson.databind.ObjectMapper;
@@ -35,6 +36,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import io.swagger.v3.oas.annotations.Parameter;
import jakarta.servlet.http.HttpServletRequest;
@@ -70,8 +72,11 @@ public class HubApiController implements HubApi {
        return Optional.ofNullable(request);
    }

    /* 
     * to register another OSL for example use   "callback": "http://localhost:13082/tmf-api/productCatalogManagement/v4/"
     */
    @Override
    @PreAuthorize("hasAnyAuthority('ROLE_ADMIN')")
    @PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_USER')")
    public ResponseEntity<EventSubscription> registerListener(@Parameter(description = "Data containing the callback endpoint to deliver the information", required = true) @Valid @RequestBody EventSubscriptionInput data) {
        try {
            EventSubscription eventSubscription = eventSubscriptionRepoService.addEventSubscription(data);
@@ -86,7 +91,8 @@ public class HubApiController implements HubApi {
    }

    @Override
    @PreAuthorize("hasAnyAuthority('ROLE_ADMIN')")
    @PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_USER')")
    @RequestMapping(value = "/hub/{id}", method = RequestMethod.DELETE, produces = { "application/json;charset=utf-8" })
    public ResponseEntity<Void> unregisterListener(@Parameter(description = "The id of the registered listener", required = true) @PathVariable("id") String id) {
        try {
            EventSubscription existing = eventSubscriptionRepoService.findById(id);
@@ -102,4 +108,16 @@ public class HubApiController implements HubApi {
        }
    }

    @Override
    @PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_USER')")
    public ResponseEntity<List<EventSubscription>> getListeners() {
        try {
            List<EventSubscription> eventSubscriptions = eventSubscriptionRepoService.findAll();
            return new ResponseEntity<>(eventSubscriptions, HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error retrieving listeners", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

}
+205 −1
Original line number Diff line number Diff line
@@ -22,17 +22,41 @@ package org.etsi.osl.tmf.pcm620.api;
import java.util.Optional;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.etsi.osl.tmf.pcm620.model.CatalogBatchEvent;
import org.etsi.osl.tmf.pcm620.model.CatalogCreateEvent;
import org.etsi.osl.tmf.pcm620.model.CatalogDeleteEvent;
import org.etsi.osl.tmf.pcm620.model.CategoryCreateEvent;
import org.etsi.osl.tmf.pcm620.model.CategoryDeleteEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingAttributeValueChangeEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingCreateEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingDeleteEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingPriceAttributeValueChangeEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingPriceCreateEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingPriceDeleteEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingPriceStateChangeEvent;
import org.etsi.osl.tmf.pcm620.model.ProductOfferingStateChangeEvent;
import org.etsi.osl.tmf.pcm620.model.ProductSpecificationCreateEvent;
import org.etsi.osl.tmf.pcm620.model.ProductSpecificationDeleteEvent;
import org.etsi.osl.tmf.pcm620.model.EventSubscription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import io.swagger.v3.oas.annotations.Parameter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
@jakarta.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-19T00:15:57.249+03:00")

@Controller("ListenerApiController620")
@RequestMapping("/productCatalogManagement/v4/")
public class ListenerApiController implements ListenerApi {

    private static final Logger log = LoggerFactory.getLogger(ListenerApiController.class);

    private final ObjectMapper objectMapper;

    private final HttpServletRequest request;
@@ -53,4 +77,184 @@ public class ListenerApiController implements ListenerApi {
        return Optional.ofNullable(request);
    }

    @Override
    public ResponseEntity<EventSubscription> listenToCatalogBatchEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody CatalogBatchEvent data) {
        try {
            log.info("Received CatalogBatchEvent: {}", data.getEventId());
            log.debug("CatalogBatchEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing CatalogBatchEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToCatalogCreateEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody CatalogCreateEvent data) {
        try {
            log.info("Received CatalogCreateEvent: {}", data.getEventId());
            log.debug("CatalogCreateEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing CatalogCreateEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToCatalogDeleteEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody CatalogDeleteEvent data) {
        try {
            log.info("Received CatalogDeleteEvent: {}", data.getEventId());
            log.debug("CatalogDeleteEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing CatalogDeleteEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToCategoryCreateEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody CategoryCreateEvent data) {
        try {
            log.info("Received CategoryCreateEvent: {}", data.getEventId());
            log.debug("CategoryCreateEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing CategoryCreateEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToCategoryDeleteEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody CategoryDeleteEvent data) {
        try {
            log.info("Received CategoryDeleteEvent: {}", data.getEventId());
            log.debug("CategoryDeleteEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing CategoryDeleteEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToProductOfferingAttributeValueChangeEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody ProductOfferingAttributeValueChangeEvent data) {
        try {
            log.info("Received ProductOfferingAttributeValueChangeEvent: {}", data.getEventId());
            log.debug("ProductOfferingAttributeValueChangeEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing ProductOfferingAttributeValueChangeEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToProductOfferingCreateEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody ProductOfferingCreateEvent data) {
        try {
            log.info("Received ProductOfferingCreateEvent: {}", data.getEventId());
            log.debug("ProductOfferingCreateEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing ProductOfferingCreateEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToProductOfferingDeleteEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody ProductOfferingDeleteEvent data) {
        try {
            log.info("Received ProductOfferingDeleteEvent: {}", data.getEventId());
            log.debug("ProductOfferingDeleteEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing ProductOfferingDeleteEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToProductOfferingPriceAttributeValueChangeEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody ProductOfferingPriceAttributeValueChangeEvent data) {
        try {
            log.info("Received ProductOfferingPriceAttributeValueChangeEvent: {}", data.getEventId());
            log.debug("ProductOfferingPriceAttributeValueChangeEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing ProductOfferingPriceAttributeValueChangeEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToProductOfferingPriceCreateEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody ProductOfferingPriceCreateEvent data) {
        try {
            log.info("Received ProductOfferingPriceCreateEvent: {}", data.getEventId());
            log.debug("ProductOfferingPriceCreateEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing ProductOfferingPriceCreateEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToProductOfferingPriceDeleteEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody ProductOfferingPriceDeleteEvent data) {
        try {
            log.info("Received ProductOfferingPriceDeleteEvent: {}", data.getEventId());
            log.debug("ProductOfferingPriceDeleteEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing ProductOfferingPriceDeleteEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToProductOfferingPriceStateChangeEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody ProductOfferingPriceStateChangeEvent data) {
        try {
            log.info("Received ProductOfferingPriceStateChangeEvent: {}", data.getEventId());
            log.debug("ProductOfferingPriceStateChangeEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing ProductOfferingPriceStateChangeEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToProductOfferingStateChangeEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody ProductOfferingStateChangeEvent data) {
        try {
            log.info("Received ProductOfferingStateChangeEvent: {}", data.getEventId());
            log.debug("ProductOfferingStateChangeEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing ProductOfferingStateChangeEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToProductSpecificationCreateEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody ProductSpecificationCreateEvent data) {
        try {
            log.info("Received ProductSpecificationCreateEvent: {}", data.getEventId());
            log.debug("ProductSpecificationCreateEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing ProductSpecificationCreateEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity<EventSubscription> listenToProductSpecificationDeleteEvent(@Parameter(description = "The event data", required = true) @Valid @RequestBody ProductSpecificationDeleteEvent data) {
        try {
            log.info("Received ProductSpecificationDeleteEvent: {}", data.getEventId());
            log.debug("ProductSpecificationDeleteEvent details: {}", data);
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (Exception e) {
            log.error("Error processing ProductSpecificationDeleteEvent", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

}
+189 −0
Original line number Diff line number Diff line
/*-
 * ========================LICENSE_START=================================
 * org.etsi.osl.tmf.api
 * %%
 * Copyright (C) 2019 - 2020 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.api;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.etsi.osl.centrallog.client.CLevel;
import org.etsi.osl.centrallog.client.CentralLogger;
import org.etsi.osl.tmf.common.model.Notification;
import org.etsi.osl.tmf.pcm620.model.CatalogCreateNotification;
import org.etsi.osl.tmf.pcm620.model.CatalogDeleteNotification;
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.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;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Configuration
@Component
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 = "";
	
	@Value("${EVENT_PRODUCT_CATALOG_DELETE}")
	private String EVENT_CATALOG_DELETE = "";
	
	@Value("${EVENT_PRODUCT_CATEGORY_CREATE}")
	private String EVENT_CATEGORY_CREATE = "";
	
	@Value("${EVENT_PRODUCT_CATEGORY_DELETE}")
	private String EVENT_CATEGORY_DELETE = "";
	
	@Value("${EVENT_PRODUCT_SPECIFICATION_CREATE}")
	private String EVENT_PRODUCT_SPECIFICATION_CREATE = "";
	
	@Value("${EVENT_PRODUCT_SPECIFICATION_DELETE}")
	private String EVENT_PRODUCT_SPECIFICATION_DELETE  = "";
	
	@Value("${EVENT_PRODUCT_OFFERING_CREATE}")
	private String EVENT_PRODUCT_OFFERING_CREATE = "";
	
	@Value("${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 = "";
	
	@Value("${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;
	
	@Autowired
	private ProducerTemplate template;

	@Autowired
	private CentralLogger centralLogger;

	@Override
	public void configure() throws Exception {
		// Configure routes for catalog events
	}

	/**
	 * Publish notification events for catalog operations
	 * @param n The notification to publish
	 * @param objId The catalog object ID
	 */
    @Transactional
	public void publishEvent(final Notification n, final String objId) {
		n.setEventType(n.getClass().getName());
		logger.info("will send Event for type " + n.getEventType());
		try {
			String msgtopic = "";
			
			if (n instanceof CatalogCreateNotification) {
				 msgtopic = EVENT_CATALOG_CREATE;
			} else if (n instanceof CatalogDeleteNotification) {
				 msgtopic = EVENT_CATALOG_DELETE;
			} else if (n instanceof CategoryCreateNotification) {
				 msgtopic = EVENT_CATEGORY_CREATE;
			} else if (n instanceof CategoryDeleteNotification) {
				 msgtopic = EVENT_CATEGORY_DELETE;
			} else if (n instanceof ProductSpecificationCreateNotification) {
				 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;
			} 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<>();
			map.put("eventid", n.getEventId());
			map.put("objId", objId);
			
			String apayload = toJsonString(n);
			template.sendBodyAndHeaders(msgtopic, apayload, map);
			
			centralLogger.log(CLevel.INFO, apayload, compname);	

		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Cannot send Event . " + e.getMessage());
		}
	}

	static String toJsonString(Object object) throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.registerModule(new JavaTimeModule());
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		return mapper.writeValueAsString(object);
	}

	static <T> T toJsonObj(String content, Class<T> valueType) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new JavaTimeModule());
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        return mapper.readValue(content, valueType);
    }
}
 No newline at end of file
Loading