Search in sources :

Example 16 with DescriptorKey

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

the class IndexConfigUpgrader method upgradePageIndexConfig.

private PatternIndexConfigDocument upgradePageIndexConfig(final PatternIndexConfigDocument sourceDocument, final NodeVersion nodeVersion) {
    final List<PropertySet> components = Lists.newArrayList(nodeVersion.getData().getSets("components"));
    final String descriptorKeyStr = nodeVersion.getData().getString(PropertyPath.from("components.page.descriptor"));
    final DescriptorKey pageDescriptorKey = descriptorKeyStr != null ? DescriptorKey.from(descriptorKeyStr) : null;
    final FlattenedPageIndexUpgrader pageIndexUpgrader = new FlattenedPageIndexUpgrader(pageDescriptorKey, components);
    return pageIndexUpgrader.upgrade(sourceDocument);
}
Also used : PropertySet(com.enonic.xp.data.PropertySet) DescriptorKey(com.enonic.xp.page.DescriptorKey) FlattenedPageIndexUpgrader(com.enonic.xp.repo.impl.dump.upgrade.flattenedpage.FlattenedPageIndexUpgrader)

Example 17 with DescriptorKey

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

the class FlattenedPageRegionsIndexUpgrader method upgradeHtmlAreas.

private void upgradeHtmlAreas(final PathIndexConfig pathIndexConfig) {
    final Matcher matcher = HTML_AREA_CONFIG_PATH_PATTERN.matcher(pathIndexConfig.getPath().toString());
    if (matcher.find()) {
        this.components.forEach(componentSet -> {
            final String componentNewType = FlattenedPageDataUpgrader.getTargetType(matcher.group(2));
            if (componentNewType != null) {
                final String descriptorKeyStr = componentSet.getString(String.join(ELEMENT_DIVIDER, componentNewType, TGT_DESCRIPTOR_KEY));
                if (descriptorKeyStr != null) {
                    final DescriptorKey descriptorKey = DescriptorKey.from(descriptorKeyStr);
                    final String property = componentSet.getString(String.join(ELEMENT_DIVIDER, componentNewType, TGT_CONFIG_KEY, getSanitizedAppName(descriptorKey), getSanitizedComponentName(descriptorKey), matcher.group(3)));
                    if (property != null) {
                        String newHtmlAreaPath = String.join(ELEMENT_DIVIDER, TGT_COMPONENTS_KEY, FlattenedPageDataUpgrader.getTargetType(matcher.group(2)), TGT_CONFIG_KEY, getSanitizedAppName(descriptorKey), getSanitizedComponentName(descriptorKey), matcher.group(3));
                        result.add(newHtmlAreaPath, pathIndexConfig.getIndexConfig());
                    }
                }
            }
        });
    }
}
Also used : Matcher(java.util.regex.Matcher) DescriptorKey(com.enonic.xp.page.DescriptorKey)

Example 18 with DescriptorKey

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

the class SchedulerServiceImplTest method createOneTimeJob.

@Test
void createOneTimeJob() throws Exception {
    final ScheduledJobName name = ScheduledJobName.from("test");
    final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.from("com.enonic.app.features"), "landing");
    final ScheduleCalendar calendar = calendarService.oneTime(Instant.parse("2021-02-25T10:44:33.170079900Z"));
    final PropertyTree config = new PropertyTree();
    config.addString("string", "value");
    final PrincipalKey user = PrincipalKey.from("user:system:user");
    final CreateScheduledJobParams params = CreateScheduledJobParams.create().name(name).descriptor(descriptor).calendar(calendar).config(config).description("description").enabled(true).user(user).build();
    final Instant now = Instant.now();
    Thread.sleep(100);
    final ScheduledJob scheduledJob = adminContext().callWith(() -> schedulerService.create(params));
    assertEquals("2021-02-25T10:44:33.170079900Z", ((OneTimeCalendar) scheduledJob.getCalendar()).getValue().toString());
    assertEquals(ScheduleCalendarType.ONE_TIME, scheduledJob.getCalendar().getType());
    assertEquals("user:system:repo-test-user", scheduledJob.getCreator().toString());
    assertEquals("user:system:repo-test-user", scheduledJob.getModifier().toString());
    assertTrue(now.isBefore(scheduledJob.getModifiedTime()));
    assertTrue(now.isBefore(scheduledJob.getCreatedTime()));
}
Also used : CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) PropertyTree(com.enonic.xp.data.PropertyTree) Instant(java.time.Instant) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar) DescriptorKey(com.enonic.xp.page.DescriptorKey) ScheduleCalendar(com.enonic.xp.scheduler.ScheduleCalendar) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 19 with DescriptorKey

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

the class SchedulerServiceImplTest method listWithoutAccess.

@Test
void listWithoutAccess() {
    assertEquals(0, schedulerService.list().size());
    final ScheduledJobName name = ScheduledJobName.from("test");
    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(name).descriptor(descriptor).calendar(calendar).config(config).description("description").build()));
    assertEquals(0, schedulerService.list().size());
}
Also used : CronCalendar(com.enonic.xp.scheduler.CronCalendar) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) 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 20 with DescriptorKey

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

the class SchedulerServiceImplTest method get.

@Test
void get() {
    final ScheduledJobName name = ScheduledJobName.from("test");
    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(name).descriptor(descriptor).calendar(calendar).config(config).description("description").build()));
    final ScheduledJob scheduledJob = adminContext().callWith(() -> schedulerService.get(name));
    assertEquals(name, scheduledJob.getName());
    assertEquals(descriptor, scheduledJob.getDescriptor());
    assertEquals(calendar.getCronValue(), ((CronCalendar) scheduledJob.getCalendar()).getCronValue());
    assertEquals(calendar.getTimeZone(), ((CronCalendar) scheduledJob.getCalendar()).getTimeZone());
    assertEquals(config, scheduledJob.getConfig());
    assertEquals("description", scheduledJob.getDescription());
}
Also used : CronCalendar(com.enonic.xp.scheduler.CronCalendar) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) PropertyTree(com.enonic.xp.data.PropertyTree) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) DescriptorKey(com.enonic.xp.page.DescriptorKey) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

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