use of com.enonic.xp.task.SubmitTaskParams in project xp by enonic.
the class SubmitTaskHandler method submitTask.
public String submitTask() {
descriptor = descriptor == null ? "" : descriptor;
final DescriptorKey taskKey;
if (descriptor.contains(":")) {
taskKey = DescriptorKey.from(descriptor);
} else {
final ApplicationKey app = getApplication();
if (app == null) {
throw new RuntimeException("Could not resolve current application for descriptord task: '" + descriptor + "'");
}
taskKey = DescriptorKey.from(app, descriptor);
}
final TaskService taskService = taskServiceSupplier.get();
PropertyTree data = propertyTreeMarshallerServiceSupplier.get().marshal(Optional.ofNullable(config).map(ScriptValue::getMap).orElse(Map.of()));
final SubmitTaskParams params = SubmitTaskParams.create().descriptorKey(taskKey).data(data).build();
final TaskId taskId = taskService.submitTask(params);
return taskId.toString();
}
use of com.enonic.xp.task.SubmitTaskParams in project xp by enonic.
the class AuditLogResourceTest method cleanUpAuditLog.
@Test
public void cleanUpAuditLog() throws Exception {
Mockito.when(taskService.submitTask(isA(SubmitTaskParams.class))).thenReturn(TaskId.from("task-id"));
final CleanUpAuditLogRequestJson requestJson = new CleanUpAuditLogRequestJson("PT1s");
final TaskResultJson result = resource.cleanup(requestJson);
final ArgumentCaptor<SubmitTaskParams> captor = ArgumentCaptor.forClass(SubmitTaskParams.class);
Mockito.verify(taskService, Mockito.times(1)).submitTask(captor.capture());
assertEquals("task-id", result.getTaskId());
assertEquals(1, captor.getValue().getData().getTotalSize());
assertEquals("PT1s", captor.getValue().getData().getString("ageThreshold"));
}
Aggregations