diff --git a/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTask.java b/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTask.java index b960b886..3651a73b 100644 --- a/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTask.java +++ b/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTask.java @@ -50,6 +50,12 @@ */ String value(); + /** + * Standard prioritet for task type + */ + @Nonbinding + int prioritet() default 1; + /** * Cron-expression to schedule next instance of a repeating task. */ diff --git a/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTaskData.java b/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTaskData.java index 0cbf032e..933524ca 100644 --- a/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTaskData.java +++ b/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTaskData.java @@ -49,7 +49,9 @@ public class ProsessTaskData implements ProsessTaskInfo { } public static ProsessTaskData forProsessTask(Class clazz) { - return new ProsessTaskData(TaskType.forProsessTask(clazz)); + var prosessTaskData = new ProsessTaskData(TaskType.forProsessTask(clazz)); + prosessTaskData.setPrioritet(TaskType.prioritet(clazz)); + return prosessTaskData; } public static ProsessTaskData forTaskType(TaskType taskType) { diff --git a/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTaskDataBuilder.java b/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTaskDataBuilder.java index 47b097d2..c05d8707 100644 --- a/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTaskDataBuilder.java +++ b/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/ProsessTaskDataBuilder.java @@ -20,7 +20,7 @@ private ProsessTaskDataBuilder(TaskType taskType) { } public static ProsessTaskDataBuilder forProsessTask(Class clazz) { - return new ProsessTaskDataBuilder(TaskType.forProsessTask(clazz)); + return new ProsessTaskDataBuilder(TaskType.forProsessTask(clazz)).medPrioritet(TaskType.prioritet(clazz)); } public static ProsessTaskDataBuilder forTaskType(TaskType taskType) { diff --git a/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/TaskType.java b/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/TaskType.java index ffe96073..1ee1ef38 100644 --- a/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/TaskType.java +++ b/task/src/main/java/no/nav/vedtak/felles/prosesstask/api/TaskType.java @@ -17,4 +17,8 @@ public record TaskType(String value) { public static TaskType forProsessTask(Class clazz) { return new TaskType(clazz.getAnnotation(ProsessTask.class).value()); } + + public static int prioritet(Class clazz) { + return clazz.getAnnotation(ProsessTask.class).prioritet(); + } } diff --git a/task/src/main/java/no/nav/vedtak/felles/prosesstask/impl/ProsessTaskHandlerRef.java b/task/src/main/java/no/nav/vedtak/felles/prosesstask/impl/ProsessTaskHandlerRef.java index 6e98a263..4f80b62c 100644 --- a/task/src/main/java/no/nav/vedtak/felles/prosesstask/impl/ProsessTaskHandlerRef.java +++ b/task/src/main/java/no/nav/vedtak/felles/prosesstask/impl/ProsessTaskHandlerRef.java @@ -3,14 +3,13 @@ import java.lang.annotation.Annotation; import java.util.Set; -import jakarta.enterprise.context.Dependent; -import jakarta.enterprise.inject.spi.CDI; -import jakarta.enterprise.util.AnnotationLiteral; - import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.inject.spi.CDI; +import jakarta.enterprise.util.AnnotationLiteral; import no.nav.vedtak.felles.prosesstask.api.ProsessTask; import no.nav.vedtak.felles.prosesstask.api.ProsessTaskData; import no.nav.vedtak.felles.prosesstask.api.ProsessTaskHandler; @@ -111,6 +110,11 @@ public String value() { return taskType; } + @Override + public int prioritet() { + return 1; + } + @Override public String cronExpression() { return ""; diff --git a/task/src/test/java/no/nav/vedtak/felles/prosesstask/impl/ProsessTaskTjenesteImplTest.java b/task/src/test/java/no/nav/vedtak/felles/prosesstask/impl/ProsessTaskTjenesteImplTest.java index 4ef93bbd..65a43a89 100644 --- a/task/src/test/java/no/nav/vedtak/felles/prosesstask/impl/ProsessTaskTjenesteImplTest.java +++ b/task/src/test/java/no/nav/vedtak/felles/prosesstask/impl/ProsessTaskTjenesteImplTest.java @@ -37,7 +37,7 @@ class ProsessTaskTjenesteImplTest { private ProsessTaskTjeneste prosessTaskTjeneste; - @ProsessTask(TASK_TYPE_NAME_OPPR) + @ProsessTask(value = TASK_TYPE_NAME_OPPR, prioritet = 3) private static class DummyHandlerOpprett implements ProsessTaskHandler { @Override public void doTask(ProsessTaskData prosessTaskData) { @@ -61,6 +61,8 @@ void skal_opprette_task() { .medProperty(REQUIRED_PROPERTY, "Verdi") .build(); + assertThat(ptd.getPriority()).isEqualTo(TaskType.prioritet(DummyHandlerOpprett.class)); + when(prosessTaskRepositoryMock.lagre(any(ProsessTaskData.class))).thenReturn("gruppe-id"); prosessTaskTjeneste.lagreValidert(ptd); @@ -72,6 +74,7 @@ void skal_opprette_task() { verify(prosessTaskRepositoryMock, times(1)).lagre(any(ProsessTaskGruppe.class)); assertThat(dataTilPersistering.getTasks().get(0).task().taskType()).isEqualTo(TaskType.forProsessTask(DummyHandlerOpprett.class)); + assertThat(dataTilPersistering.getTasks().get(0).task().getPriority()).isEqualTo(TaskType.prioritet(DummyHandlerOpprett.class)); } @Test