Commit a50dd692 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

fixes for addressing issue #63

parent 72fc080d
Loading
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -22,15 +22,14 @@ package org.etsi.osl.tmf.ri639.repo;
import java.util.List;
import java.util.Optional;
import org.etsi.osl.tmf.ri639.model.Resource;
import org.springframework.data.jpa.repository.JpaRepository;
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
public interface ResourceRepository extends  CrudRepository<Resource, Long>, PagingAndSortingRepository<Resource, Long> {
public interface ResourceRepository extends  JpaRepository<Resource, Long> {

	
	Optional<Resource> findByUuid(String id);
+17 −12
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.transform.ResultTransformer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import jakarta.persistence.EntityManagerFactory;
import jakarta.validation.Valid;
@@ -199,7 +200,7 @@ public class ResourceRepoService {
    return (List<Resource>) this.resourceRepo.findByRolename(name);
  }


  @Transactional
  public Resource addResource(@Valid ResourceCreate resource) {
    logger.info("Will add Resource: " + resource.getName());

@@ -272,7 +273,7 @@ public class ResourceRepoService {
    noteItem.setDate(OffsetDateTime.now(ZoneOffset.UTC));
    s.addNoteItem(noteItem);

    s = this.resourceRepo.save(s);
    s = this.resourceRepo.saveAndFlush(s);

    raiseResourceCreateNotification(s);
    return s;
@@ -448,7 +449,7 @@ public class ResourceRepoService {
    }


    resource = this.resourceRepo.save(resource);
    resource = this.resourceRepo.saveAndFlush(resource);
    
    if (resourceCharacteristicChanged) {
      raiseResourceAttributeValueChangeEventNotification(resource);
@@ -458,6 +459,7 @@ public class ResourceRepoService {
    return resource;
  }

  @Transactional
  public String getResourceEagerAsString(String id) throws JsonProcessingException {
    Resource s = this.getResourceEager(id);
    ObjectMapper mapper = new ObjectMapper();
@@ -467,11 +469,13 @@ public class ResourceRepoService {
    return res;
  }


  @Transactional
  public Resource getResourceEager(String id) {
    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    
    Resource s = null;
    try {
    try(Session session = sessionFactory.openSession()) {
      Transaction tx = session.beginTransaction();
      s = (Resource) session.get(Resource.class, id);
      if (s == null) {
        return this.findByUuid(id);// last resort
@@ -487,15 +491,15 @@ public class ResourceRepoService {


      tx.commit();
    } finally {
      session.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return s;
  }


  @Transactional
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  private void raiseResourceCreateNotification(Resource so) {
    ResourceCreateNotification n = new ResourceCreateNotification();
    ResourceCreateEvent event = new ResourceCreateEvent();
@@ -505,7 +509,7 @@ public class ResourceRepoService {

  }

  @Transactional
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  private void raiseResourceAttributeValueChangeEventNotification(Resource so) {
    ResourceAttributeValueChangeNotification n = new ResourceAttributeValueChangeNotification();
    ResourceAttributeValueChangeEvent event = new ResourceAttributeValueChangeEvent();
@@ -517,7 +521,7 @@ public class ResourceRepoService {
  
  

  @Transactional
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  private void raiseResourceStateChangeEventNotification(Resource so) {
    ResourceStateChangeNotification n = new ResourceStateChangeNotification();
    ResourceStateChangeEvent event = new ResourceStateChangeEvent();
@@ -554,6 +558,7 @@ public class ResourceRepoService {
    return result;
  }

  @Transactional
  public Void deleteByUuid(String id) {
    Optional<Resource> optionalCat = this.resourceRepo.findByUuid(id);
    Resource s = optionalCat.get();
+2 −3
Original line number Diff line number Diff line
@@ -22,15 +22,14 @@ package org.etsi.osl.tmf.sim638.repo;
import java.util.List;
import java.util.Optional;
import org.etsi.osl.tmf.sim638.model.Service;
import org.springframework.data.jpa.repository.JpaRepository;
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
public interface ServiceRepository extends CrudRepository<Service, Long>,  PagingAndSortingRepository<Service, Long> {
public interface ServiceRepository extends JpaRepository<Service, Long> {

	
	Optional<Service> findByUuid(String id);
+13 −11
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.transform.ResultTransformer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.etsi.osl.model.nfv.DeploymentDescriptor;
import org.etsi.osl.model.nfv.DeploymentDescriptorVxFInstanceInfo;
@@ -340,7 +341,7 @@ public class ServiceRepoService {
		noteItem.setDate(OffsetDateTime.now(ZoneOffset.UTC) );
		s.addNoteItem(noteItem);		
		
		s = this.serviceRepo.save( s );
		s = this.serviceRepo.saveAndFlush( s );

		raiseServiceCreateNotification(s);
		return s;
@@ -621,7 +622,7 @@ public class ServiceRepoService {
		}

		
		service = this.serviceRepo.save( service );
		service = this.serviceRepo.saveAndFlush( service );
		

		
@@ -867,14 +868,14 @@ public class ServiceRepoService {
	}


    @Transactional
	public Service getServiceEager(String id) {
		if ( id == null || id.equals("")) {
			return null;
		}
		Session session = sessionFactory.openSession();
		Transaction tx = session.beginTransaction();
		Service s = null;
		try {
		try (Session session = sessionFactory.openSession()) {
	        Transaction tx = session.beginTransaction();
			s = (Service) session.get(Service.class, id);
			if (s == null) {
				return this.findByUuid(id);// last resort
@@ -891,15 +892,16 @@ public class ServiceRepoService {
			Hibernate.initialize(s.getPlace()  );
			
			tx.commit();
		} finally {
			session.close();
		} catch (Exception e) {
	        e.printStackTrace();
	      }

		
		return s;
	}
	

	@Transactional
    @Transactional(propagation = Propagation.REQUIRES_NEW)
	private void raiseServiceCreateNotification(Service so) {
		ServiceCreateNotification n = new ServiceCreateNotification();
		ServiceCreateEvent event = new ServiceCreateEvent();
@@ -909,7 +911,7 @@ public class ServiceRepoService {
		
	}

	@Transactional
    @Transactional(propagation = Propagation.REQUIRES_NEW)
	private void raiseServiceStateChangedNotification(Service so) {
		ServiceStateChangeNotification n = new ServiceStateChangeNotification();
		ServiceStateChangeEvent event = new ServiceStateChangeEvent();
@@ -919,7 +921,7 @@ public class ServiceRepoService {
		
	}

	@Transactional
    @Transactional(propagation = Propagation.REQUIRES_NEW)
	private void raiseServiceAttributeValueChangedNotification(Service so) {
		ServiceAttributeValueChangeNotification n = new ServiceAttributeValueChangeNotification();
		ServiceAttributeValueChangeEvent event = new ServiceAttributeValueChangeEvent();
+2 −3
Original line number Diff line number Diff line
@@ -24,14 +24,13 @@ import java.util.Optional;
import org.etsi.osl.tmf.common.model.UserPartRoleType;
import org.etsi.osl.tmf.so641.model.ServiceOrder;
import org.etsi.osl.tmf.so641.model.ServiceOrderStateType;
import org.springframework.data.jpa.repository.JpaRepository;
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
public interface ServiceOrderRepository extends CrudRepository<ServiceOrder, Long>, PagingAndSortingRepository<ServiceOrder, Long> {
public interface ServiceOrderRepository extends JpaRepository<ServiceOrder, Long> {


	Optional<ServiceOrder> findByUuid(String id);
Loading