Commit 32f6252e authored by Anastasios Poimenidis's avatar Anastasios Poimenidis
Browse files

fix: use one @Transactional annotation when deleting serviceCandidate,...

fix: use one @Transactional annotation when deleting serviceCandidate, serviceCategory or ServiceCatalog
parent 53163657
Loading
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -143,6 +143,10 @@ public class ServiceCandidateService {

    @Transactional
    public ServiceCandidateEntity getServiceCandidateById(String id) {
        return getServiceCandidateEntity(id);
    }

    private ServiceCandidateEntity getServiceCandidateEntity(String id) {
        Optional<ServiceCandidateEntity> serviceCandidate = serviceCandidateRepository.findById(id);
        if (serviceCandidate.isPresent()) {
            return serviceCandidate.get();
@@ -219,7 +223,7 @@ public class ServiceCandidateService {

    @Transactional
    public ServiceCandidateEntity deleteServiceCandidate(String id) {
        ServiceCandidateEntity serviceCandidate = getServiceCandidateById(id);
        ServiceCandidateEntity serviceCandidate = this.getServiceCandidateEntity(id);
        serviceCandidate.setServiceSpecification(null);
        serviceCandidateRepository.persist(serviceCandidate);
        serviceCandidateRepository.delete(serviceCandidate);
+5 −1
Original line number Diff line number Diff line
@@ -169,6 +169,10 @@ public class ServiceCatalogService {

    @Transactional
    public ServiceCatalogEntity getById(String id) {
        return getServiceCatalogEntity(id);
    }

    private ServiceCatalogEntity getServiceCatalogEntity(String id) {
        Optional<ServiceCatalogEntity> serviceCatalogue = serviceCatalogRepository.findById(id);
        if (serviceCatalogue.isPresent()) {
            return serviceCatalogue.get();
@@ -368,7 +372,7 @@ public class ServiceCatalogService {

    @Transactional
    public ServiceCatalogEntity deleteServiceCatalog(String id) {
        ServiceCatalogEntity serviceCatalogEntity = getById(id);
        ServiceCatalogEntity serviceCatalogEntity = this.getServiceCatalogEntity(id);
        serviceCatalogRepository.delete(serviceCatalogEntity);
        return serviceCatalogEntity;
    }
+7 −8
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import org.etsi.osl.hypo.api.tmf.services.catalog.api.repository.ServiceCategory
import org.etsi.osl.hypo.api.tmf.services.catalog.schema.ServiceCandidateEntity;
import org.etsi.osl.hypo.api.tmf.services.catalog.schema.ServiceCategoryEntity;
import org.jboss.logging.Logger;
import org.jspecify.annotations.NonNull;

@ApplicationScoped
public class ServiceCategoryService {
@@ -162,6 +163,10 @@ public class ServiceCategoryService {

    @Transactional
    public ServiceCategoryEntity getById(String id) {
        return getServiceCategoryEntity(id);
    }

    private @NonNull ServiceCategoryEntity getServiceCategoryEntity(String id) {
        Optional<ServiceCategoryEntity> serviceCategory = serviceCategoryRepository.findById(id);
        if (serviceCategory.isPresent()) {
            return serviceCategory.get();
@@ -169,11 +174,6 @@ public class ServiceCategoryService {
        throw new ServiceNotFoundException("Service Category with id " + id + " not found");
    }

    @Transactional
    public Optional<ServiceCategoryEntity> findCategoryById(String id) {
        return serviceCategoryRepository.findById(id);
    }

    @Transactional
    public Optional<ServiceCategoryEntity> findServiceCategoryByName(String categoryName) {
        return serviceCategoryRepository.findByName(categoryName);
@@ -246,10 +246,9 @@ public class ServiceCategoryService {
    }

    @Transactional
    public ServiceCategoryEntity deleteServiceCategory(String id) {
        ServiceCategoryEntity serviceCategory = getById(id);
    public void deleteServiceCategory(String id) {
        ServiceCategoryEntity serviceCategory = this.getServiceCategoryEntity(id);
        serviceCategoryRepository.delete(serviceCategory);
        return serviceCategory;
    }

    @Transactional