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