Search in sources :

Example 31 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class ContentAuditLogSupportImpl method publish.

@Override
public void publish(final PushContentParams params, final PublishContentResult result) {
    final Context context = ContextBuilder.copyOf(ContextAccessor.current()).build();
    executor.execute(() -> doPublish(params, result, context));
}
Also used : Context(com.enonic.xp.context.Context)

Example 32 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class ContentAuditLogSupportImpl method unpublishContent.

@Override
public void unpublishContent(final UnpublishContentParams params, final UnpublishContentsResult result) {
    final Context context = ContextBuilder.copyOf(ContextAccessor.current()).build();
    executor.execute(() -> doUnpublishContent(params, result, context));
}
Also used : Context(com.enonic.xp.context.Context)

Example 33 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class NodesHasPermissionResolver method execute.

public boolean execute() {
    final Context context = ContextAccessor.current();
    if (context.getAuthInfo().hasRole(RoleKeys.ADMIN)) {
        return true;
    }
    if (nodeIds.isEmpty()) {
        return false;
    }
    final NodeQuery query = NodeQuery.create().addQueryFilter(IdFilter.create().fieldName(NodeIndexPath.ID.getPath()).values(nodeIds).build()).addQueryFilter(ValueFilter.create().fieldName(getPermissionFieldName().getPath()).addValues(context.getAuthInfo().getPrincipals().stream().map(PrincipalKey::toString).collect(Collectors.toList())).build()).searchMode(SearchMode.COUNT).build();
    final FindNodesByQueryResult result = FindNodesByQueryCommand.create(this).query(query).build().execute();
    return result.getTotalHits() == nodeIds.getSize();
}
Also used : Context(com.enonic.xp.context.Context) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 34 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class PushNodesCommand method targetAlreadyExists.

private boolean targetAlreadyExists(final NodePath nodePath, final NodeComparisons comparisons, final Context currentContext) {
    // Checks if a node exist
    final Context targetContext = createTargetContext(currentContext);
    final NodeId nodeId = targetContext.callWith(() -> GetNodeIdByPathCommand.create(this).nodePath(nodePath).build().execute());
    // If the node does not exist, returns false
    if (nodeId == null) {
        return false;
    }
    // Else, if the existing node is being deleted or moved during the current push, returns false
    final NodeComparison nodeComparison = comparisons.get(nodeId);
    return nodeComparison == null || (CompareStatus.MOVED != nodeComparison.getCompareStatus() && CompareStatus.PENDING_DELETE != nodeComparison.getCompareStatus());
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) NodeComparison(com.enonic.xp.node.NodeComparison) NodeId(com.enonic.xp.node.NodeId)

Example 35 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class NodeServiceImpl method getByNodeVersionKey.

@Override
public NodeVersion getByNodeVersionKey(final NodeVersionKey nodeVersionKey) {
    verifyContext();
    final Context currentContext = ContextAccessor.current();
    return this.nodeStorageService.getNodeVersion(nodeVersionKey, InternalContext.from(currentContext));
}
Also used : Context(com.enonic.xp.context.Context) InternalContext(com.enonic.xp.repo.impl.InternalContext)

Aggregations

Context (com.enonic.xp.context.Context)101 Test (org.junit.jupiter.api.Test)35 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)21 Node (com.enonic.xp.node.Node)16 InternalContext (com.enonic.xp.repo.impl.InternalContext)16 User (com.enonic.xp.security.User)13 Content (com.enonic.xp.content.Content)11 PropertyTree (com.enonic.xp.data.PropertyTree)11 PrincipalKey (com.enonic.xp.security.PrincipalKey)10 Branch (com.enonic.xp.branch.Branch)9 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)9 ContextAccessor (com.enonic.xp.context.ContextAccessor)8 NodePath (com.enonic.xp.node.NodePath)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)7 ContentId (com.enonic.xp.content.ContentId)6 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)6 Repository (com.enonic.xp.repository.Repository)6 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)5 ProcessUpdateParams (com.enonic.xp.content.processor.ProcessUpdateParams)5 NodeComparison (com.enonic.xp.node.NodeComparison)5