Search in sources :

Example 26 with BinaryReference

use of com.enonic.xp.util.BinaryReference in project xp by enonic.

the class AbstractGetBinaryCommand method getByPropertyPath.

ByteSource getByPropertyPath(final Node node) {
    final BinaryReference binaryReference = node.data().getBinaryReference(this.propertyPath);
    if (binaryReference == null) {
        return null;
    }
    final AttachedBinary attachedBinary = node.getAttachedBinaries().getByBinaryReference(binaryReference);
    return doGetByteSource(attachedBinary);
}
Also used : BinaryReference(com.enonic.xp.util.BinaryReference) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 27 with BinaryReference

use of com.enonic.xp.util.BinaryReference in project xp by enonic.

the class RepoDumperTest method binaries.

@Test
public void binaries() throws Exception {
    final BinaryReference fiskRef = BinaryReference.from("fisk");
    final PropertyTree data = new PropertyTree();
    data.addBinaryReference("myBinaryRef", fiskRef);
    final Node node1 = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("myName").data(data).attachBinary(fiskRef, ByteSource.wrap("myBinaryData".getBytes())).build());
    final AttachedBinary attachedBinary = node1.getAttachedBinaries().getByBinaryReference(fiskRef);
    final TestDumpWriter writer = new TestDumpWriter();
    doDump(writer);
    assertTrue(writer.getBinaries().contains(BlobKey.from(attachedBinary.getBlobKey())));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) BinaryReference(com.enonic.xp.util.BinaryReference) AttachedBinary(com.enonic.xp.node.AttachedBinary) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 28 with BinaryReference

use of com.enonic.xp.util.BinaryReference in project xp by enonic.

the class NodeServiceImplTest method test_get_binary_key.

@Test
public void test_get_binary_key() {
    final PropertyTree data = new PropertyTree();
    final BinaryReference binaryRef1 = BinaryReference.from("binary");
    data.addBinaryReference("my-binary-1", binaryRef1);
    final String binarySource = "binary_source";
    final Node node = this.nodeService.create(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).data(data).attachBinary(binaryRef1, ByteSource.wrap(binarySource.getBytes())).build());
    final String key = this.nodeService.getBinaryKey(node.id(), binaryRef1);
    assertNotNull(key);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) BinaryReference(com.enonic.xp.util.BinaryReference) Test(org.junit.jupiter.api.Test)

Example 29 with BinaryReference

use of com.enonic.xp.util.BinaryReference in project xp by enonic.

the class NodeServiceImplTest method test_get_binary.

@Test
public void test_get_binary() throws IOException {
    final PropertyTree data = new PropertyTree();
    final BinaryReference binaryRef1 = BinaryReference.from("binary");
    data.addBinaryReference("my-binary-1", binaryRef1);
    final String binarySource = "binary_source";
    final Node node = this.nodeService.create(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).data(data).attachBinary(binaryRef1, ByteSource.wrap(binarySource.getBytes())).build());
    final ByteSource source = this.nodeService.getBinary(node.id(), binaryRef1);
    assertArrayEquals(source.read(), binarySource.getBytes());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) ByteSource(com.google.common.io.ByteSource) BinaryReference(com.enonic.xp.util.BinaryReference) Test(org.junit.jupiter.api.Test)

Example 30 with BinaryReference

use of com.enonic.xp.util.BinaryReference in project xp by enonic.

the class GetBinaryCommandTest method get_by_reference.

@Test
public void get_by_reference() throws Exception {
    final PropertyTree data = new PropertyTree();
    final BinaryReference imageRef = BinaryReference.from("myImage");
    data.addBinaryReferences("myBinary", imageRef);
    final Node node = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).data(data).attachBinary(imageRef, ByteSource.wrap("thisIsMyImage".getBytes())).build());
    final ByteSource myImage = GetBinaryCommand.create().nodeId(node.id()).binaryReference(imageRef).indexServiceInternal(this.indexServiceInternal).binaryService(this.binaryService).storageService(this.storageService).searchService(this.searchService).build().execute();
    assertNotNull(myImage);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) ByteSource(com.google.common.io.ByteSource) BinaryReference(com.enonic.xp.util.BinaryReference) Test(org.junit.jupiter.api.Test)

Aggregations

BinaryReference (com.enonic.xp.util.BinaryReference)37 Test (org.junit.jupiter.api.Test)26 PropertyTree (com.enonic.xp.data.PropertyTree)25 Node (com.enonic.xp.node.Node)23 ByteSource (com.google.common.io.ByteSource)16 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)13 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)12 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)8 AttachedBinary (com.enonic.xp.node.AttachedBinary)7 NodePath (com.enonic.xp.node.NodePath)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 Attachment (com.enonic.xp.attachment.Attachment)4 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)4 NodeExportResult (com.enonic.xp.export.NodeExportResult)3 NodeBinaryReferenceException (com.enonic.xp.node.NodeBinaryReferenceException)3 NodeHelper (com.enonic.xp.repo.impl.node.NodeHelper)3 ByteStreams (com.google.common.io.ByteStreams)3