Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow initialize the recipe multiple times #3696

Merged
merged 4 commits into from
Nov 21, 2023
Merged
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 @@ -70,13 +70,13 @@ public boolean causesAnotherCycle() {
private final List<Recipe> preconditions = new ArrayList<>();

public void addPrecondition(Recipe recipe) {
preconditions.add(recipe);
uninitializedPreconditions.add(recipe);
joanvr marked this conversation as resolved.
Show resolved Hide resolved
}

@JsonIgnore
private Validated<Object> validation = Validated.test("initialization",
"initialize(..) must be called on DeclarativeRecipe prior to use.",
this, r -> uninitializedRecipes.isEmpty());
private Validated<Object> validation = Validated.none();
@JsonIgnore
private Validated<Object> initValidation = null;

@Override
public Duration getEstimatedEffortPerOccurrence() {
Expand All @@ -85,11 +85,13 @@ public Duration getEstimatedEffortPerOccurrence() {
}

public void initialize(Collection<Recipe> availableRecipes, Map<String, List<Contributor>> recipeToContributors) {
initValidation = Validated.none();
initialize(uninitializedRecipes, recipeList, availableRecipes, recipeToContributors);
initialize(uninitializedPreconditions, preconditions, availableRecipes, recipeToContributors);
}

private void initialize(List<Recipe> uninitialized, List<Recipe> initialized, Collection<Recipe> availableRecipes, Map<String, List<Contributor>> recipeToContributors) {
initialized.clear();
for (int i = 0; i < uninitialized.size(); i++) {
Recipe recipe = uninitialized.get(i);
if (recipe instanceof LazyLoadedRecipe) {
Expand All @@ -103,7 +105,7 @@ private void initialize(List<Recipe> uninitialized, List<Recipe> initialized, Co
}
initialized.add(subRecipe);
} else {
validation = validation.and(
initValidation = initValidation.and(
invalid(name + ".recipeList" +
"[" + i + "] (in " + source + ")",
recipeFqn,
Expand All @@ -118,7 +120,6 @@ private void initialize(List<Recipe> uninitialized, List<Recipe> initialized, Co
initialized.add(recipe);
}
}
uninitialized.clear();
joanvr marked this conversation as resolved.
Show resolved Hide resolved
}

@Value
Expand Down Expand Up @@ -304,7 +305,11 @@ public void addValidation(Validated<Object> validated) {

@Override
public Validated<Object> validate() {
return validation;
return Validated.<Object>test("initialization",
"initialize(..) must be called on DeclarativeRecipe prior to use.",
this, r -> initValidation != null)
.and(validation)
.and(initValidation);
}

@Value
Expand Down
Loading