From 35acae742481bc9c5a98a3fae62bb5519bff2790 Mon Sep 17 00:00:00 2001 From: nvolik Date: Tue, 9 Apr 2024 13:38:28 +0200 Subject: [PATCH] Filter FRAGMENTER for interpretation tasks --- ...gistryPipelinesHistoryTrackingService.java | 25 ++++++++++++++--- ...ryPipelinesHistoryTrackingServiceTest.java | 27 ++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/registry-pipelines/src/main/java/org/gbif/registry/pipelines/DefaultRegistryPipelinesHistoryTrackingService.java b/registry-pipelines/src/main/java/org/gbif/registry/pipelines/DefaultRegistryPipelinesHistoryTrackingService.java index 52eafce1e..459a91721 100644 --- a/registry-pipelines/src/main/java/org/gbif/registry/pipelines/DefaultRegistryPipelinesHistoryTrackingService.java +++ b/registry-pipelines/src/main/java/org/gbif/registry/pipelines/DefaultRegistryPipelinesHistoryTrackingService.java @@ -46,6 +46,7 @@ import java.io.IOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.EnumMap; @@ -102,6 +103,13 @@ public class DefaultRegistryPipelinesHistoryTrackingService Collections.reverseOrder(new EndpointPriorityComparator()), EndpointCreatedComparator.INSTANCE)); + private static final Set INCLUDE_FRAGMENTER = new HashSet<>(Arrays.asList( + StepType.DWCA_TO_VERBATIM, + StepType.XML_TO_VERBATIM, + StepType.ABCD_TO_VERBATIM, + StepType.FRAGMENTER + )); + private ObjectMapper objectMapper; /** The messagePublisher can be optional. */ private final MessagePublisher publisher; @@ -430,11 +438,12 @@ public RunPipelineResponse runPipelineAttempt( .build(); } - Set finalSteps = PipelinesWorkflow.getOccurrenceWorkflow().getAllNodesFor(stepsToSend.keySet()); - // create pipelines execution PipelineExecution execution = - new PipelineExecution().setCreatedBy(user).setRerunReason(reason).setStepsToRun(finalSteps); + new PipelineExecution() + .setCreatedBy(user) + .setRerunReason(reason) + .setStepsToRun(getStepTypes(stepsToSend.keySet())); long executionKey = addPipelineExecution(process.getKey(), execution, user); @@ -471,6 +480,16 @@ public RunPipelineResponse runPipelineAttempt( return responseBuilder.build(); } + @VisibleForTesting + protected Set getStepTypes(Set stepsToSend) { + Set finalSteps = + PipelinesWorkflow.getOccurrenceWorkflow().getAllNodesFor(stepsToSend); + if (stepsToSend.stream().noneMatch(INCLUDE_FRAGMENTER::contains)) { + finalSteps.remove(StepType.FRAGMENTER); + } + return finalSteps; + } + private T createMessage(String jsonMessage, Class targetClass) throws IOException { return objectMapper.readValue(jsonMessage, targetClass); diff --git a/registry-pipelines/src/test/java/org/gbif/registry/pipelines/RegistryPipelinesHistoryTrackingServiceTest.java b/registry-pipelines/src/test/java/org/gbif/registry/pipelines/RegistryPipelinesHistoryTrackingServiceTest.java index 2f6345f3b..561a15ba3 100644 --- a/registry-pipelines/src/test/java/org/gbif/registry/pipelines/RegistryPipelinesHistoryTrackingServiceTest.java +++ b/registry-pipelines/src/test/java/org/gbif/registry/pipelines/RegistryPipelinesHistoryTrackingServiceTest.java @@ -20,6 +20,7 @@ import java.time.LocalDateTime; import java.util.Collections; +import java.util.Set; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -27,6 +28,8 @@ import org.mockito.junit.jupiter.MockitoExtension; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; @ExtendWith(MockitoExtension.class) class RegistryPipelinesHistoryTrackingServiceTest { @@ -51,8 +54,8 @@ void getLatestSuccesfulStepTest() { PipelineStep s3 = new PipelineStep() - .setType(StepType.ABCD_TO_VERBATIM) - .setStarted(LocalDateTime.now().minusMinutes(60)); + .setType(StepType.ABCD_TO_VERBATIM) + .setStarted(LocalDateTime.now().minusMinutes(60)); execution.addStep(s1); execution.addStep(s2); @@ -62,7 +65,25 @@ void getLatestSuccesfulStepTest() { PipelineProcess process = new PipelineProcess(); process.addExecution(execution); - PipelineStep step1 = trackingService.getLatestSuccessfulStep(process, StepType.ABCD_TO_VERBATIM).get(); + PipelineStep step1 = + trackingService.getLatestSuccessfulStep(process, StepType.ABCD_TO_VERBATIM).get(); assertEquals(s1, step1); } + + @Test + void getStepTypesFragmenterTest() { + Set result = + trackingService.getStepTypes(Collections.singleton(StepType.ABCD_TO_VERBATIM)); + + assertTrue(result.contains(StepType.FRAGMENTER)); + } + + @Test + void getStepTypesTest() { + + Set result = + trackingService.getStepTypes(Collections.singleton(StepType.VERBATIM_TO_INTERPRETED)); + + assertFalse(result.contains(StepType.FRAGMENTER)); + } }