private ImmutablePair<SchemaVersionLifecycleContext, SchemaVersionLifecycleState>
createSchemaVersionLifeCycleContextAndState(Long schemaVersionId) throws SchemaNotFoundException {
Collection<SchemaVersionStateStorable> schemaVersionStates =
storageManager.find(SchemaVersionStateStorable.NAME_SPACE,
Collections.singletonList(new QueryParam(SchemaVersionStateStorable.SCHEMA_VERSION_ID,
schemaVersionId.toString())),
Collections.singletonList(OrderByField.of(SchemaVersionStateStorable.SEQUENCE, true)));
if (schemaVersionStates.isEmpty()) {
throw new SchemaNotFoundException("No schema versions found with id " + schemaVersionId);
}
SchemaVersionStateStorable stateStorable = schemaVersionStates.iterator().next();
SchemaVersionLifecycleState schemaVersionLifecycleState = schemaVersionLifecycleStateMachine.getStates()
.get(stateStorable.getStateId());
SchemaVersionService schemaVersionService = createSchemaVersionService();
SchemaVersionLifecycleContext context = new SchemaVersionLifecycleContext(stateStorable.getSchemaVersionId(),
stateStorable.getSequence(),
schemaVersionService,
schemaVersionLifecycleStateMachine,
customSchemaStateExecutor);
return new ImmutablePair<>(context, schemaVersionLifecycleState);
}