Search in sources :

Example 26 with SearchResult

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

the class DocumentPdf method addContent.

@Override
protected String addContent(Document document, Map<String, Object> model, Locale locale, PdfWriter writer) throws DocumentException, IOException {
    this.locale = locale;
    String documentTitle = translationService.translate("warehouseMinimalState.report.title", locale);
    String documentAuthor = translationService.translate("qcadooReport.commons.generatedBy.label", locale);
    pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, new Date());
    DataDefinition warehouseMinimumStateDD = dataDefinitionService.get(WarehouseMinimalStateConstants.PLUGIN_IDENTIFIER, WarehouseMinimalStateConstants.MODEL_WAREHOUSE_MINIMUM_STATE);
    SearchResult searchResult = warehouseMinimumStateDD.find().add(SearchRestrictions.gt("minimumState", BigDecimal.ZERO)).list();
    List<Entity> warehouseMinimumStates = searchResult.getEntities();
    fillWarehousesLists(warehouseMinimumStates);
    addWarehouseTables(document);
    return "raport";
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchResult(com.qcadoo.model.api.search.SearchResult) DataDefinition(com.qcadoo.model.api.DataDefinition) Date(java.util.Date)

Example 27 with SearchResult

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

the class WorkPlansServiceImpl method getSelectedOrders.

@Override
public final List<Entity> getSelectedOrders(final Set<Long> selectedOrderIds) {
    List<Entity> orders = Lists.newArrayList();
    if (selectedOrderIds.isEmpty()) {
        return orders;
    }
    SearchCriteriaBuilder criteria = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).find();
    criteria.add(SearchRestrictions.in("id", selectedOrderIds));
    SearchResult result = criteria.list();
    if (result.getTotalNumberOfEntities() == 0) {
        return orders;
    }
    orders.addAll(result.getEntities());
    return orders;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchResult(com.qcadoo.model.api.search.SearchResult)

Example 28 with SearchResult

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

the class OrderDetailsHooks method hasAnyTechnologies.

private boolean hasAnyTechnologies(final Entity product) {
    SearchCriteriaBuilder searchCriteria = getTechnologyDD().find().add(SearchRestrictions.belongsTo(TechnologyFields.PRODUCT, product)).setMaxResults(1);
    SearchResult searchResult = searchCriteria.list();
    return (searchResult.getTotalNumberOfEntities() > 0);
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchResult(com.qcadoo.model.api.search.SearchResult)

Example 29 with SearchResult

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

the class HqlIntegrationTest method shouldFindByQueryWithDistinct.

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

Example 30 with SearchResult

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

the class UniqueValidator method call.

@Override
public boolean call(final Entity entity, final Object oldValue, final Object newValue) {
    if (entity.getField(fieldDefinition.getName()) == null) {
        return true;
    }
    SearchCriteriaBuilder searchCriteriaBuilder = dataDefinition.find().add(uniqueCriterionFor(entity)).setMaxResults(1);
    if (entity.getId() != null) {
        searchCriteriaBuilder.add(SearchRestrictions.idNe(entity.getId()));
    }
    SearchResult results = searchCriteriaBuilder.list();
    if (results.getTotalNumberOfEntities() == 0) {
        return true;
    } else {
        entity.addError(fieldDefinition, errorMessage);
        return false;
    }
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchResult(com.qcadoo.model.api.search.SearchResult)

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