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

Initial API change to strongly type the next state input #223

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
53 changes: 26 additions & 27 deletions src/main/java/io/iworkflow/core/StateDecision.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ public static StateDecision forceFailWorkflow() {
}


public static StateDecision forceCompleteIfInternalChannelEmptyOrElse(final String internalChannelName, final Class<? extends WorkflowState> orElseStateClass) {
public static <I> StateDecision forceCompleteIfInternalChannelEmptyOrElse(final String internalChannelName, final Class<? extends WorkflowState<? extends I>> orElseStateClass) {
return forceCompleteIfInternalChannelEmptyOrElse(internalChannelName, orElseStateClass, null);
}

public static StateDecision forceCompleteIfInternalChannelEmptyOrElse(final String internalChannelName, final Class<? extends WorkflowState> orElseStateClass, final Object stateInput) {
public static <I> StateDecision forceCompleteIfInternalChannelEmptyOrElse(final String internalChannelName, final Class<? extends WorkflowState<? extends I>> orElseStateClass, final I stateInput) {
return forceCompleteIfInternalChannelEmptyOrElse(null, internalChannelName, StateMovement.create(orElseStateClass, stateInput));
}

public static StateDecision forceCompleteIfInternalChannelEmptyOrElse(final Object completionOutput, final String internalChannelName, final Class<? extends WorkflowState> orElseStateClass) {
public static <I> StateDecision forceCompleteIfInternalChannelEmptyOrElse(final Object completionOutput, final String internalChannelName, final Class<? extends WorkflowState<? extends I>> orElseStateClass) {
return forceCompleteIfInternalChannelEmptyOrElse(completionOutput, internalChannelName, orElseStateClass, null);
}

public static StateDecision forceCompleteIfInternalChannelEmptyOrElse(final Object completionOutput, final String internalChannelName, final Class<? extends WorkflowState> orElseStateClass, final Object stateInput) {
public static <I> StateDecision forceCompleteIfInternalChannelEmptyOrElse(final Object completionOutput, final String internalChannelName, final Class<? extends WorkflowState<? extends I>> orElseStateClass, final I stateInput) {
return forceCompleteIfInternalChannelEmptyOrElse(completionOutput, internalChannelName, StateMovement.create(orElseStateClass, stateInput));
}

Expand Down Expand Up @@ -107,19 +107,19 @@ public static StateDecision forceCompleteIfInternalChannelEmptyOrElse(final Obje
.build();
}

public static StateDecision forceCompleteIfSignalChannelEmptyOrElse(final String signalChannelName, final Class<? extends WorkflowState> orElseStateClass) {
public static <I> StateDecision forceCompleteIfSignalChannelEmptyOrElse(final String signalChannelName, final Class<? extends WorkflowState<? extends I>> orElseStateClass) {
return forceCompleteIfSignalChannelEmptyOrElse(signalChannelName, orElseStateClass, null);
}

public static StateDecision forceCompleteIfSignalChannelEmptyOrElse(final String signalChannelName, final Class<? extends WorkflowState> orElseStateClass, final Object stateInput) {
public static <I> StateDecision forceCompleteIfSignalChannelEmptyOrElse(final String signalChannelName, final Class<? extends WorkflowState<? extends I>> orElseStateClass, final I stateInput) {
return forceCompleteIfSignalChannelEmptyOrElse(null, signalChannelName, StateMovement.create(orElseStateClass, stateInput));
}

public static StateDecision forceCompleteIfSignalChannelEmptyOrElse(final Object completionOutput, final String signalChannelName, final Class<? extends WorkflowState> orElseStateClass) {
public static <I> StateDecision forceCompleteIfSignalChannelEmptyOrElse(final Object completionOutput, final String signalChannelName, final Class<? extends WorkflowState<? extends I>> orElseStateClass) {
return forceCompleteIfSignalChannelEmptyOrElse(completionOutput, signalChannelName, orElseStateClass, null);
}

public static StateDecision forceCompleteIfSignalChannelEmptyOrElse(final Object completionOutput, final String signalChannelName, final Class<? extends WorkflowState> orElseStateClass, final Object stateInput) {
public static <I> StateDecision forceCompleteIfSignalChannelEmptyOrElse(final Object completionOutput, final String signalChannelName, final Class<? extends WorkflowState<? extends I>> orElseStateClass, final I stateInput) {
return forceCompleteIfSignalChannelEmptyOrElse(completionOutput, signalChannelName, StateMovement.create(orElseStateClass, stateInput));
}

Expand Down Expand Up @@ -147,59 +147,57 @@ public static StateDecision forceCompleteIfSignalChannelEmptyOrElse(final Object
}

/**
*
* @param stateClass required
* @param stateInput optional, can be null
* @param stateOptionsOverride optional, can be null. It is used to override the defined one in the State class
* @param stateClass required
* @param stateInput optional, can be null
* @param stateOptionsOverride optional, can be null. It is used to override the defined one in the State class
* @return state decision
*/
public static StateDecision singleNextState(final Class<? extends WorkflowState> stateClass, final Object stateInput, final WorkflowStateOptions stateOptionsOverride) {
public static <I> StateDecision singleNextState(final Class<? extends WorkflowState<? extends I>> stateClass, final I stateInput, final WorkflowStateOptions stateOptionsOverride) {
return singleNextState(stateClass.getSimpleName(), stateInput, stateOptionsOverride);
}

/**
*
* @param stateClass required
* @param stateInput optional, can be null
* @param stateClass required
* @param stateInput optional, can be null
* @return state decision
*/
public static StateDecision singleNextState(final Class<? extends WorkflowState> stateClass, final Object stateInput) {
public static <I> StateDecision singleNextState(final Class<? extends WorkflowState<? extends I>> stateClass, final I stateInput) {
return singleNextState(stateClass, stateInput, null);
}

/**
*
* @param stateClass required
* @param stateClass required
* @return state decision
*/
public static StateDecision singleNextState(final Class<? extends WorkflowState> stateClass) {
public static <I> StateDecision singleNextState(final Class<? extends WorkflowState<? extends I>> stateClass) {
return singleNextState(stateClass, null, null);
}

/**
* use the other one with WorkflowState class param if the stateId is provided by default, to make your code cleaner
* @param stateId required. StateId of next state
* @param stateInput optional, can be null. Input for next state
* @param stateOptionsOverride optional, can be null. It is used to override the defined one in the State class
*
* @param stateId required. StateId of next state
* @param stateInput optional, can be null. Input for next state
* @param stateOptionsOverride optional, can be null. It is used to override the defined one in the State class
* @return state decision
*/
public static StateDecision singleNextState(final String stateId, final Object stateInput, final WorkflowStateOptions stateOptionsOverride) {
public static <I> StateDecision singleNextState(final String stateId, final I stateInput, final WorkflowStateOptions stateOptionsOverride) {
return ImmutableStateDecision.builder().nextStates(Arrays.asList(
StateMovement.create(stateId, stateInput, stateOptionsOverride)
)).build();
}

/**
* use the other one with WorkflowState class param if the stateId is provided by default, to make your code cleaner
* @param stateId stateId of next state
*
* @param stateId stateId of next state
* @return state decision
*/
public static StateDecision singleNextState(final String stateId) {
return singleNextState(stateId, null, null);
}

/**
*
* @param stateMovements required
* @return state decision
*/
Expand All @@ -208,7 +206,6 @@ public static StateDecision multiNextStates(final List<StateMovement> stateMovem
}

/**
*
* @param stateMovements required
* @return state decision
*/
Expand All @@ -219,6 +216,7 @@ public static StateDecision multiNextStates(final StateMovement... stateMovement
/**
* use the other one with WorkflowState class param if the stateId is provided by default, to make your code cleaner
* or use other ones with a list of StateMovement to enable the WorkflowStateOptions overriding
*
* @param stateIds stateIds of next states
* @return state decision
*/
Expand All @@ -232,6 +230,7 @@ public static StateDecision multiNextStates(final String... stateIds) {

/**
* use other ones with a list of StateMovement to enable the WorkflowStateOptions overriding
*
* @param states required
* @return state decision
*/
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/iworkflow/core/StateMovement.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static StateMovement forceFailWorkflow(final Object output) {
* @param stateOptionsOverride optional, can be null. It is used to override the defined one in the State class
* @return state movement
*/
public static StateMovement create(final Class<? extends WorkflowState> stateClass, final Object stateInput, final WorkflowStateOptions stateOptionsOverride) {
public static <I> StateMovement create(final Class<? extends WorkflowState<? extends I>> stateClass, final I stateInput, final WorkflowStateOptions stateOptionsOverride) {
return create(stateClass.getSimpleName(), stateInput, stateOptionsOverride);
}

Expand All @@ -69,7 +69,7 @@ public static StateMovement create(final Class<? extends WorkflowState> stateCla
* @param stateInput optional, can be null
* @return state movement
*/
public static StateMovement create(final Class<? extends WorkflowState> stateClass, final Object stateInput) {
public static <I> StateMovement create(final Class<? extends WorkflowState<? extends I>> stateClass, final I stateInput) {
return create(stateClass, stateInput, null);
}

Expand All @@ -78,7 +78,7 @@ public static StateMovement create(final Class<? extends WorkflowState> stateCla
* @param stateClass required
* @return state movement
*/
public static StateMovement create(final Class<? extends WorkflowState> stateClass) {
public static <I> StateMovement create(final Class<? extends WorkflowState<? extends I>> stateClass) {
return create(stateClass, null, null);
}

Expand All @@ -89,7 +89,7 @@ public static StateMovement create(final Class<? extends WorkflowState> stateCla
* @param stateOptionsOverride optional, can be null. It is used to override the defined one in the State class
* @return state movement
*/
public static StateMovement create(final String stateId, final Object stateInput, final WorkflowStateOptions stateOptionsOverride) {
public static <I> StateMovement create(final String stateId, final I stateInput, final WorkflowStateOptions stateOptionsOverride) {
if (stateId.startsWith(RESERVED_STATE_ID_PREFIX)) {
throw new WorkflowDefinitionException("Cannot use reserved stateId prefix for your stateId");
}
Expand Down
Loading