Search in sources :

Example 1 with ModifyScheduledJobParams

use of com.enonic.xp.scheduler.ModifyScheduledJobParams in project xp by enonic.

the class ModifyScheduledJobHandler method doExecute.

@Override
protected ScheduledJobMapper doExecute() {
    final ScheduledJob existingJob = schedulerService.get().get(name);
    if (existingJob == null) {
        throw new IllegalArgumentException(String.format("[%s] job not found.", name.getValue()));
    }
    final ModifyScheduledJobParams params = ModifyScheduledJobParams.create().name(name).editor(newJobEditor()).build();
    final ScheduledJob modifiedJob = this.schedulerService.get().modify(params);
    return ScheduledJobMapper.from(modifiedJob);
}
Also used : ModifyScheduledJobParams(com.enonic.xp.scheduler.ModifyScheduledJobParams) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob)

Example 2 with ModifyScheduledJobParams

use of com.enonic.xp.scheduler.ModifyScheduledJobParams in project xp by enonic.

the class BaseScheduledJobHandlerTest method mockJob.

private void mockJob() {
    jobs = new HashMap<>();
    Mockito.when(schedulerService.create(Mockito.isA(CreateScheduledJobParams.class))).thenAnswer(invocation -> {
        final CreateScheduledJobParams params = invocation.getArgument(0);
        final ScheduledJob job = ScheduledJob.create().name(params.getName()).descriptor(params.getDescriptor()).description(params.getDescription()).calendar(params.getCalendar()).config(params.getConfig()).enabled(params.isEnabled()).user(params.getUser()).creator(PrincipalKey.from("user:system:creator")).modifier(PrincipalKey.from("user:system:creator")).createdTime(Instant.parse("2016-11-02T10:36:00Z")).modifiedTime(Instant.parse("2016-11-02T10:36:00Z")).build();
        jobs.put(job.getName(), job);
        return job;
    });
    Mockito.when(schedulerService.modify(Mockito.isA(ModifyScheduledJobParams.class))).thenAnswer(invocation -> {
        final ModifyScheduledJobParams params = invocation.getArgument(0);
        final EditableScheduledJob editableJob = new EditableScheduledJob(jobs.get(params.getName()));
        params.getEditor().edit(editableJob);
        ScheduledJob modifiedJob = editableJob.build();
        modifiedJob = ScheduledJob.create().name(modifiedJob.getName()).description(modifiedJob.getDescription()).calendar(modifiedJob.getCalendar()).enabled(modifiedJob.isEnabled()).descriptor(modifiedJob.getDescriptor()).config(modifiedJob.getConfig()).user(modifiedJob.getUser()).creator(modifiedJob.getCreator()).createdTime(modifiedJob.getCreatedTime()).modifiedTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).modifier(PrincipalKey.from("user:system:modifier")).build();
        jobs.put(params.getName(), modifiedJob);
        return modifiedJob;
    });
    Mockito.when(schedulerService.delete(Mockito.isA(ScheduledJobName.class))).thenAnswer(invocation -> {
        final ScheduledJobName name = invocation.getArgument(0);
        final ScheduledJob job = jobs.remove(name);
        return job != null;
    });
    Mockito.when(schedulerService.get(Mockito.isA(ScheduledJobName.class))).thenAnswer(invocation -> jobs.get(invocation.getArgument(0)));
    Mockito.when(schedulerService.list()).thenAnswer(invocation -> new ArrayList<>(jobs.values()));
}
Also used : CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) ModifyScheduledJobParams(com.enonic.xp.scheduler.ModifyScheduledJobParams) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob)

Example 3 with ModifyScheduledJobParams

use of com.enonic.xp.scheduler.ModifyScheduledJobParams in project xp by enonic.

the class ScheduleAuditLogSupportImplTest method testUpdateContent.

@Test
public void testUpdateContent() throws Exception {
    final PropertyTree config = new PropertyTree();
    config.addString("property", "value");
    final CronCalendarImpl calendar = CronCalendarImpl.create().value("* * * * *").timeZone(TimeZone.getTimeZone("GMT+5:30")).build();
    final DescriptorKey descriptor = DescriptorKey.from("appKey:descriptorName");
    final String jobDescription = "Job description";
    final PrincipalKey userKey = PrincipalKey.from("user:system:user");
    final OneTimeCalendarImpl oneTimeCalendar = OneTimeCalendarImpl.create().value(Instant.parse("2021-04-25T10:44:33.170079900Z")).build();
    final ModifyScheduledJobParams params = ModifyScheduledJobParams.create().name(name).editor(edit -> edit.calendar = oneTimeCalendar).build();
    final ScheduledJob job = ScheduledJob.create().name(name).calendar(oneTimeCalendar).descriptor(descriptor).description(jobDescription).config(config).enabled(true).user(userKey).creator(PrincipalKey.from("user:system:creator")).modifier(PrincipalKey.from("user:system:creator")).createdTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).modifiedTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).build();
    context.runWith(() -> support.modify(params, job));
    executor.shutdown();
    executor.awaitTermination(1, TimeUnit.MINUTES);
    final ArgumentCaptor<LogAuditLogParams> argumentCaptor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    verify(auditLogService, times(1)).log(argumentCaptor.capture());
    assertEquals(user.getKey().toString(), argumentCaptor.getValue().getData().getSet("params").getString("modifier"));
    assertEquals("2021-04-25T10:44:33.170079900Z", argumentCaptor.getValue().getData().getSet("result").getSet("calendar").getString("value"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ModifyScheduledJobParams(com.enonic.xp.scheduler.ModifyScheduledJobParams) IdProviderKey(com.enonic.xp.security.IdProviderKey) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ArgumentCaptor(org.mockito.ArgumentCaptor) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) OneTimeCalendarImpl(com.enonic.xp.impl.scheduler.distributed.OneTimeCalendarImpl) AuditLogService(com.enonic.xp.audit.AuditLogService) ContextBuilder(com.enonic.xp.context.ContextBuilder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ExecutorService(java.util.concurrent.ExecutorService) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) CronCalendarImpl(com.enonic.xp.impl.scheduler.distributed.CronCalendarImpl) User(com.enonic.xp.security.User) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TimeZone(java.util.TimeZone) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Mockito.times(org.mockito.Mockito.times) Instant(java.time.Instant) Executors(java.util.concurrent.Executors) TaskId(com.enonic.xp.task.TaskId) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) PrincipalKey(com.enonic.xp.security.PrincipalKey) DescriptorKey(com.enonic.xp.page.DescriptorKey) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) Context(com.enonic.xp.context.Context) CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) OneTimeCalendarImpl(com.enonic.xp.impl.scheduler.distributed.OneTimeCalendarImpl) ModifyScheduledJobParams(com.enonic.xp.scheduler.ModifyScheduledJobParams) CronCalendarImpl(com.enonic.xp.impl.scheduler.distributed.CronCalendarImpl) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) DescriptorKey(com.enonic.xp.page.DescriptorKey) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 4 with ModifyScheduledJobParams

use of com.enonic.xp.scheduler.ModifyScheduledJobParams in project xp by enonic.

the class ScheduleAuditLogSupportImplTest method testUpdateWithoutCreator.

@Test
public // jobs were produced with an empty `creator` and `createdTime` fields from 7.7.0 to 7.7.2
void testUpdateWithoutCreator() throws Exception {
    final PropertyTree config = new PropertyTree();
    config.addString("property", "value");
    final CronCalendarImpl calendar = CronCalendarImpl.create().value("* * * * *").timeZone(TimeZone.getTimeZone("GMT+5:30")).build();
    final DescriptorKey descriptor = DescriptorKey.from("appKey:descriptorName");
    final String jobDescription = "Job description";
    final PrincipalKey userKey = PrincipalKey.from("user:system:user");
    final OneTimeCalendarImpl oneTimeCalendar = OneTimeCalendarImpl.create().value(Instant.parse("2021-04-25T10:44:33.170079900Z")).build();
    final ModifyScheduledJobParams params = ModifyScheduledJobParams.create().name(name).editor(edit -> edit.calendar = oneTimeCalendar).build();
    final ScheduledJob job = ScheduledJob.create().name(name).calendar(oneTimeCalendar).descriptor(descriptor).description(jobDescription).config(config).enabled(true).user(userKey).modifier(PrincipalKey.from("user:system:creator")).createdTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).modifiedTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).build();
    context.runWith(() -> support.modify(params, job));
    executor.shutdown();
    executor.awaitTermination(1, TimeUnit.MINUTES);
    final ArgumentCaptor<LogAuditLogParams> argumentCaptor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    verify(auditLogService, times(1)).log(argumentCaptor.capture());
    assertNull(argumentCaptor.getValue().getData().getSet("params").getString("creator"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ModifyScheduledJobParams(com.enonic.xp.scheduler.ModifyScheduledJobParams) IdProviderKey(com.enonic.xp.security.IdProviderKey) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ArgumentCaptor(org.mockito.ArgumentCaptor) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) OneTimeCalendarImpl(com.enonic.xp.impl.scheduler.distributed.OneTimeCalendarImpl) AuditLogService(com.enonic.xp.audit.AuditLogService) ContextBuilder(com.enonic.xp.context.ContextBuilder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ExecutorService(java.util.concurrent.ExecutorService) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) CronCalendarImpl(com.enonic.xp.impl.scheduler.distributed.CronCalendarImpl) User(com.enonic.xp.security.User) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TimeZone(java.util.TimeZone) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Mockito.times(org.mockito.Mockito.times) Instant(java.time.Instant) Executors(java.util.concurrent.Executors) TaskId(com.enonic.xp.task.TaskId) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) PrincipalKey(com.enonic.xp.security.PrincipalKey) DescriptorKey(com.enonic.xp.page.DescriptorKey) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) Context(com.enonic.xp.context.Context) CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) OneTimeCalendarImpl(com.enonic.xp.impl.scheduler.distributed.OneTimeCalendarImpl) ModifyScheduledJobParams(com.enonic.xp.scheduler.ModifyScheduledJobParams) CronCalendarImpl(com.enonic.xp.impl.scheduler.distributed.CronCalendarImpl) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) DescriptorKey(com.enonic.xp.page.DescriptorKey) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Aggregations

ModifyScheduledJobParams (com.enonic.xp.scheduler.ModifyScheduledJobParams)4 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)4 CreateScheduledJobParams (com.enonic.xp.scheduler.CreateScheduledJobParams)3 ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)3 AuditLogService (com.enonic.xp.audit.AuditLogService)2 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)2 Context (com.enonic.xp.context.Context)2 ContextBuilder (com.enonic.xp.context.ContextBuilder)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 CronCalendarImpl (com.enonic.xp.impl.scheduler.distributed.CronCalendarImpl)2 OneTimeCalendarImpl (com.enonic.xp.impl.scheduler.distributed.OneTimeCalendarImpl)2 DescriptorKey (com.enonic.xp.page.DescriptorKey)2 EditableScheduledJob (com.enonic.xp.scheduler.EditableScheduledJob)2 IdProviderKey (com.enonic.xp.security.IdProviderKey)2 PrincipalKey (com.enonic.xp.security.PrincipalKey)2 User (com.enonic.xp.security.User)2 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)2 TaskId (com.enonic.xp.task.TaskId)2 Instant (java.time.Instant)2 TimeZone (java.util.TimeZone)2