Search in sources :

Example 6 with BinaryReference

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());
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) BinaryReference(com.enonic.xp.util.BinaryReference) Reference(com.enonic.xp.util.Reference) Instant(java.time.Instant) BinaryReference(com.enonic.xp.util.BinaryReference) LocalDate(java.time.LocalDate) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Date(java.util.Date) LocalDate(java.time.LocalDate) GeoPoint(com.enonic.xp.util.GeoPoint) Link(com.enonic.xp.util.Link)

Example 7 with BinaryReference

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())));
}
Also used : BinaryReference(com.enonic.xp.util.BinaryReference) BeforeEach(org.junit.jupiter.api.BeforeEach) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) BranchDumpEntry(com.enonic.xp.repo.impl.dump.model.BranchDumpEntry) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath) BlobKey(com.enonic.xp.blob.BlobKey) AttachedBinary(com.enonic.xp.node.AttachedBinary) NodeHelper(com.enonic.xp.repo.impl.node.NodeHelper) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Test(org.junit.jupiter.api.Test) List(java.util.List) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) BinaryReference(com.enonic.xp.util.BinaryReference) AttachedBinary(com.enonic.xp.node.AttachedBinary) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 8 with BinaryReference

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());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) ByteSource(com.google.common.io.ByteSource) BinaryReference(com.enonic.xp.util.BinaryReference) Application(com.enonic.xp.app.Application) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Test(org.junit.jupiter.api.Test)

Example 9 with BinaryReference

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);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) RepositoryIds(com.enonic.xp.repository.RepositoryIds) BranchDumpResult(com.enonic.xp.dump.BranchDumpResult) UpgradeListener(com.enonic.xp.upgrade.UpgradeListener) Version(com.enonic.xp.util.Version) RenameNodeCommand(com.enonic.xp.repo.impl.node.RenameNodeCommand) Branch(com.enonic.xp.branch.Branch) NodeHelper(com.enonic.xp.repo.impl.node.NodeHelper) NodeCommitId(com.enonic.xp.node.NodeCommitId) RepositoryId(com.enonic.xp.repository.RepositoryId) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ContextAccessor(com.enonic.xp.context.ContextAccessor) ContextBuilder(com.enonic.xp.context.ContextBuilder) URI(java.net.URI) Bundle(org.osgi.framework.Bundle) SystemConstants(com.enonic.xp.security.SystemConstants) Path(java.nio.file.Path) BinaryReference(com.enonic.xp.util.BinaryReference) FileDumpReader(com.enonic.xp.repo.impl.dump.reader.FileDumpReader) Pre5ContentConstants(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre5.Pre5ContentConstants) ImmutableMap(com.google.common.collect.ImmutableMap) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Assertions.assertIterableEquals(org.junit.jupiter.api.Assertions.assertIterableEquals) Predicate(java.util.function.Predicate) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) BundleContext(org.osgi.framework.BundleContext) NodeId(com.enonic.xp.node.NodeId) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) CreateRepositoryParams(com.enonic.xp.repository.CreateRepositoryParams) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) List(java.util.List) Repositories(com.enonic.xp.repository.Repositories) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NodeVersion(com.enonic.xp.node.NodeVersion) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) NodeCommitQuery(com.enonic.xp.node.NodeCommitQuery) SystemDumpParams(com.enonic.xp.dump.SystemDumpParams) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) SystemLoadResult(com.enonic.xp.dump.SystemLoadResult) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) Repository(com.enonic.xp.repository.Repository) Mockito.mock(org.mockito.Mockito.mock) ChildOrder(com.enonic.xp.index.ChildOrder) RefreshMode(com.enonic.xp.node.RefreshMode) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContentConstants(com.enonic.xp.content.ContentConstants) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) SystemDumpListener(com.enonic.xp.dump.SystemDumpListener) GetActiveNodeVersionsParams(com.enonic.xp.node.GetActiveNodeVersionsParams) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) IndexConfig(com.enonic.xp.index.IndexConfig) NodeCommitQueryResult(com.enonic.xp.node.NodeCommitQueryResult) TreeSet(java.util.TreeSet) RepoLoadResult(com.enonic.xp.dump.RepoLoadResult) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) NodeVersionIds(com.enonic.xp.node.NodeVersionIds) ImmutableList(com.google.common.collect.ImmutableList) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) RepoDumpResult(com.enonic.xp.dump.RepoDumpResult) StreamSupport(java.util.stream.StreamSupport) PropertyPath(com.enonic.xp.data.PropertyPath) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) DumpUpgradeResult(com.enonic.xp.dump.DumpUpgradeResult) AttachedBinaries(com.enonic.xp.node.AttachedBinaries) InternalContext(com.enonic.xp.repo.impl.InternalContext) PropertySet(com.enonic.xp.data.PropertySet) NodePath(com.enonic.xp.node.NodePath) SystemLoadListener(com.enonic.xp.dump.SystemLoadListener) Mockito.when(org.mockito.Mockito.when) Branches(com.enonic.xp.branch.Branches) SystemDumpUpgradeParams(com.enonic.xp.dump.SystemDumpUpgradeParams) UpdateRepositoryEntryParams(com.enonic.xp.repo.impl.repository.UpdateRepositoryEntryParams) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito(org.mockito.Mockito) SystemDumpResult(com.enonic.xp.dump.SystemDumpResult) NodeName(com.enonic.xp.node.NodeName) Reference(com.enonic.xp.util.Reference) SystemLoadParams(com.enonic.xp.dump.SystemLoadParams) DumpMeta(com.enonic.xp.repo.impl.dump.model.DumpMeta) VersionsLoadResult(com.enonic.xp.dump.VersionsLoadResult) NodeIds(com.enonic.xp.node.NodeIds) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) BinaryReference(com.enonic.xp.util.BinaryReference) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 10 with BinaryReference

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

Aggregations

BinaryReference (com.enonic.xp.util.BinaryReference)38 Test (org.junit.jupiter.api.Test)26 PropertyTree (com.enonic.xp.data.PropertyTree)25 Node (com.enonic.xp.node.Node)23 ByteSource (com.google.common.io.ByteSource)17 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)13 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)12 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)8 AttachedBinary (com.enonic.xp.node.AttachedBinary)7 NodePath (com.enonic.xp.node.NodePath)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Attachment (com.enonic.xp.attachment.Attachment)5 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)4 NodeExportResult (com.enonic.xp.export.NodeExportResult)3 NodeBinaryReferenceException (com.enonic.xp.node.NodeBinaryReferenceException)3 NodeHelper (com.enonic.xp.repo.impl.node.NodeHelper)3 ByteStreams (com.google.common.io.ByteStreams)3