Loading src/main/java/org/etsi/osl/tmf/ram702/api/ResourceActivationApi.java +8 −6 Original line number Diff line number Diff line Loading @@ -50,11 +50,13 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import org.etsi.osl.tmf.ram702.utils.JSONResponseUtils; @Tag(name = "resource", description = "The resource Activation API") public interface ResourceActivationApi { public static final String RESOURCE_JSON_RESPONSE = "{}"; public static final String RESOURCE_LIST_JSON_RESPONSE = "[{}]"; Logger log = LoggerFactory.getLogger(ResourceActivationApi.class); default Optional<ObjectMapper> getObjectMapper() { Loading Loading @@ -100,7 +102,7 @@ public interface ResourceActivationApi { try { return new ResponseEntity<>( getObjectMapper().get().readValue( JSONResponseUtils.RESOURCE_JSON_RESPONSE, Resource.class RESOURCE_JSON_RESPONSE, Resource.class ), HttpStatus.NOT_IMPLEMENTED ); Loading Loading @@ -190,7 +192,7 @@ public interface ResourceActivationApi { try { return new ResponseEntity<>( getObjectMapper().get().readValue( JSONResponseUtils.RESOURCE_LIST_JSON_RESPONSE, RESOURCE_LIST_JSON_RESPONSE, new TypeReference<List<Resource>>() {} ), HttpStatus.NOT_IMPLEMENTED Loading Loading @@ -244,7 +246,7 @@ public interface ResourceActivationApi { try { return new ResponseEntity<>( getObjectMapper().get().readValue( JSONResponseUtils.RESOURCE_JSON_RESPONSE, Resource.class RESOURCE_JSON_RESPONSE, Resource.class ), HttpStatus.NOT_IMPLEMENTED ); Loading Loading @@ -296,7 +298,7 @@ public interface ResourceActivationApi { try { return new ResponseEntity<>( getObjectMapper().get().readValue( JSONResponseUtils.RESOURCE_JSON_RESPONSE, Resource.class RESOURCE_JSON_RESPONSE, Resource.class ), HttpStatus.NOT_IMPLEMENTED ); Loading src/main/java/org/etsi/osl/tmf/ram702/api/ResourceActivationApiController.java +19 −46 Original line number Diff line number Diff line Loading @@ -30,8 +30,7 @@ import org.etsi.osl.tmf.common.model.UserPartRoleType; import org.etsi.osl.tmf.ri639.model.Resource; import org.etsi.osl.tmf.ri639.model.ResourceCreate; import org.etsi.osl.tmf.ri639.model.ResourceUpdate; import org.etsi.osl.tmf.ram702.reposervices.ResourceActivationRepoService; import org.etsi.osl.tmf.ri639.reposervices.ResourceRepoService; import org.etsi.osl.tmf.util.AddUserAsOwnerToRelatedParties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; Loading @@ -52,14 +51,14 @@ import jakarta.validation.Valid; * Handles HTTP requests for creating, retrieving, updating, and deleting resources. */ @Controller @RequestMapping("/resourceActivationManagement/v4/") @RequestMapping("/ResourceActivationAndConfiguration/v4/") public class ResourceActivationApiController implements ResourceActivationApi { private final ObjectMapper objectMapper; private final HttpServletRequest request; @Autowired private ResourceActivationRepoService resourceRepoService; private ResourceRepoService resourceRepoService; /** Loading Loading @@ -104,7 +103,7 @@ public class ResourceActivationApiController implements ResourceActivationApi { ); Resource createdResource = resourceRepoService.addResource(resource); return new ResponseEntity<>(createdResource, HttpStatus.CREATED); return new ResponseEntity<>(createdResource, HttpStatus.OK); } else { return new ResponseEntity<>(HttpStatus.FORBIDDEN); } Loading @@ -125,14 +124,11 @@ public class ResourceActivationApiController implements ResourceActivationApi { @Override public ResponseEntity<Void> deleteResource(String id) { try { resourceRepoService.deleteByUuid(id); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } catch (ApiException e) { log.error("Resource not found with id {}", id); return new ResponseEntity<>(HttpStatus.NOT_FOUND); // 404 if resource not found return new ResponseEntity<Void>( resourceRepoService.deleteByUuid(id), HttpStatus.OK); } catch (Exception e) { log.error("Error deleting resource with id {}", id, e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); // 500 for any other errors log.error("Couldn't serialize response for content type application/json", e); return new ResponseEntity<Void>(HttpStatus.INTERNAL_SERVER_ERROR); } } Loading Loading @@ -185,22 +181,9 @@ public class ResourceActivationApiController implements ResourceActivationApi { @Valid ResourceUpdate resource, String id ) { try { // Call the updateResource method from the service class to update the resource Resource updatedResource = resourceRepoService.updateResource(id, resource, true); Resource c = resourceRepoService.updateResource(id, resource, true); // Return the updated resource with 200 OK status return new ResponseEntity<>(updatedResource, HttpStatus.OK); } catch (ResourceNotFoundException e) { log.error("Resource not found with id {}", id, e); // Return 404 Not Found if the resource is not found return new ResponseEntity<>(HttpStatus.NOT_FOUND); } catch (Exception e) { log.error("Error updating resource with id {}", id, e); // Return 500 Internal Server Error for any other unexpected exceptions return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity< Resource >(c, HttpStatus.OK); } Loading @@ -220,21 +203,11 @@ public class ResourceActivationApiController implements ResourceActivationApi { @Valid String fields ) { try { // Call the service method to retrieve the resource Resource resource = resourceRepoService.findByUuid(id); // Return the resource with 200 OK status return new ResponseEntity<>(resource, HttpStatus.OK); } catch (ResourceNotFoundException e) { log.error("Resource not found with id {}", id, e); // Return 404 Not Found if the resource is not found return new ResponseEntity<>(HttpStatus.NOT_FOUND); return new ResponseEntity<Resource>( resourceRepoService.findByUuid(id), HttpStatus.OK); } catch (Exception e) { log.error("Error retrieving resource with id {}", id, e); // Return 500 Internal Server Error for any unexpected exceptions return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); log.error("Couldn't serialize response for content type application/json", e); return new ResponseEntity<Resource>(HttpStatus.INTERNAL_SERVER_ERROR); } } } Loading src/main/java/org/etsi/osl/tmf/ram702/api/ResourceActivationApiRouteBuilder.java +2 −3 Original line number Diff line number Diff line Loading @@ -34,8 +34,7 @@ import org.apache.commons.logging.LogFactory; import org.etsi.osl.tmf.ri639.model.ResourceCreate; import org.etsi.osl.tmf.ri639.model.ResourceUpdate; import org.etsi.osl.tmf.ram702.reposervices.ResourceActivationRepoService; import org.etsi.osl.tmf.ri639.reposervices.ResourceRepoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; Loading Loading @@ -63,7 +62,7 @@ public class ResourceActivationApiRouteBuilder extends RouteBuilder { private ProducerTemplate template; @Autowired ResourceActivationRepoService resourceRepoService; ResourceRepoService resourceRepoService; @Override public void configure() throws Exception { Loading src/main/java/org/etsi/osl/tmf/ram702/repo/ResourceActivationRepository.javadeleted 100644 → 0 +0 −57 Original line number Diff line number Diff line /*- * ========================LICENSE_START================================= * org.etsi.osl.tmf.api * %% * Copyright (C) 2024 openslice.io * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * =========================LICENSE_END================================== */ package org.etsi.osl.tmf.ram702.repo; import java.util.List; import java.util.Optional; import org.etsi.osl.tmf.ri639.model.Resource; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; @Repository("resourceActivationRepository") public interface ResourceActivationRepository extends CrudRepository<Resource, Long>, PagingAndSortingRepository<Resource, Long> { Optional<Resource> findByUuid(String id); @Query( "SELECT srv FROM RIResource srv " + "JOIN FETCH srv.relatedParty rp " + "WHERE rp.name = ?1" ) Iterable<Resource> findByRolename(String name); @Query( "SELECT srv FROM RIResource srv " + "WHERE srv.resourceStatus = org.etsi.osl.tmf.ri639.model.ResourceStatusType.AVAILABLE " + "AND srv.endOperatingDate < CURRENT_TIMESTAMP" ) List<Resource> findActiveToTerminate(); List<Resource> findByNameAndResourceVersion(String aname, String aversion); List<Resource> findByNameAndCategoryAndResourceVersion(String aname, String acategory, String aversion); } src/main/java/org/etsi/osl/tmf/ram702/repo/ResourceRepository.javadeleted 100644 → 0 +0 −63 Original line number Diff line number Diff line /*- * ========================LICENSE_START================================= * org.etsi.osl.tmf.api * %% * Copyright (C) 2024 openslice.io * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * =========================LICENSE_END================================== */ package org.etsi.osl.tmf.ram702.repo; import java.util.List; import java.util.Optional; import org.etsi.osl.tmf.ri639.model.Resource; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; @Repository("resourceRepository702") public interface ResourceRepository extends CrudRepository<Resource, Long>, PagingAndSortingRepository<Resource, Long> { Optional<Resource> findByUuid(String id); @Query("SELECT srv FROM RIResource srv JOIN FETCH srv.relatedParty rp WHERE rp.name = ?1") Iterable<Resource> findByRolename(String name); @Query("SELECT srv FROM RIResource srv WHERE srv.resourceStatus = org.etsi.osl.tmf.ri639.model.ResourceStatusType.AVAILABLE AND " + "srv.endOperatingDate < CURRENT_TIMESTAMP") List<Resource> findActiveToTerminate(); @Query("SELECT srv FROM RIResource srv " + "JOIN FETCH srv.resourceCharacteristic char " + "JOIN FETCH char.value val " + "WHERE (srv.resourceStatus = org.etsi.osl.tmf.ri639.model.ResourceStatusType.AVAILABLE OR " + " srv.resourceStatus = org.etsi.osl.tmf.ri639.model.ResourceStatusType.RESERVED OR " + " srv.resourceStatus = org.etsi.osl.tmf.ri639.model.ResourceStatusType.STANDBY) AND " + "char.name = 'externalPartnerServiceId'" ) List<Resource> findActiveAndReservedResourcesOfPartners(); List<Resource> findByNameAndResourceVersion(String aname, String aversion); List<Resource> findByNameAndCategoryAndResourceVersion(String aname, String acategory, String aversion); } Loading
src/main/java/org/etsi/osl/tmf/ram702/api/ResourceActivationApi.java +8 −6 Original line number Diff line number Diff line Loading @@ -50,11 +50,13 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import org.etsi.osl.tmf.ram702.utils.JSONResponseUtils; @Tag(name = "resource", description = "The resource Activation API") public interface ResourceActivationApi { public static final String RESOURCE_JSON_RESPONSE = "{}"; public static final String RESOURCE_LIST_JSON_RESPONSE = "[{}]"; Logger log = LoggerFactory.getLogger(ResourceActivationApi.class); default Optional<ObjectMapper> getObjectMapper() { Loading Loading @@ -100,7 +102,7 @@ public interface ResourceActivationApi { try { return new ResponseEntity<>( getObjectMapper().get().readValue( JSONResponseUtils.RESOURCE_JSON_RESPONSE, Resource.class RESOURCE_JSON_RESPONSE, Resource.class ), HttpStatus.NOT_IMPLEMENTED ); Loading Loading @@ -190,7 +192,7 @@ public interface ResourceActivationApi { try { return new ResponseEntity<>( getObjectMapper().get().readValue( JSONResponseUtils.RESOURCE_LIST_JSON_RESPONSE, RESOURCE_LIST_JSON_RESPONSE, new TypeReference<List<Resource>>() {} ), HttpStatus.NOT_IMPLEMENTED Loading Loading @@ -244,7 +246,7 @@ public interface ResourceActivationApi { try { return new ResponseEntity<>( getObjectMapper().get().readValue( JSONResponseUtils.RESOURCE_JSON_RESPONSE, Resource.class RESOURCE_JSON_RESPONSE, Resource.class ), HttpStatus.NOT_IMPLEMENTED ); Loading Loading @@ -296,7 +298,7 @@ public interface ResourceActivationApi { try { return new ResponseEntity<>( getObjectMapper().get().readValue( JSONResponseUtils.RESOURCE_JSON_RESPONSE, Resource.class RESOURCE_JSON_RESPONSE, Resource.class ), HttpStatus.NOT_IMPLEMENTED ); Loading
src/main/java/org/etsi/osl/tmf/ram702/api/ResourceActivationApiController.java +19 −46 Original line number Diff line number Diff line Loading @@ -30,8 +30,7 @@ import org.etsi.osl.tmf.common.model.UserPartRoleType; import org.etsi.osl.tmf.ri639.model.Resource; import org.etsi.osl.tmf.ri639.model.ResourceCreate; import org.etsi.osl.tmf.ri639.model.ResourceUpdate; import org.etsi.osl.tmf.ram702.reposervices.ResourceActivationRepoService; import org.etsi.osl.tmf.ri639.reposervices.ResourceRepoService; import org.etsi.osl.tmf.util.AddUserAsOwnerToRelatedParties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; Loading @@ -52,14 +51,14 @@ import jakarta.validation.Valid; * Handles HTTP requests for creating, retrieving, updating, and deleting resources. */ @Controller @RequestMapping("/resourceActivationManagement/v4/") @RequestMapping("/ResourceActivationAndConfiguration/v4/") public class ResourceActivationApiController implements ResourceActivationApi { private final ObjectMapper objectMapper; private final HttpServletRequest request; @Autowired private ResourceActivationRepoService resourceRepoService; private ResourceRepoService resourceRepoService; /** Loading Loading @@ -104,7 +103,7 @@ public class ResourceActivationApiController implements ResourceActivationApi { ); Resource createdResource = resourceRepoService.addResource(resource); return new ResponseEntity<>(createdResource, HttpStatus.CREATED); return new ResponseEntity<>(createdResource, HttpStatus.OK); } else { return new ResponseEntity<>(HttpStatus.FORBIDDEN); } Loading @@ -125,14 +124,11 @@ public class ResourceActivationApiController implements ResourceActivationApi { @Override public ResponseEntity<Void> deleteResource(String id) { try { resourceRepoService.deleteByUuid(id); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } catch (ApiException e) { log.error("Resource not found with id {}", id); return new ResponseEntity<>(HttpStatus.NOT_FOUND); // 404 if resource not found return new ResponseEntity<Void>( resourceRepoService.deleteByUuid(id), HttpStatus.OK); } catch (Exception e) { log.error("Error deleting resource with id {}", id, e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); // 500 for any other errors log.error("Couldn't serialize response for content type application/json", e); return new ResponseEntity<Void>(HttpStatus.INTERNAL_SERVER_ERROR); } } Loading Loading @@ -185,22 +181,9 @@ public class ResourceActivationApiController implements ResourceActivationApi { @Valid ResourceUpdate resource, String id ) { try { // Call the updateResource method from the service class to update the resource Resource updatedResource = resourceRepoService.updateResource(id, resource, true); Resource c = resourceRepoService.updateResource(id, resource, true); // Return the updated resource with 200 OK status return new ResponseEntity<>(updatedResource, HttpStatus.OK); } catch (ResourceNotFoundException e) { log.error("Resource not found with id {}", id, e); // Return 404 Not Found if the resource is not found return new ResponseEntity<>(HttpStatus.NOT_FOUND); } catch (Exception e) { log.error("Error updating resource with id {}", id, e); // Return 500 Internal Server Error for any other unexpected exceptions return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity< Resource >(c, HttpStatus.OK); } Loading @@ -220,21 +203,11 @@ public class ResourceActivationApiController implements ResourceActivationApi { @Valid String fields ) { try { // Call the service method to retrieve the resource Resource resource = resourceRepoService.findByUuid(id); // Return the resource with 200 OK status return new ResponseEntity<>(resource, HttpStatus.OK); } catch (ResourceNotFoundException e) { log.error("Resource not found with id {}", id, e); // Return 404 Not Found if the resource is not found return new ResponseEntity<>(HttpStatus.NOT_FOUND); return new ResponseEntity<Resource>( resourceRepoService.findByUuid(id), HttpStatus.OK); } catch (Exception e) { log.error("Error retrieving resource with id {}", id, e); // Return 500 Internal Server Error for any unexpected exceptions return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); log.error("Couldn't serialize response for content type application/json", e); return new ResponseEntity<Resource>(HttpStatus.INTERNAL_SERVER_ERROR); } } } Loading
src/main/java/org/etsi/osl/tmf/ram702/api/ResourceActivationApiRouteBuilder.java +2 −3 Original line number Diff line number Diff line Loading @@ -34,8 +34,7 @@ import org.apache.commons.logging.LogFactory; import org.etsi.osl.tmf.ri639.model.ResourceCreate; import org.etsi.osl.tmf.ri639.model.ResourceUpdate; import org.etsi.osl.tmf.ram702.reposervices.ResourceActivationRepoService; import org.etsi.osl.tmf.ri639.reposervices.ResourceRepoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; Loading Loading @@ -63,7 +62,7 @@ public class ResourceActivationApiRouteBuilder extends RouteBuilder { private ProducerTemplate template; @Autowired ResourceActivationRepoService resourceRepoService; ResourceRepoService resourceRepoService; @Override public void configure() throws Exception { Loading
src/main/java/org/etsi/osl/tmf/ram702/repo/ResourceActivationRepository.javadeleted 100644 → 0 +0 −57 Original line number Diff line number Diff line /*- * ========================LICENSE_START================================= * org.etsi.osl.tmf.api * %% * Copyright (C) 2024 openslice.io * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * =========================LICENSE_END================================== */ package org.etsi.osl.tmf.ram702.repo; import java.util.List; import java.util.Optional; import org.etsi.osl.tmf.ri639.model.Resource; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; @Repository("resourceActivationRepository") public interface ResourceActivationRepository extends CrudRepository<Resource, Long>, PagingAndSortingRepository<Resource, Long> { Optional<Resource> findByUuid(String id); @Query( "SELECT srv FROM RIResource srv " + "JOIN FETCH srv.relatedParty rp " + "WHERE rp.name = ?1" ) Iterable<Resource> findByRolename(String name); @Query( "SELECT srv FROM RIResource srv " + "WHERE srv.resourceStatus = org.etsi.osl.tmf.ri639.model.ResourceStatusType.AVAILABLE " + "AND srv.endOperatingDate < CURRENT_TIMESTAMP" ) List<Resource> findActiveToTerminate(); List<Resource> findByNameAndResourceVersion(String aname, String aversion); List<Resource> findByNameAndCategoryAndResourceVersion(String aname, String acategory, String aversion); }
src/main/java/org/etsi/osl/tmf/ram702/repo/ResourceRepository.javadeleted 100644 → 0 +0 −63 Original line number Diff line number Diff line /*- * ========================LICENSE_START================================= * org.etsi.osl.tmf.api * %% * Copyright (C) 2024 openslice.io * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * =========================LICENSE_END================================== */ package org.etsi.osl.tmf.ram702.repo; import java.util.List; import java.util.Optional; import org.etsi.osl.tmf.ri639.model.Resource; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; @Repository("resourceRepository702") public interface ResourceRepository extends CrudRepository<Resource, Long>, PagingAndSortingRepository<Resource, Long> { Optional<Resource> findByUuid(String id); @Query("SELECT srv FROM RIResource srv JOIN FETCH srv.relatedParty rp WHERE rp.name = ?1") Iterable<Resource> findByRolename(String name); @Query("SELECT srv FROM RIResource srv WHERE srv.resourceStatus = org.etsi.osl.tmf.ri639.model.ResourceStatusType.AVAILABLE AND " + "srv.endOperatingDate < CURRENT_TIMESTAMP") List<Resource> findActiveToTerminate(); @Query("SELECT srv FROM RIResource srv " + "JOIN FETCH srv.resourceCharacteristic char " + "JOIN FETCH char.value val " + "WHERE (srv.resourceStatus = org.etsi.osl.tmf.ri639.model.ResourceStatusType.AVAILABLE OR " + " srv.resourceStatus = org.etsi.osl.tmf.ri639.model.ResourceStatusType.RESERVED OR " + " srv.resourceStatus = org.etsi.osl.tmf.ri639.model.ResourceStatusType.STANDBY) AND " + "char.name = 'externalPartnerServiceId'" ) List<Resource> findActiveAndReservedResourcesOfPartners(); List<Resource> findByNameAndResourceVersion(String aname, String aversion); List<Resource> findByNameAndCategoryAndResourceVersion(String aname, String acategory, String aversion); }