Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Fix: #3876 Update task utils: removeIterationFromTaskRefName #3878

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package com.netflix.conductor.common.utils;

import java.util.Arrays;

public class TaskUtils {

private static final String LOOP_TASK_DELIMITER = "__";
Expand All @@ -26,6 +28,25 @@ public static String getLoopOverTaskRefNameSuffix(int iteration) {

public static String removeIterationFromTaskRefName(String referenceTaskName) {
String[] tokens = referenceTaskName.split(TaskUtils.LOOP_TASK_DELIMITER);
return tokens.length > 0 ? tokens[0] : referenceTaskName;
int length = tokens.length;

// Check if the last element is an integer
if (length > 1 && isInteger(tokens[length - 1])) {
// Join all elements except the last one
return String.join(TaskUtils.LOOP_TASK_DELIMITER, Arrays.copyOf(tokens, length - 1));
} else {
// No integer at the end, return the original string
return referenceTaskName;
}
}

// Helper method to check if a string is an integer
private static boolean isInteger(String s) {
try {
Integer.parseInt(s);
return true;
} catch (NumberFormatException e) {
return false;
}
}
}