Search in sources :

Example 6 with AttachedBinaries

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());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) AttachedBinaries(com.enonic.xp.node.AttachedBinaries) Test(org.junit.jupiter.api.Test)

Example 7 with AttachedBinaries

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();
}
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 8 with AttachedBinaries

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

Aggregations

AttachedBinaries (com.enonic.xp.node.AttachedBinaries)8 PropertyTree (com.enonic.xp.data.PropertyTree)4 Node (com.enonic.xp.node.Node)4 AttachedBinary (com.enonic.xp.node.AttachedBinary)3 Test (org.junit.jupiter.api.Test)3 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)2 Property (com.enonic.xp.data.Property)1 EditableNode (com.enonic.xp.node.EditableNode)1 NodeBinaryReferenceException (com.enonic.xp.node.NodeBinaryReferenceException)1 NodeId (com.enonic.xp.node.NodeId)1 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)1 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)1 UpdateRepositoryEntryParams (com.enonic.xp.repo.impl.repository.UpdateRepositoryEntryParams)1 Repository (com.enonic.xp.repository.Repository)1 RepositoryId (com.enonic.xp.repository.RepositoryId)1 PrincipalKey (com.enonic.xp.security.PrincipalKey)1 AccessControlList (com.enonic.xp.security.acl.AccessControlList)1 BinaryReference (com.enonic.xp.util.BinaryReference)1