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());
}
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);
}
}
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;
}
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;
}
Aggregations