Skip to content

Customizing Flows

Gal Koren edited this page Nov 12, 2020 · 1 revision

When we defined the AdPersistence class, we could have defined as many flows we want for our Ad entity. Nobody told us to have a single flow. However, defining many flows is a burden. It is more reasonable that for some scenario, you want to run the flow without validators, or with validators but without writing changes to the database, etc.

The ChangeFlowConfig.Builder class provides such methods.
Let's add another update method to our persistence class that accepts a flow.

class AdPersitence {

    // another overload to the original update method
    public UpdateResult<AdEntity, AdEntity.Id> update(Collection<UpdateAdCommand> commands, Consumer<ChangeFlowConfig.Builder<AdEntity>> flowModifeir) {
        var flow = flowBuilder();
        flowModifier.accept(flow);
        return new persistenceLayer.create(commands, flow.build());
    }

}

And now we can run commands like this:

adPersistence.update(commands, flow -> flow.withoutValidators());

adPersistence.update(commands, flow -> flow.withoutOutputGenerators());

adPersistence.update(commands, flow -> flow.withoutLabeledElements(MyLabels.BLA_BLA_BLA));

The 3rd example assumes you added some component to the flow using a Label and now you want to disable them.