Search in sources :

Example 21 with EntityTreeNode

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

the class TreeNumberingServiceTest method shouldNumberBranchedTree.

@Test
public void shouldNumberBranchedTree() throws Exception {
    // given
    EntityTreeNode node1A1 = getTreeNodeMock();
    EntityTreeNode node1B1 = getTreeNodeMock(2);
    EntityTreeNode node1A2 = getTreeNodeMock();
    EntityTreeNode node1A3 = getTreeNodeMock();
    EntityTreeNode node1B1A1 = getTreeNodeMock();
    EntityTreeNode node1B1A2 = getTreeNodeMock();
    EntityTreeNode node1B1A2A1 = getTreeNodeMock();
    EntityTreeNode node1B1A2B1 = getTreeNodeMock();
    EntityTreeNode node1B1B1 = getTreeNodeMock(2);
    EntityTreeNode node1B1B2 = getTreeNodeMock();
    EntityTreeNode node1B1B3 = getTreeNodeMock();
    when(rootNode.getChildren()).thenReturn(Lists.newArrayList(node1A1, node1B1));
    when(node1A1.getChildren()).thenReturn(Lists.newArrayList(node1A2));
    when(node1A2.getChildren()).thenReturn(Lists.newArrayList(node1A3));
    when(node1B1.getChildren()).thenReturn(Lists.newArrayList(node1B1A1, node1B1B1));
    when(node1B1A1.getChildren()).thenReturn(Lists.newArrayList(node1B1A2));
    when(node1B1A2.getChildren()).thenReturn(Lists.newArrayList(node1B1A2A1, node1B1A2B1));
    when(node1B1B1.getChildren()).thenReturn(Lists.newArrayList(node1B1B2));
    when(node1B1B2.getChildren()).thenReturn(Lists.newArrayList(node1B1B3));
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    // when
    treeNumberingService.generateTreeNumbers(tree);
    // then
    Mockito.verify(rootNode).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.", argument.getValue());
    Mockito.verify(node1A1).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.A.1.", argument.getValue());
    Mockito.verify(node1B1).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.B.1.", argument.getValue());
    Mockito.verify(node1A2).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.A.2.", argument.getValue());
    Mockito.verify(node1A3).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.A.3.", argument.getValue());
    Mockito.verify(node1B1A1).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.B.1.A.1.", argument.getValue());
    Mockito.verify(node1B1A2).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.B.1.A.2.", argument.getValue());
    Mockito.verify(node1B1A2A1).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.B.1.A.2.A.1.", argument.getValue());
    Mockito.verify(node1B1A2B1).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.B.1.A.2.B.1.", argument.getValue());
    Mockito.verify(node1B1B1).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.B.1.B.1.", argument.getValue());
    Mockito.verify(node1B1B2).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.B.1.B.2.", argument.getValue());
    Mockito.verify(node1B1B3).setField(Mockito.eq(NODE_NUMBER_FIELD), argument.capture());
    assertEquals("1.B.1.B.3.", argument.getValue());
}
Also used : EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) Test(org.junit.Test)

Example 22 with EntityTreeNode

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

the class TreeNumberingServiceImpl method assignNumberToTreeNode.

final void assignNumberToTreeNode(final EntityTreeNode treeNode, final Deque<String> chain) {
    treeNode.setField(TreeType.NODE_NUMBER_FIELD, convertCollectionToString(chain));
    List<EntityTreeNode> childrens = newLinkedList(treeNode.getChildren());
    Collections.sort(childrens, priorityService.getEntityPriorityComparator());
    int charNumber = 0;
    for (EntityTreeNode child : childrens) {
        Deque<String> newBranch = Lists.newLinkedList(chain);
        if (childrens.size() == 1) {
            incrementLastChainNumber(newBranch);
        } else {
            incrementLastChainCharacter(newBranch, charNumber++);
        }
        assignNumberToTreeNode(child, newBranch);
    }
}
Also used : EntityTreeNode(com.qcadoo.model.api.EntityTreeNode)

Example 23 with EntityTreeNode

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

the class EntityTreeUtilsService method getSortedEntitiesFromNode.

private List<Entity> getSortedEntitiesFromNode(final EntityTreeNode node) {
    List<Entity> nodesList = Lists.newLinkedList();
    nodesList.add(node);
    List<EntityTreeNode> childNodes = Lists.newLinkedList(node.getChildren());
    Collections.sort(childNodes, priorityService.getEntityPriorityComparator());
    for (EntityTreeNode childNode : childNodes) {
        nodesList.addAll(getSortedEntitiesFromNode(childNode));
    }
    return nodesList;
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode)

Example 24 with EntityTreeNode

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

the class TreeComponentState method createNode.

private TreeNode createNode(final EntityTreeNode entityTreeNode, final Deque<String> nodeNumberChain) {
    entityTreeNode.setField(NODE_NUMBER_FIELD, TreeNumberingServiceImpl.convertCollectionToString(nodeNumberChain));
    List<EntityTreeNode> childs = entityTreeNode.getChildren();
    TreeDataType entityType = dataTypes.get(entityTreeNode.getEntityNoteType());
    String nodeLabel = ExpressionUtils.getValue(entityTreeNode, entityType.getNodeLabelExpression(), getLocale());
    TreeNode node = new TreeNode(entityTreeNode.getId(), nodeLabel, entityType);
    int charNumber = 0;
    for (EntityTreeNode childEntityTreeNode : childs) {
        Deque<String> newNodeNumberBranch = Lists.newLinkedList(nodeNumberChain);
        if (childs.size() == 1) {
            TreeNumberingServiceImpl.incrementLastChainNumber(newNodeNumberBranch);
        } else {
            TreeNumberingServiceImpl.incrementLastChainCharacter(newNodeNumberBranch, charNumber++);
        }
        node.addChild(createNode(childEntityTreeNode, newNodeNumberBranch));
    }
    return node;
}
Also used : EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode)

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