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

Merge remote-tracking branch 'origin/128-jms-queue-to-delete-a-resource' into...

Merge remote-tracking branch 'origin/128-jms-queue-to-delete-a-resource' into 109-integrate-flyway-in-tmf-api-for-db-migration-actions
parents e619f22e 5f3304d2
Loading
Loading
Loading
Loading
Loading
+3 −2
Changes for src/main/java/org/etsi/osl/tmf/pcm620/reposervices/ProductSpecificationRepoService.java: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -208,8 +208,9 @@ public class ProductSpecificationRepoService {

	}

//	 @Transactional(propagation=Propagation.REQUIRED , readOnly=true,
//	 noRollbackFor=Exception.class)
	// The lazy collections below are initialized here, so a session must be open
	// even when the caller (e.g. a Camel JMS consumer thread) has none.
	@Transactional(readOnly = true)
	public ProductSpecification findByUuid(String id) {
		Optional<ProductSpecification> optionalCat = this.prodsOfferingRepo.findByUuid(id);
		if ( optionalCat.isPresent() ) {
+17
Changes for src/main/java/org/etsi/osl/tmf/po622/api/ProductOrderApiRouteBuilder.java: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
package org.etsi.osl.tmf.po622.api;

import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.camel.Exchange;
import org.apache.camel.LoggingLevel;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
@@ -15,6 +17,7 @@ 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;
import com.fasterxml.jackson.databind.ObjectMapper;

@Configuration
//@RefreshScope
@@ -60,6 +63,20 @@ public class ProductOrderApiRouteBuilder extends RouteBuilder {
  
  @Override
  public void configure() throws Exception {

    // Without this, an exception in any request/reply route below produces no reply at all,
    // so the requester only learns about the failure when its requestTimeout expires.
    onException(Exception.class)
        .handled(true)
        .process(exchange -> {
          Exception ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
          logger.error("Product order route " + exchange.getFromRouteId() + " failed", ex);
          Map<String, String> error = new LinkedHashMap<>();
          error.put("error", ex.getClass().getSimpleName());
          error.put("message", ex.getMessage());
          exchange.getMessage().setBody(new ObjectMapper().writeValueAsString(error));
        });

    from(CATALOG_GET_PRODUCTORDERS).log(LoggingLevel.INFO, log, CATALOG_GET_PRODUCTORDERS + " message received!")
    .to("log:DEBUG?showBody=true&showHeaders=true")
    .bean(productOrderRepoService, "findAllParamsJsonOrderIDs").convertBodyTo(String.class);
+28 −12
Changes for src/main/java/org/etsi/osl/tmf/po622/reposervices/ProductOrderRepoService.java: 28 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ import org.hibernate.query.Query;
import org.hibernate.transform.ResultTransformer;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import jakarta.persistence.EntityManager;
@@ -98,6 +99,15 @@ public class ProductOrderRepoService {
  @Autowired
  ProductOrderRepository productOrderRepo;

  /**
   * Proxied reference to this bean. Internal calls that need their own transaction
   * (e.g. addProductOrder from addProductOrderReturnEager) must go through it, since
   * a plain this.method() call bypasses the Spring proxy and its @Transactional.
   */
  @Autowired
  @Lazy
  private ProductOrderRepoService self;


  @Autowired
  ProductSpecificationRepoService  productSpecificationRepoService;
@@ -178,18 +188,18 @@ public class ProductOrderRepoService {
    return res;
  }
  
  public String addProductOrderReturnEager(@Valid ProductOrderCreate pOrderCreate) {
    try {
      ProductOrder so = this.addProductOrder(pOrderCreate);
        return this.getProductOrderEagerAsString( so.getUuid());
    } catch (JsonProcessingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
  /**
   * Entry point for the CATALOG_ADD_PRODUCTORDER JMS route.
   * <p>
   * Deliberately not @Transactional: addProductOrder must commit in its own transaction
   * (through the proxy) before getProductOrderEager re-reads the order in a separate
   * Hibernate session, which cannot see uncommitted rows.
   * Exceptions are propagated so the route's error handler can reply to the caller.
   */
  public String addProductOrderReturnEager(@Valid ProductOrderCreate pOrderCreate)
      throws NotFoundException, JsonProcessingException {
    ProductOrder so = self.addProductOrder(pOrderCreate); // transaction commits here
    return self.getProductOrderEagerAsString(so.getUuid()); // separate session can now see the order
  }
  
  /**
@@ -332,8 +342,14 @@ public class ProductOrderRepoService {
      }
      
      ProductOffering pOffer = productOfferingRepoService.findByUuid( pOfferf.getId() );
      if (pOffer == null) {
        throw new NotFoundException(400, "There is no Product Offering with Id: " + pOfferf.getId());
      }
      @Valid
      ProductSpecificationRef prodSpec = pOffer.getProductSpecification();
      if (prodSpec == null) {
        throw new NotFoundException(400, "Product Offering with Id: " + pOfferf.getId() + " has no Product Specification");
      }
      String prodSpecificationId = prodSpec.getId();

        ProductSpecification prodSpecification = productSpecificationRepoService.findByUuid(prodSpecificationId);
+22 −1
Changes for src/main/java/org/etsi/osl/tmf/ri639/api/ResourceApiRouteBuilder.java: 22 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -70,6 +70,9 @@ public class ResourceApiRouteBuilder extends RouteBuilder {
	@Value("${CATALOG_GET_RESOURCES_BY_FILTER}")
	private String CATALOG_GET_RESOURCES_BY_FILTER = "";

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

	@Autowired
	private ProducerTemplate template;
@@ -137,7 +140,25 @@ public class ResourceApiRouteBuilder extends RouteBuilder {
		.log(LoggingLevel.DEBUG, log, CATALOG_GET_RESOURCES_BY_FILTER + " message received!")
		.to("log:DEBUG?showBody=true&showHeaders=true")
		.convertBodyTo( String.class )
		.bean( resourceRepoService, "findResourcesByFilter(${body})");
		.doTry()
			.bean( resourceRepoService, "findResourcesByFilter(${body})")
		.doCatch( Exception.class )
			.setHeader("error", constant("true"))
			.setHeader("errorMessage", simple("${exception.message}"))
			.setBody(simple("{\"error\":true}"))
		.end();

		from( CATALOG_DELETE_RESOURCE )
		.log(LoggingLevel.DEBUG, log, CATALOG_DELETE_RESOURCE + " message received!")
		.to("log:DEBUG?showBody=true&showHeaders=true")
		.doTry()
			.bean( resourceRepoService, "deleteResourceById(${header.resourceId})")
			.convertBodyTo( String.class )
		.doCatch( Exception.class )
			.setHeader("error", constant("true"))
			.setHeader("errorMessage", simple("${exception.message}"))
			.setBody(simple("{\"error\":true}"))
		.end();
	}
	

+26
Changes for src/main/java/org/etsi/osl/tmf/ri639/reposervices/ResourceFilter.java: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -21,6 +21,32 @@ public class ResourceFilter {
    private String category;
    private int page = 0;
    private int pageSize = 20;
    /** "summary" (default) or "full" (complete TMF639 Resource objects) */
    private String detail;
    /** Optional characteristic filter */
    private CharacteristicFilter characteristic;

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class CharacteristicFilter {
        private String name;
        /** If set, characteristic value must equal this */
        private String value;
        /** If true, characteristic must exist with a non-empty value */
        private Boolean exists;

        public String getName() { return name; }
        public void setName(String name) { this.name = name; }
        public String getValue() { return value; }
        public void setValue(String value) { this.value = value; }
        public Boolean getExists() { return exists; }
        public void setExists(Boolean exists) { this.exists = exists; }
    }

    public String getDetail() { return detail; }
    public void setDetail(String detail) { this.detail = detail; }

    public CharacteristicFilter getCharacteristic() { return characteristic; }
    public void setCharacteristic(CharacteristicFilter characteristic) { this.characteristic = characteristic; }

    public String getCategory() { return category; }
    public void setCategory(String category) { this.category = category; }
Loading