Search in sources :

Example 1 with SubmitTaskParams

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();
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ScriptValue(com.enonic.xp.script.ScriptValue) TaskId(com.enonic.xp.task.TaskId) TaskService(com.enonic.xp.task.TaskService) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) SubmitTaskParams(com.enonic.xp.task.SubmitTaskParams)

Example 2 with SubmitTaskParams

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"));
}
Also used : SubmitTaskParams(com.enonic.xp.task.SubmitTaskParams) TaskResultJson(com.enonic.xp.task.TaskResultJson) CleanUpAuditLogRequestJson(com.enonic.xp.impl.server.rest.model.CleanUpAuditLogRequestJson) Test(org.junit.jupiter.api.Test)

Aggregations

SubmitTaskParams (com.enonic.xp.task.SubmitTaskParams)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 CleanUpAuditLogRequestJson (com.enonic.xp.impl.server.rest.model.CleanUpAuditLogRequestJson)1 DescriptorKey (com.enonic.xp.page.DescriptorKey)1 ScriptValue (com.enonic.xp.script.ScriptValue)1 TaskId (com.enonic.xp.task.TaskId)1 TaskResultJson (com.enonic.xp.task.TaskResultJson)1 TaskService (com.enonic.xp.task.TaskService)1 Test (org.junit.jupiter.api.Test)1