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