Commit 1347e4e4 authored by Kostis Trantzas's avatar Kostis Trantzas
Browse files

Merge branch 'develop' into '91-range-interval-type-validation'

# Conflicts:
#   src/main/java/org/etsi/osl/tmf/util/ServiceSpecificationValidator.java
parents 46abeb8e 42afcc30
Loading
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
 */
package org.etsi.osl.tmf.pim637.api;

import org.etsi.osl.tmf.pim637.model.Error;
import org.etsi.osl.tmf.pim637.model.EventSubscription;
import org.etsi.osl.tmf.pim637.model.EventSubscriptionInput;
import org.springframework.http.ResponseEntity;
+0 −1
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
 */
package org.etsi.osl.tmf.pim637.api;

import org.etsi.osl.tmf.pim637.model.Error;
import org.etsi.osl.tmf.pim637.model.EventSubscription;
import org.etsi.osl.tmf.pim637.model.ProductAttributeValueChangeEvent;
import org.etsi.osl.tmf.pim637.model.ProductBatchEvent;
+0 −1
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@
package org.etsi.osl.tmf.pim637.api;

import java.util.List;
import org.etsi.osl.tmf.pim637.model.Error;
import org.etsi.osl.tmf.pim637.model.Product;
import org.etsi.osl.tmf.pim637.model.ProductCreate;
import org.etsi.osl.tmf.pim637.model.ProductUpdate;
+13 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ package org.etsi.osl.tmf.scm633.api;
import org.etsi.osl.tmf.scm633.model.EventSubscription;
import org.etsi.osl.tmf.scm633.model.EventSubscriptionInput;
import org.springframework.http.ResponseEntity;
import java.util.List;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -74,4 +75,16 @@ public interface HubApi {
        method = RequestMethod.DELETE)
    ResponseEntity<Void> unregisterListener(@Parameter(description = "The id of the registered listener",required=true) @PathVariable("id") String id);

    @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)
    ResponseEntity<List<EventSubscription>> getListeners();

}
+48 −12
Original line number Diff line number Diff line
@@ -20,18 +20,24 @@
package org.etsi.osl.tmf.scm633.api;

import java.io.IOException;
import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.etsi.osl.tmf.scm633.model.EventSubscription;
import org.etsi.osl.tmf.scm633.model.EventSubscriptionInput;
import org.etsi.osl.tmf.scm633.reposervices.EventSubscriptionRepoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
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;
import jakarta.validation.Valid;
@@ -47,29 +53,59 @@ public class HubApiController implements HubApi {

    private final HttpServletRequest request;
    
    @Autowired
    @Qualifier("scm633EventSubscriptionRepoService")
    EventSubscriptionRepoService eventSubscriptionRepoService;

    @org.springframework.beans.factory.annotation.Autowired
    public HubApiController(ObjectMapper objectMapper, HttpServletRequest request) {
        this.objectMapper = objectMapper;
        this.request = request;
    }

    @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) {
        String accept = request.getHeader("Accept");
        if (accept != null && accept.contains("application/json")) {
        try {
                return new ResponseEntity<EventSubscription>(objectMapper.readValue("{  \"query\" : \"query\",  \"callback\" : \"callback\",  \"id\" : \"id\"}", EventSubscription.class), HttpStatus.NOT_IMPLEMENTED);
            } catch (IOException e) {
                log.error("Couldn't serialize response for content type application/json", e);
                return new ResponseEntity<EventSubscription>(HttpStatus.INTERNAL_SERVER_ERROR);
            EventSubscription eventSubscription = eventSubscriptionRepoService.addEventSubscription(data);
            return new ResponseEntity<>(eventSubscription, HttpStatus.CREATED);
        } catch (IllegalArgumentException e) {
            log.error("Invalid input for listener registration: {}", e.getMessage());
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        } catch (Exception e) {
            log.error("Error registering listener", e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

        return new ResponseEntity<EventSubscription>(HttpStatus.NOT_IMPLEMENTED);
    @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);
            if (existing == null) {
                return new ResponseEntity<>(HttpStatus.NOT_FOUND);
            }
            
    public ResponseEntity<Void> unregisterListener(@Parameter(description = "The id of the registered listener",required=true) @PathVariable("id") String id) {
        String accept = request.getHeader("Accept");
        return new ResponseEntity<Void>(HttpStatus.NOT_IMPLEMENTED);
            eventSubscriptionRepoService.deleteById(id);
            return new ResponseEntity<>(HttpStatus.NO_CONTENT);
        } catch (Exception e) {
            log.error("Error unregistering listener with id: " + id, e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

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

}
Loading