Search in sources :

Example 1 with BinaryAttachments

use of com.enonic.xp.node.BinaryAttachments in project xp by enonic.

the class ScriptValueTranslatorTest method binary.

@Test
public void binary() throws Exception {
    final ScriptValueTranslatorResult params = getCreateNodeHandlerParams("binary");
    final PropertyTree properties = params.getPropertyTree();
    assertNotNull(properties.getBinaryReference("myBinary"));
    validateType(properties, "myBinary", ValueTypes.BINARY_REFERENCE);
    final BinaryAttachments binaryAttachments = params.getBinaryAttachments();
    assertEquals(1, binaryAttachments.getSize());
}
Also used : BinaryAttachments(com.enonic.xp.node.BinaryAttachments) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 2 with BinaryAttachments

use of com.enonic.xp.node.BinaryAttachments in project xp by enonic.

the class CreatedEventSyncCommand method createImportParams.

private ImportContentParams createImportParams(final ContentToSync content, final ContentPath parentPath, final InsertManualStrategy insertManualStrategy) {
    final BinaryAttachments.Builder builder = BinaryAttachments.create();
    content.getSourceContent().getAttachments().forEach(attachment -> {
        final ByteSource binary = content.getSourceContext().callWith(() -> contentService.getBinary(content.getId(), attachment.getBinaryReference()));
        builder.add(new BinaryAttachment(attachment.getBinaryReference(), binary));
    });
    final ContentPath targetPath = buildNewPath(parentPath, content.getSourceContent().getName());
    final EnumSet<ContentInheritType> inheritTypes = content.getSourceContent().getName().toString().equals(targetPath.getName()) ? EnumSet.allOf(ContentInheritType.class) : EnumSet.complementOf(EnumSet.of(ContentInheritType.NAME));
    return ImportContentParams.create().importContent(content.getSourceContent()).targetPath(targetPath).binaryAttachments(builder.build()).inherit(inheritTypes).originProject(ProjectName.from(content.getSourceContext().getRepositoryId())).importPermissionsOnCreate(false).dryRun(false).insertManualStrategy(insertManualStrategy).build();
}
Also used : BinaryAttachments(com.enonic.xp.node.BinaryAttachments) ByteSource(com.google.common.io.ByteSource) ContentPath(com.enonic.xp.content.ContentPath) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) ContentInheritType(com.enonic.xp.content.ContentInheritType)

Example 3 with BinaryAttachments

use of com.enonic.xp.node.BinaryAttachments in project xp by enonic.

the class NodeImporter method processBinaryAttachments.

private BinaryAttachments processBinaryAttachments(final VirtualFile nodeFile, final Node newNode) {
    final PropertyTree data = newNode.data();
    final ImmutableList<Property> binaryReferences = data.getProperties(ValueTypes.BINARY_REFERENCE);
    if (binaryReferences.isEmpty()) {
        return BinaryAttachments.empty();
    }
    final BinaryAttachments.Builder builder = BinaryAttachments.create();
    for (final Property binaryReference : binaryReferences) {
        addBinary(nodeFile, builder, binaryReference);
    }
    return builder.build();
}
Also used : BinaryAttachments(com.enonic.xp.node.BinaryAttachments) PropertyTree(com.enonic.xp.data.PropertyTree) Property(com.enonic.xp.data.Property)

Example 4 with BinaryAttachments

use of com.enonic.xp.node.BinaryAttachments in project xp by enonic.

the class NodeImporter method importNode.

private ImportNodeResult importNode(final VirtualFile nodeFolder, final ProcessNodeSettings.Builder processNodeSettings, final Node serializedNode, final NodePath importNodePath) {
    final BinaryAttachments binaryAttachments = processBinaryAttachments(nodeFolder, serializedNode);
    final ProcessNodeSettings settings = processNodeSettings.build();
    final Node importNode = ImportNodeFactory.create().importNodeIds(this.importNodeIds).importPermissions(this.importPermissions).serializedNode(serializedNode).importPath(importNodePath).processNodeSettings(settings).build().execute();
    final ImportNodeParams importNodeParams = ImportNodeParams.create().importNode(importNode).binaryAttachments(binaryAttachments).insertManualStrategy(settings.getInsertManualStrategy()).dryRun(this.dryRun).importPermissions(this.importPermissions).importPermissionsOnCreate(this.importPermissions).build();
    return this.nodeService.importNode(importNodeParams);
}
Also used : BinaryAttachments(com.enonic.xp.node.BinaryAttachments) Node(com.enonic.xp.node.Node) ImportNodeParams(com.enonic.xp.node.ImportNodeParams)

Example 5 with BinaryAttachments

use of com.enonic.xp.node.BinaryAttachments in project xp by enonic.

the class ApplicationNodeTransformerTest method app_binary_updated.

@Test
public void app_binary_updated() throws Exception {
    final PropertyTree data = new PropertyTree();
    final BinaryReference appReference = BinaryReference.from(ApplicationNodeTransformer.APPLICATION_BINARY_REF);
    data.addBinaryReference(ApplicationNodeTransformer.APPLICATION_BINARY_REF, appReference);
    final Node existingNode = Node.create().id(NodeId.from("myNode")).parentPath(NodePath.ROOT).name("myNode").data(data).attachedBinaries(AttachedBinaries.create().add(new AttachedBinary(appReference, "abc")).build()).build();
    final Application app = Mockito.mock(Application.class);
    Mockito.when(app.getKey()).thenReturn(ApplicationKey.from("myApp"));
    Mockito.when(app.getVersion()).thenReturn(Version.valueOf("1.0.0"));
    Mockito.when(app.getMaxSystemVersion()).thenReturn("1.0.0");
    Mockito.when(app.getMinSystemVersion()).thenReturn("1.0.0.");
    Mockito.when(app.getDisplayName()).thenReturn("displayName");
    final ByteSource updatedSource = ByteSource.wrap(ByteStreams.toByteArray(newBundle("myBundleUpdated", true).build()));
    final UpdateNodeParams updateNodeParams = ApplicationNodeTransformer.toUpdateNodeParams(app, updatedSource, existingNode);
    final BinaryAttachments binaryAttachments = updateNodeParams.getBinaryAttachments();
    assertEquals(updatedSource, binaryAttachments.get(appReference).getByteSource());
}
Also used : BinaryAttachments(com.enonic.xp.node.BinaryAttachments) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) ByteSource(com.google.common.io.ByteSource) BinaryReference(com.enonic.xp.util.BinaryReference) Application(com.enonic.xp.app.Application) AttachedBinary(com.enonic.xp.node.AttachedBinary) Test(org.junit.jupiter.api.Test)

Aggregations

BinaryAttachments (com.enonic.xp.node.BinaryAttachments)6 PropertyTree (com.enonic.xp.data.PropertyTree)3 Node (com.enonic.xp.node.Node)3 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)2 ByteSource (com.google.common.io.ByteSource)2 Test (org.junit.jupiter.api.Test)2 Application (com.enonic.xp.app.Application)1 ContentInheritType (com.enonic.xp.content.ContentInheritType)1 ContentPath (com.enonic.xp.content.ContentPath)1 Property (com.enonic.xp.data.Property)1 NodeMapper (com.enonic.xp.lib.node.mapper.NodeMapper)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)1 EditableNode (com.enonic.xp.node.EditableNode)1 ImportNodeParams (com.enonic.xp.node.ImportNodeParams)1 ScriptValue (com.enonic.xp.script.ScriptValue)1 BinaryReference (com.enonic.xp.util.BinaryReference)1