Search in sources :

Example 1 with Customer

use of com.company.demo.entity.Customer in project documentation by cuba-platform.

the class CustomerChangedListener method beforePersist.

@EventListener
void beforePersist(EntityPersistingEvent<Customer> event) {
    Customer customer = event.getEntity();
    customer.setCode(obtainNewCustomerCode(customer));
}
Also used : Customer(com.company.demo.entity.Customer) EventListener(org.springframework.context.event.EventListener)

Example 2 with Customer

use of com.company.demo.entity.Customer in project documentation by cuba-platform.

the class CustomerChangedListener method beforeCommit.

// <1>
@EventListener
public void beforeCommit(EntityChangedEvent<Customer, UUID> event) {
    // <2>
    Id<Customer, UUID> entityId = event.getEntityId();
    // <3>
    EntityChangedEvent.Type changeType = event.getType();
    AttributeChanges changes = event.getChanges();
    if (changes.isChanged("name")) {
        // <4>
        // <5>
        String oldName = changes.getOldValue("name");
    // ...
    }
}
Also used : AttributeChanges(com.haulmont.cuba.core.app.events.AttributeChanges) Customer(com.company.demo.entity.Customer) EntityChangedEvent(com.haulmont.cuba.core.app.events.EntityChangedEvent) UUID(java.util.UUID) TransactionalEventListener(org.springframework.transaction.event.TransactionalEventListener) EventListener(org.springframework.context.event.EventListener)

Example 3 with Customer

use of com.company.demo.entity.Customer in project documentation by cuba-platform.

the class CustomerTest method testCreateLoadRemove.

@Test
void testCreateLoadRemove() {
    Customer customer = cont.metadata().create(Customer.class);
    customer.setName("c1");
    Customer committedCustomer = dataManager.commit(customer);
    assertEquals(customer, committedCustomer);
    Customer loadedCustomer = dataManager.load(Id.of(customer)).one();
    assertEquals(customer, loadedCustomer);
    dataManager.remove(loadedCustomer);
}
Also used : Customer(com.company.demo.entity.Customer) Test(org.junit.jupiter.api.Test)

Example 4 with Customer

use of com.company.demo.entity.Customer in project documentation by cuba-platform.

the class CustomerEditLoadDataTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    new Expectations() {

        {
            // <2>
            dataService.load((LoadContext<? extends Entity>) any);
            result = new Delegate() {

                Entity load(LoadContext lc) {
                    if ("demo_Customer".equals(lc.getEntityMetaClass())) {
                        return customer;
                    } else
                        return null;
                }
            };
        }
    };
    // <3>
    TestServiceProxy.mock(DataService.class, dataService);
    TestEntityFactory<Customer> customersFactory = environment.getContainer().getEntityFactory(Customer.class, TestEntityState.DETACHED);
    customer = customersFactory.create("name", "Homer", "email", // <4>
    "homer@simpson.com");
}
Also used : Expectations(mockit.Expectations) Entity(com.haulmont.cuba.core.entity.Entity) Delegate(mockit.Delegate) Customer(com.company.demo.entity.Customer) LoadContext(com.haulmont.cuba.core.global.LoadContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Customer (com.company.demo.entity.Customer)4 EventListener (org.springframework.context.event.EventListener)2 AttributeChanges (com.haulmont.cuba.core.app.events.AttributeChanges)1 EntityChangedEvent (com.haulmont.cuba.core.app.events.EntityChangedEvent)1 Entity (com.haulmont.cuba.core.entity.Entity)1 LoadContext (com.haulmont.cuba.core.global.LoadContext)1 UUID (java.util.UUID)1 Delegate (mockit.Delegate)1 Expectations (mockit.Expectations)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 TransactionalEventListener (org.springframework.transaction.event.TransactionalEventListener)1