Search in sources :

Example 41 with SearchCriteriaBuilder

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

the class ProductValidatorsTNFO method findCorruptedTechnologyNumbers.

// HQL form:
// -----------------------
// select
// toc.id as id,
// t.number as techNumber
// 
// from
// #technologies_technologyOperationComponent toc
// inner join toc.operationProductOutComponents opoc
// inner join opoc.product as p
// inner join toc.technology t
// left join toc.parent parentToc
// left join parentToc.operationProductInComponents opic
// 
// where
// (opoc.product.id = opic.product.id or (toc.parent is null and t.product.id = p.id))
// and t.state in ('02accepted', '05checked')
// and p.unit <> toc.productionInOneCycleUNIT
// and p.id = :productId
// 
// order by toc.id desc
private List<Entity> findCorruptedTechnologyNumbers(final Long productID) {
    MasterOutputProductCriteria criteria = MasterOutputProductCriteria.empty().withProdCriteria(idEq(productID)).withTechCriteria(in(TechnologyFields.STATE, Lists.newArrayList(TechnologyStateStringValues.ACCEPTED, TechnologyStateStringValues.CHECKED)));
    SearchCriteriaBuilder scb = mainTocOutputProductCriteriaBuilder.create(criteria);
    scb.add(neField(Aliases.OPERATION_OUTPUT_PRODUCT + "." + ProductFields.UNIT, Aliases.TOC + "." + TechnologyOperationComponentFieldsTNFO.PRODUCTION_IN_ONE_CYCLE_UNIT));
    scb.addOrder(desc("id"));
    SearchProjection techNumProjection = alias(field(Aliases.TECHNOLOGY + "." + TechnologyFields.NUMBER), "techNumber");
    SearchProjection projection = SearchProjections.list().add(techNumProjection).add(alias(id(), "id"));
    scb.setProjection(SearchProjections.distinct(projection));
    return scb.list().getEntities();
}
Also used : MasterOutputProductCriteria(com.qcadoo.mes.technologies.tree.traversing.MasterOutputProductCriteria) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchProjection(com.qcadoo.model.api.search.SearchProjection)

Example 42 with SearchCriteriaBuilder

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

the class WagesListsHooks method addDiscriminatorRestrictionToGrid.

public final void addDiscriminatorRestrictionToGrid(final ViewDefinitionState view) {
    GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    grid.setCustomRestriction(new CustomRestriction() {

        @Override
        public void addRestriction(final SearchCriteriaBuilder searchBuilder) {
            Entity ownerCompany = companyService.getCompany();
            searchBuilder.add(SearchRestrictions.or(SearchRestrictions.belongsTo("workFor", ownerCompany), SearchRestrictions.isNotNull("laborHourlyCost")));
        }
    });
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) GridComponent(com.qcadoo.view.api.components.GridComponent) CustomRestriction(com.qcadoo.model.api.search.CustomRestriction)

Example 43 with SearchCriteriaBuilder

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

the class WorkPlanServiceImplTest method shouldReturnOrdersById.

@Test
public final void shouldReturnOrdersById() throws Exception {
    // given
    Entity order1 = mock(Entity.class);
    when(order1.getId()).thenReturn(1L);
    Entity order2 = mock(Entity.class);
    when(order2.getId()).thenReturn(2L);
    Entity order3 = mock(Entity.class);
    when(order3.getId()).thenReturn(3L);
    @SuppressWarnings("unchecked") Iterator<Long> iterator = mock(Iterator.class);
    when(iterator.hasNext()).thenReturn(true, true, true, true, false);
    when(iterator.next()).thenReturn(1L, 2L, 3L, 4L);
    @SuppressWarnings("unchecked") Set<Long> selectedOrderIds = mock(Set.class);
    when(selectedOrderIds.iterator()).thenReturn(iterator);
    when(selectedOrderIds.size()).thenReturn(4);
    SearchCriteriaBuilder criteria = mock(SearchCriteriaBuilder.class);
    when(criteria.add(Mockito.any(SearchCriterion.class))).thenReturn(criteria);
    SearchResult result = mock(SearchResult.class);
    when(criteria.list()).thenReturn(result);
    when(result.getTotalNumberOfEntities()).thenReturn(3);
    when(result.getEntities()).thenReturn(Lists.newArrayList(order1, order2, order3));
    DataDefinition orderDD = mock(DataDefinition.class);
    when(orderDD.find()).thenReturn(criteria);
    when(dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER)).thenReturn(orderDD);
    // when
    List<Entity> resultList = workPlanService.getSelectedOrders(selectedOrderIds);
    // then
    Assert.assertEquals(3, resultList.size());
    Assert.assertNotNull(resultList.get(0));
    Assert.assertSame(1L, resultList.get(0).getId());
    Assert.assertNotNull(resultList.get(1));
    Assert.assertSame(2L, resultList.get(1).getId());
    Assert.assertNotNull(resultList.get(2));
    Assert.assertSame(3L, resultList.get(2).getId());
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) SearchResult(com.qcadoo.model.api.search.SearchResult) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 44 with SearchCriteriaBuilder

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

the class ProductService method findPossibleUnitConversions.

private PossibleUnitConversions findPossibleUnitConversions(final String unitName, final Entity productEntity) {
    CustomRestriction belongsToProductRestriction = new CustomRestriction() {

        @Override
        public void addRestriction(final SearchCriteriaBuilder scb) {
            scb.add(SearchRestrictions.belongsTo(UnitConversionItemFieldsB.PRODUCT, productEntity));
        }
    };
    PossibleUnitConversions possibleUnitConversions = unitConversionService.getPossibleConversions(unitName, belongsToProductRestriction);
    if (Objects.isNull(possibleUnitConversions)) {
        possibleUnitConversions = unitConversionService.getPossibleConversions(unitName);
    }
    return possibleUnitConversions;
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) CustomRestriction(com.qcadoo.model.api.search.CustomRestriction)

Example 45 with SearchCriteriaBuilder

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

the class ProductionCountingQuantityValidators method checkIfAnotherFinalProductExists.

private boolean checkIfAnotherFinalProductExists(final DataDefinition productionCountingQuantityDD, final Entity productionCountingQuantity) {
    Entity order = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.ORDER);
    SearchCriteriaBuilder searchCriteriaBuilder = productionCountingQuantityDD.find().add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order)).add(SearchRestrictions.eq(ProductionCountingQuantityFields.TYPE_OF_MATERIAL, ProductionCountingQuantityTypeOfMaterial.FINAL_PRODUCT.getStringValue()));
    if (productionCountingQuantity.getId() != null) {
        searchCriteriaBuilder.add(SearchRestrictions.ne("id", productionCountingQuantity.getId()));
    }
    SearchResult searchResult = searchCriteriaBuilder.list();
    return searchResult.getEntities().isEmpty();
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchResult(com.qcadoo.model.api.search.SearchResult)

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