Search in sources :

Example 6 with Nodes

use of com.enonic.xp.node.Nodes in project xp by enonic.

the class DuplicateNodeCommand method storeChildNodes.

private void storeChildNodes(final Node originalParent, final Node newParent, final NodeReferenceUpdatesHolder.Builder builder) {
    final FindNodesByParentResult findNodesByParentResult = doFindNodesByParent(FindNodesByParentParams.create().parentPath(originalParent.path()).from(0).size(NodeSearchService.GET_ALL_SIZE_FLAG).build());
    final Nodes children = GetNodesByIdsCommand.create(this).ids(findNodesByParentResult.getNodeIds()).build().execute();
    for (final Node node : children) {
        final CreateNodeParams.Builder paramsBuilder = CreateNodeParams.from(node).parent(newParent.path());
        decideInsertStrategy(originalParent, node, paramsBuilder);
        attachBinaries(node, paramsBuilder);
        final CreateNodeParams originalParams = paramsBuilder.build();
        final CreateNodeParams processedParams = executeProcessors(originalParams);
        final Node newChildNode = CreateNodeCommand.create(this).params(processedParams).binaryService(this.binaryService).build().execute();
        builder.add(node.id(), newChildNode.id());
        result.addChild(newChildNode);
        nodeDuplicated(1);
        storeChildNodes(node, newChildNode, builder);
    }
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Nodes(com.enonic.xp.node.Nodes)

Example 7 with Nodes

use of com.enonic.xp.node.Nodes in project xp by enonic.

the class DuplicateNodeCommandTest method assertDuplicatedTree.

private void assertDuplicatedTree(final NodePath duplicatedTreeRootPath, final Node originalNode, final Node duplicatedNode) {
    final ImmutableList<Property> originalReferences = originalNode.data().getProperties(ValueTypes.REFERENCE);
    final ImmutableList<Property> duplicateReferences = duplicatedNode.data().getProperties(ValueTypes.REFERENCE);
    assertReferenceIntegrity(duplicatedTreeRootPath, originalReferences, duplicateReferences);
    final Nodes originalChildren = getNodes(findChildren(originalNode).getNodeIds());
    final Nodes duplicatedChildren = getNodes(findChildren(duplicatedNode).getNodeIds());
    assertEquals(originalChildren.getSize(), duplicatedChildren.getSize());
    originalChildren.forEach((originalChild) -> {
        final Node duplicatedChild = getNodeByName(duplicatedChildren, originalChild.name());
        assertDuplicatedTree(duplicatedTreeRootPath, originalChild, duplicatedChild);
    });
}
Also used : Node(com.enonic.xp.node.Node) Property(com.enonic.xp.data.Property) Nodes(com.enonic.xp.node.Nodes)

Example 8 with Nodes

use of com.enonic.xp.node.Nodes in project xp by enonic.

the class GetNodesByIsCommandTest method get_by_id_no_access.

@Test
public void get_by_id_no_access() throws Exception {
    createNode("1", true);
    createNode("2", true);
    createNode("3", false);
    final Nodes nodes = GetNodesByIdsCommand.create().ids(NodeIds.from("1", "2", "3")).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    assertEquals(2, nodes.getSize());
}
Also used : Nodes(com.enonic.xp.node.Nodes) Test(org.junit.jupiter.api.Test)

Example 9 with Nodes

use of com.enonic.xp.node.Nodes in project xp by enonic.

the class SecurityServiceImpl method getIdProviders.

@Override
public IdProviders getIdProviders() {
    final FindNodesByParentParams findByParent = FindNodesByParentParams.create().parentPath(IdProviderNodeTranslator.getIdProvidersParentPath()).build();
    final Nodes nodes = callWithContext(() -> {
        final FindNodesByParentResult result = this.nodeService.findByParent(findByParent);
        return this.nodeService.getByIds(result.getNodeIds());
    });
    return IdProviderNodeTranslator.fromNodes(nodes);
}
Also used : FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Nodes(com.enonic.xp.node.Nodes)

Example 10 with Nodes

use of com.enonic.xp.node.Nodes in project xp by enonic.

the class SecurityServiceImpl method query.

@Override
public UserQueryResult query(final UserQuery query) {
    try {
        final NodeQuery nodeQueryBuilder = UserQueryNodeQueryTranslator.translate(query);
        final FindNodesByQueryResult result = callWithContext(() -> this.nodeService.findByQuery(nodeQueryBuilder));
        final Nodes nodes = callWithContext(() -> this.nodeService.getByIds(result.getNodeIds()));
        final Principals principals = PrincipalNodeTranslator.fromNodes(nodes);
        return UserQueryResult.create().addUsers(principals).totalSize(Ints.checkedCast(result.getTotalHits())).build();
    } catch (NodeNotFoundException e) {
        return UserQueryResult.create().build();
    }
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Principals(com.enonic.xp.security.Principals) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) Nodes(com.enonic.xp.node.Nodes)

Aggregations

Nodes (com.enonic.xp.node.Nodes)31 Node (com.enonic.xp.node.Node)14 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)9 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)9 Test (org.junit.jupiter.api.Test)8 NodeQuery (com.enonic.xp.node.NodeQuery)5 Contents (com.enonic.xp.content.Contents)4 NodeIds (com.enonic.xp.node.NodeIds)3 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)3 CompareExpr (com.enonic.xp.query.expr.CompareExpr)3 QueryExpr (com.enonic.xp.query.expr.QueryExpr)3 Branch (com.enonic.xp.branch.Branch)2 Content (com.enonic.xp.content.Content)2 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)2 NodePaths (com.enonic.xp.node.NodePaths)2 Principals (com.enonic.xp.security.Principals)2 AccessControlList (com.enonic.xp.security.acl.AccessControlList)2 Application (com.enonic.xp.app.Application)1 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 BlobKey (com.enonic.xp.blob.BlobKey)1