use of com.enonic.xp.util.BinaryReference in project xp by enonic.
the class ScriptValueTranslator method handleValue.
private void handleValue(final PropertySet parent, final String name, final Object value) {
if (value instanceof Instant) {
parent.addInstant(name, (Instant) value);
} else if (value instanceof GeoPoint) {
parent.addGeoPoint(name, (GeoPoint) value);
} else if (value instanceof Double) {
parent.addDouble(name, (Double) value);
} else if (value instanceof Float) {
parent.addDouble(name, ((Float) value).doubleValue());
} else if (value instanceof Integer) {
parent.addLong(name, ((Integer) value).longValue());
} else if (value instanceof Byte) {
parent.addLong(name, ((Byte) value).longValue());
} else if (value instanceof Long) {
parent.addLong(name, ((Long) value));
} else if (value instanceof Number) {
parent.addDouble(name, ((Number) value).doubleValue());
} else if (value instanceof Boolean) {
parent.addBoolean(name, (Boolean) value);
} else if (value instanceof LocalDateTime) {
parent.addLocalDateTime(name, (LocalDateTime) value);
} else if (value instanceof LocalDate) {
parent.addLocalDate(name, (LocalDate) value);
} else if (value instanceof LocalTime) {
parent.addLocalTime(name, (LocalTime) value);
} else if (value instanceof Date) {
parent.addInstant(name, ((Date) value).toInstant());
} else if (value instanceof Reference) {
parent.addReference(name, (Reference) value);
} else if (value instanceof BinaryReference) {
parent.addBinaryReference(name, (BinaryReference) value);
} else if (value instanceof Link) {
parent.addLink(name, (Link) value);
} else if (value instanceof BinaryAttachment) {
final BinaryAttachment binaryAttachment = (BinaryAttachment) value;
parent.addBinaryReference(name, binaryAttachment.getReference());
if (includeBinaryAttachments) {
this.binaryAttachmentsBuilder.add(new BinaryAttachment(binaryAttachment.getReference(), binaryAttachment.getByteSource()));
}
} else {
parent.addString(name, value.toString());
}
}
use of com.enonic.xp.util.BinaryReference in project xp by enonic.
the class RepoDumperTest method binaries_with_versions.
@Test
public void binaries_with_versions() throws Exception {
final BinaryReference ref1 = BinaryReference.from("fisk");
final BinaryReference ref2 = BinaryReference.from("fisk2");
final PropertyTree data = new PropertyTree();
data.addBinaryReference("myBinaryRef", ref1);
final Node node1 = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("myName").data(data).attachBinary(ref1, ByteSource.wrap("myBinaryData".getBytes())).build());
final AttachedBinary originalBinary = node1.getAttachedBinaries().getByBinaryReference(ref1);
final Node updatedNode = updateNode(UpdateNodeParams.create().id(node1.id()).editor((e) -> {
}).attachBinary(ref2, ByteSource.wrap("myOtherBinaryData".getBytes())).build());
final AttachedBinary updateBinary = updatedNode.getAttachedBinaries().getByBinaryReference(ref1);
final TestDumpWriter writer = new TestDumpWriter();
doDump(writer);
assertTrue(writer.getBinaries().contains(BlobKey.from(originalBinary.getBlobKey())));
assertTrue(writer.getBinaries().contains(BlobKey.from(updateBinary.getBlobKey())));
}
use of com.enonic.xp.util.BinaryReference in project xp by enonic.
the class ApplicationNodeTransformerTest method binary_reference_added.
@Test
public void binary_reference_added() throws Exception {
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 appSource = ByteSource.wrap(ByteStreams.toByteArray(newBundle("myBundle", true).build()));
final CreateNodeParams createNodeParams = ApplicationNodeTransformer.toCreateNodeParams(app, appSource);
final PropertyTree data = createNodeParams.getData();
final BinaryReference binaryReference = data.getBinaryReference(ApplicationNodeTransformer.APPLICATION_BINARY_REF);
assertNotNull(binaryReference);
final BinaryAttachment binaryAttachment = createNodeParams.getBinaryAttachments().get(binaryReference);
assertEquals(appSource, binaryAttachment.getByteSource());
}
use of com.enonic.xp.util.BinaryReference in project xp by enonic.
the class DumpServiceImplTest method binaries_in_versions.
@Test
public void binaries_in_versions() throws Exception {
final PropertyTree data = new PropertyTree();
final BinaryReference binaryRef = BinaryReference.from("binaryRef");
data.addBinaryReference("myBinary", binaryRef);
final Node node = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("myNode").data(data).attachBinary(binaryRef, ByteSource.wrap("this is binary data".getBytes())).build());
final BinaryReference binaryRef2 = BinaryReference.from("anotherBinary");
final Node updatedNode = updateNode(UpdateNodeParams.create().id(node.id()).editor(n -> n.data.setBinaryReference("myBinary", binaryRef2)).attachBinary(binaryRef2, ByteSource.wrap("anotherBinary".getBytes())).build());
NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
final NodeVersionQueryResult versions = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
assertEquals(2, versions.getHits());
verifyBinaries(node, updatedNode, versions);
}
use of com.enonic.xp.util.BinaryReference in project xp by enonic.
the class DumpServiceImplTest method binaries.
@Test
public void binaries() throws Exception {
final PropertyTree data = new PropertyTree();
final BinaryReference binaryRef = BinaryReference.from("binaryRef");
data.addBinaryReference("myBinary", binaryRef);
final Node node = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("myNode").data(data).attachBinary(binaryRef, ByteSource.wrap("this is binary data".getBytes())).build());
NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
final Node currentStoredNode = this.nodeService.getById(node.id());
assertEquals(node.getAttachedBinaries(), currentStoredNode.getAttachedBinaries());
}
Aggregations