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