Search in sources :

Example 31 with SearchResult

use of com.qcadoo.model.api.search.SearchResult in project qcadoo by qcadoo.

the class DataAccessServiceFindTest method shouldReturnValidEntities.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldReturnValidEntities() throws Exception {
    // given
    List<SampleSimpleDatabaseObject> databaseObjects = new ArrayList<SampleSimpleDatabaseObject>();
    databaseObjects.add(createDatabaseObject(1L, "name1", 1));
    databaseObjects.add(createDatabaseObject(2L, "name2", 2));
    databaseObjects.add(createDatabaseObject(3L, "name3", 3));
    databaseObjects.add(createDatabaseObject(4L, "name4", 4));
    SearchCriteriaBuilder searchCriteriaBuilder = dataDefinition.find().setFirstResult(0).setMaxResults(4);
    given(hibernateService.getTotalNumberOfEntities(Mockito.any(Criteria.class))).willReturn(4);
    given(hibernateService.list(Mockito.any(Criteria.class))).willReturn((List) databaseObjects);
    // when
    SearchResult resultSet = searchCriteriaBuilder.list();
    // then
    assertEquals(4, resultSet.getTotalNumberOfEntities());
    assertEquals(4, resultSet.getEntities().size());
    assertEquals(Long.valueOf(1L), resultSet.getEntities().get(0).getId());
    assertEquals(Long.valueOf(2L), resultSet.getEntities().get(1).getId());
    assertEquals(Long.valueOf(3L), resultSet.getEntities().get(2).getId());
    assertEquals(Long.valueOf(4L), resultSet.getEntities().get(3).getId());
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) ArrayList(java.util.ArrayList) SearchResult(com.qcadoo.model.api.search.SearchResult) Criteria(org.hibernate.Criteria) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 32 with SearchResult

use of com.qcadoo.model.api.search.SearchResult in project qcadoo by qcadoo.

the class DictionaryServiceImpl method createIfNotExists.

@Override
@Transactional
@Monitorable
public void createIfNotExists(final String pluginIdentifier, final String name, final String... values) {
    SearchResult serachResult = getDictionaryDataDefinition().find().add(SearchRestrictions.eq(DictionaryFields.NAME, name)).list();
    if (serachResult.getTotalNumberOfEntities() > 0) {
        Entity dictionaryEntity = serachResult.getEntities().get(0);
        dictionaryEntity.setField(DictionaryFields.ACTIVE, true);
        getDictionaryDataDefinition().save(dictionaryEntity);
        return;
    }
    Entity dictionary = getDictionaryDataDefinition().create();
    dictionary.setField(DictionaryFields.PLUGIN_IDENTIFIER, pluginIdentifier);
    dictionary.setField(DictionaryFields.NAME, name);
    dictionary.setField(DictionaryFields.ACTIVE, true);
    dictionary = getDictionaryDataDefinition().save(dictionary);
    for (String value : values) {
        Entity item = getItemDataDefinition().create();
        item.setField(DictionaryItemFields.DICTIONARY, dictionary);
        item.setField(DictionaryItemFields.DESCRIPTION, "");
        item.setField(DictionaryItemFields.NAME, value);
        getItemDataDefinition().save(item);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchResult(com.qcadoo.model.api.search.SearchResult) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with SearchResult

use of com.qcadoo.model.api.search.SearchResult in project qcadoo by qcadoo.

the class GridComponentStateTest method shouldNotModeDownSelectedEntityOnFail.

@Test(expected = IllegalStateException.class)
public void shouldNotModeDownSelectedEntityOnFail() throws Exception {
    // given
    FieldEntityIdChangeListener listener = mock(FieldEntityIdChangeListener.class);
    SearchResult result = mock(SearchResult.class);
    given(substituteCriteria.list()).willReturn(result);
    given(result.getTotalNumberOfEntities()).willReturn(0);
    given(result.getEntities()).willReturn(Collections.<Entity>emptyList());
    willThrow(new IllegalStateException()).given(substituteDataDefinition).move(13L, 1);
    grid.initialize(json, Locale.ENGLISH);
    grid.addFieldEntityIdChangeListener("field", listener);
    // when
    grid.performEvent(viewDefinitionState, "moveDown");
}
Also used : SearchResult(com.qcadoo.model.api.search.SearchResult) FieldEntityIdChangeListener(com.qcadoo.view.internal.FieldEntityIdChangeListener) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 34 with SearchResult

use of com.qcadoo.model.api.search.SearchResult in project qcadoo by qcadoo.

the class GridComponentStateTest method shouldRefresh.

@Test
public void shouldRefresh() throws Exception {
    // given
    FieldEntityIdChangeListener listener = mock(FieldEntityIdChangeListener.class);
    SearchResult result = mock(SearchResult.class);
    given(substituteCriteria.list()).willReturn(result);
    given(result.getTotalNumberOfEntities()).willReturn(0);
    given(result.getEntities()).willReturn(Collections.<Entity>emptyList());
    grid.initialize(json, Locale.ENGLISH);
    grid.addFieldEntityIdChangeListener("field", listener);
    // when
    grid.performEvent(viewDefinitionState, "refresh");
}
Also used : SearchResult(com.qcadoo.model.api.search.SearchResult) FieldEntityIdChangeListener(com.qcadoo.view.internal.FieldEntityIdChangeListener) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 35 with SearchResult

use of com.qcadoo.model.api.search.SearchResult in project qcadoo by qcadoo.

the class GridComponentStateTest method shouldSelectEntity.

@Test
public void shouldSelectEntity() throws Exception {
    // given
    FieldEntityIdChangeListener listener = mock(FieldEntityIdChangeListener.class);
    SearchResult result = mock(SearchResult.class);
    given(substituteCriteria.list()).willReturn(result);
    given(result.getTotalNumberOfEntities()).willReturn(0);
    given(result.getEntities()).willReturn(Collections.<Entity>emptyList());
    grid.initialize(json, Locale.ENGLISH);
    grid.addFieldEntityIdChangeListener("field", listener);
    // when
    grid.performEvent(viewDefinitionState, "select");
    // then
    verify(listener).onFieldEntityIdChange(13L);
}
Also used : SearchResult(com.qcadoo.model.api.search.SearchResult) FieldEntityIdChangeListener(com.qcadoo.view.internal.FieldEntityIdChangeListener) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Aggregations

SearchResult (com.qcadoo.model.api.search.SearchResult)35 Entity (com.qcadoo.model.api.Entity)18 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)16 DataDefinition (com.qcadoo.model.api.DataDefinition)10 Test (org.junit.Test)10 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)7 SearchProjection (com.qcadoo.model.api.search.SearchProjection)4 FieldEntityIdChangeListener (com.qcadoo.view.internal.FieldEntityIdChangeListener)4 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)4 BigDecimal (java.math.BigDecimal)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 SearchQueryBuilder (com.qcadoo.model.api.search.SearchQueryBuilder)2 Date (java.util.Date)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ImmutableList (com.google.common.collect.ImmutableList)1 ProductWithQuantityAndCost (com.qcadoo.mes.costNormsForMaterials.orderRawMaterialCosts.domain.ProductWithQuantityAndCost)1 Monitorable (com.qcadoo.model.api.aop.Monitorable)1 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)1 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)1 LocalDate (java.time.LocalDate)1