Search in sources :

Example 66 with Context

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));
}
Also used : Context(com.enonic.xp.context.Context)

Example 67 with 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));
}
Also used : Context(com.enonic.xp.context.Context)

Example 68 with 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));
}
Also used : Context(com.enonic.xp.context.Context)

Example 69 with 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());
}
Also used : Context(com.enonic.xp.context.Context) User(com.enonic.xp.security.User) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Test(org.junit.jupiter.api.Test)

Example 70 with Context

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());
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) InternalContext(com.enonic.xp.repo.impl.InternalContext) Node(com.enonic.xp.node.Node)

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