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());
}
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();
}
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();
}
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);
}
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());
}
Aggregations