Search in sources :

Example 86 with Context

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

the class DeleteVersionCommand method doExecute.

private void doExecute() {
    final Context currentContext = ContextAccessor.current();
    final NodeVersionMetadata nodeVersionMetadata = this.nodeStorageService.getVersion(this.nodeId, this.nodeVersionId, InternalContext.from(currentContext));
    if (isInUse(nodeVersionMetadata.getNodeId())) {
        throw new NodeVersionDeleteException("Cannot delete version of a node that is in use");
    }
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeVersionDeleteException(com.enonic.xp.node.NodeVersionDeleteException)

Example 87 with Context

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

the class CompareNodesCommand method execute.

public NodeComparisons execute() {
    Set<NodeId> allNodeIds = new HashSet<>();
    final Context context = ContextAccessor.current();
    final NodeComparisons.Builder builder = NodeComparisons.create();
    final NodeBranchEntries sourceVersions = nodeStorageService.getBranchNodeVersions(nodeIds, false, InternalContext.from(context));
    final NodeBranchEntries targetVersions = nodeStorageService.getBranchNodeVersions(nodeIds, false, InternalContext.create(context).branch(this.target).build());
    allNodeIds.addAll(sourceVersions.getKeys());
    allNodeIds.addAll(targetVersions.getKeys());
    for (final NodeId id : allNodeIds) {
        final CompareStatus compareStatus = CompareStatusResolver.create().source(sourceVersions.get(id)).target(targetVersions.get(id)).storageService(this.nodeStorageService).build().resolve();
        builder.add(new NodeComparison(sourceVersions.get(id), targetVersions.get(id), compareStatus));
    }
    return builder.build();
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeComparison(com.enonic.xp.node.NodeComparison) NodeId(com.enonic.xp.node.NodeId) CompareStatus(com.enonic.xp.content.CompareStatus) NodeComparisons(com.enonic.xp.node.NodeComparisons) HashSet(java.util.HashSet)

Example 88 with Context

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

the class GetActiveNodeVersionsCommand method execute.

public GetActiveNodeVersionsResult execute() {
    final GetActiveNodeVersionsResult.Builder builder = GetActiveNodeVersionsResult.create();
    for (final Branch branch : branches) {
        final Context context = ContextAccessor.current();
        final NodeBranchEntry nodeBranchEntry = this.nodeStorageService.getBranchNodeVersion(this.nodeId, InternalContext.create(context).branch(branch).build());
        if (nodeBranchEntry != null) {
            builder.add(branch, this.nodeStorageService.getVersion(nodeBranchEntry.getNodeId(), nodeBranchEntry.getVersionId(), InternalContext.from(context)));
        }
    }
    return builder.build();
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) Branch(com.enonic.xp.branch.Branch) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Example 89 with Context

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

the class ContentServiceImplTest_unpublish method audit_data.

@Test
public void audit_data() throws Exception {
    final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build());
    this.contentService.publish(PushContentParams.create().target(ContentConstants.BRANCH_MASTER).contentIds(ContentIds.from(content.getId())).build());
    final Context masterContext = ContextBuilder.from(ContextAccessor.current()).branch(ContentConstants.BRANCH_MASTER).build();
    assertTrue(masterContext.callWith(() -> contentService.contentExists(content.getId())));
    this.contentService.unpublishContent(UnpublishContentParams.create().contentIds(ContentIds.from(content.getId())).unpublishBranch(ContentConstants.BRANCH_MASTER).build());
    Mockito.verify(auditLogService, Mockito.timeout(5000).atLeast(17)).log(captor.capture());
    final PropertySet logResultSet = captor.getAllValues().stream().filter(log -> log.getType().equals("system.content.unpublishContent")).findFirst().get().getData().getSet("result");
    assertEquals(content.getId().toString(), logResultSet.getStrings("unpublishedContents").iterator().next());
}
Also used : Context(com.enonic.xp.context.Context) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 90 with Context

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

the class ContentServiceImplTest_unpublish method unpublish.

@Test
public void unpublish() throws Exception {
    final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build());
    this.contentService.publish(PushContentParams.create().target(ContentConstants.BRANCH_MASTER).contentIds(ContentIds.from(content.getId())).build());
    final Context masterContext = ContextBuilder.from(ContextAccessor.current()).branch(ContentConstants.BRANCH_MASTER).build();
    assertTrue(masterContext.callWith(() -> contentService.contentExists(content.getId())));
    this.contentService.unpublishContent(UnpublishContentParams.create().contentIds(ContentIds.from(content.getId())).unpublishBranch(ContentConstants.BRANCH_MASTER).build());
    assertNotNull(contentService.contentExists(content.getId()));
    assertFalse(masterContext.callWith(() -> contentService.contentExists(content.getId())));
    final Content unpublishedContent = this.contentService.getById(content.getId());
    assertNull(unpublishedContent.getPublishInfo().getFrom());
    assertNull(unpublishedContent.getPublishInfo().getTo());
    assertNotNull(unpublishedContent.getPublishInfo().getFirst());
}
Also used : Context(com.enonic.xp.context.Context) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

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