Search in sources :

Example 6 with CreateNodeParams

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

the class CreateContentCommandTest method mockNodeServiceCreate.

private Node mockNodeServiceCreate(final InvocationOnMock invocation) throws Throwable {
    CreateNodeParams params = (CreateNodeParams) invocation.getArguments()[0];
    final AccessControlList permissions = AccessControlList.create().add(AccessControlEntry.create().allowAll().principal(PrincipalKey.ofAnonymous()).build()).build();
    return Node.create().id(params.getNodeId() != null ? params.getNodeId() : new NodeId()).parentPath(params.getParent()).name(NodeName.from(params.getName())).data(params.getData()).indexConfigDocument(params.getIndexConfigDocument()).childOrder(params.getChildOrder() != null ? params.getChildOrder() : ChildOrder.defaultOrder()).permissions(permissions).inheritPermissions(params.inheritPermissions()).nodeType(params.getNodeType() != null ? params.getNodeType() : NodeType.DEFAULT_NODE_COLLECTION).timestamp(Instant.now()).build();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 7 with CreateNodeParams

use of com.enonic.xp.node.CreateNodeParams 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 8 with CreateNodeParams

use of com.enonic.xp.node.CreateNodeParams 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());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) ChildOrder(com.enonic.xp.index.ChildOrder) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Example 9 with CreateNodeParams

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

the class GetNodeByIdCommandTest method get_by_id.

@Test
public void get_by_id() throws Exception {
    final CreateNodeParams createNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
    final Node createdNode = createNode(createNodeParams);
    final Node fetchedNode = GetNodeByIdCommand.create().indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).id(createdNode.id()).build().execute();
    assertEquals(createdNode, fetchedNode);
}
Also used : Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Example 10 with CreateNodeParams

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

the class UpdateNodeCommandTest method unreferred_binary_attachment_ignored.

@Test
public void unreferred_binary_attachment_ignored() throws Exception {
    final PropertyTree data = new PropertyTree();
    final BinaryReference binaryRef = BinaryReference.from("my-car.jpg");
    data.setBinaryReference("my-image", binaryRef);
    final CreateNodeParams params = CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").data(data).attachBinary(binaryRef, ByteSource.wrap("my-car-image-source".getBytes())).build();
    final Node node = createNode(params);
    final UpdateNodeParams updateNodeParams = UpdateNodeParams.create().editor(toBeEdited -> {
        final PropertyTree nodeData = toBeEdited.data;
        nodeData.addString("newValue", "hepp");
    }).attachBinary(BinaryReference.from("unreferred binary"), ByteSource.wrap("nothing to see here".getBytes())).id(node.id()).build();
    final Node updatedNode = updateNode(updateNodeParams);
    assertEquals(1, updatedNode.getAttachedBinaries().getSize());
}
Also used : BinaryReference(com.enonic.xp.util.BinaryReference) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath) StandardCharsets(java.nio.charset.StandardCharsets) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Test(org.junit.jupiter.api.Test) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ByteStreams(com.google.common.io.ByteStreams) NodeBinaryReferenceException(com.enonic.xp.node.NodeBinaryReferenceException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) BinaryReference(com.enonic.xp.util.BinaryReference) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Aggregations

CreateNodeParams (com.enonic.xp.node.CreateNodeParams)46 Node (com.enonic.xp.node.Node)32 Test (org.junit.jupiter.api.Test)28 PropertyTree (com.enonic.xp.data.PropertyTree)18 BinaryReference (com.enonic.xp.util.BinaryReference)9 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)8 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)7 NodeId (com.enonic.xp.node.NodeId)4 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)4 AccessControlList (com.enonic.xp.security.acl.AccessControlList)4 ByteSource (com.google.common.io.ByteSource)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 NodeBinaryReferenceException (com.enonic.xp.node.NodeBinaryReferenceException)3 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)3 NodePath (com.enonic.xp.node.NodePath)3 PrincipalAlreadyExistsException (com.enonic.xp.security.PrincipalAlreadyExistsException)3 ByteStreams (com.google.common.io.ByteStreams)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)3