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