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