use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.
the class ProductionTrackingListenerServicePFTD method updateCostsForOrder.
public void updateCostsForOrder(final Entity order) {
DataDefinition positionDD = getPositionDD();
SearchQueryBuilder searchQueryBuilder = positionDD.find("SELECT pr.id AS product, SUM(p.quantity) AS quantity, SUM(p.quantity * p.price) AS price " + "FROM #materialFlowResources_position p JOIN p.document AS d join p.product AS pr " + "WHERE d.order = :order_id AND d.type = :type " + "GROUP BY d.order, d.type, pr.id");
searchQueryBuilder.setLong("order_id", order.getId());
searchQueryBuilder.setString("type", DocumentType.INTERNAL_OUTBOUND.getStringValue());
SearchResult result = searchQueryBuilder.list();
List<ProductWithQuantityAndCost> productsWithQuantitiesAndCosts = Lists.newArrayList();
for (Entity costsForProduct : result.getEntities()) {
Long product = (Long) costsForProduct.getField(PositionFields.PRODUCT);
BigDecimal quantity = costsForProduct.getDecimalField(PositionFields.QUANTITY);
BigDecimal cost = costsForProduct.getDecimalField(PositionFields.PRICE);
productsWithQuantitiesAndCosts.add(new ProductWithQuantityAndCost(product, quantity, cost));
}
List<Entity> updatedCosts = costNormsForMaterialsService.updateCostsForProductInOrder(order, productsWithQuantitiesAndCosts);
order.setField(OrderFieldsCNFM.TECHNOLOGY_INST_OPER_PRODUCT_IN_COMPS, updatedCosts);
}
use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.
the class SupplyParametersHooksPFTD method draftOrInProgressWarehouseIssuesDoesntExist.
private boolean draftOrInProgressWarehouseIssuesDoesntExist() {
DataDefinition dd = dataDefinitionService.get(ProductFlowThruDivisionConstants.PLUGIN_IDENTIFIER, ProductFlowThruDivisionConstants.MODEL_WAREHOUSE_ISSUE);
SearchResult result = dd.find().add(SearchRestrictions.or(SearchRestrictions.eq(WarehouseIssueFields.STATE, WarehouseIssueState.DRAFT.getStringValue()), SearchRestrictions.eq(WarehouseIssueFields.STATE, WarehouseIssueState.IN_PROGRESS.getStringValue()))).list();
return result.getTotalNumberOfEntities() == 0;
}
use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.
the class OrderClosingHelperTest method stubSearchCriteriaResults.
private void stubSearchCriteriaResults(final Long... ids) {
SearchCriteriaBuilder scb = mock(SearchCriteriaBuilder.class);
// blind mock of fluent interface
given(scb.add(any(SearchCriterion.class))).willReturn(scb);
given(scb.setProjection(any(SearchProjection.class))).willReturn(scb);
List<Entity> entities = Lists.newArrayList();
for (Long id : ids) {
Entity entity = mock(Entity.class);
given(entity.getField("id")).willReturn(id);
entities.add(entity);
}
SearchResult result = mock(SearchResult.class);
given(result.getEntities()).willReturn(entities);
given(scb.list()).willReturn(result);
given(productionTrackingDD.find()).willReturn(scb);
}
use of com.qcadoo.model.api.search.SearchResult 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.SearchResult in project mes by qcadoo.
the class ProductService method checkSubstituteComponentUniqueness.
public boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent) {
Entity product = substituteComponent.getBelongsToField(SubstituteComponentFields.PRODUCT);
Entity baseProduct = substituteComponent.getBelongsToField(SubstituteComponentFields.BASE_PRODUCT);
if (Objects.isNull(baseProduct) || Objects.isNull(product)) {
return false;
}
final SearchResult searchResult = substituteComponentDD.find().add(SearchRestrictions.belongsTo(SubstituteComponentFields.PRODUCT, product)).add(SearchRestrictions.belongsTo(SubstituteComponentFields.BASE_PRODUCT, baseProduct)).list();
if (searchResult.getTotalNumberOfEntities() > 0 && !searchResult.getEntities().get(0).getId().equals(substituteComponent.getId())) {
substituteComponent.addError(substituteComponentDD.getField(SubstituteComponentFields.PRODUCT), "basic.validate.global.error.substituteComponentDuplicated");
return false;
} else {
return true;
}
}
Aggregations