Search in sources :

Example 96 with SearchCriteriaBuilder

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

the class AddressHooks method checkIfOnlyOneMainAddressExists.

private boolean checkIfOnlyOneMainAddressExists(final DataDefinition addressDD, final Entity address, final String addressType) {
    Long addressId = address.getId();
    Entity company = address.getBelongsToField(AddressFields.COMPANY);
    SearchCriteriaBuilder searchCriteriaBuilder = addressDD.find().add(SearchRestrictions.belongsTo(AddressFields.COMPANY, company)).add(SearchRestrictions.eq(AddressFields.ADDRESS_TYPE, addressType));
    if (addressId != null) {
        searchCriteriaBuilder.add(SearchRestrictions.ne("id", addressId));
    }
    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 97 with SearchCriteriaBuilder

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

the class TechnologicalProcessRateDetailsHooks method findCurrentRate.

private BigDecimal findCurrentRate(Long entityId) {
    Entity technologicalProcessRate = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, "technologicalProcessRate").get(entityId);
    SearchCriteriaBuilder scb = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, "technologicalProcessRateItem").find().addOrder(SearchOrders.desc("dateFrom")).add(SearchRestrictions.belongsTo("technologicalProcessRate", technologicalProcessRate)).add(SearchRestrictions.or(SearchRestrictions.lt("dateFrom", new Date()), SearchRestrictions.eq("dateFrom", new Date())));
    Entity technologicalProcessRateItem = scb.setMaxResults(1).uniqueResult();
    if (Objects.isNull(technologicalProcessRateItem)) {
        return null;
    } else {
        return technologicalProcessRateItem.getDecimalField("actualRate");
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) Date(java.util.Date)

Example 98 with SearchCriteriaBuilder

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

the class TechnologicalProcessRateItemHooks method findPreviousTechnologicalProcessRateItem.

private Optional<Entity> findPreviousTechnologicalProcessRateItem(final Entity technologicalProcessRateItem) {
    Entity technologicalProcessRate = technologicalProcessRateItem.getBelongsToField("technologicalProcessRate");
    Date dateFrom = technologicalProcessRateItem.getDateField("dateFrom");
    SearchCriteriaBuilder scb = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, "technologicalProcessRateItem").find().addOrder(SearchOrders.desc("dateFrom")).add(SearchRestrictions.belongsTo("technologicalProcessRate", technologicalProcessRate)).add(SearchRestrictions.lt("dateFrom", dateFrom));
    if (technologicalProcessRateItem.getId() != null) {
        scb.add(SearchRestrictions.idNe(technologicalProcessRateItem.getId()));
    }
    List<Entity> previousComponents = scb.list().getEntities();
    if (previousComponents.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(previousComponents.get(0));
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) Date(java.util.Date)

Example 99 with SearchCriteriaBuilder

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

the class DeliveredProductHooks method getDeliveredProducts.

private List<Entity> getDeliveredProducts(final Entity deliveredProduct) {
    Entity delivery = deliveredProduct.getBelongsToField(DeliveredProductFields.DELIVERY);
    Entity product = deliveredProduct.getBelongsToField(DeliveredProductFields.PRODUCT);
    SearchCriteriaBuilder searchCriteriaBuilder = deliveriesService.getDeliveredProductDD().find().add(SearchRestrictions.belongsTo(DeliveredProductFields.DELIVERY, delivery)).add(SearchRestrictions.belongsTo(OrderedProductFields.PRODUCT, product));
    if (Objects.nonNull(deliveredProduct.getId())) {
        searchCriteriaBuilder.add(SearchRestrictions.ne("id", deliveredProduct.getId()));
    }
    return searchCriteriaBuilder.list().getEntities();
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 100 with SearchCriteriaBuilder

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

the class DeliveredProductHooks method getOrderedProducts.

private List<Entity> getOrderedProducts(final Entity deliveredProduct) {
    Entity delivery = deliveredProduct.getBelongsToField(DeliveredProductFields.DELIVERY);
    Entity product = deliveredProduct.getBelongsToField(DeliveredProductFields.PRODUCT);
    SearchCriteriaBuilder searchCriteriaBuilder = deliveriesService.getOrderedProductDD().find().add(SearchRestrictions.belongsTo(OrderedProductFields.DELIVERY, delivery)).add(SearchRestrictions.belongsTo(OrderedProductFields.PRODUCT, product));
    return searchCriteriaBuilder.list().getEntities();
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Aggregations

SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)176 Entity (com.qcadoo.model.api.Entity)82 DataDefinition (com.qcadoo.model.api.DataDefinition)26 Autowired (org.springframework.beans.factory.annotation.Autowired)19 Service (org.springframework.stereotype.Service)19 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)18 EntityList (com.qcadoo.model.api.EntityList)17 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)17 Collectors (java.util.stream.Collectors)17 SearchResult (com.qcadoo.model.api.search.SearchResult)16 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)14 Objects (java.util.Objects)14 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)11 BigDecimal (java.math.BigDecimal)11 Set (java.util.Set)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 CustomRestriction (com.qcadoo.model.api.search.CustomRestriction)8