use of com.qcadoo.model.api.search.SearchCriteriaBuilder 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.SearchCriteriaBuilder in project qcadoo by qcadoo.
the class DataDefinitionImpl method count.
@Override
public long count(final SearchCriterion criterion) {
final String countAlias = "count";
SearchCriteriaBuilder scb = find();
if (criterion != null) {
scb.add(criterion);
}
scb.setProjection(alias(rowCount(), countAlias));
scb.addOrder(asc(countAlias));
Entity countProjection = scb.setMaxResults(1).uniqueResult();
return (Long) countProjection.getField(countAlias);
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder 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.SearchCriteriaBuilder in project qcadoo by qcadoo.
the class EntityListImplTest method shouldReturnCriteriaBuilder.
@Test
public void shouldReturnCriteriaBuilder() throws Exception {
// given
BelongsToType fieldType = mock(BelongsToType.class);
InternalDataDefinition dataDefinition = mock(InternalDataDefinition.class, RETURNS_DEEP_STUBS);
given(fieldType.getDataDefinition()).willReturn(dataDefinition);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(fieldType);
given(fieldDefinition.getName()).willReturn("field");
given(dataDefinition.getField("hasMany")).willReturn(fieldDefinition);
SearchCriteriaBuilder searchCriteriaBuilder = mock(SearchCriteriaBuilder.class);
given(dataDefinition.find().createAlias(fieldDefinition.getName(), fieldDefinition.getName()).add(SearchRestrictions.eq(fieldDefinition.getName() + ".id", 1L))).willReturn(searchCriteriaBuilder);
EntityList list = new EntityListImpl(dataDefinition, "hasMany", 1L);
// then
assertEquals(searchCriteriaBuilder, list.find());
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project qcadoo by qcadoo.
the class UnitConversionModelServiceImpl method find.
@Override
@Transactional(readOnly = true)
public List<Entity> find(final String unit, final CustomRestriction customRestriction) {
final CustomRestriction unitMatchingRestriction = new ConversionMatchingUnitRestriction(unit, customRestriction);
final SearchCriteriaBuilder searchCriteriaBuilder = getDataDefinition().find();
unitMatchingRestriction.addRestriction(searchCriteriaBuilder);
return searchCriteriaBuilder.list().getEntities();
}
Aggregations