Search in sources :

Example 56 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class SchedulerServiceImplTest method list.

@Test
void list() {
    assertEquals(0, adminContext().callWith(() -> schedulerService.list()).size());
    final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.from("com.enonic.app.features"), "landing");
    final CronCalendar calendar = calendarService.cron("* * * * *", TimeZone.getDefault());
    final PropertyTree config = new PropertyTree();
    config.addString("string", "value");
    adminContext().callWith(() -> schedulerService.create(CreateScheduledJobParams.create().name(ScheduledJobName.from("test1")).descriptor(descriptor).calendar(calendar).config(config).description("description").build()));
    assertEquals(1, adminContext().callWith(() -> schedulerService.list()).size());
    adminContext().callWith(() -> schedulerService.create(CreateScheduledJobParams.create().name(ScheduledJobName.from("test2")).descriptor(descriptor).calendar(calendar).config(config).description("description").build()));
    assertEquals(2, adminContext().callWith(() -> schedulerService.list()).size());
}
Also used : CronCalendar(com.enonic.xp.scheduler.CronCalendar) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 57 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class AdminToolHandler method doHandle.

@Override
protected WebResponse doHandle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
    WebHandlerHelper.checkAdminAccess(webRequest);
    PortalRequest portalRequest = (PortalRequest) webRequest;
    portalRequest.setContextPath(portalRequest.getBaseUri());
    final AdminToolHandlerWorker worker = new AdminToolHandlerWorker(portalRequest);
    worker.controllerScriptFactory = this.controllerScriptFactory;
    worker.adminToolDescriptorService = adminToolDescriptorService;
    final DescriptorKey descriptorKey = AdminToolPortalHandler.getDescriptorKey(webRequest);
    worker.descriptorKey = descriptorKey == null ? AdminToolPortalHandler.DEFAULT_DESCRIPTOR_KEY : descriptorKey;
    final Trace trace = Tracer.newTrace("portalRequest");
    if (trace == null) {
        return worker.execute();
    }
    trace.put("path", webRequest.getPath());
    trace.put("method", webRequest.getMethod().toString());
    trace.put("host", webRequest.getHost());
    trace.put("httpRequest", webRequest);
    trace.put("httpResponse", webResponse);
    trace.put("context", ContextAccessor.current());
    return Tracer.traceEx(trace, () -> {
        final PortalResponse response = worker.execute();
        addTraceInfo(trace, response);
        return response;
    });
}
Also used : Trace(com.enonic.xp.trace.Trace) PortalResponse(com.enonic.xp.portal.PortalResponse) DescriptorKey(com.enonic.xp.page.DescriptorKey) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 58 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class CreateScheduledJobParamsTest method testBuilder.

@Test
public void testBuilder() {
    final PrincipalKey user = PrincipalKey.ofUser(IdProviderKey.createDefault(), "user");
    final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.BASE, "descriptor");
    final PropertyTree config = new PropertyTree();
    config.addString("property", "value");
    final String description = "description";
    final ScheduleCalendar calendar = mock(ScheduleCalendar.class);
    final CreateScheduledJobParams params = CreateScheduledJobParams.create().name(ScheduledJobName.from("name")).config(config).user(user).descriptor(descriptor).description(description).calendar(calendar).enabled(true).build();
    assertEquals(config, params.getConfig());
    assertEquals(user, params.getUser());
    assertEquals(descriptor, params.getDescriptor());
    assertEquals(description, params.getDescription());
    assertEquals(calendar, params.getCalendar());
    assertTrue(params.isEnabled());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 59 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class ScheduledJobTest method testBuilder.

@Test
public void testBuilder() {
    final PrincipalKey user = PrincipalKey.ofUser(IdProviderKey.createDefault(), "user");
    final PrincipalKey creator = PrincipalKey.ofUser(IdProviderKey.createDefault(), "creator");
    final PrincipalKey modifier = PrincipalKey.ofUser(IdProviderKey.createDefault(), "modifier");
    final Instant createdTime = Instant.parse("2016-11-02T10:36:00Z");
    final Instant modifiedTime = Instant.parse("2020-11-02T10:36:00Z");
    final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.BASE, "descriptor");
    final PropertyTree config = new PropertyTree();
    config.addString("property", "value");
    final String description = "description";
    final ScheduledJob job = ScheduledJob.create().name(ScheduledJobName.from("name")).config(config).user(user).descriptor(descriptor).description(description).calendar(mock(ScheduleCalendar.class)).enabled(true).creator(creator).modifier(modifier).createdTime(createdTime).modifiedTime(modifiedTime).build();
    assertEquals(config, job.getConfig());
    assertEquals(user, job.getUser());
    assertEquals(descriptor, job.getDescriptor());
    assertEquals(description, job.getDescription());
    assertTrue(job.isEnabled());
    assertEquals(creator, job.getCreator());
    assertEquals(modifier, job.getModifier());
    assertEquals(createdTime, job.getCreatedTime());
    assertEquals(modifiedTime, job.getModifiedTime());
}
Also used : Instant(java.time.Instant) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 60 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class MacroDescriptorServiceImpl method getByApplication.

@Override
public MacroDescriptors getByApplication(final ApplicationKey applicationKey) {
    final List<MacroDescriptor> list = new ArrayList<>();
    if (isSystem(applicationKey)) {
        list.addAll(builtinMacrosDescriptors.getAll().getSet());
    } else {
        for (final DescriptorKey descriptorKey : descriptorKeyLocator.findKeys(applicationKey)) {
            final MacroKey macroKey = MacroKey.from(descriptorKey.getApplicationKey(), descriptorKey.getName());
            final MacroDescriptor descriptor = getByKey(macroKey);
            if (descriptor != null) {
                list.add(descriptor);
            }
        }
    }
    return MacroDescriptors.from(list);
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) ArrayList(java.util.ArrayList) DescriptorKey(com.enonic.xp.page.DescriptorKey)

Aggregations

DescriptorKey (com.enonic.xp.page.DescriptorKey)73 Test (org.junit.jupiter.api.Test)45 PropertyTree (com.enonic.xp.data.PropertyTree)25 PrincipalKey (com.enonic.xp.security.PrincipalKey)11 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)10 TaskId (com.enonic.xp.task.TaskId)10 Page (com.enonic.xp.page.Page)7 ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)7 TaskDescriptor (com.enonic.xp.task.TaskDescriptor)7 Instant (java.time.Instant)7 PropertySet (com.enonic.xp.data.PropertySet)6 ServiceDescriptor (com.enonic.xp.service.ServiceDescriptor)6 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)5 CronCalendar (com.enonic.xp.scheduler.CronCalendar)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ApplicationKey (com.enonic.xp.app.ApplicationKey)4 AbstractDescriptorServiceTest (com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)4 DescribedTask (com.enonic.xp.impl.task.distributed.DescribedTask)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 PortalResponse (com.enonic.xp.portal.PortalResponse)4