private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createStartReviewTransitionActionPair(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, START_REVIEW.getId(), "StartReview", "Starts review state"), context -> { try { transitionToStartReview(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createStartReviewTransitionActionPair(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, START_REVIEW.getId(), "StartReview", "Starts review state"), context -> { try { transitionToStartReview(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createArchiveTransitionAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, ARCHIVED.getId(), "Archive", "Archives the schema version"), context -> { try { transitionToArchiveState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createEnableTransitionAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, ENABLED.getId(), "Enable", "Enables the schema version"), context -> { try { transitionToEnableState(context); } catch (SchemaNotFoundException | IncompatibleSchemaException | SchemaBranchNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createDisableAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, DISABLED.getId(), "Disable", "Disables the schema version"), context -> { try { transitionToDisableState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createDisableAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, DISABLED.getId(), "Disable", "Disables the schema version"), context -> { try { transitionToDisableState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createArchiveTransitionAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, ARCHIVED.getId(), "Archive", "Archives the schema version"), context -> { try { transitionToArchiveState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createEnableTransitionAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, ENABLED.getId(), "Enable", "Enables the schema version"), context -> { try { transitionToEnableState(context); } catch (SchemaNotFoundException | IncompatibleSchemaException | SchemaBranchNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createDeleteTransitionActionPair( Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, DELETED.getId(), "Delete", "Deletes the schema version"), context -> { try { transitionToDeleteState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createDeleteTransitionActionPair( Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, DELETED.getId(), "Delete", "Deletes the schema version"), context -> { try { transitionToDeleteState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private InReviewState(final SchemaVersionLifecycleState targetState) { super("InReview", (byte) 32, "Finish the schema version." ); SchemaVersionLifecycleStateTransition stateTransition = new SchemaVersionLifecycleStateTransition(getId(), targetState.getId(), "FinishReview", "Finish schema review process"); SchemaVersionLifecycleStateAction stateAction = context -> { context.setState(targetState); try { context.updateSchemaVersionState(); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }; transitionActionPair = Collections.singletonList(Pair.of(stateTransition, stateAction)); }
private InReviewState(final SchemaVersionLifecycleState targetState) { super("InReview", (byte) 32, "Finish the schema version." ); SchemaVersionLifecycleStateTransition stateTransition = new SchemaVersionLifecycleStateTransition(getId(), targetState.getId(), "FinishReview", "Finish schema review process"); SchemaVersionLifecycleStateAction stateAction = context -> { context.setState(targetState); try { context.updateSchemaVersionState(); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }; transitionActionPair = Collections.singletonList(Pair.of(stateTransition, stateAction)); }
public void registerReviewedState(SchemaVersionLifecycleStateMachine.Builder builder) { builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getId(), SchemaVersionLifecycleStates.REVIEWED.getId(), SchemaVersionLifecycleStates.REVIEWED.getName(), SchemaVersionLifecycleStates.REVIEWED.getDescription()), (SchemaVersionLifecycleContext context) -> { // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database LOG.debug("Making a transition from 'TECHNICAL LEAD REVIEW' to 'REVIEWED' state"); transitionToState(context, SchemaVersionLifecycleStates.REVIEWED); }); }
public void registerChangesRequiredState(SchemaVersionLifecycleStateMachine.Builder builder) { builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.PEER_REVIEW_STATE.getId(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getId(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getName(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getDescription()), (SchemaVersionLifecycleContext context) -> { // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database LOG.debug("Making a transition from 'PEER REVIEW' to 'REJECTED' state"); transitionToState(context, SchemaVersionLifecycleStates.CHANGES_REQUIRED); }); builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getId(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getId(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getName(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getDescription()), (SchemaVersionLifecycleContext context) -> { // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database LOG.debug("Making a transition from 'TECHNICAL LEAD REVIEW' to 'REJECTED' state"); transitionToState(context, SchemaVersionLifecycleStates.CHANGES_REQUIRED); }); }
public void registerTechnicalLeadReviewState(SchemaVersionLifecycleStateMachine.Builder builder) { builder.register(CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE); builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.PEER_REVIEW_STATE.getId(), CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getId(), CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getName(), CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getDescription()), (SchemaVersionLifecycleContext context) -> { // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database LOG.debug("Making a transition from 'PEER REVIEW' to 'TECHNICAL LEAD REVIEW' state"); transitionToState(context, CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE); }); }
public void registerRejectedState(SchemaVersionLifecycleStateMachine.Builder builder) { builder.register(CustomReviewCycleStates.REJECTED_REVIEW_STATE); builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.PEER_REVIEW_STATE.getId(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getId(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getName(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getDescription()), (SchemaVersionLifecycleContext context) -> { // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database LOG.debug("Making a transition from 'PEER REVIEW' to 'REJECTED' state"); transitionToState(context, CustomReviewCycleStates.REJECTED_REVIEW_STATE); }); builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getId(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getId(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getName(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getDescription()), (SchemaVersionLifecycleContext context) -> { // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database LOG.debug("Making a transition from 'TECHNICAL LEAD REVIEW' to 'REJECTED' state"); transitionToState(context, CustomReviewCycleStates.REJECTED_REVIEW_STATE); }); }
public void executeState(Long schemaVersionId, Byte targetState, byte[] transitionDetails) throws SchemaLifecycleException, SchemaNotFoundException { ImmutablePair<SchemaVersionLifecycleContext, SchemaVersionLifecycleState> schemaLifeCycleContextAndState = createSchemaVersionLifeCycleContextAndState(schemaVersionId); SchemaVersionLifecycleContext schemaVersionLifecycleContext = schemaLifeCycleContextAndState.getLeft(); SchemaVersionLifecycleState currentState = schemaLifeCycleContextAndState.getRight(); schemaVersionLifecycleContext.setState(currentState); schemaVersionLifecycleContext.setDetails(transitionDetails); SchemaVersionLifecycleStateTransition transition = new SchemaVersionLifecycleStateTransition(currentState.getId(), targetState); SchemaVersionLifecycleStateAction action = schemaVersionLifecycleContext.getSchemaLifeCycleStatesMachine() .getTransitions() .get(transition); try { List<SchemaVersionLifecycleStateTransitionListener> listeners = schemaVersionLifecycleContext.getSchemaLifeCycleStatesMachine() .getListeners() .getOrDefault(transition, DEFAULT_LISTENERS); listeners.stream().forEach(listener -> listener.preStateTransition(schemaVersionLifecycleContext)); action.execute(schemaVersionLifecycleContext); listeners.stream().forEach(listener -> listener.postStateTransition(schemaVersionLifecycleContext)); } catch (SchemaLifecycleException e) { Throwable cause = e.getCause(); if (cause != null && cause instanceof SchemaNotFoundException) { throw (SchemaNotFoundException) cause; } throw e; } }