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());
}
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;
});
}
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());
}
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());
}
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);
}
Aggregations