Search in sources :

Example 11 with AttachedBinary

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);
}
Also used : BinaryReference(com.enonic.xp.util.BinaryReference) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 12 with 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();
}
Also used : NodeBinaryReferenceException(com.enonic.xp.node.NodeBinaryReferenceException) PropertyTree(com.enonic.xp.data.PropertyTree) AttachedBinaries(com.enonic.xp.node.AttachedBinaries) Property(com.enonic.xp.data.Property) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) RepositoryId(com.enonic.xp.repository.RepositoryId) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 13 with AttachedBinary

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);
}
Also used : RepositoryId(com.enonic.xp.repository.RepositoryId) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 14 with 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);
}
Also used : EditableRepository(com.enonic.xp.repository.EditableRepository) Repository(com.enonic.xp.repository.Repository) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 15 with 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())));
}
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)

Aggregations

AttachedBinary (com.enonic.xp.node.AttachedBinary)16 BinaryReference (com.enonic.xp.util.BinaryReference)7 PropertyTree (com.enonic.xp.data.PropertyTree)6 Node (com.enonic.xp.node.Node)4 Test (org.junit.jupiter.api.Test)4 AttachedBinaries (com.enonic.xp.node.AttachedBinaries)3 RepositoryId (com.enonic.xp.repository.RepositoryId)3 ByteSource (com.google.common.io.ByteSource)3 IndexConfig (com.enonic.xp.index.IndexConfig)2 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)2 BranchDumpEntry (com.enonic.xp.repo.impl.dump.model.BranchDumpEntry)2 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 AccessControlEntry (com.enonic.xp.security.acl.AccessControlEntry)2 AccessControlList (com.enonic.xp.security.acl.AccessControlList)2 Application (com.enonic.xp.app.Application)1 BlobKey (com.enonic.xp.blob.BlobKey)1 BlobRecord (com.enonic.xp.blob.BlobRecord)1 Segment (com.enonic.xp.blob.Segment)1 Property (com.enonic.xp.data.Property)1 PropertySet (com.enonic.xp.data.PropertySet)1