Search in sources :

Example 6 with Product

use of datamodel.ex1.entity.Product in project jmix-docs by Haulmont.

the class OrderServiceTest method testHardDelete.

@Test
void testHardDelete() {
    Product product1 = dataManager.create(Product.class);
    product1.setName("MacBook Pro");
    dataManager.save(product1);
    orderService.hardDelete(product1);
    assertFalse(dataManager.load(Id.of(product1)).hint(PersistenceHints.SOFT_DELETION, false).optional().isPresent());
}
Also used : Product(dataaccess.ex1.entity.Product) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with Product

use of datamodel.ex1.entity.Product in project jmix-docs by Haulmont.

the class OrderServiceTest method setUp.

@BeforeEach
void setUp() {
    Customer customer1 = dataManager.create(Customer.class);
    customer1.setName("Alice");
    customer1.setEmail("alice@company.com");
    Product product1 = dataManager.create(Product.class);
    product1.setName("MacBook Pro");
    product1.setPrice(BigDecimal.valueOf(2500));
    order1 = dataManager.create(Order.class);
    order1.setCustomer(customer1);
    order1.setDate(LocalDate.now());
    order1.setAmount(BigDecimal.valueOf(5000));
    OrderLine orderLine1 = dataManager.create(OrderLine.class);
    orderLine1.setOrder(order1);
    orderLine1.setProduct(product1);
    orderLine1.setQuantity(2.0);
    dataManager.save(customer1, order1, orderLine1, product1);
}
Also used : Order(dataaccess.ex1.entity.Order) Customer(dataaccess.ex1.entity.Customer) OrderLine(dataaccess.ex1.entity.OrderLine) Product(dataaccess.ex1.entity.Product) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with Product

use of datamodel.ex1.entity.Product in project jmix-docs by Haulmont.

the class ProductEntityEventListener method onProductLoading.

@EventListener
void onProductLoading(EntityLoadingEvent<Product> event) {
    Product product = event.getEntity();
    try {
        ProductPart[] productPartsArray = objectMapper.readValue(product.getParts(), ProductPart[].class);
        product.setPartsList(productPartsArray == null ? null : Arrays.asList(productPartsArray));
    } catch (JsonProcessingException e) {
        throw new RuntimeException("Error reading JSON", e);
    }
}
Also used : Product(datamodel.ex1.entity.Product) ProductPart(datamodel.ex1.entity.ProductPart) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) EventListener(org.springframework.context.event.EventListener)

Aggregations

Product (dataaccess.ex1.entity.Product)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Order (dataaccess.ex1.entity.Order)2 OrderLine (dataaccess.ex1.entity.OrderLine)2 Product (datamodel.ex1.entity.Product)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 EventListener (org.springframework.context.event.EventListener)2 Product (ui.ex1.entity.Product)2 Customer (dataaccess.ex1.entity.Customer)1 ProductPart (datamodel.ex1.entity.ProductPart)1 Subscribe (io.jmix.ui.screen.Subscribe)1 Test (org.junit.Test)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test5Service (test5.container.Test5Service)1 Product (test5.entity.Product)1