Search in sources :

Example 1 with SearchOrder

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

the class AssignmentToShiftDataProvider method findAll.

public List<Entity> findAll(final AssignmentToShiftCriteria criteria, final Optional<SearchProjection> maybeProjection, final Optional<SearchOrder> maybeSearchOrder) {
    SearchCriteriaBuilder scb = createCriteriaBuilder(criteria);
    setProjectionIfPresent(scb, maybeProjection);
    for (SearchOrder searchOrder : maybeSearchOrder.asSet()) {
        scb.addOrder(searchOrder);
    }
    return scb.list().getEntities();
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchOrder(com.qcadoo.model.api.search.SearchOrder)

Example 2 with SearchOrder

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

the class ResourceManagementServiceImpl method getResourcesForLocationCommonCodeConversion.

private List<Entity> getResourcesForLocationCommonCodeConversion(final Entity warehouse, final Entity product, final Entity additionalCode, final Entity position, final boolean resourceIrrespectiveOfConversion, final SearchOrder... searchOrders) {
    class SearchCriteriaHelper {

        private List<Entity> getAll() {
            return getAllThatSatisfies(null);
        }

        private List<Entity> getAllThatSatisfies(SearchCriterion searchCriterion) {
            SearchCriteriaBuilder scb = getSearchCriteriaForResourceForProductAndWarehouse(product, warehouse);
            if (resourceIrrespectiveOfConversion) {
                if (StringUtils.isNotEmpty(product.getStringField(ProductFields.ADDITIONAL_UNIT))) {
                    scb.add(SearchRestrictions.ne(PositionFields.CONVERSION, position.getDecimalField(PositionFields.CONVERSION)));
                } else {
                    scb.add(SearchRestrictions.ne(ResourceFields.CONVERSION, BigDecimal.ONE));
                }
            } else {
                if (StringUtils.isNotEmpty(product.getStringField(ProductFields.ADDITIONAL_UNIT))) {
                    scb.add(SearchRestrictions.eq(PositionFields.CONVERSION, position.getDecimalField(PositionFields.CONVERSION)));
                } else {
                    scb.add(SearchRestrictions.eq(ResourceFields.CONVERSION, BigDecimal.ONE));
                }
            }
            if (Objects.nonNull(position.getBelongsToField(PositionFields.BATCH))) {
                scb.add(SearchRestrictions.belongsTo(ResourceFields.BATCH, position.getBelongsToField(PositionFields.BATCH)));
            }
            scb.add(SearchRestrictions.eq(ResourceFields.BLOCKED_FOR_QUALITY_CONTROL, false));
            Optional.ofNullable(searchCriterion).ifPresent(scb::add);
            for (SearchOrder searchOrder : searchOrders) {
                scb.addOrder(searchOrder);
            }
            return scb.list().getEntities();
        }
    }
    List<Entity> resources = Lists.newArrayList();
    if (additionalCode != null) {
        resources = new SearchCriteriaHelper().getAllThatSatisfies(SearchRestrictions.belongsTo(ResourceFields.ADDITIONAL_CODE, additionalCode));
        resources.addAll(new SearchCriteriaHelper().getAllThatSatisfies(SearchRestrictions.or(SearchRestrictions.isNull(ResourceFields.ADDITIONAL_CODE), SearchRestrictions.ne("additionalCode.id", additionalCode.getId()))));
    }
    if (resources.isEmpty()) {
        resources = new SearchCriteriaHelper().getAll();
    }
    return resources;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchOrder(com.qcadoo.model.api.search.SearchOrder) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Aggregations

SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)2 SearchOrder (com.qcadoo.model.api.search.SearchOrder)2 Entity (com.qcadoo.model.api.Entity)1 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)1