use of com.enonic.xp.index.ChildOrder in project xp by enonic.
the class NodeTest method equals.
@Test
public void equals() {
NodeName name1 = NodeName.from("name1");
NodeName name2 = NodeName.from("name2");
ChildOrder childOrder1 = ChildOrder.defaultOrder();
ChildOrder childOrder2 = ChildOrder.manualOrder();
PropertyTree data1 = new PropertyTree();
data1.addString("some", "config");
PropertyTree data2 = new PropertyTree();
data2.addString("other", "config");
AbstractEqualsTest equalsTest = new AbstractEqualsTest() {
@Override
public Object getObjectX() {
return Node.create().name(name1).data(data1).childOrder(childOrder1).build();
}
@Override
public Object[] getObjectsThatNotEqualsX() {
Node notX1 = Node.create().name(name2).data(data1).childOrder(childOrder1).build();
Node notX2 = Node.create().name(name1).data(data2).childOrder(childOrder1).build();
Node notX3 = Node.create().name(name1).data(data1).childOrder(childOrder2).build();
return new Object[] { notX1, notX2, notX3 };
}
@Override
public Object getObjectThatEqualsXButNotTheSame() {
return Node.create().name(name1).data(data1).childOrder(childOrder1).build();
}
@Override
public Object getObjectThatEqualsXButNotTheSame2() {
return Node.create().name(name1).data(data1).childOrder(childOrder1).build();
}
};
equalsTest.assertEqualsAndHashCodeContract();
}
use of com.enonic.xp.index.ChildOrder in project xp by enonic.
the class FindNodeIdsByParentCommand method execute.
public FindNodesByParentResult execute() {
NodePath parentPath = getParentPath();
if (parentPath == null) {
return FindNodesByParentResult.empty();
}
final ChildOrder order = NodeChildOrderResolver.create(this).nodePath(parentPath).childOrder(childOrder).build().resolve();
final SearchResult result = this.nodeSearchService.query(createFindChildrenQuery(parentPath, order), SingleRepoSearchSource.from(ContextAccessor.current()));
if (result.getNumberOfHits() == 0) {
return FindNodesByParentResult.create().totalHits(result.getTotalHits()).build();
}
return FindNodesByParentResult.create().nodeIds(NodeIds.from(result.getIds())).totalHits(result.getTotalHits()).hits(result.getNumberOfHits()).build();
}
use of com.enonic.xp.index.ChildOrder in project xp by enonic.
the class FindNodesByParentCommand method execute.
public FindNodesByParentResult execute() {
NodePath parentPath = params.getParentPath();
if (parentPath == null) {
Node parent = GetNodeByIdCommand.create(this).id(params.getParentId()).build().execute();
if (parent == null) {
return FindNodesByParentResult.empty();
}
parentPath = parent.path();
}
final ChildOrder order = NodeChildOrderResolver.create(this).nodePath(parentPath).childOrder(params.getChildOrder()).build().resolve();
final SearchResult result = this.nodeSearchService.query(NodeQuery.create().parent(parentPath).addQueryFilters(params.getQueryFilters()).from(params.getFrom()).size(params.getSize()).searchMode(params.isCountOnly() ? SearchMode.COUNT : SearchMode.SEARCH).setOrderExpressions(order.getOrderExpressions()).accurateScoring(true).build(), SingleRepoSearchSource.from(ContextAccessor.current()));
if (result.isEmpty()) {
return FindNodesByParentResult.create().hits(0).totalHits(result.getTotalHits()).nodeIds(NodeIds.empty()).build();
}
return FindNodesByParentResult.create().nodeIds(NodeIds.from(result.getIds())).totalHits(result.getTotalHits()).hits(result.getNumberOfHits()).build();
}
use of com.enonic.xp.index.ChildOrder in project xp by enonic.
the class NodeServiceImplTest method testReorderChildren.
@Test
public void testReorderChildren() {
final Node parent = createNode(CreateNodeParams.create().name("my-parent").parent(NodePath.ROOT).childOrder(ChildOrder.manualOrder()).build());
final Node child1 = createNode(CreateNodeParams.create().name("my-child-1").parent(parent.path()).build());
final Node child2 = createNode(CreateNodeParams.create().name("my-child-2").parent(parent.path()).build());
final Node child3 = createNode(CreateNodeParams.create().name("my-child-3").parent(parent.path()).build());
final ReorderChildNodesParams params = ReorderChildNodesParams.create().add(ReorderChildNodeParams.create().nodeId(child1.id()).moveBefore(child2.id()).build()).add(ReorderChildNodeParams.create().nodeId(child3.id()).moveBefore(child1.id()).build()).processor(data -> {
data.addString("processedValue", "value");
return data;
}).build();
final ReorderChildNodesResult result = this.nodeService.reorderChildren(params);
assertThat(result.getNodeIds()).containsExactly(child1.id(), child3.id());
assertThat(result.getParentNodes().getIds()).containsExactly(parent.id());
assertThat(nodeService.findByParent(FindNodesByParentParams.create().parentId(parent.id()).build()).getNodeIds()).containsExactly(child3.id(), child1.id(), child2.id());
nodeService.refresh(RefreshMode.ALL);
final Node processedParent = this.nodeService.getById(parent.id());
assertEquals("value", processedParent.data().getString("processedValue"));
}
use of com.enonic.xp.index.ChildOrder in project xp by enonic.
the class NodeServiceImplTest method create.
@Test
public void create() throws Exception {
final ChildOrder childOrder = ChildOrder.create().add(FieldOrderExpr.create(NodeIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).add(FieldOrderExpr.create(NodeIndexPath.NAME, OrderExpr.Direction.ASC)).build();
final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:rmy")).allow(Permission.READ).build()).build();
final CreateNodeParams params = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(aclList).childOrder(childOrder).build();
final Node node = this.nodeService.create(params);
refresh();
assertTrue(node.getPermissions() != null);
assertEquals(aclList, node.getPermissions());
assertEquals(childOrder, node.getChildOrder());
}
Aggregations