Search in sources :

Example 46 with DataDefinition

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

the class CriteriaIntegrationTest method shouldCountRestrictedEntities.

@Test
public void shouldCountRestrictedEntities() {
    // given
    DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
    productDao.save(createProduct("asd", "asd"));
    productDao.save(createProduct("asd1", "asd1"));
    productDao.save(createProduct("bsd", "bsd"));
    // when
    long count = productDao.count(SearchRestrictions.like("name", "asd", SearchRestrictions.SearchMatchMode.START));
    // then
    assertEquals(2L, count);
}
Also used : DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 47 with DataDefinition

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

the class CriteriaIntegrationTest method shouldFindByQueryWithWhere.

@Test
public void shouldFindByQueryWithWhere() throws Exception {
    // given
    DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
    Entity product5 = createProduct("cee", "cee");
    product5.setField("quantity", 3);
    productDao.save(product5);
    Entity product1 = createProduct("bsd", "bsd1");
    product1.setField("quantity", 1);
    productDao.save(product1);
    Entity product2 = createProduct("bsd", "bsd2");
    product2.setField("quantity", 3);
    productDao.save(product2);
    Entity product3 = createProduct("abc", "abc");
    product3.setField("quantity", 1);
    productDao.save(product3);
    Entity product4 = createProduct("bef", "bef");
    product4.setField("quantity", 2);
    productDao.save(product4);
    // when
    SearchResult searchResult = productDao.find().add(SearchRestrictions.or(SearchRestrictions.like("name", "b%"), SearchRestrictions.like("name", "c%"))).setProjection(SearchProjections.list().add(SearchProjections.groupField("name")).add(SearchProjections.alias(SearchProjections.sum("quantity"), "quantity")).add(SearchProjections.alias(SearchProjections.rowCount(), "products"))).setFirstResult(0).setMaxResults(2).addOrder(SearchOrders.asc("name")).list();
    // then
    assertEquals(3, searchResult.getTotalNumberOfEntities());
    assertEquals(2, searchResult.getEntities().size());
    assertEquals("bef", searchResult.getEntities().get(0).getField("0"));
    assertEquals(Long.valueOf(2), searchResult.getEntities().get(0).getField("quantity"));
    assertEquals(Long.valueOf(1), searchResult.getEntities().get(0).getField("products"));
    assertEquals("bsd", searchResult.getEntities().get(1).getField("0"));
    assertEquals(Long.valueOf(4), searchResult.getEntities().get(1).getField("quantity"));
    assertEquals(Long.valueOf(2), searchResult.getEntities().get(1).getField("products"));
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 48 with DataDefinition

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

the class CriteriaIntegrationTest method findByQueryWithBelongsToField.

private void findByQueryWithBelongsToField(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);
    Entity product = createProduct("asd", "asd");
    product.setField("quantity", 1);
    product = productDao.save(product);
    partDao.save(createPart("name", product));
    // when
    Entity result = partDao.find().add(SearchRestrictions.like("product.name", "asd")).createAlias("product", "product", joinType).setProjection(SearchProjections.list().add(SearchProjections.field("product.quantity")).add(SearchProjections.field("name")).add(SearchProjections.field("product"))).uniqueResult();
    // then
    assertEquals(IntegerType.class, result.getDataDefinition().getField("0").getType().getClass());
    assertEquals(StringType.class, result.getDataDefinition().getField("1").getType().getClass());
    assertEquals(BelongsToEntityType.class, result.getDataDefinition().getField("2").getType().getClass());
    assertEquals(1, result.getField("0"));
    assertEquals("name", result.getStringField("1"));
    assertEquals(product.getId(), result.getBelongsToField("2").getId());
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 49 with DataDefinition

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

the class CriteriaIntegrationTest method shouldCountAllEntities.

@Test
public void shouldCountAllEntities() {
    // given
    DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
    productDao.save(createProduct("asd", "asd"));
    productDao.save(createProduct("bsd", "bsd"));
    productDao.save(createProduct("csd", "csd"));
    // when
    long count = productDao.count();
    // then
    assertEquals(3L, count);
}
Also used : DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 50 with DataDefinition

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

the class CriteriaIntegrationTest method shouldFindByQueryWithAlias.

@Test
public void shouldFindByQueryWithAlias() 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.findWithAlias("xxx").add(SearchRestrictions.eq("xxx.name", "asd")).list();
    // then
    assertEquals(1, result.getTotalNumberOfEntities());
    assertEquals(1, result.getEntities().size());
}
Also used : 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