Search in sources :

Example 21 with SearchCriteriaBuilder

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;
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 22 with SearchCriteriaBuilder

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();
    }
}
Also used : AnotherChangeInProgressException(com.qcadoo.mes.states.exception.AnotherChangeInProgressException) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 23 with SearchCriteriaBuilder

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();
    }
}
Also used : AnotherChangeInProgressException(com.qcadoo.mes.states.exception.AnotherChangeInProgressException) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 24 with SearchCriteriaBuilder

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 25 with SearchCriteriaBuilder

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());
}
Also used : SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) Date(java.util.Date) GeneratorContextFields(com.qcadoo.mes.technologiesGenerator.constants.GeneratorContextFields) TechnologiesGeneratorConstants(com.qcadoo.mes.technologiesGenerator.constants.TechnologiesGeneratorConstants) DateTime(org.joda.time.DateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) SearchProjections.id(com.qcadoo.model.api.search.SearchProjections.id) ContextId(com.qcadoo.mes.technologiesGenerator.domain.ContextId) Collectors(java.util.stream.Collectors) com.qcadoo.model.api(com.qcadoo.model.api) List(java.util.List) Lists(com.google.common.collect.Lists) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) Service(org.springframework.stereotype.Service) Either(com.qcadoo.commons.functional.Either) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) Optional(java.util.Optional) SearchProjections.alias(com.qcadoo.model.api.search.SearchProjections.alias) 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