Search in sources :

Example 31 with SearchCriterion

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

the class TechnologicalProcessRateItemHooks method checkIfRateForGivenTimeExists.

public boolean checkIfRateForGivenTimeExists(final Entity technologicalProcessRateItem) {
    Entity technologicalProcessRate = technologicalProcessRateItem.getBelongsToField("technologicalProcessRate");
    Date dateFrom = technologicalProcessRateItem.getDateField(L_DATE_FROM);
    Date dateTo = technologicalProcessRateItem.getDateField(L_DATE_TO);
    SearchCriterion scb = SearchRestrictions.belongsTo("technologicalProcessRate", technologicalProcessRate);
    if (dateTo == null) {
        scb = SearchRestrictions.and(scb, SearchRestrictions.or(SearchRestrictions.ge(L_DATE_FROM, dateFrom), SearchRestrictions.and(SearchRestrictions.le(L_DATE_FROM, dateFrom), SearchRestrictions.gt(L_DATE_TO, dateFrom))));
    } else {
        scb = SearchRestrictions.and(scb, SearchRestrictions.and(SearchRestrictions.le(L_DATE_FROM, dateFrom), SearchRestrictions.gt(L_DATE_TO, dateFrom)));
    }
    if (technologicalProcessRateItem.getId() != null) {
        scb = SearchRestrictions.and(scb, SearchRestrictions.ne("id", technologicalProcessRateItem.getId()));
    }
    long count = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, "technologicalProcessRateItem").count(scb);
    return count != 0;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) Date(java.util.Date)

Example 32 with SearchCriterion

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

the class SubassemblyValidators method validateUniquenessOfWorkstationAndType.

public void validateUniquenessOfWorkstationAndType(final DataDefinition subassemblyDD, final Entity subassembly) {
    Entity workstationEntity = subassembly.getBelongsToField(SubassemblyFields.WORKSTATION);
    if (workstationEntity != null) {
        SearchCriterion criterionWorkstation = SearchRestrictions.belongsTo(SubassemblyFields.WORKSTATION, workstationEntity);
        SearchCriterion criterionType = SearchRestrictions.eq(SubassemblyFields.TYPE, subassembly.getStringField(SubassemblyFields.TYPE));
        SearchCriterion criterionId = subassembly.getId() == null ? null : SearchRestrictions.idNe(subassembly.getId());
        Long count = criterionId == null ? subassemblyDD.count(SearchRestrictions.and(criterionWorkstation, criterionType)) : subassemblyDD.count(SearchRestrictions.and(criterionWorkstation, criterionType, criterionId));
        if (count > 0) {
            subassembly.addError(subassemblyDD.getField(SubassemblyFields.WORKSTATION), "basic.validate.global.error.uniquenessOfWorkstationAndType");
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 33 with SearchCriterion

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

the class DeliveredProductReservationHooks method locationUnique.

private boolean locationUnique(final Entity deliveredProductReservation) {
    Entity location = deliveredProductReservation.getBelongsToField(DeliveredProductReservationFields.LOCATION);
    Entity deliveredProduct = deliveredProductReservation.getBelongsToField(DeliveredProductReservationFields.DELIVERED_PRODUCT);
    if (Objects.nonNull(location)) {
        SearchCriterion criterion;
        SearchCriterion criterionLocation = SearchRestrictions.belongsTo(DeliveredProductReservationFields.LOCATION, location);
        SearchCriterion criterionDeliveredProduct = SearchRestrictions.belongsTo(DeliveredProductReservationFields.DELIVERED_PRODUCT, deliveredProduct);
        Long deliveredProductReservationId = deliveredProductReservation.getId();
        if (Objects.isNull(deliveredProductReservationId)) {
            criterion = SearchRestrictions.and(criterionLocation, criterionDeliveredProduct);
        } else {
            SearchCriterion criterionId = SearchRestrictions.idNe(deliveredProductReservationId);
            criterion = SearchRestrictions.and(criterionLocation, criterionDeliveredProduct, criterionId);
        }
        boolean locationUnique = deliveredProductReservation.getDataDefinition().count(criterion) == 0;
        if (!locationUnique) {
            FieldDefinition locationField = deliveredProductReservation.getDataDefinition().getField(DeliveredProductReservationFields.LOCATION);
            deliveredProductReservation.addError(locationField, "deliveries.deliveredProductReservation.error.locationNotUnique");
        }
        return locationUnique;
    }
    return true;
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 34 with SearchCriterion

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

the class OrderedProductReservationHooks method sumIsNotExceeded.

private boolean sumIsNotExceeded(final Entity orderedProductReservation) {
    Entity orderedProduct = orderedProductReservation.getBelongsToField(OrderedProductReservationFields.ORDERED_PRODUCT);
    BigDecimal productOrderedQuantity = orderedProduct.getDecimalField(OrderedProductReservationFields.ORDERED_QUANTITY);
    BigDecimal reservationOrderedQuantity = orderedProductReservation.getDecimalField(OrderedProductReservationFields.ORDERED_QUANTITY);
    SearchCriteriaBuilder searchCriteriaBuilder = orderedProductReservation.getDataDefinition().find();
    SearchProjection sumOfQuantityProjection = SearchProjections.alias(SearchProjections.sum(OrderedProductReservationFields.ORDERED_QUANTITY), L_SUM_OF_QUANTITY);
    searchCriteriaBuilder.setProjection(SearchProjections.list().add(sumOfQuantityProjection).add(SearchProjections.rowCount()));
    SearchCriterion criterion;
    SearchCriterion criterionOrderedProduct = SearchRestrictions.belongsTo(OrderedProductReservationFields.ORDERED_PRODUCT, orderedProduct);
    Long orderedProductReservationId = orderedProductReservation.getId();
    if (Objects.isNull(orderedProductReservationId)) {
        criterion = criterionOrderedProduct;
    } else {
        SearchCriterion criterionId = SearchRestrictions.idNe(orderedProductReservationId);
        criterion = SearchRestrictions.and(criterionOrderedProduct, criterionId);
    }
    searchCriteriaBuilder.add(criterion);
    searchCriteriaBuilder.addOrder(SearchOrders.asc(L_SUM_OF_QUANTITY));
    SearchResult resList = searchCriteriaBuilder.setMaxResults(1).list();
    BigDecimal sumOfQuantity = resList.getTotalNumberOfEntities() == 0 ? BigDecimal.ZERO : resList.getEntities().get(0).getDecimalField(L_SUM_OF_QUANTITY);
    sumOfQuantity = BigDecimalUtils.convertNullToZero(sumOfQuantity);
    boolean sumIsNotExceeded = productOrderedQuantity.compareTo(reservationOrderedQuantity.add(sumOfQuantity)) >= 0;
    if (!sumIsNotExceeded) {
        FieldDefinition orderedQuantityField = orderedProductReservation.getDataDefinition().getField(OrderedProductReservationFields.ORDERED_QUANTITY);
        orderedProductReservation.addError(orderedQuantityField, "deliveries.deliveredProductReservation.error.sumIsExceeded");
    }
    return sumIsNotExceeded;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchProjection(com.qcadoo.model.api.search.SearchProjection) FieldDefinition(com.qcadoo.model.api.FieldDefinition) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) SearchResult(com.qcadoo.model.api.search.SearchResult) BigDecimal(java.math.BigDecimal)

Example 35 with SearchCriterion

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

the class ChangeoverNormsSearchServiceImpl method getTechnologiesRestrictions.

private SearchCriterion getTechnologiesRestrictions(final Long fromTechnologyId, final Long fromTechnologyGroupId, final Long toTechnologyId, final Long toTechnologyGroupId) {
    SearchCriterion matchTechnologies = getPairRestriction(LineChangeoverNormsFields.FROM_TECHNOLOGY, fromTechnologyId, LineChangeoverNormsFields.TO_TECHNOLOGY, toTechnologyId);
    SearchCriterion matchTechnologyGroups = getPairRestriction(LineChangeoverNormsFields.FROM_TECHNOLOGY_GROUP, fromTechnologyGroupId, LineChangeoverNormsFields.TO_TECHNOLOGY_GROUP, toTechnologyGroupId);
    Preconditions.checkArgument(matchTechnologies != null || matchTechnologyGroups != null, "you have to provide pair of technologies or pair of technology groups.");
    SearchDisjunction disjunction = SearchRestrictions.disjunction();
    if (matchTechnologies != null) {
        disjunction.add(matchTechnologies);
    }
    if (matchTechnologyGroups != null) {
        disjunction.add(matchTechnologyGroups);
    }
    return disjunction;
}
Also used : SearchDisjunction(com.qcadoo.model.api.search.SearchDisjunction) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Aggregations

SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)41 Entity (com.qcadoo.model.api.Entity)16 Test (org.junit.Test)12 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 DataDefinition (com.qcadoo.model.api.DataDefinition)4 SearchProjection (com.qcadoo.model.api.search.SearchProjection)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 SearchResult (com.qcadoo.model.api.search.SearchResult)3 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ImmutableList (com.google.common.collect.ImmutableList)1 BatchNumberUniqueness (com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness)1 AssignmentToShiftCriteria (com.qcadoo.mes.assignmentToShift.dataProviders.AssignmentToShiftCriteria)1 SearchDisjunction (com.qcadoo.model.api.search.SearchDisjunction)1 SearchOrder (com.qcadoo.model.api.search.SearchOrder)1 ParseException (java.text.ParseException)1 List (java.util.List)1