Search in sources :

Example 1 with ScheduledJob

use of com.enonic.xp.scheduler.ScheduledJob 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 ScheduledJob

use of com.enonic.xp.scheduler.ScheduledJob 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 ScheduledJob

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

the class ModifyScheduledJobCommand method doExecute.

private ScheduledJob doExecute() {
    final ScheduledJob original = GetScheduledJobCommand.create().nodeService(nodeService).name(params.getName()).build().execute();
    final UpdateNodeParams updateNodeParams = UpdateNodeParams.create().path(NodePath.create(NodePath.ROOT, params.getName().getValue()).build()).editor((toBeEdited -> toBeEdited.data = SchedulerSerializer.toUpdateNodeData(params, original))).build();
    final Node updatedNode = nodeService.update(updateNodeParams);
    nodeService.refresh(RefreshMode.ALL);
    return SchedulerSerializer.fromNode(updatedNode);
}
Also used : ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Node(com.enonic.xp.node.Node)

Example 4 with ScheduledJob

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

the class SchedulerServiceImpl method create.

@Override
public ScheduledJob create(final CreateScheduledJobParams params) {
    final ScheduledJob job = CreateScheduledJobCommand.create().nodeService(nodeService).params(params).build().execute();
    auditLogSupport.create(params, job);
    return job;
}
Also used : ScheduledJob(com.enonic.xp.scheduler.ScheduledJob)

Example 5 with ScheduledJob

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

the class SchedulerSerializer method toUpdateNodeData.

public static PropertyTree toUpdateNodeData(final ModifyScheduledJobParams params, final ScheduledJob original) {
    final ScheduledJob modifiedJob = editScheduledJob(params.getEditor(), original);
    final PropertyTree tree = new PropertyTree();
    final PropertySet data = tree.getRoot();
    data.ifNotNull().setString(ScheduledJobPropertyNames.DESCRIPTION, modifiedJob.getDescription());
    data.setBoolean(ScheduledJobPropertyNames.ENABLED, modifiedJob.isEnabled());
    addCalendar(modifiedJob, data);
    if (modifiedJob.getDescriptor() != null) {
        data.setString(ScheduledJobPropertyNames.DESCRIPTOR, modifiedJob.getDescriptor().toString());
    }
    if (modifiedJob.getConfig() != null) {
        data.setSet(ScheduledJobPropertyNames.CONFIG, modifiedJob.getConfig().getRoot().copy(data.getTree()));
    }
    if (modifiedJob.getUser() != null) {
        data.setString(ScheduledJobPropertyNames.USER, modifiedJob.getUser().toString());
    }
    if (modifiedJob.getCreator() != null) {
        data.setString(ScheduledJobPropertyNames.CREATOR, modifiedJob.getCreator().toString());
    }
    if (modifiedJob.getCreatedTime() != null) {
        data.setInstant(ScheduledJobPropertyNames.CREATED_TIME, modifiedJob.getCreatedTime());
    }
    data.setString(ScheduledJobPropertyNames.MODIFIER, getCurrentUser().getKey().toString());
    data.setInstant(ScheduledJobPropertyNames.MODIFIED_TIME, Instant.now());
    return tree;
}
Also used : ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet)

Aggregations

ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)23 PropertyTree (com.enonic.xp.data.PropertyTree)14 Test (org.junit.jupiter.api.Test)13 DescriptorKey (com.enonic.xp.page.DescriptorKey)11 CreateScheduledJobParams (com.enonic.xp.scheduler.CreateScheduledJobParams)10 ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)10 PrincipalKey (com.enonic.xp.security.PrincipalKey)9 EditableScheduledJob (com.enonic.xp.scheduler.EditableScheduledJob)7 Instant (java.time.Instant)7 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)6 CronCalendar (com.enonic.xp.scheduler.CronCalendar)6 ModifyScheduledJobParams (com.enonic.xp.scheduler.ModifyScheduledJobParams)6 ScheduleCalendar (com.enonic.xp.scheduler.ScheduleCalendar)6 Context (com.enonic.xp.context.Context)5 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)5 AuditLogService (com.enonic.xp.audit.AuditLogService)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4 OneTimeCalendar (com.enonic.xp.scheduler.OneTimeCalendar)4 IdProviderKey (com.enonic.xp.security.IdProviderKey)4 User (com.enonic.xp.security.User)4