use of com.enonic.xp.node.AttachedBinary 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.node.AttachedBinary 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.AttachedBinary in project xp by enonic.
the class UpdatedAttachedBinariesResolver method storeAndAttachBinary.
private void storeAndAttachBinary(final Map<BinaryReference, AttachedBinary> resolved, final BinaryAttachment newBinaryAttachment) {
final RepositoryId repositoryId = ContextAccessor.current().getRepositoryId();
final AttachedBinary attachedBinary = binaryService.store(repositoryId, newBinaryAttachment);
resolved.put(newBinaryAttachment.getReference(), attachedBinary);
}
use of com.enonic.xp.node.AttachedBinary in project xp by enonic.
the class RepositoryServiceImpl method getBinary.
@Override
public ByteSource getBinary(final RepositoryId repositoryId, final BinaryReference binaryReference) {
requireAdminRole();
Repository repository = repositoryEntryService.getRepositoryEntry(repositoryId);
if (repository == null) {
throw new RepositoryNotFoundException(repositoryId);
}
final AttachedBinary attachedBinary = repository.getAttachments().getByBinaryReference(binaryReference);
return attachedBinary == null ? null : repositoryEntryService.getBinary(attachedBinary);
}
use of com.enonic.xp.node.AttachedBinary 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())));
}
Aggregations