Search in sources :

Example 6 with Customer

use of ui.ex1.entity.Customer in project jmix-docs by jmix-framework.

the class CustomerServiceTest method setUp.

@BeforeEach
void setUp() {
    customer1 = dataManager.create(Customer.class);
    customer1.setName("Alice");
    customer1.setEmail("alice@company.com");
    customer1.setGrade(CustomerGrade.PLATINUM);
    customer2 = dataManager.create(Customer.class);
    customer2.setName("Bob");
    customer2.setEmail("bob@company.com");
    customer2.setGrade(CustomerGrade.GOLD);
    dataManager.save(customer1, customer2);
    for (int i = 1; i <= 50; i++) {
        Customer customer = dataManager.create(Customer.class);
        customer.setName("cust-" + Strings.padStart(String.valueOf(i), 2, '0'));
        customer.setEmail("cust-" + i + "@mail.com");
        customer.setGrade(i > 40 ? CustomerGrade.PLATINUM : (i > 30 ? CustomerGrade.GOLD : CustomerGrade.BRONZE));
        dataManager.save(customer);
    }
}
Also used : Customer(dataaccess.ex1.entity.Customer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with Customer

use of ui.ex1.entity.Customer in project jmix-docs by jmix-framework.

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 Customer

use of ui.ex1.entity.Customer in project jmix-docs by jmix-framework.

the class OrderService method saveAndReturnNothing.

// end::save-context[]
// tag::save-discard[]
void saveAndReturnNothing(List<Customer> entities) {
    SaveContext saveContext = new SaveContext().setDiscardSaved(true);
    for (Customer entity : entities) {
        saveContext.saving(entity);
    }
    dataManager.save(saveContext);
}
Also used : Customer(dataaccess.ex1.entity.Customer)

Example 9 with Customer

use of ui.ex1.entity.Customer in project jmix-docs by jmix-framework.

the class CustomerEventListener method onCustomerSaving.

@EventListener
void onCustomerSaving(EntitySavingEvent<Customer> event) {
    Customer customer = event.getEntity();
    String encrypted = encryptionService.encrypt(customer.getSensitiveData());
    customer.setEncryptedData(encrypted);
}
Also used : Customer(dataaccess.ex1.entity.Customer) TransactionalEventListener(org.springframework.transaction.event.TransactionalEventListener) EventListener(org.springframework.context.event.EventListener)

Example 10 with Customer

use of ui.ex1.entity.Customer in project jmix-docs by jmix-framework.

the class ActionScreen method onCustomersTableEdit.

// end::edit-action-performed-event[]
// tag::edit-action-performed-event-2[]
@Subscribe("customersTable.edit")
public void onCustomersTableEdit(Action.ActionPerformedEvent event) {
    screenBuilders.editor(customersTable).withOpenMode(OpenMode.DIALOG).withScreenClass(CustomerEdit.class).withAfterCloseListener(afterScreenCloseEvent -> {
        if (afterScreenCloseEvent.closedWith(StandardOutcome.COMMIT)) {
            Customer committedCustomer = (afterScreenCloseEvent.getSource()).getEditedEntity();
            System.out.println("Updated " + committedCustomer);
        }
    }).build().show();
}
Also used : Customer(ui.ex1.entity.Customer) CustomerEdit(ui.ex1.screen.entity.customer.CustomerEdit)

Aggregations

Customer (ui.ex1.entity.Customer)34 Customer (dataaccess.ex1.entity.Customer)25 Autowired (org.springframework.beans.factory.annotation.Autowired)12 BaseAction (io.jmix.ui.action.BaseAction)10 io.jmix.ui.screen (io.jmix.ui.screen)10 Named (javax.inject.Named)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10 CustomerEdit (ui.ex1.screen.entity.customer.CustomerEdit)10 Test (org.junit.jupiter.api.Test)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 Notifications (io.jmix.ui.Notifications)8 Action (io.jmix.ui.action.Action)8 io.jmix.ui.component (io.jmix.ui.component)8 Order (dataaccess.ex1.entity.Order)7 Metadata (io.jmix.core.Metadata)6 ParamsMap (io.jmix.core.common.util.ParamsMap)6 ScreenBuilders (io.jmix.ui.ScreenBuilders)6 DialogAction (io.jmix.ui.action.DialogAction)6 JmixIcon (io.jmix.ui.icon.JmixIcon)6 BigDecimal (java.math.BigDecimal)6