use of com.enonic.xp.context.Context in project xp by enonic.
the class ContentAuditLogSupportImpl method duplicate.
@Override
public void duplicate(final DuplicateContentParams params, final DuplicateContentsResult result) {
final Context context = ContextBuilder.copyOf(ContextAccessor.current()).build();
executor.execute(() -> doDuplicate(params, result, context));
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class ContentAuditLogSupportImpl method createSite.
@Override
public void createSite(final CreateSiteParams params, final Site site) {
final Context context = ContextBuilder.copyOf(ContextAccessor.current()).build();
executor.execute(() -> doCreateSite(params, site, context));
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class ContentAuditLogSupportImpl method restore.
@Override
public void restore(final RestoreContentParams params, final RestoreContentsResult result) {
final Context context = ContextBuilder.copyOf(ContextAccessor.current()).build();
executor.execute(() -> doRestore(params, result, context));
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class ContentAuditLogSupportImplTest method testCreateContent.
@Test
public void testCreateContent() throws Exception {
final PropertyTree propertyTree = new PropertyTree();
propertyTree.addString("test-data", "test-data");
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.site()).parent(ContentPath.ROOT).contentData(propertyTree).displayName("displayName").build();
final Content content = Content.create().id(ContentId.from("contentId")).type(ContentTypeName.site()).name("contentName").displayName("displayName").parentPath(ContentPath.ROOT).build();
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "testUser")).displayName("Test User").modifiedTime(Instant.now()).email("test-user@enonic.com").login("test-user").build();
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN_LOGIN).build();
final Context context = ContextBuilder.create().branch(ContentConstants.BRANCH_DRAFT).repositoryId(RepositoryId.from("test-repository")).authInfo(authInfo).build();
// test
context.runWith(() -> support.createContent(params, content));
executor.shutdown();
executor.awaitTermination(1, TimeUnit.MINUTES);
// verify and assert
final ArgumentCaptor<LogAuditLogParams> argumentCaptor = ArgumentCaptor.forClass(LogAuditLogParams.class);
Mockito.verify(auditLogService, Mockito.times(1)).log(argumentCaptor.capture());
Assertions.assertEquals(user.getKey(), argumentCaptor.getValue().getUser());
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class RepositoryServiceImpl method createRootNode.
private void createRootNode(final CreateRepositoryParams params) {
final Context rootNodeContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(params.getRepositoryId()).branch(RepositoryConstants.MASTER_BRANCH).build();
final InternalContext rootNodeInternalContext = InternalContext.create(rootNodeContext).build();
final Node rootNode = this.nodeStorageService.store(Node.createRoot().permissions(params.getRootPermissions()).inheritPermissions(false).childOrder(params.getRootChildOrder()).build(), rootNodeInternalContext);
rootNodeContext.runWith(() -> RefreshCommand.create().indexServiceInternal(this.indexServiceInternal).refreshMode(RefreshMode.ALL).build().execute());
LOG.info("Created root node with id [{}] in repository [{}]", rootNode.id(), params.getRepositoryId());
}
Aggregations