use of com.enonic.xp.repo.impl.InternalContext in project xp by enonic.
the class BranchServiceImplTest method path_fetched_from_cache_after_stored.
@Test
public void path_fetched_from_cache_after_stored() throws Exception {
final InternalContext context = InternalContext.create().branch(Branch.from("myBranch")).repositoryId(RepositoryId.from("my-repo")).build();
final NodePath path = NodePath.create(NodePath.ROOT, "fisk").build();
Mockito.when(this.storageDao.store(Mockito.isA(StoreRequest.class))).thenReturn("123_myBranch");
this.branchService.store(NodeBranchEntry.create().nodeId(NodeId.from("123")).nodePath(path).nodeState(NodeState.DEFAULT).nodeVersionId(NodeVersionId.from("nodeVersionId")).nodeVersionKey(NodeVersionKey.from("nodeBlobKey", "indexConfigBlobKey", "accessControlBlobKey")).timestamp(Instant.now()).build(), context);
Mockito.when(this.storageDao.getById(Mockito.isA(GetByIdRequest.class))).thenReturn(GetResult.create().id("123_myBranch").resultFieldValues(ReturnValues.create().add(BranchIndexPath.PATH.getPath(), "/fisk").add(BranchIndexPath.STATE.getPath(), "default").add(BranchIndexPath.VERSION_ID.getPath(), "nodeVersionId").add(BranchIndexPath.NODE_BLOB_KEY.getPath(), "nodeBlobKey").add(BranchIndexPath.INDEX_CONFIG_BLOB_KEY.getPath(), "indexConfigBlobKey").add(BranchIndexPath.ACCESS_CONTROL_BLOB_KEY.getPath(), "accessControlBlobKey").add(BranchIndexPath.NODE_ID.getPath(), "123").add(BranchIndexPath.TIMESTAMP.getPath(), Instant.now().toString()).build()).build());
Mockito.when(this.searchDao.search(Mockito.isA(SearchRequest.class))).thenReturn(SearchResult.create().build());
final NodeBranchEntry fetchEntry = this.branchService.get(path, context);
assertNotNull(fetchEntry);
}
use of com.enonic.xp.repo.impl.InternalContext in project xp by enonic.
the class FindNodesWithVersionDifferenceCommand method execute.
public NodeVersionDiffResult execute() {
final InternalContext context = InternalContext.from(ContextAccessor.current());
final ExcludeEntries excludeEntries = getExcludePaths(context);
final SearchResult result = this.nodeSearchService.query(NodeVersionDiffQuery.create().source(source).target(target).nodePath(nodePath).excludes(excludeEntries).size(this.size).batchSize(BATCH_SIZE).build(), SingleRepoStorageSource.create(ContextAccessor.current().getRepositoryId(), SingleRepoStorageSource.Type.VERSION));
return NodeVersionDiffResultFactory.create(result);
}
use of com.enonic.xp.repo.impl.InternalContext in project xp by enonic.
the class NodeServiceImpl method commit.
@Override
public NodeCommitEntry commit(final NodeCommitEntry nodeCommitEntry, final NodeIds nodeIds) {
verifyContext();
final InternalContext context = InternalContext.from(ContextAccessor.current());
final RoutableNodeVersionIds.Builder routableNodeVersionIds = RoutableNodeVersionIds.create();
final NodeBranchEntries branchNodeVersions = nodeStorageService.getBranchNodeVersions(nodeIds, false, context);
branchNodeVersions.stream().map(branchEntry -> RoutableNodeVersionId.from(branchEntry.getNodeId(), branchEntry.getVersionId())).forEach(routableNodeVersionIds::add);
return nodeStorageService.commit(nodeCommitEntry, routableNodeVersionIds.build(), context);
}
use of com.enonic.xp.repo.impl.InternalContext in project xp by enonic.
the class PushNodesCommand method pushNodes.
private InternalPushNodesResult.Builder pushNodes(final Context context, final NodeBranchEntries nodeBranchEntries, final NodeComparisons comparisons) {
final PushNodeEntries.Builder publishBuilder = PushNodeEntries.create().targetBranch(this.target).targetRepo(context.getRepositoryId());
final InternalPushNodesResult.Builder builder = InternalPushNodesResult.create();
final ArrayList<NodeBranchEntry> list = new ArrayList<>(nodeBranchEntries.getSet());
list.sort(Comparator.comparing(NodeBranchEntry::getNodePath));
for (final NodeBranchEntry branchEntry : list) {
final NodeComparison comparison = comparisons.get(branchEntry.getNodeId());
final NodeBranchEntry nodeBranchEntry = nodeBranchEntries.get(comparison.getNodeId());
final boolean hasPublishPermission = NodesHasPermissionResolver.create(this).nodeIds(NodeIds.from(nodeBranchEntry.getNodeId())).permission(Permission.PUBLISH).build().execute();
if (!hasPublishPermission) {
builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.ACCESS_DENIED);
nodePushed(1);
continue;
}
if (comparison.getCompareStatus() == CompareStatus.EQUAL) {
builder.addSuccess(nodeBranchEntry);
nodePushed(1);
continue;
}
if ((CompareStatus.NEW == comparison.getCompareStatus() || CompareStatus.MOVED == comparison.getCompareStatus()) && targetAlreadyExists(nodeBranchEntry.getNodePath(), comparisons, context)) {
builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.ALREADY_EXIST);
nodePushed(1);
continue;
}
if (!targetParentExists(nodeBranchEntry.getNodePath(), builder, context)) {
builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.PARENT_NOT_FOUND);
nodePushed(1);
continue;
}
publishBuilder.add(PushNodeEntry.create().nodeBranchEntry(nodeBranchEntry).currentTargetPath(comparison.getTargetPath()).build());
builder.addSuccess(nodeBranchEntry);
if (comparison.getCompareStatus() == CompareStatus.MOVED) {
updateTargetChildrenMetaData(nodeBranchEntry, builder);
}
}
final PushNodeEntries pushNodeEntries = publishBuilder.build();
builder.setPushNodeEntries(pushNodeEntries);
final InternalContext pushContext = InternalContext.create(context).skipConstraints(true).build();
this.nodeStorageService.push(pushNodeEntries, pushListener, pushContext);
return builder;
}
use of com.enonic.xp.repo.impl.InternalContext in project xp by enonic.
the class NodeMovedHandler method handleEvent.
@Override
public void handleEvent(NodeStorageService nodeStorageService, final Event event, final InternalContext context) {
final List<Map<Object, Object>> valueMapList = getValueMapList(event);
for (final Map<Object, Object> map : valueMapList) {
final InternalContext nodeContext = createNodeContext(map, context);
final NodeMovedParams nodeMovedParams = new NodeMovedParams(getPath(map), NodePath.create(map.get(NEW_PATH).toString()).build(), getId(map));
nodeStorageService.handleNodeMoved(nodeMovedParams, nodeContext);
}
}
Aggregations