Search in sources :

Example 41 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.

the class BelongsToIntegrationTest method shouldSaveBelongsToField.

@Test
public void shouldSaveBelongsToField() throws Exception {
    // given
    DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
    DataDefinition machineDao = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
    DataDefinition componentDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_COMPONENT);
    Entity machine = machineDao.save(createMachine("asd"));
    Entity product = productDao.save(createProduct("asd", "asd"));
    Entity component = createComponent("name", product, machine);
    // when
    component = componentDao.save(component);
    // then
    assertNotNull(component);
    assertEquals(product.getId(), ((Entity) component.getField("product")).getId());
    Map<String, Object> result = jdbcTemplate.queryForMap("select * from " + TABLE_NAME_COMPONENT);
    assertNotNull(result);
    assertEquals(product.getId(), result.get("product_id"));
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 42 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.

the class BelongsToIntegrationTest method shouldSaveBelongsToFieldWithId.

@Test
public void shouldSaveBelongsToFieldWithId() throws Exception {
    // given
    DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
    DataDefinition machineDao = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
    DataDefinition componentDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_COMPONENT);
    Entity machine = machineDao.save(createMachine("asd"));
    Entity product = productDao.save(createProduct("asd", "asd"));
    Entity component = createComponent("name", product.getId(), machine.getId());
    // when
    component = componentDao.save(component);
    // then
    assertNotNull(component);
    assertEquals(product.getId(), ((Entity) component.getField("product")).getId());
    Map<String, Object> result = jdbcTemplate.queryForMap("select * from " + TABLE_NAME_COMPONENT);
    assertNotNull(result);
    assertEquals(product.getId(), result.get("product_id"));
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 43 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.

the class CriteriaIntegrationTest method findByQueryWithBelongsToSubqueries.

private void findByQueryWithBelongsToSubqueries(final JoinType joinType) throws Exception {
    // given
    DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
    DataDefinition partDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PART);
    productDao.save(createProduct("qwe", "qwe"));
    Entity product = productDao.save(createProduct("asd", "asd"));
    Entity expectedPart = partDao.save(createPart("name", product));
    // when
    SearchCriteriaBuilder criteria = partDao.find();
    criteria.createCriteria("product", "product", joinType).add(SearchRestrictions.eq("name", "asd"));
    Entity part = criteria.uniqueResult();
    // then
    assertEquals(expectedPart.getId(), part.getId());
    assertEquals(expectedPart.getDataDefinition(), part.getDataDefinition());
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 44 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.

the class CriteriaIntegrationTest method shouldFindAllByQuery.

@Test
public void shouldFindAllByQuery() throws Exception {
    // given
    DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
    productDao.save(createProduct("asd", "asd"));
    productDao.save(createProduct("asd2", "asd2"));
    // when
    SearchResult result = productDao.find().list();
    // then
    assertEquals(2, result.getTotalNumberOfEntities());
    assertEquals(2, result.getEntities().size());
}
Also used : DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 45 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.

the class CriteriaIntegrationTest method shouldFindByQueryWithAliasedSubqueries.

@Test
public void shouldFindByQueryWithAliasedSubqueries() throws Exception {
    // given
    DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
    DataDefinition partDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PART);
    productDao.save(createProduct("qwe", "qwe"));
    Entity expectedProduct = productDao.save(createProduct("asd", "asd"));
    partDao.save(createPart("name", expectedProduct));
    // when
    SearchCriteriaBuilder subcriteria = partDao.findWithAlias("part").add(SearchRestrictions.eqField("part.product.id", "p.id")).setProjection(SearchProjections.id());
    Entity product = productDao.findWithAlias("p").add(SearchSubqueries.exists(subcriteria)).uniqueResult();
    // then
    assertEquals(expectedProduct.getId(), product.getId());
    assertEquals(expectedProduct.getDataDefinition(), product.getDataDefinition());
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Aggregations

DataDefinition (com.qcadoo.model.api.DataDefinition)415 Entity (com.qcadoo.model.api.Entity)285 Test (org.junit.Test)165 BigDecimal (java.math.BigDecimal)53 FieldDefinition (com.qcadoo.model.api.FieldDefinition)48 List (java.util.List)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 Service (org.springframework.stereotype.Service)31 Autowired (org.springframework.beans.factory.annotation.Autowired)27 Date (java.util.Date)26 Map (java.util.Map)26 Collectors (java.util.stream.Collectors)26 FormComponent (com.qcadoo.view.api.components.FormComponent)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)22 IOException (java.io.IOException)21 Objects (java.util.Objects)21 GridComponent (com.qcadoo.view.api.components.GridComponent)20 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)20 Lists (com.google.common.collect.Lists)16