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

fix lazy init errors and add hub GET

parent 7214aa27
Loading
Loading
Loading
Loading
Loading
+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);
    }

}
+18 −0
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,6 +72,9 @@ 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', 'ROLE_USER')")
    public ResponseEntity<EventSubscription> registerListener(@Parameter(description = "Data containing the callback endpoint to deliver the information", required = true) @Valid @RequestBody EventSubscriptionInput data) {
@@ -87,6 +92,7 @@ public class HubApiController implements HubApi {

    @Override
    @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);
        }
    }

}
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ 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;
@@ -174,12 +175,14 @@ public class ProductCatalogApiRouteBuilderEvents extends RouteBuilder {

	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);
    }
+5 −4
Original line number Diff line number Diff line
@@ -80,8 +80,9 @@ public class CatalogCallbackService {
     * @param event The catalog create event
     */
    private void sendCatalogCreateEventToCallback(String callbackUrl, CatalogCreateEvent event) {
        try {
      
        String url = buildCallbackUrl(callbackUrl, "/listener/catalogCreateEvent");
        try {
            
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
@@ -94,7 +95,7 @@ public class CatalogCallbackService {
                url, response.getStatusCode());
            
        } catch (Exception e) {
            logger.error("Failed to send catalog create event to callback URL: {}", callbackUrl, e);
            logger.error("Failed to send catalog create event to callback URL: {}", url, e);
        }
    }

@@ -104,8 +105,8 @@ public class CatalogCallbackService {
     * @param event The catalog delete event
     */
    private void sendCatalogDeleteEventToCallback(String callbackUrl, CatalogDeleteEvent event) {
        try {
        String url = buildCallbackUrl(callbackUrl, "/listener/catalogDeleteEvent");
        try {
            
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
@@ -118,7 +119,7 @@ public class CatalogCallbackService {
                url, response.getStatusCode());
            
        } catch (Exception e) {
            logger.error("Failed to send catalog delete event to callback URL: {}", callbackUrl, e);
            logger.error("Failed to send catalog delete event to callback URL: {}", url, e);
        }
    }

+9 −5
Original line number Diff line number Diff line
@@ -156,6 +156,15 @@ public class ProductCategoryRepoService {
		
		Category categoryToDelete = optionalCat.get();
		
		// Trigger lazy loading of associations before deletion to avoid lazy initialization exception
		categoryToDelete.getProductOfferingObj().size(); // This will initialize the lazy collection
		categoryToDelete.getCategoryObj().size(); // This will initialize the lazy collection
		
		// Publish category delete notification BEFORE deletion to ensure session is still active
		if (categoryNotificationService != null) {
			categoryNotificationService.publishCategoryDeleteNotification(categoryToDelete);
		}
		
		if ( categoryToDelete.getParentId() != null ) {
			Category parentCat = (this.categsRepo.findByUuid( categoryToDelete.getParentId() )).get();
			
@@ -171,11 +180,6 @@ public class ProductCategoryRepoService {
		
		this.categsRepo.delete( categoryToDelete);
		
		// Publish category delete notification
		if (categoryNotificationService != null) {
			categoryNotificationService.publishCategoryDeleteNotification(categoryToDelete);
		}
		
		return true;
		
	}
Loading