Search in sources :

Example 1 with NodeService

use of com.enonic.xp.node.NodeService in project xp by enonic.

the class ContentNodeTranslatorTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    this.nodeService = Mockito.mock(NodeService.class);
    final PartDescriptorService partDescriptorService = Mockito.mock(PartDescriptorService.class);
    final LayoutDescriptorService layoutDescriptorService = Mockito.mock(LayoutDescriptorService.class);
    final PageDescriptorService pageDescriptorService = Mockito.mock(PageDescriptorService.class);
    final ContentDataSerializer contentDataSerializer = ContentDataSerializer.create().layoutDescriptorService(layoutDescriptorService).pageDescriptorService(pageDescriptorService).partDescriptorService(partDescriptorService).build();
    this.contentNodeTranslator = new ContentNodeTranslator(nodeService, contentDataSerializer);
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) ContentDataSerializer(com.enonic.xp.core.impl.content.serializer.ContentDataSerializer) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) NodeService(com.enonic.xp.node.NodeService) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with NodeService

use of com.enonic.xp.node.NodeService in project xp by enonic.

the class SchedulableTaskImpl method run.

@Override
public void run() {
    try {
        final TaskId taskId = taskContext().callWith(() -> OsgiSupport.withService(TaskService.class, taskService -> taskService.submitTask(SubmitTaskParams.create().descriptorKey(job.getDescriptor()).data(job.getConfig()).build())));
        adminContext().runWith(() -> OsgiSupport.withService(NodeService.class, nodeService -> UpdateLastRunCommand.create().nodeService(nodeService).name(job.getName()).lastRun(Instant.now()).lastTaskId(taskId).build().execute()));
    } catch (Exception e) {
        LOG.warn("Error while running job [{}]", this.job.getName(), e);
    } catch (Throwable t) {
        LOG.error("Error while running job [{}], no further attempts will be made", this.job.getName(), t);
        throw t;
    }
}
Also used : SubmitTaskParams(com.enonic.xp.task.SubmitTaskParams) LoggerFactory(org.slf4j.LoggerFactory) UpdateLastRunCommand(com.enonic.xp.impl.scheduler.UpdateLastRunCommand) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeService(com.enonic.xp.node.NodeService) TaskService(com.enonic.xp.task.TaskService) ContextBuilder(com.enonic.xp.context.ContextBuilder) VerifiedUsernameAuthToken(com.enonic.xp.security.auth.VerifiedUsernameAuthToken) SecurityService(com.enonic.xp.security.SecurityService) PropertyTree(com.enonic.xp.data.PropertyTree) User(com.enonic.xp.security.User) Logger(org.slf4j.Logger) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Instant(java.time.Instant) OsgiSupport(com.enonic.xp.core.internal.osgi.OsgiSupport) Serializable(java.io.Serializable) TaskId(com.enonic.xp.task.TaskId) PrincipalKey(com.enonic.xp.security.PrincipalKey) DescriptorKey(com.enonic.xp.page.DescriptorKey) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) RoleKeys(com.enonic.xp.security.RoleKeys) Preconditions(com.google.common.base.Preconditions) Context(com.enonic.xp.context.Context) ScheduleCalendar(com.enonic.xp.scheduler.ScheduleCalendar) TaskId(com.enonic.xp.task.TaskId) TaskService(com.enonic.xp.task.TaskService) NodeService(com.enonic.xp.node.NodeService)

Example 3 with NodeService

use of com.enonic.xp.node.NodeService in project xp by enonic.

the class AuditLogServiceImplTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    PropertyTree data = new PropertyTree();
    data.setString("a", "b");
    data.setBoolean("c", false);
    auditLogParams = LogAuditLogParams.create().type("testType").source("testSource").objectUris(AuditLogUris.from("a:b:c", "d:e:f")).data(data).build();
    CreateNodeParams createNodeParams = AuditLogSerializer.toCreateNodeParams(auditLogParams).setNodeId(new NodeId()).build();
    Node node = Node.create().id(createNodeParams.getNodeId()).data(createNodeParams.getData()).build();
    nodeService = mock(NodeService.class);
    when(nodeService.create(any(CreateNodeParams.class))).thenReturn(node);
    when(nodeService.getById(any(NodeId.class))).thenReturn(node);
    when(nodeService.getByIds(any(NodeIds.class))).thenReturn(Nodes.from(node));
    when(nodeService.findByQuery(any(NodeQuery.class))).thenReturn(FindNodesByQueryResult.create().addNodeHit(NodeHit.create().nodeId(node.id()).build()).totalHits(1).hits(1).build());
    IndexService indexService = mock(IndexService.class);
    when(indexService.isMaster()).thenReturn(true);
    when(indexService.waitForYellowStatus()).thenReturn(true);
    RepositoryService repositoryService = mock(RepositoryService.class);
    config = mock(AuditLogConfig.class);
    when(config.isEnabled()).thenReturn(true);
    when(config.isOutputLogs()).thenReturn(true);
    auditLogService = new AuditLogServiceImpl(config, indexService, repositoryService, nodeService);
    auditLogService.initialize();
}
Also used : IndexService(com.enonic.xp.index.IndexService) NodeIds(com.enonic.xp.node.NodeIds) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeService(com.enonic.xp.node.NodeService) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) AuditLogConfig(com.enonic.xp.core.impl.audit.config.AuditLogConfig) RepositoryService(com.enonic.xp.repository.RepositoryService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

NodeService (com.enonic.xp.node.NodeService)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 AuditLogConfig (com.enonic.xp.core.impl.audit.config.AuditLogConfig)1 ContentDataSerializer (com.enonic.xp.core.impl.content.serializer.ContentDataSerializer)1 OsgiSupport (com.enonic.xp.core.internal.osgi.OsgiSupport)1 UpdateLastRunCommand (com.enonic.xp.impl.scheduler.UpdateLastRunCommand)1 IndexService (com.enonic.xp.index.IndexService)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 Node (com.enonic.xp.node.Node)1 NodeId (com.enonic.xp.node.NodeId)1 NodeIds (com.enonic.xp.node.NodeIds)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 DescriptorKey (com.enonic.xp.page.DescriptorKey)1 PageDescriptorService (com.enonic.xp.page.PageDescriptorService)1 LayoutDescriptorService (com.enonic.xp.region.LayoutDescriptorService)1 PartDescriptorService (com.enonic.xp.region.PartDescriptorService)1