Search in sources :

Example 81 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class AbstractStateChangeAspectTest method shouldNotFireChangeStateIfStateChangeHaveErrorMessages.

@Test
public final void shouldNotFireChangeStateIfStateChangeHaveErrorMessages() {
    // given
    AnotherStateChangeService anotherStateChangeService = new AnotherStateChangeService();
    EntityList messagesEntityList = mockEntityList(Lists.newArrayList(mockMessage(StateMessageType.FAILURE, "fail")));
    given(stateChangeEntity.getHasManyField(DESCRIBER.getMessagesFieldName())).willReturn(messagesEntityList);
    given(stateChangeEntity.getField(DESCRIBER.getMessagesFieldName())).willReturn(messagesEntityList);
    // when
    anotherStateChangeService.changeState(stateChangeContext);
    // then
    verify(ownerEntity, never()).setField(Mockito.eq(STATE_FIELD_NAME), Mockito.any());
}
Also used : EntityList(com.qcadoo.model.api.EntityList) Test(org.junit.Test) StateChangeTest(com.qcadoo.mes.states.StateChangeTest)

Example 82 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class MrpAlgorithmStrategyTSTest method init.

@Before
public void init() {
    algorithmStrategyTS = new MrpAlgorithmStrategyTS();
    MockitoAnnotations.initMocks(this);
    ReflectionTestUtils.setField(algorithmStrategyTS, "productQuantitiesService", productQuantitiesService);
    EntityList opComp1InComp = mockEntityListIterator(asList(productInComponent1, productInComponent3));
    EntityList opComp1OutComp = mockEntityListIterator(asList(productOutComponent2));
    EntityList opComp2InComp = mockEntityListIterator(asList(productInComponent2));
    EntityList opComp2OutComp = mockEntityListIterator(asList(productOutComponent4));
    when(operComp1.getHasManyField("operationProductInComponents")).thenReturn(opComp1InComp);
    when(operComp1.getHasManyField("operationProductOutComponents")).thenReturn(opComp1OutComp);
    when(operComp2.getHasManyField("operationProductInComponents")).thenReturn(opComp2InComp);
    when(operComp2.getHasManyField("operationProductOutComponents")).thenReturn(opComp2OutComp);
    when(productInComponent1.getField("quantity")).thenReturn(new BigDecimal(5));
    when(productInComponent3.getField("quantity")).thenReturn(BigDecimal.ONE);
    when(productOutComponent2.getField("quantity")).thenReturn(BigDecimal.ONE);
    when(productInComponent2.getField("quantity")).thenReturn(new BigDecimal(2));
    when(productOutComponent4.getField("quantity")).thenReturn(BigDecimal.ONE);
    productComponentQuantities = new OperationProductComponentWithQuantityContainer();
    nonComponents = Sets.newHashSet();
    productComponentQuantities.put(productInComponent1, new BigDecimal(5));
    productComponentQuantities.put(productInComponent3, BigDecimal.ONE);
    productComponentQuantities.put(productOutComponent2, BigDecimal.ONE);
    productComponentQuantities.put(productOutComponent4, BigDecimal.ONE);
    productComponentQuantities.put(productInComponent2, new BigDecimal(2));
    nonComponents.add(new OperationProductComponentHolder(productInComponent2));
    when(product1.getId()).thenReturn(1L);
    when(product2.getId()).thenReturn(2L);
    when(product3.getId()).thenReturn(3L);
    when(product4.getId()).thenReturn(4L);
    when(productInComponent1.getBelongsToField("product")).thenReturn(product1);
    when(productInComponent2.getBelongsToField("product")).thenReturn(product2);
    when(productInComponent3.getBelongsToField("product")).thenReturn(product3);
    when(productOutComponent2.getBelongsToField("product")).thenReturn(product2);
    when(productOutComponent4.getBelongsToField("product")).thenReturn(product4);
    when(productInComponent1.getBelongsToField("operationComponent")).thenReturn(operComp1);
    when(productInComponent3.getBelongsToField("operationComponent")).thenReturn(operComp1);
    when(productOutComponent2.getBelongsToField("operationComponent")).thenReturn(operComp1);
    when(productInComponent2.getBelongsToField("operationComponent")).thenReturn(operComp2);
    when(productOutComponent4.getBelongsToField("operationComponent")).thenReturn(operComp2);
    when(ddIn.getName()).thenReturn("productInComponent");
    when(ddOut.getName()).thenReturn("productOutComponent");
    when(productInComponent1.getDataDefinition()).thenReturn(ddIn);
    when(productInComponent2.getDataDefinition()).thenReturn(ddIn);
    when(productInComponent3.getDataDefinition()).thenReturn(ddIn);
    when(productOutComponent2.getDataDefinition()).thenReturn(ddOut);
    when(productOutComponent4.getDataDefinition()).thenReturn(ddOut);
    when(ddIn.getName()).thenReturn("operationProductInComponent");
    when(ddOut.getName()).thenReturn("operationProductOutComponent");
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) EntityList(com.qcadoo.model.api.EntityList) BigDecimal(java.math.BigDecimal) Before(org.junit.Before)

Example 83 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class TechnologyTreeValidationServiceImplTest method mockOperationComponent.

private EntityTreeNode mockOperationComponent(final Long id, final String nodeNumber, final Collection<Entity> inputProducts, final Collection<Entity> outputProducts, final List<EntityTreeNode> subOperations) {
    EntityTreeNode operationComponent = mock(EntityTreeNode.class);
    given(operationComponent.getId()).willReturn(id);
    EntityList inputProductsList = mockProductComponentsList(inputProducts);
    given(operationComponent.getHasManyField(OPERATION_PRODUCT_IN_COMPONENTS)).willReturn(inputProductsList);
    given(operationComponent.getField(OPERATION_PRODUCT_IN_COMPONENTS)).willReturn(inputProductsList);
    EntityList outputProductsList = mockProductComponentsList(outputProducts);
    given(operationComponent.getHasManyField(OPERATION_PRODUCT_OUT_COMPONENTS)).willReturn(outputProductsList);
    given(operationComponent.getField(OPERATION_PRODUCT_OUT_COMPONENTS)).willReturn(outputProductsList);
    given(operationComponent.getField(NODE_NUMBER)).willReturn(nodeNumber);
    given(operationComponent.getStringField(NODE_NUMBER)).willReturn(nodeNumber);
    given(operationComponent.getChildren()).willReturn(subOperations);
    return operationComponent;
}
Also used : EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) EntityList(com.qcadoo.model.api.EntityList)

Example 84 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class WorkstationCriteriaModifiersTNFO method filterByTOC.

public void filterByTOC(final SearchCriteriaBuilder scb, final FilterValueHolder filterValueHolder) {
    Long technologyOperationComponentId = filterValueHolder.getLong(TECHNOLOGY_OPERATION_COMPONENT_ID);
    EntityList workstations = getTOCDD().get(technologyOperationComponentId).getHasManyField(TechnologyOperationComponentFields.WORKSTATIONS);
    if (!workstations.isEmpty()) {
        Set<Long> workstationIds = workstations.stream().map(Entity::getId).collect(Collectors.toSet());
        scb.add(SearchRestrictions.in("id", workstationIds));
        SearchCriteriaBuilder subCriteria = getTOCDD().findWithAlias(TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).add(SearchRestrictions.idEq(technologyOperationComponentId)).createAlias(TechnologyOperationComponentFieldsTNFO.TECH_OPER_COMP_WORKSTATION_TIMES, TechnologyOperationComponentFieldsTNFO.TECH_OPER_COMP_WORKSTATION_TIMES, JoinType.INNER).createAlias(TechnologyOperationComponentFieldsTNFO.TECH_OPER_COMP_WORKSTATION_TIMES + L_DOT + TechOperCompWorkstationTimeFields.WORKSTATION, TechOperCompWorkstationTimeFields.WORKSTATION, JoinType.INNER).add(SearchRestrictions.eqField(TechOperCompWorkstationTimeFields.WORKSTATION + L_DOT + L_ID, L_THIS_ID)).setProjection(SearchProjections.id());
        if (filterValueHolder.has(L_WORKSTATION_ID)) {
            scb.add(SearchRestrictions.or(SearchSubqueries.notExists(subCriteria), SearchRestrictions.idEq(filterValueHolder.getLong(L_WORKSTATION_ID))));
        } else {
            scb.add(SearchSubqueries.notExists(subCriteria));
        }
    } else {
        scb.add(SearchRestrictions.idEq(-1));
    }
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) EntityList(com.qcadoo.model.api.EntityList)

Example 85 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class WorkstationCriteriaModifiersTNFO method filterByOperation.

public void filterByOperation(final SearchCriteriaBuilder scb, final FilterValueHolder filterValueHolder) {
    Long operationId = filterValueHolder.getLong(L_OPERATION_ID);
    EntityList workstations = getOperationDD().get(operationId).getHasManyField(OperationFields.WORKSTATIONS);
    if (!workstations.isEmpty()) {
        Set<Long> workstationIds = workstations.stream().map(Entity::getId).collect(Collectors.toSet());
        scb.add(SearchRestrictions.in("id", workstationIds));
        SearchCriteriaBuilder subCriteria = getOperationDD().findWithAlias(TechnologiesConstants.MODEL_OPERATION).add(SearchRestrictions.idEq(operationId)).createAlias(OperationFieldsTFNO.OPERATION_WORKSTATION_TIMES, OperationFieldsTFNO.OPERATION_WORKSTATION_TIMES, JoinType.INNER).createAlias(OperationFieldsTFNO.OPERATION_WORKSTATION_TIMES + L_DOT + OperationWorkstationTimeFields.WORKSTATION, OperationWorkstationTimeFields.WORKSTATION, JoinType.INNER).add(SearchRestrictions.eqField(OperationWorkstationTimeFields.WORKSTATION + L_DOT + L_ID, L_THIS_ID)).setProjection(SearchProjections.id());
        if (filterValueHolder.has(L_WORKSTATION_ID)) {
            scb.add(SearchRestrictions.or(SearchSubqueries.notExists(subCriteria), SearchRestrictions.idEq(filterValueHolder.getLong(L_WORKSTATION_ID))));
        } else {
            scb.add(SearchSubqueries.notExists(subCriteria));
        }
    } else {
        scb.add(SearchRestrictions.idEq(-1));
    }
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) EntityList(com.qcadoo.model.api.EntityList)

Aggregations

EntityList (com.qcadoo.model.api.EntityList)103 Entity (com.qcadoo.model.api.Entity)52 Test (org.junit.Test)27 DataDefinition (com.qcadoo.model.api.DataDefinition)16 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)16 Before (org.junit.Before)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)10 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 Objects (java.util.Objects)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 Service (org.springframework.stereotype.Service)10 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)9 BigDecimal (java.math.BigDecimal)9 StateChangeTest (com.qcadoo.mes.states.StateChangeTest)5