Search in sources :

Example 11 with EntityTreeNode

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

the class TechnologyTreeValidationServiceImplTest method shouldReturnNotEmptyMapIfParentOpConsumeManyOutputsFromOneSubOp.

@Test
public final void shouldReturnNotEmptyMapIfParentOpConsumeManyOutputsFromOneSubOp() {
    // given
    Entity product1 = mockProductComponent(1L);
    Entity product2 = mockProductComponent(2L);
    Entity product3 = mockProductComponent(3L);
    Entity product4 = mockProductComponent(4L);
    Entity product5 = mockProductComponent(5L);
    Entity product6 = mockProductComponent(6L);
    EntityTreeNode node3 = mockOperationComponent("3.", newArrayList(product6), newArrayList(product3, product4, product5));
    EntityTreeNode node2 = mockOperationComponent("2.", newArrayList(product3, product4), newArrayList(product2), newArrayList(node3));
    EntityTreeNode node1 = mockOperationComponent("1.", newArrayList(product2), newArrayList(product1), newArrayList(node2));
    given(tree.getRoot()).willReturn(node1);
    // when
    resultMap = technologyTreeValidationService.checkConsumingManyProductsFromOneSubOp(tree);
    // then
    assertNotNull(resultMap);
    assertFalse(resultMap.isEmpty());
    assertEquals(1, resultMap.size());
    hasNodeNumbersFor(node2, node3);
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) Test(org.junit.Test)

Example 12 with EntityTreeNode

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

the class TechnologyTreeValidationServiceImplTest method shouldReturnNotEmptyMapIfManyParentOpConsumesManyOutputsFromOneSubOp.

@Test
public final void shouldReturnNotEmptyMapIfManyParentOpConsumesManyOutputsFromOneSubOp() {
    // given
    Entity product1 = mockProductComponent(1L);
    Entity product2 = mockProductComponent(2L);
    Entity product3 = mockProductComponent(3L);
    Entity product4 = mockProductComponent(4L);
    Entity product5 = mockProductComponent(5L);
    Entity product6 = mockProductComponent(6L);
    Entity product7 = mockProductComponent(7L);
    Entity product8 = mockProductComponent(8L);
    Entity product9 = mockProductComponent(9L);
    Entity product10 = mockProductComponent(10L);
    Entity product11 = mockProductComponent(11L);
    Entity product12 = mockProductComponent(12L);
    EntityTreeNode node1A3 = mockOperationComponent("1.A.3.", newArrayList(product11, product12), newArrayList(product10));
    EntityTreeNode node1A2 = mockOperationComponent("1.A.2.", newArrayList(product10), newArrayList(product7, product8, product9), newArrayList(node1A3));
    EntityTreeNode node1A1 = mockOperationComponent("1.A.1.", newArrayList(product7, product8, product9), newArrayList(product2, product3), newArrayList(node1A2));
    EntityTreeNode node1B1 = mockOperationComponent("1.B.1.", newArrayList(product6), newArrayList(product4, product5));
    EntityTreeNode node1 = mockOperationComponent("1.", newArrayList(product2, product3, product4, product5), newArrayList(product1), newArrayList(node1A1, node1B1));
    given(tree.getRoot()).willReturn(node1);
    // when
    resultMap = technologyTreeValidationService.checkConsumingManyProductsFromOneSubOp(tree);
    // then
    assertNotNull(resultMap);
    assertFalse(resultMap.isEmpty());
    assertEquals(2, resultMap.size());
    assertEquals(2, resultMap.get(node1.getStringField(NODE_NUMBER)).size());
    hasNodeNumbersFor(node1, node1A1);
    hasNodeNumbersFor(node1, node1B1);
    hasNodeNumbersFor(node1A1, node1A2);
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) Test(org.junit.Test)

Example 13 with EntityTreeNode

use of com.qcadoo.model.api.EntityTreeNode 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 14 with EntityTreeNode

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

the class TechnologyValidationService method checkTopComponentsProducesProductForTechnology.

private boolean checkTopComponentsProducesProductForTechnology(final StateChangeContext stateChangeContext, final FormComponent technologyForm, final Entity technology) {
    final Entity savedTechnology = technology.getDataDefinition().get(technology.getId());
    final Entity product = savedTechnology.getBelongsToField(TechnologyFields.PRODUCT);
    final EntityTree operationComponents = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    final EntityTreeNode root = operationComponents.getRoot();
    if (Objects.nonNull(root)) {
        final EntityList operationProductOutComponents = root.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS);
        for (Entity operationProductOutComponent : operationProductOutComponents) {
            if (product.getId().equals(operationProductOutComponent.getBelongsToField(OperationProductOutComponentFields.PRODUCT).getId())) {
                return true;
            }
        }
    }
    if (Objects.nonNull(technologyForm)) {
        technologyForm.addMessage("technologies.technology.validate.global.error.noFinalProductInTechnologyTree", MessageType.FAILURE);
    } else {
        stateChangeContext.addValidationError("technologies.technology.validate.global.error.noFinalProductInTechnologyTree");
    }
    return false;
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) EntityList(com.qcadoo.model.api.EntityList) EntityTree(com.qcadoo.model.api.EntityTree)

Example 15 with EntityTreeNode

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

the class TechnologyOperationComponentHooks method setParentIfRootNodeAlreadyExists.

private void setParentIfRootNodeAlreadyExists(final Entity technologyOperationComponent) {
    Entity technology = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
    EntityTree tree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    if (Objects.isNull(tree) || tree.isEmpty()) {
        return;
    }
    EntityTreeNode rootNode = tree.getRoot();
    if (Objects.isNull(rootNode) || Objects.nonNull(technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.PARENT))) {
        return;
    }
    technologyOperationComponent.setField(TechnologyOperationComponentFields.PARENT, rootNode);
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) EntityTree(com.qcadoo.model.api.EntityTree)

Aggregations

EntityTreeNode (com.qcadoo.model.api.EntityTreeNode)24 Entity (com.qcadoo.model.api.Entity)11 Test (org.junit.Test)10 Set (java.util.Set)4 EntityTree (com.qcadoo.model.api.EntityTree)3 EntityList (com.qcadoo.model.api.EntityList)2 OperationTimes (com.qcadoo.mes.operationTimeCalculations.dto.OperationTimes)1 BigDecimal (java.math.BigDecimal)1 MathContext (java.math.MathContext)1 ArrayList (java.util.ArrayList)1