Search in sources :

Example 6 with SearchResult

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchQueryBuilder(com.qcadoo.model.api.search.SearchQueryBuilder) SearchResult(com.qcadoo.model.api.search.SearchResult) DataDefinition(com.qcadoo.model.api.DataDefinition) BigDecimal(java.math.BigDecimal) ProductWithQuantityAndCost(com.qcadoo.mes.costNormsForMaterials.orderRawMaterialCosts.domain.ProductWithQuantityAndCost)

Example 7 with SearchResult

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

Example 8 with SearchResult

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

Example 9 with SearchResult

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());
}
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 10 with SearchResult

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

Aggregations

SearchResult (com.qcadoo.model.api.search.SearchResult)35 Entity (com.qcadoo.model.api.Entity)18 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)16 DataDefinition (com.qcadoo.model.api.DataDefinition)10 Test (org.junit.Test)10 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)7 SearchProjection (com.qcadoo.model.api.search.SearchProjection)4 FieldEntityIdChangeListener (com.qcadoo.view.internal.FieldEntityIdChangeListener)4 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)4 BigDecimal (java.math.BigDecimal)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 SearchQueryBuilder (com.qcadoo.model.api.search.SearchQueryBuilder)2 Date (java.util.Date)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ImmutableList (com.google.common.collect.ImmutableList)1 ProductWithQuantityAndCost (com.qcadoo.mes.costNormsForMaterials.orderRawMaterialCosts.domain.ProductWithQuantityAndCost)1 Monitorable (com.qcadoo.model.api.aop.Monitorable)1 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)1 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)1 LocalDate (java.time.LocalDate)1