Search in sources :

Example 1 with SearchResult

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

the class CustomTranslationModelHooks method checkIfCustomTranslationIsUnique.

public boolean checkIfCustomTranslationIsUnique(final DataDefinition customTranslationDD, final Entity customTranslation) {
    String pluginIdentifier = customTranslation.getStringField(PLUGIN_IDENTIFIER);
    String locale = customTranslation.getStringField(LOCALE);
    String key = customTranslation.getStringField(KEY);
    SearchCriteriaBuilder searchCriteriaBuilder = customTranslationDD.find().add(SearchRestrictions.eq(PLUGIN_IDENTIFIER, pluginIdentifier)).add(SearchRestrictions.eq(LOCALE, locale)).add(SearchRestrictions.eq(KEY, key));
    if (customTranslation.getId() != null) {
        searchCriteriaBuilder.add(SearchRestrictions.ne("id", customTranslation.getId()));
    }
    SearchResult searchResult = searchCriteriaBuilder.list();
    if (!searchResult.getEntities().isEmpty()) {
        customTranslation.addError(customTranslationDD.getField(KEY), "customTranslation.customTranslation.error.customTranslationIsntUnique");
        return false;
    }
    return true;
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchResult(com.qcadoo.model.api.search.SearchResult)

Example 2 with SearchResult

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

the class DictionaryItemValidators method checkIfDictionaryItemIsUnique.

private boolean checkIfDictionaryItemIsUnique(final DataDefinition dictionaryItemDD, final Entity dictionaryItem, final String fieldName) {
    Entity dictionary = dictionaryItem.getBelongsToField(DictionaryItemFields.DICTIONARY);
    String fieldValue = dictionaryItem.getStringField(fieldName);
    SearchCriteriaBuilder searchCriteriaBuilder = dictionaryItemDD.find().add(SearchRestrictions.belongsTo(DictionaryItemFields.DICTIONARY, dictionary)).add(SearchRestrictions.eq(fieldName, fieldValue));
    if (Objects.nonNull(dictionaryItem.getId())) {
        searchCriteriaBuilder.add(SearchRestrictions.idNe(dictionaryItem.getId()));
    }
    SearchResult searchResult = searchCriteriaBuilder.list();
    return searchResult.getEntities().isEmpty();
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchResult(com.qcadoo.model.api.search.SearchResult)

Example 3 with SearchResult

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

the class GridComponentStateTest method shouldNotModeUpSelectedEntityOnFail.

@Test(expected = IllegalStateException.class)
public void shouldNotModeUpSelectedEntityOnFail() 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, "moveUp");
}
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 4 with SearchResult

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

the class HqlIntegrationTest method shouldFindByQueryWithOrderBy.

@Test
public void shouldFindByQueryWithOrderBy() throws Exception {
    // given
    DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
    productDao.save(createProduct("asd", "asd"));
    productDao.save(createProduct("csd", "csd"));
    productDao.save(createProduct("bsd", "bsd"));
    // when
    SearchResult result = productDao.find("select p.name from #products_product p order by p.name desc)").list();
    // then
    assertEquals(3, result.getTotalNumberOfEntities());
    assertEquals("csd", result.getEntities().get(0).getField("0"));
    assertEquals("bsd", result.getEntities().get(1).getField("0"));
    assertEquals("asd", result.getEntities().get(2).getField("0"));
}
Also used : SearchResult(com.qcadoo.model.api.search.SearchResult) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 5 with SearchResult

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

the class HqlIntegrationTest 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 : SearchResult(com.qcadoo.model.api.search.SearchResult) DataDefinition(com.qcadoo.model.api.DataDefinition) 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