From a61c2ffa20866c1f10beb66a244e92760f62cf7d Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Tue, 9 Apr 2024 18:02:44 +0300 Subject: [PATCH 01/10] TMF 673 REST Api endpoint for geographicAddress --- .../etsi/osl/tmf/gam673/api/Generated.java | 16 ++ .../api/GeographicAddressManagementApi.java | 158 ++++++++++++++++++ ...graphicAddressManagementApiController.java | 95 +++++++++++ ...GeographicAddressManagementRepository.java | 15 ++ .../GeographicAddressManagementService.java | 62 +++++++ 5 files changed, 346 insertions(+) create mode 100644 src/main/java/org/etsi/osl/tmf/gam673/api/Generated.java create mode 100644 src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java create mode 100644 src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java create mode 100644 src/main/java/org/etsi/osl/tmf/gam673/repo/GeographicAddressManagementRepository.java create mode 100644 src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/Generated.java b/src/main/java/org/etsi/osl/tmf/gam673/api/Generated.java new file mode 100644 index 0000000..f860fd5 --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/Generated.java @@ -0,0 +1,16 @@ +package org.etsi.osl.tmf.gam673.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/gam673/api/GeographicAddressManagementApi.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java new file mode 100644 index 0000000..ddc27e0 --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java @@ -0,0 +1,158 @@ +package org.etsi.osl.tmf.gam673.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sun.org.slf4j.internal.Logger; +import com.sun.org.slf4j.internal.LoggerFactory; +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.gam673.model.GeographicAddress; +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 java.io.IOException; +import java.util.List; +import java.util.Optional; + +@Generated +public interface GeographicAddressManagementApi { + Logger log = LoggerFactory.getLogger(GeographicAddressManagementApi.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 'GeographicAddress'", operationId = "createGeographicAddress", description = "", tags={ "geographicAddress", }) + @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 = "/geographicAddress", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.POST) + default ResponseEntity createGeographicAddress(@Parameter(description = "The geographic address to be created", required = true) @Valid @RequestBody GeographicAddress geographicAddress) { + 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\" } ]}", GeographicAddress.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); + } + } + + @Operation(summary = "Deletes a 'GeographicAddress' by Id", operationId = "deleteGeographicAddress", description = "", tags={ "GeographicAddress", }) + @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 = "/geographicAddress/{id}", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.DELETE) + default ResponseEntity deleteGeographicAddress(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id) { + if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + } else { + log.warn("ObjectMapper or HttpServletRequest not configured in default GeographicAddressManagementApi interface so no example is generated"); + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + + @Operation(summary = "List or find 'GeographicAddress' objects", operationId = "listGeographicAddress", description = "" , tags={ "GeographicAddress", }) + @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 = "/geographicAddress", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.GET) + default ResponseEntity> listGeographicAddress() { + 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); + } + + } + + + @Operation(summary = "Updates partially a 'GeographicAddress' by Id", operationId = "patchGeographicAddress", description = "", tags={ "GeographicAddress", }) + @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 = "/geographicAddress/{id}", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.PATCH) + default ResponseEntity patchGeographicAddress(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id, @Parameter(description = "The Service Level Specification to be updated", required = true) @Valid @RequestBody GeographicAddress geographicAddress) { + 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\" } ]}", GeographicAddress.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); + } + } + + + @Operation(summary = "Retrieves a 'GeographicAddress' by Id", operationId = "retrieveGeographicAddress", description = "" , tags={ "GeographicAddress", }) + @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 = "/geographicAddress/{id}", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.GET) + default ResponseEntity retrieveGeographicAddress() { + 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\" } ]} ]", GeographicAddress.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/gam673/api/GeographicAddressManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java new file mode 100644 index 0000000..7a2a064 --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java @@ -0,0 +1,95 @@ +package org.etsi.osl.tmf.gam673.api; + + +import io.swagger.v3.oas.annotations.Parameter; +import jakarta.validation.Valid; +import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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("/geographicAddressManagement/v4/") +public class GeographicAddressManagementApiController implements GeographicAddressManagementApi{ + private static final Logger log = LoggerFactory.getLogger(GeographicAddressManagementApiController.class); + + private static final String COULD_NOT_SERIALIZE="Couldn't serialize response for content type application/json"; + private final GeographicAddressManagementService geographicAddressManagementService; + + @Autowired + public GeographicAddressManagementApiController(GeographicAddressManagementService geographicAddressManagementService) { + this.geographicAddressManagementService = geographicAddressManagementService; + } + + // @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) + @Override + public ResponseEntity> listGeographicAddress() { + try { + return new ResponseEntity<>(geographicAddressManagementService.findAllGeographicAddresss(), 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 createGeographicAddress( + @Parameter(description = "The geographic address to be created", required = true) @Valid @RequestBody GeographicAddress geographicAddress + ) { + + try { + + GeographicAddress c = geographicAddressManagementService.createGeographicAddress(geographicAddress); + + 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 deleteGeographicAddress( + @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id) { + + try { + return new ResponseEntity<>(geographicAddressManagementService.deleteGeographicAddressById(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 patchGeographicAddress( + @Parameter(description = "Identifier of the ServiceOrder", required = true) @PathVariable("id") String id, + @Parameter(description = "The ServiceOrder to be updated", required = true) @Valid @RequestBody GeographicAddress geographicAddress) { + try{ + GeographicAddress c = geographicAddressManagementService.updateGeographicAddress(id, geographicAddress); + + 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/gam673/repo/GeographicAddressManagementRepository.java b/src/main/java/org/etsi/osl/tmf/gam673/repo/GeographicAddressManagementRepository.java new file mode 100644 index 0000000..1a7f90e --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gam673/repo/GeographicAddressManagementRepository.java @@ -0,0 +1,15 @@ +package org.etsi.osl.tmf.gam673.repo; + +import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface GeographicAddressManagementRepository extends CrudRepository, PagingAndSortingRepository { + + Optional findByUuid(String id); + +} diff --git a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java new file mode 100644 index 0000000..fb5a95a --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java @@ -0,0 +1,62 @@ +package org.etsi.osl.tmf.gam673.reposervices; + +import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository; +import org.etsi.osl.tmf.prm669.model.RelatedParty; +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 GeographicAddressManagementService { + + private static final Logger log = LoggerFactory.getLogger(GeographicAddressManagementService.class); + + private final GeographicAddressManagementRepository geographicAddressManagementRepository; + + @Autowired + public GeographicAddressManagementService(GeographicAddressManagementRepository geographicAddressManagementRepository) { + this.geographicAddressManagementRepository = geographicAddressManagementRepository; + } + + public List findAllGeographicAddresss(){ + return (List) geographicAddressManagementRepository.findAll(); + } + + public Optional findGeographicAddressByUUID(String uuid){ + return geographicAddressManagementRepository.findByUuid(uuid); + } + + public GeographicAddress createGeographicAddress(GeographicAddress geographicAddress){ + log.info("Add another geographic address: {}",geographicAddress); + return geographicAddressManagementRepository.save(geographicAddress); + + } + + public GeographicAddress updateGeographicAddress(String id,GeographicAddress geographicAddress){ + log.info("Update geographic address with id: {}",id); + Optional gs=geographicAddressManagementRepository.findByUuid(id); + return gs.map(address -> updateFields(geographicAddress, address)).orElse(null); + } + + public Void deleteGeographicAddressById(String id){ + log.info("Delete geographic address with id: {}",id); + GeographicAddress gs=geographicAddressManagementRepository.findByUuid(id).orElseThrow(); + geographicAddressManagementRepository.delete(gs); + return null; + } + + private GeographicAddress updateFields(GeographicAddress newSite, GeographicAddress existingSite){ + + geographicAddressManagementRepository.save(existingSite); + return existingSite; + } + + +} -- GitLab From de23e83ea1fd107bc4b6500695efb4b9b08df138 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Wed, 10 Apr 2024 12:59:14 +0300 Subject: [PATCH 02/10] Add TMF 673 Geographic Address Validation endpoints --- .../api/GeographicAddressManagementApi.java | 82 ++++++------ ...graphicAddressManagementApiController.java | 56 ++++++-- ...graphicAddressValidationManagementApi.java | 121 ++++++++++++++++++ ...ressValidationManagementApiController.java | 109 ++++++++++++++++ ...AddressValidationManagementRepository.java | 15 +++ .../GeographicAddressManagementService.java | 19 ++- ...hicAddressValidationManagementService.java | 61 +++++++++ 7 files changed, 413 insertions(+), 50 deletions(-) create mode 100644 src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java create mode 100644 src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApiController.java create mode 100644 src/main/java/org/etsi/osl/tmf/gam673/repo/GeographicAddressValidationManagementRepository.java create mode 100644 src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java index ddc27e0..722d689 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java @@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import java.io.IOException; import java.util.List; import java.util.Optional; +import java.util.Set; @Generated public interface GeographicAddressManagementApi { @@ -51,14 +53,7 @@ public interface GeographicAddressManagementApi { produces = { "application/json" }, consumes = { "application/json" }, method = RequestMethod.POST) - default ResponseEntity createGeographicAddress(@Parameter(description = "The geographic address to be created", required = true) @Valid @RequestBody GeographicAddress geographicAddress) { - 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\" } ]}", GeographicAddress.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); - } - } + ResponseEntity createGeographicAddress(@Parameter(description = "The geographic address to be created", required = true) @Valid @RequestBody GeographicAddress geographicAddress); @Operation(summary = "Deletes a 'GeographicAddress' by Id", operationId = "deleteGeographicAddress", description = "", tags={ "GeographicAddress", }) @ApiResponses(value = { @@ -74,13 +69,7 @@ public interface GeographicAddressManagementApi { produces = { "application/json" }, consumes = { "application/json" }, method = RequestMethod.DELETE) - default ResponseEntity deleteGeographicAddress(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id) { - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { - } else { - log.warn("ObjectMapper or HttpServletRequest not configured in default GeographicAddressManagementApi interface so no example is generated"); - } - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } + ResponseEntity deleteGeographicAddress(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id); @Operation(summary = "List or find 'GeographicAddress' objects", operationId = "listGeographicAddress", description = "" , tags={ "GeographicAddress", }) @@ -97,15 +86,7 @@ public interface GeographicAddressManagementApi { produces = { "application/json" }, consumes = { "application/json" }, method = RequestMethod.GET) - default ResponseEntity> listGeographicAddress() { - 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); - } - - } + ResponseEntity> listGeographicAddress(); @Operation(summary = "Updates partially a 'GeographicAddress' by Id", operationId = "patchGeographicAddress", description = "", tags={ "GeographicAddress", }) @@ -122,14 +103,7 @@ public interface GeographicAddressManagementApi { produces = { "application/json" }, consumes = { "application/json" }, method = RequestMethod.PATCH) - default ResponseEntity patchGeographicAddress(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id, @Parameter(description = "The Service Level Specification to be updated", required = true) @Valid @RequestBody GeographicAddress geographicAddress) { - 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\" } ]}", GeographicAddress.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); - } - } + ResponseEntity patchGeographicAddress(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id, @Parameter(description = "The Service Level Specification to be updated", required = true) @Valid @RequestBody GeographicAddress geographicAddress); @Operation(summary = "Retrieves a 'GeographicAddress' by Id", operationId = "retrieveGeographicAddress", description = "" , tags={ "GeographicAddress", }) @@ -146,13 +120,41 @@ public interface GeographicAddressManagementApi { produces = { "application/json" }, consumes = { "application/json" }, method = RequestMethod.GET) - default ResponseEntity retrieveGeographicAddress() { - 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\" } ]} ]", GeographicAddress.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); - } - } + ResponseEntity retrieveGeographicAddress(@Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id); + + @Operation(summary = "Retrieves a 'GeographicSubAddress' by Id", operationId = "retrieveGeographicSubAddress", description = "" , tags={ "GeographicSubAddress", }) + @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 = "/geographicAddress/{id}/geographicSubAddress", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.GET) + ResponseEntity> retrieveGeographicSubAddress( + @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id); + + @Operation(summary = "Retrieves a 'GeographicSubAddress' by Id", operationId = "retrieveGeographicSubAddress", description = "" , tags={ "GeographicSubAddress", }) + @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 = "/geographicAddress/{id}/geographicSubAddress/{id}", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.GET) + ResponseEntity retrieveGeographicSubAddress( + @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String geoAddressId, + @Parameter(description = "Identifier of the geographic sub address", required = true) @PathVariable("id") String geoSubAddressId); } diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java index 7a2a064..7efb1d1 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java @@ -4,6 +4,7 @@ package org.etsi.osl.tmf.gam673.api; import io.swagger.v3.oas.annotations.Parameter; import jakarta.validation.Valid; import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import java.util.List; +import java.util.Set; @Controller @RequestMapping("/geographicAddressManagement/v4/") @@ -48,14 +50,9 @@ public class GeographicAddressManagementApiController implements GeographicAddre public ResponseEntity createGeographicAddress( @Parameter(description = "The geographic address to be created", required = true) @Valid @RequestBody GeographicAddress geographicAddress ) { - - try { - + try{ GeographicAddress c = geographicAddressManagementService.createGeographicAddress(geographicAddress); - return new ResponseEntity<>(c, HttpStatus.OK); - - } catch (Exception e) { log.error(COULD_NOT_SERIALIZE, e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); @@ -76,12 +73,40 @@ public class GeographicAddressManagementApiController implements GeographicAddre } + @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) + @Override + public ResponseEntity retrieveGeographicAddress( + @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id) { + try{ + GeographicAddress c = geographicAddressManagementService.findGeographicAddressByUUID(id); + + 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> retrieveGeographicSubAddress( + @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id) { + try{ + Set c = geographicAddressManagementService.findAllGeographicSubAddresses(id); + + 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 patchGeographicAddress( - @Parameter(description = "Identifier of the ServiceOrder", required = true) @PathVariable("id") String id, - @Parameter(description = "The ServiceOrder to be updated", required = true) @Valid @RequestBody GeographicAddress geographicAddress) { + @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id, + @Parameter(description = "The Geographic Address to be updated", required = true) @Valid @RequestBody GeographicAddress geographicAddress) { try{ GeographicAddress c = geographicAddressManagementService.updateGeographicAddress(id, geographicAddress); @@ -92,4 +117,19 @@ public class GeographicAddressManagementApiController implements GeographicAddre } } + @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) + @Override + public ResponseEntity retrieveGeographicSubAddress( + @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String geoAddressId, + @Parameter(description = "Identifier of the geographic sub address", required = true) @PathVariable("id") String geoSubAddressId){ + try{ + GeographicSubAddress c = geographicAddressManagementService.findGeographicSubAddressByUUID(geoAddressId,geoSubAddressId); + + 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/gam673/api/GeographicAddressValidationManagementApi.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java new file mode 100644 index 0000000..ef8c91f --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java @@ -0,0 +1,121 @@ +package org.etsi.osl.tmf.gam673.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sun.org.slf4j.internal.Logger; +import com.sun.org.slf4j.internal.LoggerFactory; +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.gam673.model.GeographicAddressValidation; +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 java.util.List; +import java.util.Optional; + +@Generated +public interface GeographicAddressValidationManagementApi { + Logger log = LoggerFactory.getLogger(GeographicAddressValidationManagementApi.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 'GeographicAddressValidation'", operationId = "createGeographicAddressValidation", description = "", tags={ "geographicAddress", }) + @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 = "/geographicAddressValidation", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.POST) + ResponseEntity createGeographicAddressValidation(@Parameter(description = "The geographic address to be created", required = true) @Valid @RequestBody GeographicAddressValidation geographicAddressValidation); + + @Operation(summary = "Deletes a 'GeographicAddressValidation' by Id", operationId = "deleteGeographicAddressValidation", description = "", tags={ "GeographicAddressValidation", }) + @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 = "/geographicAddressValidation/{id}", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.DELETE) + ResponseEntity deleteGeographicAddressValidation(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id); + + + @Operation(summary = "List or find 'GeographicAddressValidation' objects", operationId = "listGeographicAddressValidation", description = "" , tags={ "GeographicAddressValidation", }) + @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 = "/geographicAddressValidation", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.GET) + ResponseEntity> listGeographicAddressValidation(); + + + @Operation(summary = "Updates partially a 'GeographicAddressValidation' by Id", operationId = "patchGeographicAddressValidation", description = "", tags={ "GeographicAddressValidation", }) + @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 = "/geographicAddressValidation/{id}", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.PATCH) + ResponseEntity patchGeographicAddressValidation(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id, @Parameter(description = "The Service Level Specification to be updated", required = true) @Valid @RequestBody GeographicAddressValidation geographicAddressValidation); + + + @Operation(summary = "Retrieves a 'GeographicAddressValidation' by Id", operationId = "retrieveGeographicAddressValidation", description = "" , tags={ "GeographicAddressValidation", }) + @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 = "/geographicAddressValidation/{id}", + produces = { "application/json" }, + consumes = { "application/json" }, + method = RequestMethod.GET) + ResponseEntity retrieveGeographicAddressValidation(@Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id); + +} diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApiController.java new file mode 100644 index 0000000..139b4ef --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApiController.java @@ -0,0 +1,109 @@ +package org.etsi.osl.tmf.gam673.api; + + +import io.swagger.v3.oas.annotations.Parameter; +import jakarta.validation.Valid; +import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.model.GeographicAddressValidation; +import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; +import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService; +import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressValidationManagementService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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; +import java.util.Set; + +@Controller +@RequestMapping("/geographicAddressValidationManagement/v4/") +public class GeographicAddressValidationManagementApiController implements GeographicAddressValidationManagementApi{ + private static final Logger log = LoggerFactory.getLogger(GeographicAddressValidationManagementApiController.class); + + private static final String COULD_NOT_SERIALIZE="Couldn't serialize response for content type application/json"; + private final GeographicAddressValidationManagementService geographicAddressValidationManagementService; + + @Autowired + public GeographicAddressValidationManagementApiController(GeographicAddressValidationManagementService geographicAddressValidationManagementService) { + this.geographicAddressValidationManagementService = geographicAddressValidationManagementService; + } + + // @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) + @Override + public ResponseEntity> listGeographicAddressValidation() { + try { + return new ResponseEntity<>(geographicAddressValidationManagementService.findAllGeographicAddressValidations(), 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 createGeographicAddressValidation( + @Parameter(description = "The geographic address validation to be created", required = true) @Valid @RequestBody GeographicAddressValidation geographicAddressValidatio + ) { + try{ + GeographicAddressValidation c = geographicAddressValidationManagementService.createGeographicAddressValidation(geographicAddress); + 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 deleteGeographicAddressValidation( + @Parameter(description = "Identifier of the geographic address validation", required = true) @PathVariable("id") String id) { + + try { + return new ResponseEntity<>(geographicAddressValidationManagementService.deleteGeographicAddressValidationById(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 retrieveGeographicAddressValidation( + @Parameter(description = "Identifier of the geographic address validation", required = true) @PathVariable("id") String id) { + try{ + GeographicAddressValidation c = geographicAddressValidationManagementService.findGeographicAddressValidationByUUID(id); + + 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 patchGeographicAddressValidation( + @Parameter(description = "Identifier of the geographic address validation", required = true) @PathVariable("id") String id, + @Parameter(description = "The Geographic Address Validation to be updated", required = true) @Valid @RequestBody GeographicAddressValidation geographicAddress) { + try{ + GeographicAddressValidation c = geographicAddressValidationManagementService.updateGeographicAddressValidation(id, geographicAddress); + + 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/gam673/repo/GeographicAddressValidationManagementRepository.java b/src/main/java/org/etsi/osl/tmf/gam673/repo/GeographicAddressValidationManagementRepository.java new file mode 100644 index 0000000..51eb5b1 --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gam673/repo/GeographicAddressValidationManagementRepository.java @@ -0,0 +1,15 @@ +package org.etsi.osl.tmf.gam673.repo; + +import org.etsi.osl.tmf.gam673.model.GeographicAddressValidation; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface GeographicAddressValidationManagementRepository extends CrudRepository, PagingAndSortingRepository { + + Optional findByUuid(String id); + +} diff --git a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java index fb5a95a..f62f5bc 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java @@ -1,6 +1,7 @@ package org.etsi.osl.tmf.gam673.reposervices; import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository; import org.etsi.osl.tmf.prm669.model.RelatedParty; import org.slf4j.Logger; @@ -11,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Optional; +import java.util.Set; @Service @Transactional @@ -29,8 +31,21 @@ public class GeographicAddressManagementService { return (List) geographicAddressManagementRepository.findAll(); } - public Optional findGeographicAddressByUUID(String uuid){ - return geographicAddressManagementRepository.findByUuid(uuid); + public GeographicAddress findGeographicAddressByUUID(String uuid){ + return geographicAddressManagementRepository.findByUuid(uuid).get(); + } + + public Set findAllGeographicSubAddresses(String uuid){ + Optional geoAddress = geographicAddressManagementRepository.findByUuid(uuid); + return geoAddress.get().getGeographicSubAddresses(); + } + + public GeographicSubAddress findGeographicSubAddressByUUID(String geoAddressId , String geoSubAddressId){ + Optional geoAddress = geographicAddressManagementRepository.findByUuid(geoAddressId); + return geoAddress.get().getGeographicSubAddresses().stream() + .filter(geoSubAddress -> geoSubAddress.getUuid().equals(geoSubAddressId)) + .map(geoSubAddress -> geoSubAddress) + .collect(java.util.stream.Collectors.toList()).get(0); } public GeographicAddress createGeographicAddress(GeographicAddress geographicAddress){ diff --git a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java new file mode 100644 index 0000000..6e82654 --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java @@ -0,0 +1,61 @@ +package org.etsi.osl.tmf.gam673.reposervices; + +import org.etsi.osl.tmf.gam673.model.GeographicAddressValidation; +import org.etsi.osl.tmf.gam673.repo.GeographicAddressValidationManagementRepository; +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 GeographicAddressValidationManagementService { + + private static final Logger log = LoggerFactory.getLogger(GeographicAddressValidationManagementService.class); + + private final GeographicAddressValidationManagementRepository geographicAddressValidationManagementRepository; + + @Autowired + public GeographicAddressValidationManagementService(GeographicAddressValidationManagementRepository geographicAddressValidationManagementRepository) { + this.geographicAddressValidationManagementRepository = geographicAddressValidationManagementRepository; + } + + public List findAllGeographicAddressValidations(){ + return (List) geographicAddressValidationManagementRepository.findAll(); + } + + public GeographicAddressValidation findGeographicAddressValidationByUUID(String uuid){ + return geographicAddressValidationManagementRepository.findByUuid(uuid).get(); + } + + public GeographicAddressValidation createGeographicAddressValidation(GeographicAddressValidation geographicAddressValidation){ + log.info("Add another geographic address validation: {}",geographicAddressValidation); + return geographicAddressValidationManagementRepository.save(geographicAddressValidation); + + } + + public GeographicAddressValidation updateGeographicAddressValidation(String id,GeographicAddressValidation geographicAddressValidation){ + log.info("Update geographic address validation with id: {}",id); + Optional gs=geographicAddressValidationManagementRepository.findByUuid(id); + return gs.map(address -> updateFields(geographicAddressValidation, address)).orElse(null); + } + + public Void deleteGeographicAddressValidationById(String id){ + log.info("Delete geographic address validation with id: {}",id); + GeographicAddressValidation gs=geographicAddressValidationManagementRepository.findByUuid(id).orElseThrow(); + geographicAddressValidationManagementRepository.delete(gs); + return null; + } + + private GeographicAddressValidation updateFields(GeographicAddressValidation newSite, GeographicAddressValidation existingSite){ + + geographicAddressValidationManagementRepository.save(existingSite); + return existingSite; + } + + +} -- GitLab From 20c6e16849bde43c473c6c34ea8c618aa33e3020 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Wed, 10 Apr 2024 14:35:48 +0300 Subject: [PATCH 03/10] Add update service method for GeoAddressValidation and GeoAddress --- .../osl/tmf/gam673/mapper/MapperUtils.java | 39 +++++++++++++++++++ .../GeographicAddressManagementService.java | 11 ++++-- ...hicAddressValidationManagementService.java | 28 +++++++++++-- 3 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java diff --git a/src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java b/src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java new file mode 100644 index 0000000..178835d --- /dev/null +++ b/src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java @@ -0,0 +1,39 @@ +package org.etsi.osl.tmf.gam673.mapper; + +import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; + +public class MapperUtils { + + public static GeographicAddress geographicAddressMap(GeographicAddress newGeographicAddress, GeographicAddress existingGeographicAddress){ + if(newGeographicAddress.getCity()!=null) existingGeographicAddress.setCity(newGeographicAddress.getCity()); + if(newGeographicAddress.getCountry()!=null) existingGeographicAddress.setCountry(newGeographicAddress.getCountry()); + if(newGeographicAddress.getLocality()!=null) existingGeographicAddress.setLocality(newGeographicAddress.getLocality()); + if(newGeographicAddress.getPostcode()!=null) existingGeographicAddress.setPostcode(newGeographicAddress.getPostcode()); + if(newGeographicAddress.getStateOrProvince()!=null) existingGeographicAddress.setStateOrProvince(newGeographicAddress.getStateOrProvince()); + if(newGeographicAddress.getStreetName()!=null) existingGeographicAddress.setStreetName(newGeographicAddress.getStreetName()); + if(newGeographicAddress.getStreetNr()!=null) existingGeographicAddress.setStreetNr(newGeographicAddress.getStreetNr()); + if(newGeographicAddress.getStreetNrLast()!=null) existingGeographicAddress.setStreetNrLast(newGeographicAddress.getStreetNrLast()); + if(newGeographicAddress.getStreetNrLastSuffix()!=null) existingGeographicAddress.setStreetNrLastSuffix(newGeographicAddress.getStreetNrLastSuffix()); + if(newGeographicAddress.getStreetSuffix()!=null) existingGeographicAddress.setStreetSuffix(newGeographicAddress.getStreetSuffix()); + if(newGeographicAddress.getStreetType()!=null) existingGeographicAddress.setStreetType(newGeographicAddress.getStreetType()); + if(newGeographicAddress.getHref()!=null) existingGeographicAddress.setHref(newGeographicAddress.getHref()); + if(newGeographicAddress.getName()!=null) existingGeographicAddress.setName(newGeographicAddress.getName()); + + if(newGeographicAddress.getGeographicLocation()!=null){ + if(newGeographicAddress.getGeographicLocation().getReferredType()!=null) existingGeographicAddress.getGeographicLocation().setReferredType(newGeographicAddress.getGeographicLocation().getReferredType()); + if(newGeographicAddress.getGeographicLocation().getRole()!=null) existingGeographicAddress.getGeographicLocation().setRole(newGeographicAddress.getGeographicLocation().getRole()); + } + + + if(newGeographicAddress.getGeographicSubAddresses()!=null){ + for(GeographicSubAddress n : newGeographicAddress.getGeographicSubAddresses()){ + if(n.getUuid()==null){ + existingGeographicAddress.addGeographicSubAddress(n); + } + } + } + return existingGeographicAddress; + } + +} diff --git a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java index f62f5bc..a4aa209 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java @@ -1,5 +1,6 @@ package org.etsi.osl.tmf.gam673.reposervices; +import org.etsi.osl.tmf.gam673.mapper.MapperUtils; import org.etsi.osl.tmf.gam673.model.GeographicAddress; import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository; @@ -22,6 +23,8 @@ public class GeographicAddressManagementService { private final GeographicAddressManagementRepository geographicAddressManagementRepository; + private MapperUtils mapperUtils; + @Autowired public GeographicAddressManagementService(GeographicAddressManagementRepository geographicAddressManagementRepository) { this.geographicAddressManagementRepository = geographicAddressManagementRepository; @@ -67,10 +70,12 @@ public class GeographicAddressManagementService { return null; } - private GeographicAddress updateFields(GeographicAddress newSite, GeographicAddress existingSite){ + private GeographicAddress updateFields(GeographicAddress newGeographicAddress, GeographicAddress existingGeographicAddress){ + + existingGeographicAddress = mapperUtils.geographicAddressMap(newGeographicAddress, existingGeographicAddress); - geographicAddressManagementRepository.save(existingSite); - return existingSite; + geographicAddressManagementRepository.save(existingGeographicAddress); + return existingGeographicAddress; } diff --git a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java index 6e82654..fd2ea06 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java @@ -1,5 +1,7 @@ package org.etsi.osl.tmf.gam673.reposervices; +import org.etsi.osl.tmf.gam673.mapper.MapperUtils; +import org.etsi.osl.tmf.gam673.model.GeographicAddress; import org.etsi.osl.tmf.gam673.model.GeographicAddressValidation; import org.etsi.osl.tmf.gam673.repo.GeographicAddressValidationManagementRepository; import org.slf4j.Logger; @@ -19,6 +21,8 @@ public class GeographicAddressValidationManagementService { private final GeographicAddressValidationManagementRepository geographicAddressValidationManagementRepository; + private MapperUtils mapperUtils; + @Autowired public GeographicAddressValidationManagementService(GeographicAddressValidationManagementRepository geographicAddressValidationManagementRepository) { this.geographicAddressValidationManagementRepository = geographicAddressValidationManagementRepository; @@ -51,10 +55,28 @@ public class GeographicAddressValidationManagementService { return null; } - private GeographicAddressValidation updateFields(GeographicAddressValidation newSite, GeographicAddressValidation existingSite){ + private GeographicAddressValidation updateFields(GeographicAddressValidation newGeographicAddressValidation, GeographicAddressValidation existingGeographicAddressValidation){ + + if(newGeographicAddressValidation.getValidationDate()!=null) existingGeographicAddressValidation.setValidationDate(newGeographicAddressValidation.getValidationDate()); + if(newGeographicAddressValidation.getStatus()!=null) existingGeographicAddressValidation.setStatus(newGeographicAddressValidation.getStatus()); + if(newGeographicAddressValidation.getValidationResult()!=null) existingGeographicAddressValidation.setValidationResult(newGeographicAddressValidation.getValidationResult()); + if(newGeographicAddressValidation.getProvideAlternative()!=null) existingGeographicAddressValidation.setProvideAlternative(newGeographicAddressValidation.getProvideAlternative()); + + if(newGeographicAddressValidation.getAlternateGeographicAddresses()!=null){ + for(GeographicAddress n : newGeographicAddressValidation.getAlternateGeographicAddresses()){ + if(n.getUuid()==null){ + existingGeographicAddressValidation.addGeographicAddress(n); + } + } + } + + if(newGeographicAddressValidation.getValidAddress()!=null){ + GeographicAddress geographicAddress = mapperUtils.geographicAddressMap(newGeographicAddressValidation.getValidAddress(), existingGeographicAddressValidation.getValidAddress()); + existingGeographicAddressValidation.setValidAddress(geographicAddress); + } - geographicAddressValidationManagementRepository.save(existingSite); - return existingSite; + geographicAddressValidationManagementRepository.save(existingGeographicAddressValidation); + return existingGeographicAddressValidation; } -- GitLab From b75e188e2db5de451bbb91c098dc80ebf787f0d6 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Thu, 11 Apr 2024 14:22:39 +0300 Subject: [PATCH 04/10] Add TMF 673 unit tests. Remove unnecessary log configuration. --- .../api/GeographicAddressManagementApi.java | 55 +++----- ...graphicAddressManagementApiController.java | 2 +- ...graphicAddressValidationManagementApi.java | 37 ++---- ...ressValidationManagementApiController.java | 8 +- ...raphicAddressManagementControllerTest.java | 123 ++++++++++++++++++ ...eographicAddressManagementServiceTest.java | 106 +++++++++++++++ 6 files changed, 266 insertions(+), 65 deletions(-) create mode 100644 src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementControllerTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementServiceTest.java diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java index 722d689..030761c 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java @@ -1,8 +1,6 @@ package org.etsi.osl.tmf.gam673.api; import com.fasterxml.jackson.databind.ObjectMapper; -import com.sun.org.slf4j.internal.Logger; -import com.sun.org.slf4j.internal.LoggerFactory; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -11,22 +9,20 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import org.etsi.osl.tmf.gam673.model.GeographicAddress; import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import java.io.IOException; import java.util.List; import java.util.Optional; import java.util.Set; @Generated public interface GeographicAddressManagementApi { - Logger log = LoggerFactory.getLogger(GeographicAddressManagementApi.class); - default Optional getObjectMapper() { return Optional.empty(); } @@ -49,10 +45,9 @@ public interface GeographicAddressManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddress", + @PostMapping(value = "/geographicAddress", produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.POST) + consumes = { "application/json" }) ResponseEntity createGeographicAddress(@Parameter(description = "The geographic address to be created", required = true) @Valid @RequestBody GeographicAddress geographicAddress); @Operation(summary = "Deletes a 'GeographicAddress' by Id", operationId = "deleteGeographicAddress", description = "", tags={ "GeographicAddress", }) @@ -65,10 +60,9 @@ public interface GeographicAddressManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddress/{id}", + @DeleteMapping(value = "/geographicAddress/{id}", produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.DELETE) + consumes = { "application/json" }) ResponseEntity deleteGeographicAddress(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id); @@ -82,10 +76,8 @@ public interface GeographicAddressManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddress", - produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.GET) + @GetMapping(value = "/geographicAddress", + produces = { "application/json" }) ResponseEntity> listGeographicAddress(); @@ -99,10 +91,9 @@ public interface GeographicAddressManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddress/{id}", + @PatchMapping(value = "/geographicAddress/{id}", produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.PATCH) + consumes = { "application/json" }) ResponseEntity patchGeographicAddress(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id, @Parameter(description = "The Service Level Specification to be updated", required = true) @Valid @RequestBody GeographicAddress geographicAddress); @@ -116,10 +107,8 @@ public interface GeographicAddressManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddress/{id}", - produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.GET) + @GetMapping(value = "/geographicAddress/{id}", + produces = { "application/json" }) ResponseEntity retrieveGeographicAddress(@Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id); @Operation(summary = "Retrieves a 'GeographicSubAddress' by Id", operationId = "retrieveGeographicSubAddress", description = "" , tags={ "GeographicSubAddress", }) @@ -132,10 +121,8 @@ public interface GeographicAddressManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddress/{id}/geographicSubAddress", - produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.GET) + @GetMapping(value = "/geographicAddress/{id}/geographicSubAddress", + produces = { "application/json" }) ResponseEntity> retrieveGeographicSubAddress( @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id); @@ -149,12 +136,10 @@ public interface GeographicAddressManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddress/{id}/geographicSubAddress/{id}", - produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.GET) + @GetMapping(value = "/geographicAddress/{geoAddressId}/geographicSubAddress/{geoSubAddressId}", + produces = { "application/json" }) ResponseEntity retrieveGeographicSubAddress( - @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String geoAddressId, - @Parameter(description = "Identifier of the geographic sub address", required = true) @PathVariable("id") String geoSubAddressId); + @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("geoAddressId") String geoAddressId, + @Parameter(description = "Identifier of the geographic sub address", required = true) @PathVariable("geoSubAddressId") String geoSubAddressId); } diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java index 7efb1d1..522eaa7 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java @@ -33,7 +33,7 @@ public class GeographicAddressManagementApiController implements GeographicAddre this.geographicAddressManagementService = geographicAddressManagementService; } - // @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) + @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) @Override public ResponseEntity> listGeographicAddress() { try { diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java index ef8c91f..93d5aeb 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java @@ -1,8 +1,6 @@ package org.etsi.osl.tmf.gam673.api; import com.fasterxml.jackson.databind.ObjectMapper; -import com.sun.org.slf4j.internal.Logger; -import com.sun.org.slf4j.internal.LoggerFactory; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -11,18 +9,18 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import org.etsi.osl.tmf.gam673.model.GeographicAddressValidation; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; 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 java.util.Optional; @Generated public interface GeographicAddressValidationManagementApi { - Logger log = LoggerFactory.getLogger(GeographicAddressValidationManagementApi.class); - default Optional getObjectMapper() { return Optional.empty(); } @@ -45,10 +43,9 @@ public interface GeographicAddressValidationManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddressValidation", + @PostMapping(value = "/geographicAddressValidation", produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.POST) + consumes = { "application/json" }) ResponseEntity createGeographicAddressValidation(@Parameter(description = "The geographic address to be created", required = true) @Valid @RequestBody GeographicAddressValidation geographicAddressValidation); @Operation(summary = "Deletes a 'GeographicAddressValidation' by Id", operationId = "deleteGeographicAddressValidation", description = "", tags={ "GeographicAddressValidation", }) @@ -61,10 +58,9 @@ public interface GeographicAddressValidationManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddressValidation/{id}", + @DeleteMapping(value = "/geographicAddressValidation/{id}", produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.DELETE) + consumes = { "application/json" }) ResponseEntity deleteGeographicAddressValidation(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id); @@ -78,10 +74,8 @@ public interface GeographicAddressValidationManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddressValidation", - produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.GET) + @GetMapping(value = "/geographicAddressValidation", + produces = { "application/json" }) ResponseEntity> listGeographicAddressValidation(); @@ -95,10 +89,9 @@ public interface GeographicAddressValidationManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddressValidation/{id}", + @PatchMapping(value = "/geographicAddressValidation/{id}", produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.PATCH) + consumes = { "application/json" }) ResponseEntity patchGeographicAddressValidation(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id, @Parameter(description = "The Service Level Specification to be updated", required = true) @Valid @RequestBody GeographicAddressValidation geographicAddressValidation); @@ -112,10 +105,8 @@ public interface GeographicAddressValidationManagementApi { @ApiResponse(responseCode = "405", description = "Method Not allowed" ), @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) - @RequestMapping(value = "/geographicAddressValidation/{id}", - produces = { "application/json" }, - consumes = { "application/json" }, - method = RequestMethod.GET) + @GetMapping(value = "/geographicAddressValidation/{id}", + produces = { "application/json" }) ResponseEntity retrieveGeographicAddressValidation(@Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id); } diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApiController.java index 139b4ef..514d57a 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApiController.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApiController.java @@ -3,10 +3,7 @@ package org.etsi.osl.tmf.gam673.api; import io.swagger.v3.oas.annotations.Parameter; import jakarta.validation.Valid; -import org.etsi.osl.tmf.gam673.model.GeographicAddress; import org.etsi.osl.tmf.gam673.model.GeographicAddressValidation; -import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; -import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService; import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressValidationManagementService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,7 +17,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import java.util.List; -import java.util.Set; @Controller @RequestMapping("/geographicAddressValidationManagement/v4/") @@ -50,10 +46,10 @@ public class GeographicAddressValidationManagementApiController implements Geogr @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) @Override public ResponseEntity createGeographicAddressValidation( - @Parameter(description = "The geographic address validation to be created", required = true) @Valid @RequestBody GeographicAddressValidation geographicAddressValidatio + @Parameter(description = "The geographic address validation to be created", required = true) @Valid @RequestBody GeographicAddressValidation geographicAddressValidation ) { try{ - GeographicAddressValidation c = geographicAddressValidationManagementService.createGeographicAddressValidation(geographicAddress); + GeographicAddressValidation c = geographicAddressValidationManagementService.createGeographicAddressValidation(geographicAddressValidation); return new ResponseEntity<>(c, HttpStatus.OK); } catch (Exception e) { log.error(COULD_NOT_SERIALIZE, e); diff --git a/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementControllerTest.java b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementControllerTest.java new file mode 100644 index 0000000..b45608a --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementControllerTest.java @@ -0,0 +1,123 @@ +package org.etsi.osl.services.api.gam673; + +import org.etsi.osl.tmf.gam673.api.GeographicAddressManagementApiController; +import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService; +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.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; + +class GeographicAddressManagementControllerTest { + + @InjectMocks + private GeographicAddressManagementApiController controller; + + + @Mock + private GeographicAddressManagementService service; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + } + + @Test + void testRetrieveGeographicAddresses() { + List addresses = new ArrayList<>(); + // Add test data to address list + when(service.findAllGeographicAddresss()).thenReturn(addresses); + + ResponseEntity> response = controller.listGeographicAddress(); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(addresses, response.getBody()); + } + + @Test + void throwExceptionTestWhenRetrieveGeographicAddresses(){ + when(service.findAllGeographicAddresss()).thenThrow(RuntimeException.class); + ResponseEntity> response = controller.listGeographicAddress(); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + + } + @Test + void testCreateGeographicAddress() { + GeographicAddress address = new GeographicAddress(); + + when(service.createGeographicAddress(any())).thenReturn(address); + + ResponseEntity response = controller.createGeographicAddress(address); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(address, response.getBody()); + } + + @Test + void testExceptionWhenCreateGeographicAddress(){ + GeographicAddress address = new GeographicAddress(); + + when(service.createGeographicAddress(any())).thenThrow(RuntimeException.class); + + ResponseEntity response = controller.createGeographicAddress(address); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + } + + @Test + void testDeleteGeographicAddress() { + + doNothing().when(service).deleteGeographicAddressById(anyString()); + ResponseEntity response = controller.deleteGeographicAddress("addressId"); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + } + + @Test + void testDeleteGeographicAddressException() { + + doThrow(RuntimeException.class).when(service).deleteGeographicAddressById(anyString()); + ResponseEntity response = controller.deleteGeographicAddress("addressId"); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + } + + @Test + void testPatchGeographicAddress() { + String addressId = "addressId"; + GeographicAddress updatedAddress = new GeographicAddress(); + // Set up mock service behavior + when(service.updateGeographicAddress(anyString(), any())).thenReturn(updatedAddress); + + ResponseEntity response = controller.patchGeographicAddress(addressId, updatedAddress); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(updatedAddress, response.getBody()); + } + + @Test + void testPatchGeographicAddressException() { + String addressId = "addressId"; + GeographicAddress updatedAddress = new GeographicAddress(); + // Set up mock service behavior + when(service.updateGeographicAddress(anyString(), any())).thenThrow(RuntimeException.class); + + ResponseEntity response = controller.patchGeographicAddress(addressId, updatedAddress); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + } + +} diff --git a/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementServiceTest.java b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementServiceTest.java new file mode 100644 index 0000000..4b2bb10 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementServiceTest.java @@ -0,0 +1,106 @@ +package org.etsi.osl.services.api.gam673; + +import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository; +import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; +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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@AutoConfigureMockMvc +@ActiveProfiles("testing") +class GeographicAddressManagementServiceTest { + + @InjectMocks + private GeographicAddressManagementService service; + + @Mock + private GeographicAddressManagementRepository repository; + + @BeforeEach + void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + void testFindAllGeographicAddress() { + // Mock data + List addresses = List.of(new GeographicAddress(), new GeographicAddress()); + when(repository.findAll()).thenReturn(addresses); + + List result = service.findAllGeographicAddresss(); + + assertEquals(addresses, result); + } + + @Test + void testFindGeographicAddressByUUID() { + // Mock data + String uuid = "123"; + GeographicAddress address = new GeographicAddress(); + address.setUuid(uuid); + when(repository.findByUuid(uuid)).thenReturn(Optional.of(address)); + + GeographicAddress result = service.findGeographicAddressByUUID(uuid); + + assertNotNull(result); + assertEquals(address, result); + } + + @Test + void testCreateGeographicAddress() { + // Mock data + GeographicAddress address = new GeographicAddress(); + when(repository.save(any())).thenReturn(address); + + GeographicAddress result = service.createGeographicAddress(address); + + assertEquals(address, result); + } + + @Test + void testUpdateGeographicAddress() { + // Mock data + String id = "123"; + GeographicAddress existingAddress = new GeographicAddress(); + GeographicAddress newAddress = new GeographicAddress(); + when(repository.findByUuid(id)).thenReturn(Optional.of(existingAddress)); + when(repository.save(any())).thenReturn(existingAddress); + + GeographicAddress result = service.updateGeographicAddress(id, newAddress); + + assertNotNull(result); + assertEquals(existingAddress, result); + // Add additional assertions for updated fields if needed + } + + @Test + void testDeleteGeographicAddressById() { + // Mock data + String id = "123"; + GeographicAddress existingAddress = new GeographicAddress(); + when(repository.findByUuid(id)).thenReturn(Optional.of(existingAddress)); + + Void result = service.deleteGeographicAddressById(id); + + assertNull(result); + verify(repository, times(1)).delete(existingAddress); + } + +} -- GitLab From c828f74c68c10ba2c62b4cb3a4bad8366e28b320 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Thu, 11 Apr 2024 14:39:48 +0300 Subject: [PATCH 05/10] Add TMF 673 swagger UI configuration. --- .../SwaggerDocumentationConfig.java | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 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 ea00cc6..e42863b 100644 --- a/src/main/java/org/etsi/osl/tmf/configuration/SwaggerDocumentationConfig.java +++ b/src/main/java/org/etsi/osl/tmf/configuration/SwaggerDocumentationConfig.java @@ -22,7 +22,6 @@ package org.etsi.osl.tmf.configuration; import org.springdoc.core.customizers.OpenApiCustomizer; import org.springdoc.core.models.GroupedOpenApi; import org.springdoc.core.utils.SpringDocUtils; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -31,7 +30,6 @@ import io.swagger.v3.oas.annotations.security.OAuthFlow; import io.swagger.v3.oas.annotations.security.OAuthFlows; import io.swagger.v3.oas.annotations.security.OAuthScope; import io.swagger.v3.oas.annotations.security.SecurityScheme; -import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.ExternalDocumentation; import io.swagger.v3.oas.models.SpecVersion; import io.swagger.v3.oas.models.info.Info; @@ -811,8 +809,46 @@ public class SwaggerDocumentationConfig { .build(); } - - + + + /** + * TMF 673 Geographic Address Management + * @return + */ + + + @Bean + public OpenApiCustomizer gam673OpenAPI() { + return openApi -> openApi + .specVersion( SpecVersion.V30 ).addSecurityItem(new SecurityRequirement().addList("security_auth")) + .info(new Info() + .title("TMF 673 Geographic Address Management") + .description("## TMF API Reference: TMF673 - Geographic Address Management ### Release : 20.0 - May 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 gam673(){ + + 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-673-Geographic Address Management-v4.0.0") + .addOpenApiCustomizer( this.stm653OpenAPI() ) + .packagesToScan("org.etsi.osl.tmf.gam673.api") + .build(); + + } + + + // @Bean // public SecurityConfiguration security() { // return SecurityConfigurationBuilder.builder() -- GitLab From 60664f0cb285f064d4aa1b5c45592dee6a3e9df4 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Fri, 12 Apr 2024 15:47:21 +0300 Subject: [PATCH 06/10] Add TMF 673 fixes for swagger ui. --- .../osl/tmf/gam673/api/GeographicAddressManagementApi.java | 5 ++--- .../gam673/api/GeographicAddressManagementApiController.java | 4 ++-- .../gam673/api/GeographicAddressValidationManagementApi.java | 2 +- .../reposervices/GeographicAddressManagementService.java | 2 +- .../GeographicAddressValidationManagementService.java | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java index 030761c..b268ed2 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java @@ -35,7 +35,7 @@ public interface GeographicAddressManagementApi { return getRequest().map(r -> r.getHeader("Accept")); } - @Operation(summary = "Creates a 'GeographicAddress'", operationId = "createGeographicAddress", description = "", tags={ "geographicAddress", }) + @Operation(summary = "Creates a 'GeographicAddress'", operationId = "createGeographicAddress", description = "", tags={ "GeographicAddress", }) @ApiResponses(value = { @ApiResponse(responseCode = "400", description = "Created" ), @ApiResponse(responseCode = "400", description = "Bad Request" ), @@ -61,8 +61,7 @@ public interface GeographicAddressManagementApi { @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) @DeleteMapping(value = "/geographicAddress/{id}", - produces = { "application/json" }, - consumes = { "application/json" }) + produces = { "application/json" }) ResponseEntity deleteGeographicAddress(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id); diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java index 522eaa7..c6c1b3b 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java @@ -120,8 +120,8 @@ public class GeographicAddressManagementApiController implements GeographicAddre @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) @Override public ResponseEntity retrieveGeographicSubAddress( - @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String geoAddressId, - @Parameter(description = "Identifier of the geographic sub address", required = true) @PathVariable("id") String geoSubAddressId){ + @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("geoAddressId") String geoAddressId, + @Parameter(description = "Identifier of the geographic sub address", required = true) @PathVariable("geoSubAddressId") String geoSubAddressId){ try{ GeographicSubAddress c = geographicAddressManagementService.findGeographicSubAddressByUUID(geoAddressId,geoSubAddressId); diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java index 93d5aeb..e97171c 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java @@ -33,7 +33,7 @@ public interface GeographicAddressValidationManagementApi { return getRequest().map(r -> r.getHeader("Accept")); } - @Operation(summary = "Creates a 'GeographicAddressValidation'", operationId = "createGeographicAddressValidation", description = "", tags={ "geographicAddress", }) + @Operation(summary = "Creates a 'GeographicAddressValidation'", operationId = "createGeographicAddressValidation", description = "", tags={ "GeographicAddressValidation", }) @ApiResponses(value = { @ApiResponse(responseCode = "400", description = "Created" ), @ApiResponse(responseCode = "400", description = "Bad Request" ), diff --git a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java index a4aa209..fba3bea 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java @@ -59,7 +59,7 @@ public class GeographicAddressManagementService { public GeographicAddress updateGeographicAddress(String id,GeographicAddress geographicAddress){ log.info("Update geographic address with id: {}",id); - Optional gs=geographicAddressManagementRepository.findByUuid(id); + Optional gs = geographicAddressManagementRepository.findByUuid(id); return gs.map(address -> updateFields(geographicAddress, address)).orElse(null); } diff --git a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java index fd2ea06..6d862bc 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java @@ -42,10 +42,10 @@ public class GeographicAddressValidationManagementService { } - public GeographicAddressValidation updateGeographicAddressValidation(String id,GeographicAddressValidation geographicAddressValidation){ + public GeographicAddressValidation updateGeographicAddressValidation(String id,GeographicAddressValidation newGeographicAddressValidation){ log.info("Update geographic address validation with id: {}",id); Optional gs=geographicAddressValidationManagementRepository.findByUuid(id); - return gs.map(address -> updateFields(geographicAddressValidation, address)).orElse(null); + return gs.map(oldAddress -> updateFields(newGeographicAddressValidation, oldAddress)).orElse(null); } public Void deleteGeographicAddressValidationById(String id){ -- GitLab From 177291ee3741c6d3c187d7e731ef46352c8ecbdf Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Mon, 15 Apr 2024 12:27:31 +0300 Subject: [PATCH 07/10] Add TMF 673 additional tests. Change the updateFields method. --- .../api/GeographicAddressManagementApi.java | 2 +- ...graphicAddressManagementApiController.java | 4 +- .../GeographicAddressManagementService.java | 3 +- ...hicAddressValidationManagementService.java | 6 + ...raphicAddressManagementControllerTest.java | 67 +++++++- ...eographicAddressManagementServiceTest.java | 48 +++++- ...essValidationManagementControllerTest.java | 145 ++++++++++++++++++ ...ddressValidationManagementServiceTest.java | 120 +++++++++++++++ 8 files changed, 387 insertions(+), 8 deletions(-) create mode 100644 src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressValidationManagementControllerTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressValidationManagementServiceTest.java diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java index b268ed2..474b79d 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApi.java @@ -122,7 +122,7 @@ public interface GeographicAddressManagementApi { @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) @GetMapping(value = "/geographicAddress/{id}/geographicSubAddress", produces = { "application/json" }) - ResponseEntity> retrieveGeographicSubAddress( + ResponseEntity> retrieveGeographicSubAddresses( @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id); @Operation(summary = "Retrieves a 'GeographicSubAddress' by Id", operationId = "retrieveGeographicSubAddress", description = "" , tags={ "GeographicSubAddress", }) diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java index c6c1b3b..5541f5e 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressManagementApiController.java @@ -37,7 +37,7 @@ public class GeographicAddressManagementApiController implements GeographicAddre @Override public ResponseEntity> listGeographicAddress() { try { - return new ResponseEntity<>(geographicAddressManagementService.findAllGeographicAddresss(), HttpStatus.OK); + return new ResponseEntity<>(geographicAddressManagementService.findAllGeographicAddress(), HttpStatus.OK); } catch (Exception e) { log.error(COULD_NOT_SERIALIZE, e); @@ -89,7 +89,7 @@ public class GeographicAddressManagementApiController implements GeographicAddre @PreAuthorize("hasAnyAuthority('ROLE_USER')" ) @Override - public ResponseEntity> retrieveGeographicSubAddress( + public ResponseEntity> retrieveGeographicSubAddresses( @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id) { try{ Set c = geographicAddressManagementService.findAllGeographicSubAddresses(id); diff --git a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java index fba3bea..33cc305 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressManagementService.java @@ -4,7 +4,6 @@ import org.etsi.osl.tmf.gam673.mapper.MapperUtils; import org.etsi.osl.tmf.gam673.model.GeographicAddress; import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository; -import org.etsi.osl.tmf.prm669.model.RelatedParty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -30,7 +29,7 @@ public class GeographicAddressManagementService { this.geographicAddressManagementRepository = geographicAddressManagementRepository; } - public List findAllGeographicAddresss(){ + public List findAllGeographicAddress(){ return (List) geographicAddressManagementRepository.findAll(); } diff --git a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java index 6d862bc..40e5e77 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/reposervices/GeographicAddressValidationManagementService.java @@ -66,6 +66,12 @@ public class GeographicAddressValidationManagementService { for(GeographicAddress n : newGeographicAddressValidation.getAlternateGeographicAddresses()){ if(n.getUuid()==null){ existingGeographicAddressValidation.addGeographicAddress(n); + }else { + for (GeographicAddress oldGeographicAddress : existingGeographicAddressValidation.getAlternateGeographicAddresses()){ + if (n.getUuid().equals(oldGeographicAddress.getUuid())){ + GeographicAddress geographicAddress = mapperUtils.geographicAddressMap(n, oldGeographicAddress); + } + } } } } diff --git a/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementControllerTest.java b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementControllerTest.java index b45608a..a54f533 100644 --- a/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementControllerTest.java @@ -2,6 +2,7 @@ package org.etsi.osl.services.api.gam673; import org.etsi.osl.tmf.gam673.api.GeographicAddressManagementApiController; import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -12,7 +13,9 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -35,11 +38,71 @@ class GeographicAddressManagementControllerTest { MockitoAnnotations.openMocks(this); } + @Test + void testRetrieveGeographicAddressByUUID() { + GeographicAddress address = new GeographicAddress(); + // Add test data to address list + when(service.findGeographicAddressByUUID("test")).thenReturn(address); + + ResponseEntity response = controller.retrieveGeographicAddress("test"); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(address, response.getBody()); + } + + @Test + void throwExceptionTestWhenRetrieveGeographicAddressByUUID(){ + when(service.findGeographicAddressByUUID("test")).thenThrow(RuntimeException.class); + ResponseEntity response = controller.retrieveGeographicAddress("test"); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + + } + + @Test + void testRetrieveGeographicSubAddressByUUID() { + GeographicSubAddress address = new GeographicSubAddress(); + // Add test data to address list + when(service.findGeographicSubAddressByUUID("test","test")).thenReturn(address); + + ResponseEntity response = controller.retrieveGeographicSubAddress("test","test"); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(address, response.getBody()); + } + + @Test + void throwExceptionTestWhenRetrieveGeographicSubAddressByUUID(){ + when(service.findGeographicSubAddressByUUID("test","test")).thenThrow(RuntimeException.class); + ResponseEntity response = controller.retrieveGeographicSubAddress("test","test"); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + + } + + @Test + void testRetrieveGeographicSubAddresses() { + Set subAddress = new HashSet<>(); + // Add test data to address list + when(service.findAllGeographicSubAddresses("test")).thenReturn(subAddress); + + ResponseEntity> response = controller.retrieveGeographicSubAddresses("test"); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(subAddress, response.getBody()); + } + + @Test + void throwExceptionTestWhenRetrieveGeographicSubAddresses(){ + when(service.findAllGeographicSubAddresses("test")).thenThrow(RuntimeException.class); + ResponseEntity> response = controller.retrieveGeographicSubAddresses("test"); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + + } + @Test void testRetrieveGeographicAddresses() { List addresses = new ArrayList<>(); // Add test data to address list - when(service.findAllGeographicAddresss()).thenReturn(addresses); + when(service.findAllGeographicAddress()).thenReturn(addresses); ResponseEntity> response = controller.listGeographicAddress(); @@ -49,7 +112,7 @@ class GeographicAddressManagementControllerTest { @Test void throwExceptionTestWhenRetrieveGeographicAddresses(){ - when(service.findAllGeographicAddresss()).thenThrow(RuntimeException.class); + when(service.findAllGeographicAddress()).thenThrow(RuntimeException.class); ResponseEntity> response = controller.listGeographicAddress(); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); diff --git a/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementServiceTest.java b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementServiceTest.java index 4b2bb10..c9c2184 100644 --- a/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementServiceTest.java +++ b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressManagementServiceTest.java @@ -1,6 +1,7 @@ package org.etsi.osl.services.api.gam673; import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository; import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService; import org.junit.jupiter.api.Test; @@ -13,6 +14,7 @@ import org.springframework.test.context.ActiveProfiles; import java.util.List; import java.util.Optional; +import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -44,7 +46,7 @@ class GeographicAddressManagementServiceTest { List addresses = List.of(new GeographicAddress(), new GeographicAddress()); when(repository.findAll()).thenReturn(addresses); - List result = service.findAllGeographicAddresss(); + List result = service.findAllGeographicAddress(); assertEquals(addresses, result); } @@ -63,6 +65,50 @@ class GeographicAddressManagementServiceTest { assertEquals(address, result); } + @Test + void testFindAllGeographicSubAddress() { + Optional address = Optional.of(new GeographicAddress()); + + GeographicSubAddress subAddress = new GeographicSubAddress(); + subAddress.setSubAddressType("test"); + subAddress.setBuildingName("test"); + subAddress.setSubUnitType("test"); + + address.get().setGeographicSubAddresses(Set.of(subAddress)); + + // Mock data + when(repository.findByUuid("test")).thenReturn(address); + + Set result = service.findAllGeographicSubAddresses("test"); + + assertEquals(address.get().getGeographicSubAddresses(), result); + } + + @Test + void testFindGeographicSubAddressByUUID() { + // Mock data + String addressId = "123"; + String subAddressId = "321"; + + GeographicSubAddress subAddress = new GeographicSubAddress(); + subAddress.setSubAddressType("test"); + subAddress.setBuildingName("test"); + subAddress.setSubUnitType("test"); + subAddress.setUuid(subAddressId); + + GeographicAddress address = new GeographicAddress(); + address.setUuid(addressId); + + address.setGeographicSubAddresses(Set.of(subAddress)); + + when(repository.findByUuid(addressId)).thenReturn(Optional.of(address)); + + GeographicSubAddress result = service.findGeographicSubAddressByUUID(addressId, subAddressId); + + assertNotNull(result); + assertEquals(subAddress, result); + } + @Test void testCreateGeographicAddress() { // Mock data diff --git a/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressValidationManagementControllerTest.java b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressValidationManagementControllerTest.java new file mode 100644 index 0000000..b8d2a94 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressValidationManagementControllerTest.java @@ -0,0 +1,145 @@ +package org.etsi.osl.services.api.gam673; + +import org.etsi.osl.tmf.gam673.api.GeographicAddressValidationManagementApiController; +import org.etsi.osl.tmf.gam673.model.GeographicAddressValidation; +import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressValidationManagementService; +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.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; + +class GeographicAddressValidationManagementControllerTest { + + @InjectMocks + private GeographicAddressValidationManagementApiController controller; + + + @Mock + private GeographicAddressValidationManagementService service; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + } + + @Test + void testRetrieveGeographicAddressValidation() { + List addresses = new ArrayList<>(); + // Add test data to address list + when(service.findAllGeographicAddressValidations()).thenReturn(addresses); + + ResponseEntity> response = controller.listGeographicAddressValidation(); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(addresses, response.getBody()); + } + + @Test + void throwExceptionTestWhenRetrieveGeographicAddressValidation(){ + when(service.findAllGeographicAddressValidations()).thenThrow(RuntimeException.class); + ResponseEntity> response = controller.listGeographicAddressValidation(); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + + } + + @Test + void testRetrieveGeographicAddressValidationByUUID() { + GeographicAddressValidation addressValidation = new GeographicAddressValidation(); + // Add test data to address list + when(service.findGeographicAddressValidationByUUID("Test")).thenReturn(addressValidation); + + ResponseEntity response = controller.retrieveGeographicAddressValidation("Test"); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(addressValidation, response.getBody()); + } + + @Test + void throwExceptionTestWhenRetrieveGeographicAddressValidationByUUID(){ + when(service.findGeographicAddressValidationByUUID("test")).thenThrow(RuntimeException.class); + ResponseEntity response = controller.retrieveGeographicAddressValidation("test"); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + + } + + + @Test + void testCreateGeographicAddressValidation() { + GeographicAddressValidation address = new GeographicAddressValidation(); + + when(service.createGeographicAddressValidation(any())).thenReturn(address); + + ResponseEntity response = controller.createGeographicAddressValidation(address); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(address, response.getBody()); + } + + @Test + void testExceptionWhenCreateGeographicAddressValidation(){ + GeographicAddressValidation address = new GeographicAddressValidation(); + + when(service.createGeographicAddressValidation(any())).thenThrow(RuntimeException.class); + + ResponseEntity response = controller.createGeographicAddressValidation(address); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + } + + @Test + void testDeleteGeographicAddressValidation() { + + doNothing().when(service).deleteGeographicAddressValidationById(anyString()); + ResponseEntity response = controller.deleteGeographicAddressValidation("addressId"); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + } + + @Test + void testDeleteGeographicAddressValidationException() { + + doThrow(RuntimeException.class).when(service).deleteGeographicAddressValidationById(anyString()); + ResponseEntity response = controller.deleteGeographicAddressValidation("addressId"); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + } + + @Test + void testPatchGeographicAddressValidation() { + String addressId = "addressId"; + GeographicAddressValidation updatedAddress = new GeographicAddressValidation(); + // Set up mock service behavior + when(service.updateGeographicAddressValidation(anyString(), any())).thenReturn(updatedAddress); + + ResponseEntity response = controller.patchGeographicAddressValidation(addressId, updatedAddress); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(updatedAddress, response.getBody()); + } + + @Test + void testPatchGeographicAddressValidationException() { + String addressId = "addressId"; + GeographicAddressValidation updatedAddress = new GeographicAddressValidation(); + // Set up mock service behavior + when(service.updateGeographicAddressValidation(anyString(), any())).thenThrow(RuntimeException.class); + + ResponseEntity response = controller.patchGeographicAddressValidation(addressId, updatedAddress); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + } + +} diff --git a/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressValidationManagementServiceTest.java b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressValidationManagementServiceTest.java new file mode 100644 index 0000000..b1c1568 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/gam673/GeographicAddressValidationManagementServiceTest.java @@ -0,0 +1,120 @@ +package org.etsi.osl.services.api.gam673; + +import org.etsi.osl.tmf.gam673.model.GeographicAddress; +import org.etsi.osl.tmf.gam673.model.GeographicAddressValidation; +import org.etsi.osl.tmf.gam673.repo.GeographicAddressValidationManagementRepository; +import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressValidationManagementService; +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 java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@AutoConfigureMockMvc +@ActiveProfiles("testing") +class GeographicAddressValidationManagementServiceTest { + + @InjectMocks + private GeographicAddressValidationManagementService service; + + @Mock + private GeographicAddressValidationManagementRepository repository; + + @BeforeEach + void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + void testFindAllGeographicAddressValidation() { + // Mock data + List addresses = List.of(new GeographicAddressValidation(), new GeographicAddressValidation()); + when(repository.findAll()).thenReturn(addresses); + + List result = service.findAllGeographicAddressValidations(); + + assertEquals(addresses, result); + } + + @Test + void testFindGeographicAddressValidationByUUID() { + // Mock data + String uuid = "123"; + GeographicAddressValidation address = new GeographicAddressValidation(); + address.setUuid(uuid); + when(repository.findByUuid(uuid)).thenReturn(Optional.of(address)); + + GeographicAddressValidation result = service.findGeographicAddressValidationByUUID(uuid); + + assertNotNull(result); + assertEquals(address, result); + } + + @Test + void testCreateGeographicAddressValidation() { + // Mock data + GeographicAddressValidation address = new GeographicAddressValidation(); + when(repository.save(any())).thenReturn(address); + + GeographicAddressValidation result = service.createGeographicAddressValidation(address); + + assertEquals(address, result); + } + + @Test + void testUpdateGeographicAddressValidation() { + // Mock data + String id = "123"; + + GeographicAddress newAlternativeAddress= new GeographicAddress(); + newAlternativeAddress.setUuid("1234"); + newAlternativeAddress.setLocality("localityNew"); + + GeographicAddress oldAlternativeAddress= new GeographicAddress(); + oldAlternativeAddress.setUuid("1234"); + oldAlternativeAddress.setLocality("localityOld"); + + GeographicAddressValidation existingAddress = new GeographicAddressValidation(); + existingAddress.setAlternateGeographicAddresses(Set.of(oldAlternativeAddress)); + + GeographicAddressValidation newAddress = new GeographicAddressValidation(); + newAddress.setAlternateGeographicAddresses(Set.of(newAlternativeAddress)); + + when(repository.findByUuid(id)).thenReturn(Optional.of(existingAddress)); + when(repository.save(any())).thenReturn(existingAddress); + + GeographicAddressValidation result = service.updateGeographicAddressValidation(id, newAddress); + + assertNotNull(result); + assertEquals(existingAddress, result); + // Add additional assertions for updated fields if needed + } + + @Test + void testDeleteGeographicAddressValidationById() { + // Mock data + String id = "123"; + GeographicAddressValidation existingAddress = new GeographicAddressValidation(); + when(repository.findByUuid(id)).thenReturn(Optional.of(existingAddress)); + + Void result = service.deleteGeographicAddressValidationById(id); + + assertNull(result); + verify(repository, times(1)).delete(existingAddress); + } + +} -- GitLab From ef47b0490f23a07d0712d7ffe089d1aef7987e58 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Mon, 15 Apr 2024 12:57:36 +0300 Subject: [PATCH 08/10] TMF 673 remove unnecessary annotation from delete method. --- .../gam673/api/GeographicAddressValidationManagementApi.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java index e97171c..ce79126 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/api/GeographicAddressValidationManagementApi.java @@ -59,8 +59,7 @@ public interface GeographicAddressValidationManagementApi { @ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) @DeleteMapping(value = "/geographicAddressValidation/{id}", - produces = { "application/json" }, - consumes = { "application/json" }) + produces = { "application/json" }) ResponseEntity deleteGeographicAddressValidation(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id); -- GitLab From 4f55d76a4a8b13ff9ba11427bda6cb45751d7fd9 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Mon, 15 Apr 2024 17:17:22 +0300 Subject: [PATCH 09/10] TMF 673 update geographic sub address list. --- .../osl/tmf/gam673/mapper/MapperUtils.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java b/src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java index 178835d..69dcac4 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java @@ -30,10 +30,30 @@ public class MapperUtils { for(GeographicSubAddress n : newGeographicAddress.getGeographicSubAddresses()){ if(n.getUuid()==null){ existingGeographicAddress.addGeographicSubAddress(n); + }else { + for (GeographicSubAddress oldGeographicSubAddress : existingGeographicAddress.geographicSubAddresses()){ + if (n.getUuid().equals(oldGeographicSubAddress.getUuid())){ + GeographicSubAddress geographicSubAddress = geographicSubAddressMap(n, oldGeographicSubAddress); + } + } } } } return existingGeographicAddress; } + public static GeographicSubAddress geographicSubAddressMap(GeographicSubAddress newGeographicSubAddress, GeographicSubAddress existingGeographicSubAddress){ + if(newGeographicSubAddress.getSubAddressType()!=null) existingGeographicSubAddress.setSubAddressType(newGeographicSubAddress.getSubAddressType()); + if(newGeographicSubAddress.getName()!=null) existingGeographicSubAddress.setName(newGeographicSubAddress.getName()); + if(newGeographicSubAddress.getBuildingName()!=null) existingGeographicSubAddress.setBuildingName(newGeographicSubAddress.getBuildingName()); + if(newGeographicSubAddress.getLevelNumber()!=null) existingGeographicSubAddress.setLevelNumber(newGeographicSubAddress.getLevelNumber()); + if(newGeographicSubAddress.getLevelType()!=null) existingGeographicSubAddress.setLevelType(newGeographicSubAddress.getLevelType()); + if(newGeographicSubAddress.getPrivateStreetName()!=null) existingGeographicSubAddress.setPrivateStreetName(newGeographicSubAddress.getPrivateStreetName()); + if(newGeographicSubAddress.getPrivateStreetNumber()!=null) existingGeographicSubAddress.setPrivateStreetNumber(newGeographicSubAddress.getPrivateStreetNumber()); + if(newGeographicSubAddress.getSubUnitNumber()!=null) existingGeographicSubAddress.setSubUnitNumber(newGeographicSubAddress.getSubUnitNumber()); + if(newGeographicSubAddress.getSubUnitType()!=null) existingGeographicSubAddress.setSubUnitType(newGeographicSubAddress.getSubUnitType()); + + return existingGeographicSubAddress; + } + } -- GitLab From 84c71fc0860484e153f18b00f58c5d1cd14d505a Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Mon, 15 Apr 2024 17:24:02 +0300 Subject: [PATCH 10/10] TMF 673 revert update geographic sub address list. --- .../osl/tmf/gam673/mapper/MapperUtils.java | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java b/src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java index 69dcac4..178835d 100644 --- a/src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java +++ b/src/main/java/org/etsi/osl/tmf/gam673/mapper/MapperUtils.java @@ -30,30 +30,10 @@ public class MapperUtils { for(GeographicSubAddress n : newGeographicAddress.getGeographicSubAddresses()){ if(n.getUuid()==null){ existingGeographicAddress.addGeographicSubAddress(n); - }else { - for (GeographicSubAddress oldGeographicSubAddress : existingGeographicAddress.geographicSubAddresses()){ - if (n.getUuid().equals(oldGeographicSubAddress.getUuid())){ - GeographicSubAddress geographicSubAddress = geographicSubAddressMap(n, oldGeographicSubAddress); - } - } } } } return existingGeographicAddress; } - public static GeographicSubAddress geographicSubAddressMap(GeographicSubAddress newGeographicSubAddress, GeographicSubAddress existingGeographicSubAddress){ - if(newGeographicSubAddress.getSubAddressType()!=null) existingGeographicSubAddress.setSubAddressType(newGeographicSubAddress.getSubAddressType()); - if(newGeographicSubAddress.getName()!=null) existingGeographicSubAddress.setName(newGeographicSubAddress.getName()); - if(newGeographicSubAddress.getBuildingName()!=null) existingGeographicSubAddress.setBuildingName(newGeographicSubAddress.getBuildingName()); - if(newGeographicSubAddress.getLevelNumber()!=null) existingGeographicSubAddress.setLevelNumber(newGeographicSubAddress.getLevelNumber()); - if(newGeographicSubAddress.getLevelType()!=null) existingGeographicSubAddress.setLevelType(newGeographicSubAddress.getLevelType()); - if(newGeographicSubAddress.getPrivateStreetName()!=null) existingGeographicSubAddress.setPrivateStreetName(newGeographicSubAddress.getPrivateStreetName()); - if(newGeographicSubAddress.getPrivateStreetNumber()!=null) existingGeographicSubAddress.setPrivateStreetNumber(newGeographicSubAddress.getPrivateStreetNumber()); - if(newGeographicSubAddress.getSubUnitNumber()!=null) existingGeographicSubAddress.setSubUnitNumber(newGeographicSubAddress.getSubUnitNumber()); - if(newGeographicSubAddress.getSubUnitType()!=null) existingGeographicSubAddress.setSubUnitType(newGeographicSubAddress.getSubUnitType()); - - return existingGeographicSubAddress; - } - } -- GitLab