Search in sources :

Example 6 with NodeVersionKey

use of com.enonic.xp.blob.NodeVersionKey in project xp by enonic.

the class NodeStorageServiceImplTest method testGetNode.

@Test
public void testGetNode() {
    final NodePath nodePath = NodePath.create("path").build();
    final NodeVersionMetadata nodeVersionMetadata = NodeVersionMetadata.create().nodeVersionId(nodeVersionId).nodeVersionKey(versionKey).nodePath(nodePath).build();
    final NodeVersion nodeVersion = NodeVersion.create().permissions(AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.EVERYONE).allow(Permission.READ).build()).build()).build();
    when(versionService.getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class))).thenReturn(nodeVersionMetadata);
    when(nodeVersionService.get(any(NodeVersionKey.class), any(InternalContext.class))).thenReturn(nodeVersion);
    final Node result = instance.getNode(nodeId, nodeVersionId, context);
    assertNotNull(result);
    verify(versionService, times(1)).getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class));
    verify(nodeVersionService, times(1)).get(any(NodeVersionKey.class), any(InternalContext.class));
    verifyNoMoreInteractions(versionService, nodeVersionService);
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) NodeVersionId(com.enonic.xp.node.NodeVersionId) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 7 with NodeVersionKey

use of com.enonic.xp.blob.NodeVersionKey in project xp by enonic.

the class NodeBranchVersionFactory method create.

public static NodeBranchEntry create(final ReturnValues returnValues) {
    final Object path = returnValues.getSingleValue(BranchIndexPath.PATH.getPath());
    final Object state = returnValues.getSingleValue(BranchIndexPath.STATE.getPath());
    final Object versionId = returnValues.getSingleValue(BranchIndexPath.VERSION_ID.getPath());
    final Object nodeBlobKey = returnValues.getSingleValue(BranchIndexPath.NODE_BLOB_KEY.getPath());
    final Object indexConfigBlobKey = returnValues.getSingleValue(BranchIndexPath.INDEX_CONFIG_BLOB_KEY.getPath());
    final Object accessControlBlobKey = returnValues.getSingleValue(BranchIndexPath.ACCESS_CONTROL_BLOB_KEY.getPath());
    final Object timestamp = returnValues.getSingleValue(BranchIndexPath.TIMESTAMP.getPath());
    final Object nodeId = returnValues.getSingleValue(BranchIndexPath.NODE_ID.getPath());
    final NodeVersionKey nodeVersionKey = NodeVersionKey.from(nodeBlobKey.toString(), indexConfigBlobKey.toString(), accessControlBlobKey.toString());
    return NodeBranchEntry.create().nodePath(path != null ? NodePath.create(path.toString()).build() : NodePath.ROOT).nodeState(state != null ? NodeState.from(state.toString()) : NodeState.DEFAULT).nodeVersionId(NodeVersionId.from(versionId.toString())).nodeVersionKey(nodeVersionKey).timestamp(Instant.parse(timestamp.toString())).nodeId(NodeId.from(nodeId.toString())).build();
}
Also used : NodeVersionKey(com.enonic.xp.blob.NodeVersionKey)

Example 8 with NodeVersionKey

use of com.enonic.xp.blob.NodeVersionKey in project xp by enonic.

the class NodeStorageServiceImpl method move.

@Override
public Node move(final StoreMovedNodeParams params, final InternalContext context) {
    final NodeVersionKey nodeVersionKey;
    final NodeBranchEntry nodeBranchEntry = this.branchService.get(params.getNode().id(), context);
    if (params.isUpdateMetadataOnly()) {
        nodeVersionKey = nodeBranchEntry.getNodeVersionKey();
    } else {
        nodeVersionKey = nodeVersionService.store(NodeVersion.from(params.getNode()), context);
    }
    NodeVersionId nodeVersionId = params.getNodeVersionId();
    if (nodeVersionId == null) {
        nodeVersionId = new NodeVersionId();
        storeVersionMetadata(params.getNode(), nodeVersionId, nodeVersionKey, context);
    }
    return moveInBranchAndReIndex(params.getNode(), nodeVersionId, nodeVersionKey, nodeBranchEntry.getNodePath(), context);
}
Also used : NodeVersionId(com.enonic.xp.node.NodeVersionId) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Example 9 with NodeVersionKey

use of com.enonic.xp.blob.NodeVersionKey in project xp by enonic.

the class NodeVersionFactory method create.

public static NodeVersionMetadata create(final GetResult getResult) {
    final ReturnValues values = getResult.getReturnValues();
    final String versionId = values.getSingleValue(VersionIndexPath.VERSION_ID.getPath()).toString();
    final String nodeBlobKey = values.getSingleValue(VersionIndexPath.NODE_BLOB_KEY.getPath()).toString();
    final String indexConfigBlobKey = values.getSingleValue(VersionIndexPath.INDEX_CONFIG_BLOB_KEY.getPath()).toString();
    final String accessControlBlobKey = values.getSingleValue(VersionIndexPath.ACCESS_CONTROL_BLOB_KEY.getPath()).toString();
    final ReturnValue binaryBlobKeysReturnValue = values.get(VersionIndexPath.BINARY_BLOB_KEYS.getPath());
    final Instant timestamp = Instant.parse(values.getSingleValue(VersionIndexPath.TIMESTAMP.getPath()).toString());
    final String id = values.getSingleValue(VersionIndexPath.NODE_ID.getPath()).toString();
    final String path = values.getSingleValue(VersionIndexPath.NODE_PATH.getPath()).toString();
    final Object commitId = values.getSingleValue(VersionIndexPath.COMMIT_ID.getPath());
    final NodeVersionKey nodeVersionKey = NodeVersionKey.from(nodeBlobKey, indexConfigBlobKey, accessControlBlobKey);
    final BlobKeys binaryBlobKeys = toBlobKeys(binaryBlobKeysReturnValue);
    return NodeVersionMetadata.create().nodeId(NodeId.from(id)).nodePath(NodePath.create(path).build()).timestamp(timestamp).nodeVersionId(NodeVersionId.from(versionId)).nodeVersionKey(nodeVersionKey).binaryBlobKeys(binaryBlobKeys).nodeCommitId(commitId == null ? null : NodeCommitId.from(commitId.toString())).build();
}
Also used : BlobKeys(com.enonic.xp.blob.BlobKeys) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) Instant(java.time.Instant) ReturnValue(com.enonic.xp.repo.impl.ReturnValue) ReturnValues(com.enonic.xp.repo.impl.ReturnValues)

Example 10 with NodeVersionKey

use of com.enonic.xp.blob.NodeVersionKey in project xp by enonic.

the class NodeVersionServiceImplTest method getVersionCorrupted.

@Test
public void getVersionCorrupted() throws Exception {
    final CreateNodeParams createNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
    final Node createdNode = createNode(createNodeParams);
    final NodeVersionKey nodeVersionKey = getNodeVersionKey(createdNode);
    final Segment segment = createSegment(NODE_SEGMENT_LEVEL);
    final BlobRecord blob = this.blobStore.getRecord(segment, nodeVersionKey.getNodeBlobKey());
    byte[] blobData = blob.getBytes().read();
    blobData = Arrays.copyOf(blobData, blobData.length / 2);
    final MemoryBlobRecord corruptedBlob = new MemoryBlobRecord(blob.getKey(), ByteSource.wrap(blobData));
    this.blobStore.addRecord(segment, corruptedBlob);
    try {
        nodeDao.get(nodeVersionKey, createInternalContext());
        fail("Expected exception");
    } catch (RuntimeException e) {
        assertTrue(e.getMessage().startsWith("Failed to load blobs with keys"));
    }
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) MemoryBlobRecord(com.enonic.xp.internal.blobstore.MemoryBlobRecord) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Segment(com.enonic.xp.blob.Segment) MemoryBlobRecord(com.enonic.xp.internal.blobstore.MemoryBlobRecord) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)14 NodeVersionId (com.enonic.xp.node.NodeVersionId)7 Node (com.enonic.xp.node.Node)6 Test (org.junit.jupiter.api.Test)6 NodeVersion (com.enonic.xp.node.NodeVersion)5 NodeId (com.enonic.xp.node.NodeId)4 RoutableNodeVersionId (com.enonic.xp.node.RoutableNodeVersionId)4 BlobRecord (com.enonic.xp.blob.BlobRecord)3 MemoryBlobRecord (com.enonic.xp.internal.blobstore.MemoryBlobRecord)3 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)3 InternalContext (com.enonic.xp.repo.impl.InternalContext)3 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)3 BlobKeys (com.enonic.xp.blob.BlobKeys)2 Segment (com.enonic.xp.blob.Segment)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 NodePath (com.enonic.xp.node.NodePath)2 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)2 ReturnValue (com.enonic.xp.repo.impl.ReturnValue)2 PropertyTree (com.enonic.xp.data.PropertyTree)1 CachedBlobStore (com.enonic.xp.internal.blobstore.cache.CachedBlobStore)1