Search in sources :

Example 11 with InternalContext

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);
}
Also used : SearchRequest(com.enonic.xp.repo.impl.search.SearchRequest) InternalContext(com.enonic.xp.repo.impl.InternalContext) StoreRequest(com.enonic.xp.repo.impl.storage.StoreRequest) GetByIdRequest(com.enonic.xp.repo.impl.storage.GetByIdRequest) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 12 with InternalContext

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);
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) ExcludeEntries(com.enonic.xp.repo.impl.version.search.ExcludeEntries) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 13 with InternalContext

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);
}
Also used : RoutableNodeVersionIds(com.enonic.xp.node.RoutableNodeVersionIds) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) FindNodePathsByQueryResult(com.enonic.xp.node.FindNodePathsByQueryResult) NodePaths(com.enonic.xp.node.NodePaths) Nodes(com.enonic.xp.node.Nodes) SetNodeStateResult(com.enonic.xp.node.SetNodeStateResult) FindNodesByMultiRepoQueryResult(com.enonic.xp.node.FindNodesByMultiRepoQueryResult) RepositoryService(com.enonic.xp.repository.RepositoryService) NodeComparison(com.enonic.xp.node.NodeComparison) NodesHasChildrenResult(com.enonic.xp.node.NodesHasChildrenResult) Branch(com.enonic.xp.branch.Branch) Trace(com.enonic.xp.trace.Trace) NodeCommitId(com.enonic.xp.node.NodeCommitId) RepositoryId(com.enonic.xp.repository.RepositoryId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeService(com.enonic.xp.node.NodeService) PushNodesResult(com.enonic.xp.node.PushNodesResult) BinaryReference(com.enonic.xp.util.BinaryReference) NodeSearchService(com.enonic.xp.repo.impl.search.NodeSearchService) CreateRootNodeParams(com.enonic.xp.node.CreateRootNodeParams) NodeComparisons(com.enonic.xp.node.NodeComparisons) AccessControlList(com.enonic.xp.security.acl.AccessControlList) Collectors(java.util.stream.Collectors) NodeId(com.enonic.xp.node.NodeId) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) OrderExpr(com.enonic.xp.query.expr.OrderExpr) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) MoveNodeResult(com.enonic.xp.node.MoveNodeResult) BinaryService(com.enonic.xp.repo.impl.binary.BinaryService) ImportNodeVersionParams(com.enonic.xp.node.ImportNodeVersionParams) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) NodeVersion(com.enonic.xp.node.NodeVersion) Context(com.enonic.xp.context.Context) ApplyNodePermissionsResult(com.enonic.xp.node.ApplyNodePermissionsResult) LoadNodeResult(com.enonic.xp.node.LoadNodeResult) NodeCommitQuery(com.enonic.xp.node.NodeCommitQuery) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) PushNodesListener(com.enonic.xp.node.PushNodesListener) SyncWorkResolverParams(com.enonic.xp.node.SyncWorkResolverParams) Repository(com.enonic.xp.repository.Repository) RefreshMode(com.enonic.xp.node.RefreshMode) NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) ResolveSyncWorkResult(com.enonic.xp.node.ResolveSyncWorkResult) NodeStorageService(com.enonic.xp.repo.impl.storage.NodeStorageService) EventPublisher(com.enonic.xp.event.EventPublisher) RoutableNodeVersionIds(com.enonic.xp.node.RoutableNodeVersionIds) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) MultiRepoNodeQuery(com.enonic.xp.node.MultiRepoNodeQuery) GetActiveNodeVersionsParams(com.enonic.xp.node.GetActiveNodeVersionsParams) Node(com.enonic.xp.node.Node) DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) NodeCommitQueryResult(com.enonic.xp.node.NodeCommitQueryResult) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) ImportNodeResult(com.enonic.xp.node.ImportNodeResult) ImportNodeCommitParams(com.enonic.xp.node.ImportNodeCommitParams) Component(org.osgi.service.component.annotations.Component) SetNodeChildOrderParams(com.enonic.xp.node.SetNodeChildOrderParams) Tracer(com.enonic.xp.trace.Tracer) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) NodeEvents(com.enonic.xp.repo.impl.NodeEvents) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Activate(org.osgi.service.component.annotations.Activate) ByteSource(com.google.common.io.ByteSource) NodeQuery(com.enonic.xp.node.NodeQuery) VersionIndexPath(com.enonic.xp.repo.impl.version.VersionIndexPath) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) NodePath(com.enonic.xp.node.NodePath) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams) MoveNodeListener(com.enonic.xp.node.MoveNodeListener) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) ImportNodeParams(com.enonic.xp.node.ImportNodeParams) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) SetNodeStateParams(com.enonic.xp.node.SetNodeStateParams) BranchNotFoundException(com.enonic.xp.repository.BranchNotFoundException) ApplyNodePermissionsParams(com.enonic.xp.node.ApplyNodePermissionsParams) DeleteNodeListener(com.enonic.xp.node.DeleteNodeListener) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Reference(org.osgi.service.component.annotations.Reference) LoadNodeParams(com.enonic.xp.node.LoadNodeParams) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) NodeIds(com.enonic.xp.node.NodeIds) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) InternalContext(com.enonic.xp.repo.impl.InternalContext)

Example 14 with InternalContext

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;
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) InternalContext(com.enonic.xp.repo.impl.InternalContext) ArrayList(java.util.ArrayList) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) PushNodeEntries(com.enonic.xp.node.PushNodeEntries)

Example 15 with InternalContext

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);
    }
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeMovedParams(com.enonic.xp.repo.impl.storage.NodeMovedParams) Map(java.util.Map)

Aggregations

InternalContext (com.enonic.xp.repo.impl.InternalContext)18 Node (com.enonic.xp.node.Node)6 Context (com.enonic.xp.context.Context)5 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)5 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)5 NodePath (com.enonic.xp.node.NodePath)5 NodeBranchEntries (com.enonic.xp.node.NodeBranchEntries)4 NodeId (com.enonic.xp.node.NodeId)4 Map (java.util.Map)4 Branch (com.enonic.xp.branch.Branch)3 NodeIds (com.enonic.xp.node.NodeIds)3 NodePaths (com.enonic.xp.node.NodePaths)3 NodeVersion (com.enonic.xp.node.NodeVersion)3 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)2 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)2 NodeCommitEntry (com.enonic.xp.node.NodeCommitEntry)2 NodeCommitId (com.enonic.xp.node.NodeCommitId)2 NodeComparison (com.enonic.xp.node.NodeComparison)2 NodeVersionId (com.enonic.xp.node.NodeVersionId)2