From 8f43a2a05a01478952a19a01b9745bc72094fde4 Mon Sep 17 00:00:00 2001 From: lpapadopoulos Date: Fri, 29 Mar 2024 17:00:44 +0200 Subject: [PATCH 1/9] tmf 674 Rest API implementation --- .../api/GeographicSiteManagementApi.java | 187 ++++++++++++++++++ ...GeographicSiteManagementApiController.java | 12 ++ .../GeographicSiteManagementRepository.java | 13 ++ .../GeographicSiteManagementService.java | 7 + 4 files changed, 219 insertions(+) create mode 100644 src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java create mode 100644 src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java create mode 100644 src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java create mode 100644 src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java new file mode 100644 index 0000000..7f54dec --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java @@ -0,0 +1,187 @@ +package org.etsi.osl.tmf.gsm674.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; + +import org.etsi.osl.tmf.gsm674.model.GeographicSite; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +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 org.springframework.web.bind.annotation.RequestParam; + +import java.io.IOException; +import java.util.List; +import java.util.Optional; + +public interface GeographicSiteManagementApi { + Logger log = LoggerFactory.getLogger(GeographicSiteManagementApi.class); + + default Optional getObjectMapper() { + return Optional.empty(); + } + + default Optional getRequest() { + return Optional.empty(); + } + + default Optional getAcceptHeader() { + return getRequest().map(r -> r.getHeader("Accept")); + } + + @Operation(summary = "Creates a 'GeographicSite'", operationId = "createGeographicSite", description = "", tags={ "geographicSite", }) + @ApiResponses(value = { + @ApiResponse(responseCode = "400", description = "Created" ), + @ApiResponse(responseCode = "400", description = "Bad Request" ), + @ApiResponse(responseCode = "401", description = "Unauthorized" ), + @ApiResponse(responseCode = "403", description = "Forbidden" ), + @ApiResponse(responseCode = "404", description = "Not Found" ), + @ApiResponse(responseCode = "405", description = "Method Not allowed" ), + @ApiResponse(responseCode = "409", description = "Conflict" ), + @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) + @RequestMapping(value = "/geographicSite", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.POST) + default ResponseEntity createGeographicSite(@Parameter(description = "The geographic site to be created" ,required=true ) @Valid @RequestBody GeographicSite geographicSite) { + if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getAcceptHeader().get().contains("application/json")) { + try { + return new ResponseEntity<>(getObjectMapper().get().readValue("{ \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}", GeographicSite.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 GeographicSiteManagementApi interface so no example is generated"); + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + + @Operation(summary = "Deletes a 'GeographicSite' by Id", operationId = "deleteGeographicSite", description = "", tags={ "GeographicSite", }) + @ApiResponses(value = { + @ApiResponse(responseCode = "204", description = "Deleted" ), + @ApiResponse(responseCode = "400", description = "Bad Request" ), + @ApiResponse(responseCode = "401", description = "Unauthorized" ), + @ApiResponse(responseCode = "403", description = "Forbidden" ), + @ApiResponse(responseCode = "404", description = "Not Found" ), + @ApiResponse(responseCode = "405", description = "Method Not allowed" ), + @ApiResponse(responseCode = "409", description = "Conflict" ), + @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) + @RequestMapping(value = "/geographicSite/{id}", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.DELETE) + default ResponseEntity deleteGeographicSite(@Parameter(description = "Identifier of the Geographic site",required=true) @PathVariable("id") String id) { + if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + } else { + log.warn("ObjectMapper or HttpServletRequest not configured in default GeographicSiteManagementApi interface so no example is generated"); + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + + @Operation(summary = "List or find 'GeographicSite' objects", operationId = "listGeographicSite", description = "" , tags={ "GeographicSite", }) + @ApiResponses(value = { + @ApiResponse(responseCode ="200", description = "Ok" ), + @ApiResponse(responseCode = "400", description = "Bad Request" ), + @ApiResponse(responseCode = "401", description = "Unauthorized" ), + @ApiResponse(responseCode = "403", description = "Forbidden" ), + @ApiResponse(responseCode = "404", description = "Not Found" ), + @ApiResponse(responseCode = "405", description = "Method Not allowed" ), + @ApiResponse(responseCode = "409", description = "Conflict" ), + @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) + @RequestMapping(value = "/geographicSite", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.GET) + default ResponseEntity> listGeographicSite(@Parameter(description = "Comma separated properties to display in response") @Valid @RequestParam(value = "fields", required = false) String fields, @Parameter(description = "Requested index for start of resources to be provided in response") @Valid @RequestParam(value = "offset", required = false) Integer offset, @Parameter(description = "Requested number of resources to be provided in response") @Valid @RequestParam(value = "limit", required = false) Integer limit) { + if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getAcceptHeader().get().contains("application/json")) { + try { + return new ResponseEntity<>(getObjectMapper().get().readValue("[ { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}, { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"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 GeographicSiteManagementApi interface so no example is generated"); + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + + @Operation(summary = "Updates partially a 'GeographicSite' by Id", operationId = "patchGeographicSite", description = "", tags={ "GeographicSite", }) + @ApiResponses(value = { + @ApiResponse(responseCode ="200", description = "Updated" ), + @ApiResponse(responseCode = "400", description = "Bad Request" ), + @ApiResponse(responseCode = "401", description = "Unauthorized" ), + @ApiResponse(responseCode = "403", description = "Forbidden" ), + @ApiResponse(responseCode = "404", description = "Not Found" ), + @ApiResponse(responseCode = "405", description = "Method Not allowed" ), + @ApiResponse(responseCode = "409", description = "Conflict" ), + @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) + @RequestMapping(value = "/geographicSite/{id}", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.PATCH) + default ResponseEntity patchGeographicSite(@Parameter(description = "Identifier of the Geographic site",required=true) @PathVariable("id") String id,@Parameter(description = "The Service Level Specification to be updated" ,required=true ) @Valid @RequestBody GeographicSite geographicSite) { + if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getAcceptHeader().get().contains("application/json")) { + try { + return new ResponseEntity<>(getObjectMapper().get().readValue("{ \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}", GeographicSite.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 GeographicSiteManagementApi interface so no example is generated"); + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + + @Operation(summary = "Retrieves a 'GeographicSite' by Id", operationId = "retrieveGeographicSite", description = "" , tags={ "GeographicSite", }) + @ApiResponses(value = { + @ApiResponse(responseCode ="200", description = "Ok" ), + @ApiResponse(responseCode = "400", description = "Bad Request" ), + @ApiResponse(responseCode = "401", description = "Unauthorized" ), + @ApiResponse(responseCode = "403", description = "Forbidden" ), + @ApiResponse(responseCode = "404", description = "Not Found" ), + @ApiResponse(responseCode = "405", description = "Method Not allowed" ), + @ApiResponse(responseCode = "409", description = "Conflict" ), + @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) + @RequestMapping(value = "/geographicSite/{id}", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.GET) + default ResponseEntity> retrieveGeographicSite(@Parameter(description = "Identifier geographic site",required=true) @PathVariable("id") String id) { + if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getAcceptHeader().get().contains("application/json")) { + try { + return new ResponseEntity<>(getObjectMapper().get().readValue("[ { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}, { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"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 GeographicSiteManagementApi interface so no example is generated"); + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + +} diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java new file mode 100644 index 0000000..58a5654 --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java @@ -0,0 +1,12 @@ +package org.etsi.osl.tmf.gsm674.api; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping("/geographicSiteManagement/v4/") +public class GeographicSiteManagementApiController implements GeographicSiteManagementApi{ + + + +} diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java b/src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java new file mode 100644 index 0000000..4b2a3ab --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java @@ -0,0 +1,13 @@ +package org.etsi.osl.tmf.gsm674.repo; + +import org.etsi.osl.tmf.gsm674.model.GeographicSite; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface GeographicSiteManagementRepository extends CrudRepository, PagingAndSortingRepository { + Optional findByUuid(String id); +} diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java b/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java new file mode 100644 index 0000000..86f72f8 --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java @@ -0,0 +1,7 @@ +package org.etsi.osl.tmf.gsm674.reposervices; + +import org.springframework.stereotype.Service; + +@Service +public class GeographicSiteManagementService { +} -- GitLab From 0ea8555d59d67366f28c379d966c957ea5b5bb81 Mon Sep 17 00:00:00 2001 From: lpapadopoulos Date: Tue, 2 Apr 2024 19:18:44 +0300 Subject: [PATCH 2/9] tmf 674 Rest API implementation --- .../api/GeographicSiteManagementApi.java | 65 ++++++++-------- ...GeographicSiteManagementApiController.java | 75 +++++++++++++++++++ .../GeographicSiteManagementRepository.java | 2 + .../GeographicSiteManagementService.java | 52 +++++++++++++ 4 files changed, 162 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java index 7f54dec..86fc977 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java @@ -13,6 +13,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import java.io.IOException; +import java.security.Principal; import java.util.List; import java.util.Optional; @@ -68,7 +70,6 @@ public interface GeographicSiteManagementApi { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } - @Operation(summary = "Deletes a 'GeographicSite' by Id", operationId = "deleteGeographicSite", description = "", tags={ "GeographicSite", }) @ApiResponses(value = { @ApiResponse(responseCode = "204", description = "Deleted" ), @@ -92,35 +93,35 @@ public interface GeographicSiteManagementApi { } - @Operation(summary = "List or find 'GeographicSite' objects", operationId = "listGeographicSite", description = "" , tags={ "GeographicSite", }) - @ApiResponses(value = { - @ApiResponse(responseCode ="200", description = "Ok" ), - @ApiResponse(responseCode = "400", description = "Bad Request" ), - @ApiResponse(responseCode = "401", description = "Unauthorized" ), - @ApiResponse(responseCode = "403", description = "Forbidden" ), - @ApiResponse(responseCode = "404", description = "Not Found" ), - @ApiResponse(responseCode = "405", description = "Method Not allowed" ), - @ApiResponse(responseCode = "409", description = "Conflict" ), - @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicSite", - produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.GET) - default ResponseEntity> listGeographicSite(@Parameter(description = "Comma separated properties to display in response") @Valid @RequestParam(value = "fields", required = false) String fields, @Parameter(description = "Requested index for start of resources to be provided in response") @Valid @RequestParam(value = "offset", required = false) Integer offset, @Parameter(description = "Requested number of resources to be provided in response") @Valid @RequestParam(value = "limit", required = false) Integer limit) { - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { - if (getAcceptHeader().get().contains("application/json")) { - try { - return new ResponseEntity<>(getObjectMapper().get().readValue("[ { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}, { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"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 GeographicSiteManagementApi interface so no example is generated"); - } - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } +// @Operation(summary = "List or find 'GeographicSite' objects", operationId = "listGeographicSite", description = "" , tags={ "GeographicSite", }) +// @ApiResponses(value = { +// @ApiResponse(responseCode ="200", description = "Ok" ), +// @ApiResponse(responseCode = "400", description = "Bad Request" ), +// @ApiResponse(responseCode = "401", description = "Unauthorized" ), +// @ApiResponse(responseCode = "403", description = "Forbidden" ), +// @ApiResponse(responseCode = "404", description = "Not Found" ), +// @ApiResponse(responseCode = "405", description = "Method Not allowed" ), +// @ApiResponse(responseCode = "409", description = "Conflict" ), +// @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) +// @RequestMapping(value = "/geographicSite", +// produces = { "application/json" }, +// consumes = { "application/json" }, +// method = RequestMethod.GET) +// default ResponseEntity> listGeographicSite(@Parameter(description = "Comma separated properties to display in response") @Valid @RequestParam(value = "fields", required = false) String fields, @Parameter(description = "Requested index for start of resources to be provided in response") @Valid @RequestParam(value = "offset", required = false) Integer offset, @Parameter(description = "Requested number of resources to be provided in response") @Valid @RequestParam(value = "limit", required = false) Integer limit) { +// if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { +// if (getAcceptHeader().get().contains("application/json")) { +// try { +// return new ResponseEntity<>(getObjectMapper().get().readValue("[ { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}, { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"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 GeographicSiteManagementApi interface so no example is generated"); +// } +// return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); +// } @Operation(summary = "Updates partially a 'GeographicSite' by Id", operationId = "patchGeographicSite", description = "", tags={ "GeographicSite", }) @@ -137,7 +138,7 @@ public interface GeographicSiteManagementApi { produces = { "application/json" }, consumes = { "application/json" }, method = RequestMethod.PATCH) - default ResponseEntity patchGeographicSite(@Parameter(description = "Identifier of the Geographic site",required=true) @PathVariable("id") String id,@Parameter(description = "The Service Level Specification to be updated" ,required=true ) @Valid @RequestBody GeographicSite geographicSite) { + default ResponseEntity patchGeographicalSite(@Parameter(description = "Identifier of the Geographic site",required=true) @PathVariable("id") String id,@Parameter(description = "The Service Level Specification to be updated" ,required=true ) @Valid @RequestBody GeographicSite geographicSite) { if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { if (getAcceptHeader().get().contains("application/json")) { try { @@ -168,7 +169,7 @@ public interface GeographicSiteManagementApi { produces = { "application/json" }, consumes = { "application/json" }, method = RequestMethod.GET) - default ResponseEntity> retrieveGeographicSite(@Parameter(description = "Identifier geographic site",required=true) @PathVariable("id") String id) { + default ResponseEntity> retrieveGeographicSite() { if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { if (getAcceptHeader().get().contains("application/json")) { try { diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java index 58a5654..1237d8e 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java @@ -1,12 +1,87 @@ package org.etsi.osl.tmf.gsm674.api; +import io.swagger.v3.oas.annotations.Parameter; +import jakarta.validation.Valid; +import org.etsi.osl.tmf.gsm674.model.GeographicSite; +import org.etsi.osl.tmf.gsm674.reposervices.GeographicSiteManagementService; +import org.springframework.beans.factory.annotation.Autowired; +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 java.util.List; + @Controller @RequestMapping("/geographicSiteManagement/v4/") public class GeographicSiteManagementApiController implements GeographicSiteManagementApi{ + private static final String COULD_NOT_SERIALIZE="Couldn't serialize response for content type application/json"; + private final GeographicSiteManagementService geographicSiteManagementService; + + @Autowired + public GeographicSiteManagementApiController(GeographicSiteManagementService geographicSiteManagementService) { + this.geographicSiteManagementService = geographicSiteManagementService; + } + + @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) + @Override + public ResponseEntity> retrieveGeographicSite() { + + + try { + return new ResponseEntity<>(geographicSiteManagementService.findAllGeographicSites(), HttpStatus.OK); + + } catch (Exception e) { + log.error(COULD_NOT_SERIALIZE, e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) + @Override + public ResponseEntity createGeographicSite( + @Parameter(description = "The geographic site to be created", required = true) @Valid @RequestBody GeographicSite geographicSite + ) { + + try { + + GeographicSite c = geographicSiteManagementService.createGeographicSite(geographicSite); + + return new ResponseEntity<>(c, HttpStatus.OK); + + + } catch (Exception e) { + log.error(COULD_NOT_SERIALIZE, e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) + @Override + public ResponseEntity deleteGeographicSite( + @Parameter(description = "Identifier of the geographic site", required = true) @PathVariable("id") String id) { + + try { + return new ResponseEntity<>(geographicSiteManagementService.deleteGeographicSiteById(id), HttpStatus.OK); + }catch (Exception e) { + log.error(COULD_NOT_SERIALIZE, e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + + } + + @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) + @Override + public ResponseEntity patchGeographicalSite( + @Parameter(description = "Identifier of the ServiceOrder", required = true) @PathVariable("id") String id, + @Parameter(description = "The ServiceOrder to be updated", required = true) @Valid @RequestBody GeographicSite geographicSite) { + GeographicSite c = geographicSiteManagementService.updateGeographicSite(id, geographicSite); + return new ResponseEntity<>(c, HttpStatus.OK); + } } diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java b/src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java index 4b2a3ab..a48f344 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java @@ -5,9 +5,11 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository public interface GeographicSiteManagementRepository extends CrudRepository, PagingAndSortingRepository { Optional findByUuid(String id); + } diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java b/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java index 86f72f8..3a39668 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java @@ -1,7 +1,59 @@ package org.etsi.osl.tmf.gsm674.reposervices; +import org.etsi.osl.tmf.gsm674.model.GeographicSite; +import org.etsi.osl.tmf.gsm674.repo.GeographicSiteManagementRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Optional; @Service +@Transactional public class GeographicSiteManagementService { + private static final Logger log = LoggerFactory.getLogger(GeographicSiteManagementService.class); + + + private final GeographicSiteManagementRepository geographicSiteManagementRepository; + + @Autowired + public GeographicSiteManagementService(GeographicSiteManagementRepository geographicSiteManagementRepository) { + this.geographicSiteManagementRepository = geographicSiteManagementRepository; + } + + public List findAllGeographicSites(){ + return (List) geographicSiteManagementRepository.findAll(); + } + + public Optional findGeographicSiteByUUID(String uuid){ + return geographicSiteManagementRepository.findByUuid(uuid); + } + + public GeographicSite createGeographicSite(GeographicSite geographicSite){ + log.info("Add another geographic site: {}",geographicSite); + return geographicSiteManagementRepository.save(geographicSite); + + } + + public GeographicSite updateGeographicSite(String id,GeographicSite geographicSite){ + Optional gs=geographicSiteManagementRepository.findByUuid(id); + return gs.map(site -> updateFields(geographicSite, site)).orElse(null); + } + + public Void deleteGeographicSiteById(String id){ + GeographicSite gs=geographicSiteManagementRepository.findByUuid(id).orElseThrow(); + geographicSiteManagementRepository.delete(gs); + return null; + } + + private GeographicSite updateFields(GeographicSite newSite, GeographicSite existingSite){ + + + geographicSiteManagementRepository.save(existingSite); + return existingSite; + } + } -- GitLab From aa5fc8dea9a3d0f34533aeefed108981e04f4399 Mon Sep 17 00:00:00 2001 From: lpapadopoulos Date: Thu, 4 Apr 2024 18:31:33 +0300 Subject: [PATCH 3/9] tmf 674 Implementation + tests --- .../etsi/osl/tmf/gsm674/api/Generated.java | 16 +++ .../api/GeographicSiteManagementApi.java | 1 + ...GeographicSiteManagementApiController.java | 5 + .../GeographicSiteManagementRepository.java | 1 - .../GeographicSiteManagementService.java | 43 +++++- ...raphicSiteManagementApiControllerTest.java | 127 ++++++++++++++++++ .../GeographicSiteManagementServiceTest.java | 97 +++++++++++++ 7 files changed, 288 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/etsi/osl/tmf/gsm674/api/Generated.java create mode 100644 src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementServiceTest.java diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/Generated.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/Generated.java new file mode 100644 index 0000000..92fbaec --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/Generated.java @@ -0,0 +1,16 @@ +package org.etsi.osl.tmf.gsm674.api; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Documented +@Retention(RUNTIME) +@Target({TYPE, METHOD, CONSTRUCTOR}) +public @interface Generated { +} diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java index 86fc977..f87c25b 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java @@ -25,6 +25,7 @@ import java.security.Principal; import java.util.List; import java.util.Optional; +@Generated public interface GeographicSiteManagementApi { Logger log = LoggerFactory.getLogger(GeographicSiteManagementApi.class); diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java index 1237d8e..479a58f 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java @@ -80,8 +80,13 @@ public class GeographicSiteManagementApiController implements GeographicSiteMana public ResponseEntity patchGeographicalSite( @Parameter(description = "Identifier of the ServiceOrder", required = true) @PathVariable("id") String id, @Parameter(description = "The ServiceOrder to be updated", required = true) @Valid @RequestBody GeographicSite geographicSite) { + try{ GeographicSite c = geographicSiteManagementService.updateGeographicSite(id, geographicSite); return new ResponseEntity<>(c, HttpStatus.OK); + }catch (Exception e){ + log.error(COULD_NOT_SERIALIZE, e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } } } diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java b/src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java index a48f344..c65f209 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/repo/GeographicSiteManagementRepository.java @@ -5,7 +5,6 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; -import java.util.List; import java.util.Optional; @Repository diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java b/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java index 3a39668..68a3ead 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java @@ -1,7 +1,11 @@ package org.etsi.osl.tmf.gsm674.reposervices; +import org.etsi.osl.tmf.gsm674.model.CalendarPeriod; import org.etsi.osl.tmf.gsm674.model.GeographicSite; +import org.etsi.osl.tmf.gsm674.model.GeographicSiteRelationship; +import org.etsi.osl.tmf.gsm674.model.PlaceRefOrValue; import org.etsi.osl.tmf.gsm674.repo.GeographicSiteManagementRepository; +import org.etsi.osl.tmf.prm669.model.RelatedParty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -16,7 +20,6 @@ import java.util.Optional; public class GeographicSiteManagementService { private static final Logger log = LoggerFactory.getLogger(GeographicSiteManagementService.class); - private final GeographicSiteManagementRepository geographicSiteManagementRepository; @Autowired @@ -39,11 +42,13 @@ public class GeographicSiteManagementService { } public GeographicSite updateGeographicSite(String id,GeographicSite geographicSite){ + log.info("Update geographic site with id: {}",id); Optional gs=geographicSiteManagementRepository.findByUuid(id); return gs.map(site -> updateFields(geographicSite, site)).orElse(null); } public Void deleteGeographicSiteById(String id){ + log.info("Delete geographic site with id: {}",id); GeographicSite gs=geographicSiteManagementRepository.findByUuid(id).orElseThrow(); geographicSiteManagementRepository.delete(gs); return null; @@ -51,6 +56,42 @@ public class GeographicSiteManagementService { private GeographicSite updateFields(GeographicSite newSite, GeographicSite existingSite){ + if(newSite.getName()!=null) existingSite.setCalendar(newSite.getCalendar()); + if(newSite.getDescription()!=null) existingSite.setDescription(newSite.getDescription()); + if(newSite.getCode()!=null) existingSite.setCode(newSite.getCode()); + if (newSite.getStatus()!=null) existingSite.setStatus(newSite.getStatus()); + + if(newSite.getGeographicSiteRelationship()!=null){ + for(GeographicSiteRelationship n : newSite.getGeographicSiteRelationship()){ + if(n.getUuid()==null){ + existingSite.addGeographicSiteRelationship(n); + } + } + } + + if(newSite.getCalendar()!=null){ + for(CalendarPeriod c: newSite.getCalendar()){ + if(c.getUuid()==null){ + existingSite.addCalendarPeriod(c); + } + } + } + + if(newSite.getPlaceRefOrValue()!=null){ + for(PlaceRefOrValue p: newSite.getPlaceRefOrValue()){ + if (p.getUuid()==null){ + existingSite.addPlaceRefOrValue(p); + } + } + } + + if(newSite.getRelatedParties()!=null){ + for(RelatedParty party: newSite.getRelatedParties()){ + if(party.getUuid()==null){ + existingSite.addRelatedParty(party); + } + } + } geographicSiteManagementRepository.save(existingSite); return existingSite; diff --git a/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java new file mode 100644 index 0000000..fe22f9b --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java @@ -0,0 +1,127 @@ +package org.etsi.osl.services.api.gsm674; + +import org.etsi.osl.tmf.gsm674.api.GeographicSiteManagementApiController; +import org.etsi.osl.tmf.gsm674.model.GeographicSite; +import org.etsi.osl.tmf.gsm674.reposervices.GeographicSiteManagementService; +import org.junit.jupiter.api.BeforeEach; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.test.context.ActiveProfiles; + +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.when; + +@AutoConfigureMockMvc +@ActiveProfiles("testing") +class GeographicSiteManagementApiControllerTest { + + @InjectMocks + private GeographicSiteManagementApiController controller; + + @Mock + private GeographicSiteManagementService service; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + } + + @Test + void testRetrieveGeographicSite() { + List sites = new ArrayList<>(); + // Add test data to sites list + when(service.findAllGeographicSites()).thenReturn(sites); + + ResponseEntity> response = controller.retrieveGeographicSite(); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(sites, response.getBody()); + } + + @Test + void throwExceptionTestWhenRetrieveGeographicSites(){ + when(service.findAllGeographicSites()).thenThrow(RuntimeException.class); + ResponseEntity> response = controller.retrieveGeographicSite(); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + + } + @Test + void testCreateGeographicSite() { + GeographicSite site = new GeographicSite(); + + when(service.createGeographicSite(any())).thenReturn(site); + + ResponseEntity response = controller.createGeographicSite(site); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(site, response.getBody()); + } + + @Test + void testExceptionWhenCreateGeographicSite(){ + GeographicSite site = new GeographicSite(); + + when(service.createGeographicSite(any())).thenThrow(RuntimeException.class); + + ResponseEntity response = controller.createGeographicSite(site); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + } + + @Test + void testDeleteGeographicSite() { + + doNothing().when(service).deleteGeographicSiteById(anyString()); + ResponseEntity response = controller.deleteGeographicSite("siteId"); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + } + + @Test + void testDeleteGeographicSiteException() { + + doThrow(RuntimeException.class).when(service).deleteGeographicSiteById(anyString()); + ResponseEntity response = controller.deleteGeographicSite("siteId"); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + } + + @Test + void testPatchGeographicalSite() { + String siteId = "siteId"; + GeographicSite updatedSite = new GeographicSite(); + // Set up mock service behavior + when(service.updateGeographicSite(anyString(), any())).thenReturn(updatedSite); + + ResponseEntity response = controller.patchGeographicalSite(siteId, updatedSite); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(updatedSite, response.getBody()); + } + + @Test + void testPatchGeographicalSiteException() { + String siteId = "siteId"; + GeographicSite updatedSite = new GeographicSite(); + // Set up mock service behavior + when(service.updateGeographicSite(anyString(), any())).thenThrow(RuntimeException.class); + + ResponseEntity response = controller.patchGeographicalSite(siteId, updatedSite); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + } + +} diff --git a/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementServiceTest.java b/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementServiceTest.java new file mode 100644 index 0000000..7c7952d --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementServiceTest.java @@ -0,0 +1,97 @@ +package org.etsi.osl.services.api.gsm674; +import org.etsi.osl.tmf.gsm674.model.GeographicSite; +import org.etsi.osl.tmf.gsm674.repo.GeographicSiteManagementRepository; +import org.etsi.osl.tmf.gsm674.reposervices.GeographicSiteManagementService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.test.context.ActiveProfiles; + +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + +@AutoConfigureMockMvc +@ActiveProfiles("testing") +class GeographicSiteManagementServiceTest { + @InjectMocks + private GeographicSiteManagementService service; + + @Mock + private GeographicSiteManagementRepository repository; + + @BeforeEach + void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + void testFindAllGeographicSites() { + // Mock data + List sites = List.of(new GeographicSite(), new GeographicSite()); + when(repository.findAll()).thenReturn(sites); + + List result = service.findAllGeographicSites(); + + assertEquals(sites, result); + } + + @Test + void testFindGeographicSiteByUUID() { + // Mock data + String uuid = "123"; + GeographicSite site = new GeographicSite(); + when(repository.findByUuid(uuid)).thenReturn(Optional.of(site)); + + Optional result = service.findGeographicSiteByUUID(uuid); + + assertTrue(result.isPresent()); + assertEquals(site, result.get()); + } + + @Test + void testCreateGeographicSite() { + // Mock data + GeographicSite site = new GeographicSite(); + when(repository.save(any())).thenReturn(site); + + GeographicSite result = service.createGeographicSite(site); + + assertEquals(site, result); + } + + @Test + void testUpdateGeographicSite() { + // Mock data + String id = "123"; + GeographicSite existingSite = new GeographicSite(); + GeographicSite newSite = new GeographicSite(); + when(repository.findByUuid(id)).thenReturn(Optional.of(existingSite)); + when(repository.save(any())).thenReturn(existingSite); + + GeographicSite result = service.updateGeographicSite(id, newSite); + + assertNotNull(result); + assertEquals(existingSite, result); + // Add additional assertions for updated fields if needed + } + + @Test + void testDeleteGeographicSiteById() { + // Mock data + String id = "123"; + GeographicSite existingSite = new GeographicSite(); + when(repository.findByUuid(id)).thenReturn(Optional.of(existingSite)); + + Void result = service.deleteGeographicSiteById(id); + + assertNull(result); + verify(repository, times(1)).delete(existingSite); + } +} -- GitLab From f8bd166db2f4e1157323d7b055ea7e1d47724ed3 Mon Sep 17 00:00:00 2001 From: lpapadopoulos Date: Mon, 8 Apr 2024 13:09:12 +0300 Subject: [PATCH 4/9] tmf 674 swagger config --- .../SwaggerDocumentationConfig.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/etsi/osl/tmf/configuration/SwaggerDocumentationConfig.java b/src/main/java/org/etsi/osl/tmf/configuration/SwaggerDocumentationConfig.java index ea00cc6..9cd05ca 100644 --- a/src/main/java/org/etsi/osl/tmf/configuration/SwaggerDocumentationConfig.java +++ b/src/main/java/org/etsi/osl/tmf/configuration/SwaggerDocumentationConfig.java @@ -728,7 +728,41 @@ public class SwaggerDocumentationConfig { .build(); } - + /** + * TMF 674 Geographic Site Management + * @return + */ + + + @Bean + public OpenApiCustomizer gsm674OpenAPI() { + return openApi -> openApi + .specVersion( SpecVersion.V30 ).addSecurityItem(new SecurityRequirement().addList("security_auth")) + .info(new Info() + .title("TMF 674 Geographic Site Management") + .description("## TMF API Reference: TMF674 - Geographic Site Management ### Release : 20.0 - April 2020 ") + .version("4.0.0") + .license(new License() + .name("Apache 2.0") + .url("http://openslice.io"))) + .externalDocs(new ExternalDocumentation() + .description("TMF API Tables") + .url("https://www.tmforum.org/oda/open-apis/table")); + } + + @Bean + public GroupedOpenApi gsm674(){ + + SpringDocUtils.getConfig().replaceWithClass(java.time.LocalDate.class, java.sql.Date.class); + SpringDocUtils.getConfig().replaceWithClass(java.time.OffsetDateTime.class, java.util.Date.class); + + return GroupedOpenApi.builder() + .group("tmf-api-674-Geographic Site Management-v4.0.0") + .addOpenApiCustomizer( this.stm653OpenAPI() ) + .packagesToScan("org.etsi.osl.tmf.gsm674.api") + .build(); + + } /** -- GitLab From 9cc88ab16859745ad0458960dfd82648b610f256 Mon Sep 17 00:00:00 2001 From: lpapadopoulos Date: Mon, 8 Apr 2024 15:31:16 +0300 Subject: [PATCH 5/9] tmf 674 api fixes --- .../api/GeographicSiteManagementApi.java | 62 +++++++++---------- ...GeographicSiteManagementApiController.java | 4 +- ...raphicSiteManagementApiControllerTest.java | 8 +-- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java index f87c25b..c2661e8 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java @@ -94,35 +94,35 @@ public interface GeographicSiteManagementApi { } -// @Operation(summary = "List or find 'GeographicSite' objects", operationId = "listGeographicSite", description = "" , tags={ "GeographicSite", }) -// @ApiResponses(value = { -// @ApiResponse(responseCode ="200", description = "Ok" ), -// @ApiResponse(responseCode = "400", description = "Bad Request" ), -// @ApiResponse(responseCode = "401", description = "Unauthorized" ), -// @ApiResponse(responseCode = "403", description = "Forbidden" ), -// @ApiResponse(responseCode = "404", description = "Not Found" ), -// @ApiResponse(responseCode = "405", description = "Method Not allowed" ), -// @ApiResponse(responseCode = "409", description = "Conflict" ), -// @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) -// @RequestMapping(value = "/geographicSite", -// produces = { "application/json" }, -// consumes = { "application/json" }, -// method = RequestMethod.GET) -// default ResponseEntity> listGeographicSite(@Parameter(description = "Comma separated properties to display in response") @Valid @RequestParam(value = "fields", required = false) String fields, @Parameter(description = "Requested index for start of resources to be provided in response") @Valid @RequestParam(value = "offset", required = false) Integer offset, @Parameter(description = "Requested number of resources to be provided in response") @Valid @RequestParam(value = "limit", required = false) Integer limit) { -// if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { -// if (getAcceptHeader().get().contains("application/json")) { -// try { -// return new ResponseEntity<>(getObjectMapper().get().readValue("[ { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}, { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"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 GeographicSiteManagementApi interface so no example is generated"); -// } -// return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); -// } + @Operation(summary = "List or find 'GeographicSite' objects", operationId = "listGeographicSite", description = "" , tags={ "GeographicSite", }) + @ApiResponses(value = { + @ApiResponse(responseCode ="200", description = "Ok" ), + @ApiResponse(responseCode = "400", description = "Bad Request" ), + @ApiResponse(responseCode = "401", description = "Unauthorized" ), + @ApiResponse(responseCode = "403", description = "Forbidden" ), + @ApiResponse(responseCode = "404", description = "Not Found" ), + @ApiResponse(responseCode = "405", description = "Method Not allowed" ), + @ApiResponse(responseCode = "409", description = "Conflict" ), + @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) + @RequestMapping(value = "/geographicSite", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.GET) + default ResponseEntity> listGeographicSite() { + if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getAcceptHeader().get().contains("application/json")) { + try { + return new ResponseEntity<>(getObjectMapper().get().readValue("[ { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}, { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"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 GeographicSiteManagementApi interface so no example is generated"); + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } @Operation(summary = "Updates partially a 'GeographicSite' by Id", operationId = "patchGeographicSite", description = "", tags={ "GeographicSite", }) @@ -170,11 +170,11 @@ public interface GeographicSiteManagementApi { produces = { "application/json" }, consumes = { "application/json" }, method = RequestMethod.GET) - default ResponseEntity> retrieveGeographicSite() { + default ResponseEntity retrieveGeographicSite() { if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { if (getAcceptHeader().get().contains("application/json")) { try { - return new ResponseEntity<>(getObjectMapper().get().readValue("[ { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}, { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]} ]", List.class), HttpStatus.NOT_IMPLEMENTED); + return new ResponseEntity<>(getObjectMapper().get().readValue("[ { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}, { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]} ]", GeographicSite.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); diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java index 479a58f..fb9fade 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java @@ -27,9 +27,9 @@ public class GeographicSiteManagementApiController implements GeographicSiteMana this.geographicSiteManagementService = geographicSiteManagementService; } - @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) +// @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) @Override - public ResponseEntity> retrieveGeographicSite() { + public ResponseEntity> listGeographicSite() { try { diff --git a/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java index fe22f9b..cdbb474 100644 --- a/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java @@ -40,12 +40,12 @@ class GeographicSiteManagementApiControllerTest { } @Test - void testRetrieveGeographicSite() { + void testRetrieveGeographicSites() { List sites = new ArrayList<>(); // Add test data to sites list when(service.findAllGeographicSites()).thenReturn(sites); - ResponseEntity> response = controller.retrieveGeographicSite(); + ResponseEntity> response = controller.listGeographicSite(); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(sites, response.getBody()); @@ -54,8 +54,8 @@ class GeographicSiteManagementApiControllerTest { @Test void throwExceptionTestWhenRetrieveGeographicSites(){ when(service.findAllGeographicSites()).thenThrow(RuntimeException.class); - ResponseEntity> response = controller.retrieveGeographicSite(); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + ResponseEntity response = controller.retrieveGeographicSite(); + assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode()); } @Test -- GitLab From 3b7502709c487c8699ad8847c84a990e67e5b4dc Mon Sep 17 00:00:00 2001 From: lpapadopoulos Date: Tue, 9 Apr 2024 15:00:04 +0300 Subject: [PATCH 6/9] tmf 674 api enhancements + new test --- .../gsm674/api/GeographicSiteManagementApi.java | 2 +- .../GeographicSiteManagementApiController.java | 16 +++++++++++++++- .../GeographicSiteManagementService.java | 6 ++++-- ...eographicSiteManagementApiControllerTest.java | 15 +++++++++++---- .../GeographicSiteManagementServiceTest.java | 5 ++--- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java index c2661e8..c50b604 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java @@ -170,7 +170,7 @@ public interface GeographicSiteManagementApi { produces = { "application/json" }, consumes = { "application/json" }, method = RequestMethod.GET) - default ResponseEntity retrieveGeographicSite() { + default ResponseEntity retrieveGeographicSite(@Parameter(description = "Identifier of the Geographic site",required=true) @PathVariable("id") String id) { if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { if (getAcceptHeader().get().contains("application/json")) { try { diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java index fb9fade..23f1be2 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApiController.java @@ -27,7 +27,7 @@ public class GeographicSiteManagementApiController implements GeographicSiteMana this.geographicSiteManagementService = geographicSiteManagementService; } -// @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) + @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) @Override public ResponseEntity> listGeographicSite() { @@ -41,6 +41,20 @@ public class GeographicSiteManagementApiController implements GeographicSiteMana } } + @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) + @Override + public ResponseEntity retrieveGeographicSite(@PathVariable("id") String id) { + + + try { + return new ResponseEntity<>(geographicSiteManagementService.findGeographicSiteByUUID(id), HttpStatus.OK); + + } catch (Exception e) { + log.error(COULD_NOT_SERIALIZE, e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) @Override public ResponseEntity createGeographicSite( diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java b/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java index 68a3ead..3b36430 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java @@ -31,8 +31,10 @@ public class GeographicSiteManagementService { return (List) geographicSiteManagementRepository.findAll(); } - public Optional findGeographicSiteByUUID(String uuid){ - return geographicSiteManagementRepository.findByUuid(uuid); + public GeographicSite findGeographicSiteByUUID(String uuid){ + Optional gs=geographicSiteManagementRepository.findByUuid(uuid); + return gs.orElse(null); + } public GeographicSite createGeographicSite(GeographicSite geographicSite){ diff --git a/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java index cdbb474..04878fd 100644 --- a/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementApiControllerTest.java @@ -16,6 +16,8 @@ import org.springframework.http.ResponseEntity; import java.util.ArrayList; import java.util.List; +import java.util.Optional; +import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -52,12 +54,17 @@ class GeographicSiteManagementApiControllerTest { } @Test - void throwExceptionTestWhenRetrieveGeographicSites(){ - when(service.findAllGeographicSites()).thenThrow(RuntimeException.class); - ResponseEntity response = controller.retrieveGeographicSite(); - assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode()); + void testFetchGeographicSite() { + GeographicSite site = new GeographicSite(); + // Add test data to sites list + when(service.findGeographicSiteByUUID("123")).thenReturn(site); + + ResponseEntity response = controller.retrieveGeographicSite("123"); + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(site, response.getBody()); } + @Test void testCreateGeographicSite() { GeographicSite site = new GeographicSite(); diff --git a/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementServiceTest.java b/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementServiceTest.java index 7c7952d..0ffbb2c 100644 --- a/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementServiceTest.java +++ b/src/test/java/org/etsi/osl/services/api/gsm674/GeographicSiteManagementServiceTest.java @@ -49,10 +49,9 @@ class GeographicSiteManagementServiceTest { GeographicSite site = new GeographicSite(); when(repository.findByUuid(uuid)).thenReturn(Optional.of(site)); - Optional result = service.findGeographicSiteByUUID(uuid); + GeographicSite result = service.findGeographicSiteByUUID(uuid); - assertTrue(result.isPresent()); - assertEquals(site, result.get()); + assertEquals(site, result); } @Test -- GitLab From ff2646a9ae4ea64ec89a5964588b86dcc0dee4ec Mon Sep 17 00:00:00 2001 From: lpapadopoulos Date: Tue, 9 Apr 2024 17:41:24 +0300 Subject: [PATCH 7/9] refactor code --- .../SwaggerDocumentationConfig.java | 4 +- .../api/GeographicSiteManagementApi.java | 54 +------------------ 2 files changed, 3 insertions(+), 55 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/configuration/SwaggerDocumentationConfig.java b/src/main/java/org/etsi/osl/tmf/configuration/SwaggerDocumentationConfig.java index 9cd05ca..239be29 100644 --- a/src/main/java/org/etsi/osl/tmf/configuration/SwaggerDocumentationConfig.java +++ b/src/main/java/org/etsi/osl/tmf/configuration/SwaggerDocumentationConfig.java @@ -740,7 +740,7 @@ public class SwaggerDocumentationConfig { .specVersion( SpecVersion.V30 ).addSecurityItem(new SecurityRequirement().addList("security_auth")) .info(new Info() .title("TMF 674 Geographic Site Management") - .description("## TMF API Reference: TMF674 - Geographic Site Management ### Release : 20.0 - April 2020 ") + .description("## TMF API Reference: TMF674 - Geographic Site Management ") .version("4.0.0") .license(new License() .name("Apache 2.0") @@ -758,7 +758,7 @@ public class SwaggerDocumentationConfig { return GroupedOpenApi.builder() .group("tmf-api-674-Geographic Site Management-v4.0.0") - .addOpenApiCustomizer( this.stm653OpenAPI() ) + .addOpenApiCustomizer( this.gsm674OpenAPI() ) .packagesToScan("org.etsi.osl.tmf.gsm674.api") .build(); diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java index c50b604..4dc6258 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java @@ -56,18 +56,6 @@ public interface GeographicSiteManagementApi { consumes = { "application/json" }, method = RequestMethod.POST) default ResponseEntity createGeographicSite(@Parameter(description = "The geographic site to be created" ,required=true ) @Valid @RequestBody GeographicSite geographicSite) { - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { - if (getAcceptHeader().get().contains("application/json")) { - try { - return new ResponseEntity<>(getObjectMapper().get().readValue("{ \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}", GeographicSite.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 GeographicSiteManagementApi interface so no example is generated"); - } return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -86,10 +74,6 @@ public interface GeographicSiteManagementApi { consumes = { "application/json" }, method = RequestMethod.DELETE) default ResponseEntity deleteGeographicSite(@Parameter(description = "Identifier of the Geographic site",required=true) @PathVariable("id") String id) { - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { - } else { - log.warn("ObjectMapper or HttpServletRequest not configured in default GeographicSiteManagementApi interface so no example is generated"); - } return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -109,19 +93,7 @@ public interface GeographicSiteManagementApi { consumes = { "application/json" }, method = RequestMethod.GET) default ResponseEntity> listGeographicSite() { - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { - if (getAcceptHeader().get().contains("application/json")) { - try { - return new ResponseEntity<>(getObjectMapper().get().readValue("[ { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}, { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"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 GeographicSiteManagementApi interface so no example is generated"); - } - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -140,18 +112,6 @@ public interface GeographicSiteManagementApi { consumes = { "application/json" }, method = RequestMethod.PATCH) default ResponseEntity patchGeographicalSite(@Parameter(description = "Identifier of the Geographic site",required=true) @PathVariable("id") String id,@Parameter(description = "The Service Level Specification to be updated" ,required=true ) @Valid @RequestBody GeographicSite geographicSite) { - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { - if (getAcceptHeader().get().contains("application/json")) { - try { - return new ResponseEntity<>(getObjectMapper().get().readValue("{ \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}", GeographicSite.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 GeographicSiteManagementApi interface so no example is generated"); - } return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -171,18 +131,6 @@ public interface GeographicSiteManagementApi { consumes = { "application/json" }, method = RequestMethod.GET) default ResponseEntity retrieveGeographicSite(@Parameter(description = "Identifier of the Geographic site",required=true) @PathVariable("id") String id) { - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { - if (getAcceptHeader().get().contains("application/json")) { - try { - return new ResponseEntity<>(getObjectMapper().get().readValue("[ { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]}, { \"@baseType\" : \"@baseType\", \"validFor\" : { \"startDateTime\" : \"2000-01-23T04:56:07.000+00:00\", \"endDateTime\" : \"2000-01-23T04:56:07.000+00:00\" }, \"@type\" : \"@type\", \"name\" : \"name\", \"description\" : \"description\", \"href\" : \"href\", \"id\" : \"id\", \"@schemaLocation\" : \"@schemaLocation\", \"objective\" : [ { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" }, { \"@referredType\" : \"@referredType\", \"href\" : \"href\", \"id\" : \"id\" } ]} ]", GeographicSite.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 GeographicSiteManagementApi interface so no example is generated"); - } return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } -- GitLab From a5271e4ec8658a7a3363757663513f34f4427002 Mon Sep 17 00:00:00 2001 From: lpapadopoulos Date: Wed, 10 Apr 2024 12:48:41 +0300 Subject: [PATCH 8/9] remove unnecessary consumes from Request mapping --- .../etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java index 4dc6258..380afa7 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/api/GeographicSiteManagementApi.java @@ -71,7 +71,6 @@ public interface GeographicSiteManagementApi { @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) @RequestMapping(value = "/geographicSite/{id}", produces = { "application/json" }, - consumes = { "application/json" }, method = RequestMethod.DELETE) default ResponseEntity deleteGeographicSite(@Parameter(description = "Identifier of the Geographic site",required=true) @PathVariable("id") String id) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); @@ -90,7 +89,6 @@ public interface GeographicSiteManagementApi { @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) @RequestMapping(value = "/geographicSite", produces = { "application/json" }, - consumes = { "application/json" }, method = RequestMethod.GET) default ResponseEntity> listGeographicSite() { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); @@ -128,7 +126,6 @@ public interface GeographicSiteManagementApi { @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) @RequestMapping(value = "/geographicSite/{id}", produces = { "application/json" }, - consumes = { "application/json" }, method = RequestMethod.GET) default ResponseEntity retrieveGeographicSite(@Parameter(description = "Identifier of the Geographic site",required=true) @PathVariable("id") String id) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); -- GitLab From 4f764b1b5a94fc1806beadcc9e6b80b5b3879cab Mon Sep 17 00:00:00 2001 From: lpapadopoulos Date: Wed, 10 Apr 2024 16:18:20 +0300 Subject: [PATCH 9/9] update fields in PATCH operation --- .../GeographicSiteManagementService.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java b/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java index 3b36430..0887b38 100644 --- a/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java +++ b/src/main/java/org/etsi/osl/tmf/gsm674/reposervices/GeographicSiteManagementService.java @@ -58,7 +58,7 @@ public class GeographicSiteManagementService { private GeographicSite updateFields(GeographicSite newSite, GeographicSite existingSite){ - if(newSite.getName()!=null) existingSite.setCalendar(newSite.getCalendar()); + if(newSite.getName()!=null) existingSite.setName(newSite.getName()); if(newSite.getDescription()!=null) existingSite.setDescription(newSite.getDescription()); if(newSite.getCode()!=null) existingSite.setCode(newSite.getCode()); if (newSite.getStatus()!=null) existingSite.setStatus(newSite.getStatus()); @@ -67,7 +67,15 @@ public class GeographicSiteManagementService { for(GeographicSiteRelationship n : newSite.getGeographicSiteRelationship()){ if(n.getUuid()==null){ existingSite.addGeographicSiteRelationship(n); - } + }else { + for (GeographicSiteRelationship oldGeographicRelationship : existingSite.getGeographicSiteRelationship()){ + if (n.getUuid().equals(oldGeographicRelationship.getUuid())){ + if (n.getRole() !=null) oldGeographicRelationship.setRole(n.getRole()); + if (n.getRelationshipType() !=null) oldGeographicRelationship.setRelationshipType(n.getRelationshipType()); + if (n.getValidFor() !=null) oldGeographicRelationship.setValidFor(n.getValidFor()); + } + } + } } } @@ -75,6 +83,15 @@ public class GeographicSiteManagementService { for(CalendarPeriod c: newSite.getCalendar()){ if(c.getUuid()==null){ existingSite.addCalendarPeriod(c); + } else { + for (CalendarPeriod oldCalendarPeriod: existingSite.getCalendar()){ + if (c.getUuid().equals(oldCalendarPeriod.getUuid())){ + if( c.getDay() !=null) oldCalendarPeriod.setDay(c.getDay()); + if( c.getStatus() !=null) oldCalendarPeriod.setStatus(c.getStatus()); + if( c.getTimeZone() !=null) oldCalendarPeriod.setTimeZone(c.getTimeZone()); + if( c.getHourPeriod() !=null) oldCalendarPeriod.setHourPeriod(c.getHourPeriod()); + } + } } } } @@ -91,6 +108,13 @@ public class GeographicSiteManagementService { for(RelatedParty party: newSite.getRelatedParties()){ if(party.getUuid()==null){ existingSite.addRelatedParty(party); + } else { + for (RelatedParty rp: existingSite.getRelatedParties()){ + if(party.getUuid().equals(rp.getUuid())){ + if (party.getRole() !=null) rp.setRole(party.getRole()); + if (party.getName() !=null) rp.setName(party.getName()); + } + } } } } -- GitLab