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

update product order api

parent a7917289
Loading
Loading
Loading
Loading
+95 −0
Original line number Diff line number Diff line
package org.etsi.osl.tmf.pcm620.api;

import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.dataformat.JsonLibrary;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.etsi.osl.tmf.pcm620.model.ProductSpecificationCreate;
import org.etsi.osl.tmf.pcm620.model.ProductSpecificationUpdate;
import org.etsi.osl.tmf.pcm620.reposervices.ProductOfferingRepoService;
import org.etsi.osl.tmf.pcm620.reposervices.ProductSpecificationRepoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
//@RefreshScope
@Component
public class ProductSpecificationApiRouteBuilder extends RouteBuilder {

  private static final transient Log logger = LogFactory.getLog(ProductSpecificationApiRouteBuilder.class.getName());

  @Value("${CATALOG_GET_PRODUCTSPEC_BY_ID}")
  private String CATALOG_GET_PRODUCTSPEC_BY_ID = "";
  

  @Value("${CATALOG_ADD_PRODUCTSPEC}")
  private String CATALOG_ADD_PRODUCTSPEC = "";
  

  @Value("${CATALOG_UPD_PRODUCTSPEC}")
  private String CATALOG_UPD_PRODUCTSPEC = "";
  
  @Value("${CATALOG_UPDADD_PRODUCTSPEC}")
  private String CATALOG_UPDADD_PRODUCTSPEC = "";
  

  @Value("${CATALOG_GET_PRODUCTOFFERING_BY_ID}")
  private String CATALOG_GET_PRODUCTOFFERING_BY_ID = "";
  
  
  
  @Autowired
  ProductSpecificationRepoService productSpecificationRepoService;

  @Autowired
  ProductOfferingRepoService productOfferingRepoService;
  

  @Override
  public void configure() throws Exception {
    from( CATALOG_GET_PRODUCTSPEC_BY_ID )
    .log(LoggingLevel.INFO, log, CATALOG_GET_PRODUCTSPEC_BY_ID + " message received!")
    .to("log:DEBUG?showBody=true&showHeaders=true")
    .bean( productSpecificationRepoService, "findByUuidEager")
    .marshal().json( JsonLibrary.Jackson, String.class)
    .convertBodyTo( String.class );

    
    from( CATALOG_ADD_PRODUCTSPEC )
    .log(LoggingLevel.INFO, log, CATALOG_ADD_PRODUCTSPEC + " message received!")
    .to("log:DEBUG?showBody=true&showHeaders=true")
    .unmarshal().json( JsonLibrary.Jackson, ProductSpecificationCreate .class, true)
    .bean( productSpecificationRepoService, "addProductSpecification(${body})")
    .marshal().json( JsonLibrary.Jackson)
    .convertBodyTo( String.class );
            
    from( CATALOG_UPD_PRODUCTSPEC )
    .log(LoggingLevel.INFO, log, CATALOG_UPD_PRODUCTSPEC + " message received!")
    .to("log:DEBUG?showBody=true&showHeaders=true")
    .unmarshal().json( JsonLibrary.Jackson, ProductSpecificationUpdate.class, true)
    .bean( productSpecificationRepoService, "updateProductSpecification(${header.serviceSpecId},  ${body} )")
    .marshal().json( JsonLibrary.Jackson)
    .convertBodyTo( String.class );

    from( CATALOG_UPDADD_PRODUCTSPEC )
    .log(LoggingLevel.INFO, log, CATALOG_UPD_PRODUCTSPEC + " message received!")
    .to("log:DEBUG?showBody=true&showHeaders=true")
    .unmarshal().json( JsonLibrary.Jackson, ProductSpecificationUpdate.class, true)
    .bean( productSpecificationRepoService, "updateOrAddProductSpecification(${header.serviceSpecId}, ${header.forceId}, ${body} )")
    .marshal().json( JsonLibrary.Jackson)
    .convertBodyTo( String.class );
    

    from( CATALOG_GET_PRODUCTOFFERING_BY_ID )
    .log(LoggingLevel.INFO, log, CATALOG_GET_PRODUCTOFFERING_BY_ID + " message received!")
    .to("log:DEBUG?showBody=true&showHeaders=true")
    .bean( productOfferingRepoService, "findByUuidEager")
    .marshal().json( JsonLibrary.Jackson, String.class)
    .convertBodyTo( String.class );
    
    
  }
}
+3 −0
Original line number Diff line number Diff line
@@ -222,6 +222,8 @@ public class ProductOfferingRepoService {
		try {
			dd = session.get(ProductOffering.class, id);
			if (dd == null) {
			    tx.rollback();
	            session.close();
				return this.findByUuid(id);// last resort
			}
			Hibernate.initialize(dd.getAttachment());
@@ -238,6 +240,7 @@ public class ProductOfferingRepoService {
			Hibernate.initialize(dd.getProductOfferingTerm() );
			Hibernate.initialize(dd.getServiceCandidate() );
			Hibernate.initialize(dd.getResourceCandidate() );
            Hibernate.initialize(dd.getChannel());

			tx.commit();
		} finally {
+22 −9
Original line number Diff line number Diff line
@@ -208,6 +208,8 @@ public class ProductSpecificationRepoService {
		return optionalCat.orElse(null);
	}


    @Transactional
	public ProductSpecification findByUuidEager(String id) {
		Session session = sessionFactory.openSession();
		Transaction tx = session.beginTransaction(); // instead of begin transaction, is it possible to continue?
@@ -215,6 +217,7 @@ public class ProductSpecificationRepoService {
		try {
			dd = session.get(ProductSpecification.class, id);
			if (dd == null) {
	            session.close();
				return this.findByUuid(id);// last resort
			}
			Hibernate.initialize(dd.getAttachment());
@@ -222,9 +225,10 @@ public class ProductSpecificationRepoService {
			Hibernate.initialize(dd.getBundledProductSpecification() );
			Hibernate.initialize(dd.getResourceSpecification() );
            Hibernate.initialize(dd.getServiceSpecification() );
            Hibernate.initialize(dd.getProductSpecificationRelationship() );
			for (ProductSpecificationCharacteristic schar : dd.getProductSpecCharacteristic() ) {
				Hibernate.initialize(schar.getProductSpecCharacteristicValue() );

				Hibernate.initialize(schar.getProductSpecCharRelationship() );
			}
			

@@ -618,13 +622,13 @@ public class ProductSpecificationRepoService {
          if ( prodSpec.findProdCharacteristicByName( ssc.getName() ) == null ) {
            
            ProductSpecificationCharacteristic cnew = new ProductSpecificationCharacteristic();          
            cnew.setName(  cnew.getName() ); 
            cnew.setDescription( cnew.getDescription());
            cnew.isUnique(cnew.isIsUnique())
            .extensible(cnew.isExtensible())
            .maxCardinality(cnew.getMaxCardinality())
            .minCardinality(cnew.getMinCardinality())
            .valueType(cnew.getValueType());
            cnew.setName(  ssc.getName() ); 
            cnew.setDescription( ssc.getDescription());
            cnew.isUnique(ssc.isIsUnique())
            .extensible(ssc.isExtensible())
            .maxCardinality(ssc.getMaxCardinality())
            .minCardinality(ssc.getMinCardinality())
            .valueType(ssc.getValueType());
            for (ServiceSpecCharacteristicValue r : ssc.getServiceSpecCharacteristicValue()) {
              ProductSpecificationCharacteristicValue pcval = new ProductSpecificationCharacteristicValue();
              pcval.isDefault(r.isIsDefault())
@@ -667,4 +671,13 @@ public class ProductSpecificationRepoService {
    return responseProdSpec;
  }
  
  public ProductSpecification updateOrAddProductSpecification(String id, ProductSpecificationCreate productSpecificatioCreate) {
    ProductSpecification serviceSpec = updateProductSpecification(id, productSpecificatioCreate );
    if ( serviceSpec == null ) {            
            serviceSpec = addProductSpecification( productSpecificatioCreate );
    }
    
    return serviceSpec;  
  }
	
}
+1 −0
Original line number Diff line number Diff line
@@ -147,6 +147,7 @@ public class ProductOrderApiController implements ProductOrderApi {
  }

  @Override
  @PreAuthorize("hasAnyAuthority('ROLE_ADMIN')")
  public ResponseEntity<List<ProductOrder>> listProductOrder(Principal principal,
      @Valid String fields, @Valid Integer offset, @Valid Integer limit, @Valid Date starttime,
      @Valid Date endtime) {
+18 −6
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import org.etsi.osl.tmf.prm669.model.RelatedParty;
import org.etsi.osl.tmf.sim638.model.ServiceUpdate;
import org.etsi.osl.tmf.sim638.service.ServiceRepoService;
import org.etsi.osl.tmf.so641.api.NotFoundException;
import org.etsi.osl.tmf.so641.reposervices.ServiceOrderRepoService;
import org.etsi.osl.tmf.util.KrokiClient;
import org.hibernate.Hibernate;
import org.hibernate.Session;
@@ -112,6 +113,9 @@ public class ProductOrderRepoService {
  @Autowired
  ServiceRepoService serviceRepoService;

  @Autowired
  ServiceOrderRepoService serviceOrderRepoService;

  private SessionFactory sessionFactory;

  @PersistenceContext EntityManager entityManager;
@@ -222,8 +226,8 @@ public class ProductOrderRepoService {
              }
              
          }           
          sql += "  FROM ProductOrder sor "
                  + "JOIN sor.relatedParty rp ";
          sql += "  FROM ProductOrder por "
                  + "JOIN por.relatedParty rp ";
          
          if (allParams.size() > 0) {
              sql += " WHERE rp.role = 'REQUESTER' AND ";
@@ -353,6 +357,10 @@ public class ProductOrderRepoService {
        so.getNote().addAll(productOrderCreate.getNote());
    }
    
    so.setState( productOrderCreate.getState() );
    
    
      
    
    

@@ -510,7 +518,7 @@ public class ProductOrderRepoService {
  
  }
  
  
  @Transactional
  public ProductOrder getProductOrderEager(String id) {

    Session session = sessionFactory.openSession();
@@ -527,8 +535,11 @@ public class ProductOrderRepoService {
            Hibernate.initialize(s.getRelatedParty());
            Hibernate.initialize(s.getProductOrderItem() );
            Hibernate.initialize(s.getNote() );
            Hibernate.initialize(s.getChannel());
            for (ProductOrderItem soi : s.getProductOrderItem()) {
              if ( soi.getProduct() != null ) {
                Hibernate.initialize( soi.getProduct().getProductCharacteristic() );                
              }
              Hibernate.initialize( soi.getProductOffering()  );
            }
            
@@ -539,7 +550,7 @@ public class ProductOrderRepoService {
        
        return s;
    } catch (Exception e) {
        // TODO: handle exception
      e.printStackTrace();
    }

    session.close();
@@ -548,6 +559,7 @@ public class ProductOrderRepoService {
    
}

  @Transactional
  public String getProductOrderEagerAsString(String id) throws JsonProcessingException {
    ProductOrder s = this.getProductOrderEager(id);
    ObjectMapper mapper = new ObjectMapper();
Loading