Skip to content

Commit

Permalink
Filter FRAGMENTER for interpretation tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
muttcg committed Apr 9, 2024
1 parent 5d73f3b commit 35acae7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,6 +103,13 @@ public class DefaultRegistryPipelinesHistoryTrackingService
Collections.reverseOrder(new EndpointPriorityComparator()),
EndpointCreatedComparator.INSTANCE));

private static final Set<StepType> 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;
Expand Down Expand Up @@ -430,11 +438,12 @@ public RunPipelineResponse runPipelineAttempt(
.build();
}

Set<StepType> 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);

Expand Down Expand Up @@ -471,6 +480,16 @@ public RunPipelineResponse runPipelineAttempt(
return responseBuilder.build();
}

@VisibleForTesting
protected Set<StepType> getStepTypes(Set<StepType> stepsToSend) {
Set<StepType> finalSteps =
PipelinesWorkflow.getOccurrenceWorkflow().getAllNodesFor(stepsToSend);
if (stepsToSend.stream().noneMatch(INCLUDE_FRAGMENTER::contains)) {
finalSteps.remove(StepType.FRAGMENTER);
}
return finalSteps;
}

private <T extends PipelineBasedMessage> T createMessage(String jsonMessage, Class<T> targetClass)
throws IOException {
return objectMapper.readValue(jsonMessage, targetClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@

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;
import org.mockito.InjectMocks;
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 {
Expand All @@ -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);
Expand All @@ -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<StepType> result =
trackingService.getStepTypes(Collections.singleton(StepType.ABCD_TO_VERBATIM));

assertTrue(result.contains(StepType.FRAGMENTER));
}

@Test
void getStepTypesTest() {

Set<StepType> result =
trackingService.getStepTypes(Collections.singleton(StepType.VERBATIM_TO_INTERPRETED));

assertFalse(result.contains(StepType.FRAGMENTER));
}
}

0 comments on commit 35acae7

Please sign in to comment.