use of com.enonic.xp.node.AttachedBinaries in project xp by enonic.
the class CreateNodeCommandTest method attach_binaries.
@Test
public void attach_binaries() throws Exception {
PropertyTree data = new PropertyTree();
data.setBinaryReference("myCar", BinaryReference.from("myImage"));
data.setBinaryReference("myOtherCar", BinaryReference.from("myOtherImage"));
final Node node = createNode(CreateNodeParams.create().name("test").parent(NodePath.ROOT).data(data).attachBinary(BinaryReference.from("myImage"), ByteSource.wrap("myImageBytes".getBytes())).attachBinary(BinaryReference.from("myOtherImage"), ByteSource.wrap("myOtherImageBytes".getBytes())).build());
final AttachedBinaries attachedBinaries = node.getAttachedBinaries();
assertEquals(2, attachedBinaries.getSize());
}
use of com.enonic.xp.node.AttachedBinaries in project xp by enonic.
the class CreateNodeCommand method storeAndAttachBinaries.
private AttachedBinaries storeAndAttachBinaries() {
final PropertyTree data = params.getData();
final AttachedBinaries.Builder builder = AttachedBinaries.create();
final ImmutableList<Property> binaryReferences = data.getProperties(ValueTypes.BINARY_REFERENCE);
for (final Property binaryRef : binaryReferences) {
final BinaryAttachment binaryAttachment = this.params.getBinaryAttachments().get(binaryRef.getBinaryReference());
if (binaryAttachment == null) {
throw new NodeBinaryReferenceException("No binary with reference " + binaryRef + " attached in createNodeParams");
}
final RepositoryId repositoryId = ContextAccessor.current().getRepositoryId();
final AttachedBinary attachedBinary = this.binaryService.store(repositoryId, binaryAttachment);
builder.add(attachedBinary);
}
return builder.build();
}
use of com.enonic.xp.node.AttachedBinaries in project xp by enonic.
the class AbstractGetBinaryCommand method getByBinaryReference.
ByteSource getByBinaryReference(final Node node) {
final AttachedBinaries attachedBinaries = node.getAttachedBinaries();
if (attachedBinaries == null) {
return null;
}
final AttachedBinary attachedBinary = attachedBinaries.getByBinaryReference(this.binaryReference);
if (attachedBinary == null) {
return null;
}
return doGetByteSource(attachedBinary);
}
Aggregations