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