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;
}
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();
}
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");
}
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"));
}
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());
}
Aggregations