use of com.enonic.xp.util.BinaryReference 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());
}
use of com.enonic.xp.util.BinaryReference in project xp by enonic.
the class ContentDataSerializer method extractAttachments.
private void extractAttachments(final PropertySet contentAsSet, final Content.Builder<?> builder) {
final Attachments attachments = dataToAttachments(contentAsSet.getSets(ATTACHMENT));
builder.attachments(attachments);
final Attachment thumbnailAttachment = attachments.byName(AttachmentNames.THUMBNAIL);
if (thumbnailAttachment != null) {
final BinaryReference thumbnailBinaryRef = thumbnailAttachment.getBinaryReference();
final Thumbnail thumbnail = Thumbnail.from(thumbnailBinaryRef, thumbnailAttachment.getMimeType(), thumbnailAttachment.getSize());
builder.thumbnail(thumbnail);
}
}
use of com.enonic.xp.util.BinaryReference in project xp by enonic.
the class ContentDataSerializer method mergeExistingAndUpdatedAttachments.
private Attachments mergeExistingAndUpdatedAttachments(final Attachments existingAttachments, final UpdateContentTranslatorParams params) {
CreateAttachments createAttachments = params.getCreateAttachments();
BinaryReferences removeAttachments = params.getRemoveAttachments();
if (createAttachments == null && removeAttachments == null && !params.isClearAttachments()) {
return existingAttachments;
}
createAttachments = createAttachments == null ? CreateAttachments.empty() : createAttachments;
removeAttachments = removeAttachments == null ? BinaryReferences.empty() : removeAttachments;
final Map<BinaryReference, Attachment> attachments = new LinkedHashMap<>();
if (!params.isClearAttachments()) {
existingAttachments.stream().forEach((a) -> attachments.put(a.getBinaryReference(), a));
}
removeAttachments.stream().forEach(attachments::remove);
// added attachments with same BinaryReference will replace existing ones
for (final CreateAttachment createAttachment : createAttachments) {
final Attachment attachment = Attachment.create().name(createAttachment.getName()).label(createAttachment.getLabel()).mimeType(createAttachment.getMimeType()).size(attachmentSize(createAttachment)).textContent(createAttachment.getTextContent()).build();
attachments.put(attachment.getBinaryReference(), attachment);
}
return Attachments.from(attachments.values());
}
use of com.enonic.xp.util.BinaryReference in project xp by enonic.
the class NodeExporter method exportNodeBinaries.
private void exportNodeBinaries(final Node relativeNode, final Path nodeDataFolder) {
for (final AttachedBinary attachedBinary : relativeNode.getAttachedBinaries()) {
final BinaryReference reference = attachedBinary.getBinaryReference();
final ByteSource byteSource = this.nodeService.getBinary(relativeNode.id(), relativeNode.getNodeVersionId(), reference);
if (!dryRun) {
this.exportWriter.writeSource(nodeDataFolder.resolve(NodeExportPathResolver.BINARY_FOLDER).resolve(reference.toString()), byteSource);
}
result.addBinary(relativeNode.path(), reference);
}
}
use of com.enonic.xp.util.BinaryReference in project xp by enonic.
the class NodeExportIntegrationTest method single_node_with_binary.
@Test
public void single_node_with_binary() throws Exception {
final BinaryReference binaryRef = BinaryReference.from("myFile");
final PropertyTree data = new PropertyTree();
data.addBinaryReference("myBinary", binaryRef);
final Node myNode = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("myNode").data(data).attachBinary(binaryRef, ByteSource.wrap("this is a binary file".getBytes())).build());
final NodeExportResult result = doExportRoot(false);
assertEquals(2, result.size());
assertEquals(1, result.getExportedBinaries().size());
assertExported(myNode);
assertBinaryExported(myNode, binaryRef);
}
Aggregations