Search in sources :

Example 11 with UpdateNodeParams

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

the class SecurityServiceImpl method removeRelationships.

private void removeRelationships(final IdProviderKey from) {
    callWithContext(() -> {
        final NodePath idProviderNodePath = IdProviderNodeTranslator.toIdProviderNodePath(from);
        final Node node = this.nodeService.getByPath(idProviderNodePath);
        final UpdateNodeParams updateNodeParams = IdProviderNodeTranslator.removeAllRelationshipsToUpdateNodeParams(node);
        nodeService.update(updateNodeParams);
        this.nodeService.refresh(RefreshMode.SEARCH);
        return null;
    });
}
Also used : Node(com.enonic.xp.node.Node) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodePath(com.enonic.xp.node.NodePath)

Example 12 with UpdateNodeParams

use of com.enonic.xp.node.UpdateNodeParams 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)

Example 13 with UpdateNodeParams

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

the class UpdateNodeCommandTest method keep_existing_binaries.

@Test
public void keep_existing_binaries() 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");
    }).id(node.id()).build();
    final Node updatedNode = updateNode(updateNodeParams);
    assertEquals(1, updatedNode.getAttachedBinaries().getSize());
}
Also used : 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)

Example 14 with UpdateNodeParams

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

the class UpdateNodeCommandTest method add_new_binary.

@Test
public void add_new_binary() 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;
        final BinaryReference newBinaryRef = BinaryReference.from("my-other-car.jpg");
        nodeData.addBinaryReferences("new-binary", newBinaryRef);
    }).attachBinary(BinaryReference.from("my-other-car.jpg"), ByteSource.wrap("my-new-binary".getBytes())).id(node.id()).build();
    final Node updatedNode = updateNode(updateNodeParams);
    assertEquals(2, 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)

Example 15 with UpdateNodeParams

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

the class UpdateNodeCommandTest method try_add_new_without_source.

@Test
public void try_add_new_without_source() 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.addBinaryReferences("piratedValue", BinaryReference.from("new-binary-ref"));
    }).id(node.id()).build();
    assertThrows(NodeBinaryReferenceException.class, () -> updateNode(updateNodeParams));
}
Also used : 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

UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)31 Node (com.enonic.xp.node.Node)24 PropertyTree (com.enonic.xp.data.PropertyTree)13 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)11 Test (org.junit.jupiter.api.Test)11 BinaryReference (com.enonic.xp.util.BinaryReference)10 NodePath (com.enonic.xp.node.NodePath)8 ByteSource (com.google.common.io.ByteSource)6 NodeIds (com.enonic.xp.node.NodeIds)4 User (com.enonic.xp.security.User)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Content (com.enonic.xp.content.Content)3 Context (com.enonic.xp.context.Context)3 NodeBinaryReferenceException (com.enonic.xp.node.NodeBinaryReferenceException)3 NodeId (com.enonic.xp.node.NodeId)3 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)3 PrincipalNotFoundException (com.enonic.xp.security.PrincipalNotFoundException)3