Skip to content

Commit 1c0f27f

Browse files
committed
feat: add retrieval of condition result and DR by name
Signed-off-by: Chris Laprun <[email protected]>
1 parent bf82f42 commit 1c0f27f

File tree

1 file changed

+38
-0
lines changed
  • operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow

1 file changed

+38
-0
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,40 @@ protected Map<DependentResource, Detail<?>> results() {
3434
return results;
3535
}
3636

37+
/**
38+
* Retrieves the {@link DependentResource} associated with the specified name if it exists,
39+
* {@link Optional#empty()} otherwise.
40+
*
41+
* @param name the name of the {@link DependentResource} to retrieve
42+
* @return the {@link DependentResource} associated with the specified name if it exists,
43+
* {@link Optional#empty()} otherwise
44+
*/
45+
public Optional<DependentResource> getDependentResourceByName(String name) {
46+
if (name == null || name.isEmpty()) {
47+
return Optional.empty();
48+
}
49+
return results.keySet().stream().filter(dr -> dr.name().equals(name)).findFirst();
50+
}
51+
52+
/**
53+
* Retrieves the optional result of the condition with the specified type for the specified
54+
* dependent resource.
55+
*
56+
* @param <T> the expected result type of the condition
57+
* @param dependentResourceName the dependent resource for which we want to retrieve a condition
58+
* result
59+
* @param conditionType the condition type which result we're interested in
60+
* @param expectedResultType the expected result type of the condition
61+
* @return the dependent condition result if it exists or {@link Optional#empty()} otherwise
62+
* @throws IllegalArgumentException if a result exists but is not of the expected type
63+
*/
64+
public <T> Optional<T> getDependentConditionResult(String dependentResourceName,
65+
Condition.Type conditionType, Class<T> expectedResultType) {
66+
return getDependentConditionResult(
67+
getDependentResourceByName(dependentResourceName).orElse(null), conditionType,
68+
expectedResultType);
69+
}
70+
3771
/**
3872
* Retrieves the optional result of the condition with the specified type for the specified
3973
* dependent resource.
@@ -48,6 +82,10 @@ protected Map<DependentResource, Detail<?>> results() {
4882
*/
4983
public <T> Optional<T> getDependentConditionResult(DependentResource dependentResource,
5084
Condition.Type conditionType, Class<T> expectedResultType) {
85+
if (dependentResource == null) {
86+
return Optional.empty();
87+
}
88+
5189
final var result = new Object[1];
5290
try {
5391
return Optional.ofNullable(results().get(dependentResource))

0 commit comments

Comments
 (0)