use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class OrderHooksPPS method startDatesHasBeenChanged.
private boolean startDatesHasBeenChanged(final Entity order) {
SearchCriteriaBuilder scb = order.getDataDefinition().find();
scb.setProjection(id());
scb.add(idEq(order.getId()));
for (String dateFieldName : Sets.newHashSet(OrderFields.DATE_FROM, OrderFields.CORRECTED_DATE_FROM, OrderFields.EFFECTIVE_DATE_FROM)) {
scb.add(eq(dateFieldName, order.getDateField(dateFieldName)));
}
return scb.setMaxResults(1).uniqueResult() == null;
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class StateExecutorService method checkForUnfinishedStateChange.
private void checkForUnfinishedStateChange(final StateChangeEntityDescriber describer, final Entity owner) {
final String ownerFieldName = describer.getOwnerFieldName();
final String statusFieldName = describer.getStatusFieldName();
final Set<String> unfinishedStatuses = Sets.newHashSet(IN_PROGRESS.getStringValue(), PAUSED.getStringValue());
final SearchCriteriaBuilder searchCriteria = describer.getDataDefinition().find();
searchCriteria.createAlias(ownerFieldName, ownerFieldName);
searchCriteria.add(SearchRestrictions.eq(ownerFieldName + ".id", owner.getId()));
searchCriteria.add(SearchRestrictions.in(statusFieldName, unfinishedStatuses));
if (searchCriteria.list().getTotalNumberOfEntities() > 0) {
throw new AnotherChangeInProgressException();
}
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class StateChangeContextBuilderImpl method checkForUnfinishedStateChange.
/**
* Checks if given owner entity have not any unfinished state change request.
*
* @param owner
* state change's owner entity
* @throws AnotherChangeInProgressException
* if at least one unfinished state change request for given owner entity is found.
*/
protected void checkForUnfinishedStateChange(final StateChangeEntityDescriber describer, final Entity owner) {
final String ownerFieldName = describer.getOwnerFieldName();
final String statusFieldName = describer.getStatusFieldName();
final Set<String> unfinishedStatuses = Sets.newHashSet(IN_PROGRESS.getStringValue(), PAUSED.getStringValue());
final SearchCriteriaBuilder searchCriteria = describer.getDataDefinition().find();
searchCriteria.createAlias(ownerFieldName, ownerFieldName);
searchCriteria.add(SearchRestrictions.eq(ownerFieldName + ".id", owner.getId()));
searchCriteria.add(SearchRestrictions.in(statusFieldName, unfinishedStatuses));
if (searchCriteria.list().getTotalNumberOfEntities() > 0) {
throw new AnotherChangeInProgressException();
}
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class OfferProductValidators method checkIfOfferProductAlreadyExists.
public boolean checkIfOfferProductAlreadyExists(final DataDefinition offerProductDD, final Entity offerProduct) {
SearchCriteriaBuilder searchCriteriaBuilder = offerProductDD.find().add(SearchRestrictions.belongsTo(OfferProductFields.OFFER, offerProduct.getBelongsToField(OfferProductFields.OFFER))).add(SearchRestrictions.belongsTo(OfferProductFields.PRODUCT, offerProduct.getBelongsToField(OfferProductFields.PRODUCT)));
if (offerProduct.getId() != null) {
searchCriteriaBuilder.add(SearchRestrictions.ne("id", offerProduct.getId()));
}
Entity negotiationProductFromDB = searchCriteriaBuilder.setMaxResults(1).uniqueResult();
if (negotiationProductFromDB == null) {
return true;
}
offerProduct.addError(offerProductDD.getField(OfferProductFields.PRODUCT), "supplyNegotiations.offerProduct.error.productAlreadyExists");
return false;
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class GeneratorContextDataProvider method findContextsOlderThan.
private List<Long> findContextsOlderThan(final DateTime threshold) {
SearchCriteriaBuilder scb = getContextDD().find();
scb.add(getCriteria(threshold.toDate()));
scb.add(SearchRestrictions.eq(GeneratorContextFields.SAVED, false));
scb.setProjection(alias(id(), "id"));
return scb.list().getEntities().stream().map(e -> (Long) e.getField("id")).collect(Collectors.toList());
}
Aggregations