Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ gem 'good_job', '~> 4.0'
gem 'rotp'

gem 'grpc', '~> 1.67'
gem 'tucana', '0.0.41'
gem 'tucana', '0.0.42'

gem 'code0-identities', '~> 0.0.2'

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ GEM
thor (1.4.0)
timeout (0.4.4)
tsort (0.2.0)
tucana (0.0.41)
tucana (0.0.42)
grpc (~> 1.64)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -430,7 +430,7 @@ DEPENDENCIES
simplecov (~> 0.22.0)
simplecov-cobertura (~> 3.0)
test-prof (~> 1.0)
tucana (= 0.0.41)
tucana (= 0.0.42)
tzinfo-data

RUBY VERSION
Expand Down
3 changes: 0 additions & 3 deletions app/grpc/data_type_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

class DataTypeHandler < Tucana::Sagittarius::DataTypeService::Service
include GrpcHandler
include Code0::ZeroTrack::Loggable

def update(request, _call)
current_runtime = Runtime.find(Code0::ZeroTrack::Context.current[:runtime][:id])

response = Runtimes::DataTypes::UpdateService.new(current_runtime, request.data_types).execute

logger.info(message: 'Data types updated', runtime_id: current_runtime.id, response: response.to_h)

Tucana::Sagittarius::DataTypeUpdateResponse.new(success: response.success?)
end
end
1 change: 1 addition & 0 deletions app/services/error_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def self.error_codes
no_datatype_identifier_for_generic_key: { description: 'No data type identifier could be found for the given generic key' },
invalid_generic_mapper: { description: 'The generic mapper is invalid because of active model errors' },
invalid_data_type: { description: 'The data type is invalid because of active model errors' },
invalid_flow_type: { description: 'The flow type is invalid because of active model errors' },

primary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },
secondary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },
Expand Down
18 changes: 14 additions & 4 deletions app/services/runtimes/data_types/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Runtimes
module DataTypes
class UpdateService
include Sagittarius::Database::Transactional
include Code0::ZeroTrack::Loggable

attr_reader :current_runtime, :data_types

Expand All @@ -18,14 +19,22 @@ def execute
DataType.where(runtime: current_runtime).update_all(removed_at: Time.zone.now)
# rubocop:enable Rails/SkipsModelValidations
sort_data_types(data_types).each do |data_type|
unless update_datatype(data_type, t)
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update data type',
error_code: :invalid_data_type, details: data_type.errors)
end
db_data_type = update_datatype(data_type, t)
next if db_data_type.persisted?

logger.error(message: 'Failed to update data type',
runtime_id: current_runtime.id,
data_type_identifier: data_type.identifier,
errors: db_data_type.errors.full_messages)

t.rollback_and_return! ServiceResponse.error(message: 'Failed to update data type',
error_code: :invalid_data_type, details: db_data_type.errors)
end

UpdateRuntimeCompatibilityJob.perform_later({ runtime_id: current_runtime.id })

logger.info(message: 'Updated data types for runtime', runtime_id: current_runtime.id)

ServiceResponse.success(message: 'Updated data types', payload: data_types)
end
end
Expand Down Expand Up @@ -80,6 +89,7 @@ def update_datatype(data_type, t)
db_object.generic_keys = data_type.generic_keys.to_a
db_object.version = "#{data_type.version.major}.#{data_type.version.minor}.#{data_type.version.patch}"
db_object.save
db_object
end

def find_data_type_identifier(parent_type_rule_config, t)
Expand Down
21 changes: 17 additions & 4 deletions app/services/runtimes/flow_types/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Runtimes
module FlowTypes
class UpdateService
include Sagittarius::Database::Transactional
include Code0::ZeroTrack::Loggable

attr_reader :current_runtime, :flow_types

Expand All @@ -18,14 +19,25 @@ def execute
FlowType.where(runtime: current_runtime).update_all(removed_at: Time.zone.now)
# rubocop:enable Rails/SkipsModelValidations
flow_types.each do |flow_type|
unless update_flowtype(flow_type, t)
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update flow type',
payload: flow_type.errors)
end
db_flow_type = update_flowtype(flow_type, t)
next if db_flow_type.persisted?

logger.error(
message: 'Failed to update flow type',
runtime_id: current_runtime.id,
flow_type_identifier: flow_type.identifier,
errors: db_flow_type.errors.full_messages
)

t.rollback_and_return! ServiceResponse.error(message: 'Failed to update flow type',
error_code: :invalid_flow_type,
details: db_flow_type.errors)
end

UpdateRuntimeCompatibilityJob.perform_later({ runtime_id: current_runtime.id })

logger.info(message: 'Updated flow types for runtime', runtime_id: current_runtime.id)

ServiceResponse.success(message: 'Updated data types', payload: flow_types)
end
end
Expand All @@ -49,6 +61,7 @@ def update_flowtype(flow_type, t)
db_object.aliases = update_translations(flow_type.alias, db_object.aliases)
db_object.version = "#{flow_type.version.major}.#{flow_type.version.minor}.#{flow_type.version.patch}"
db_object.save
db_object
end

def find_datatype(identifier, t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Runtimes
module RuntimeFunctionDefinitions
class UpdateService
include Sagittarius::Database::Transactional
include Code0::ZeroTrack::Loggable

attr_reader :current_runtime, :runtime_function_definitions

Expand All @@ -19,14 +20,22 @@ def execute
# rubocop:enable Rails/SkipsModelValidations
runtime_function_definitions.each do |runtime_function_definition|
response = update_runtime_function_definition(runtime_function_definition, t)
unless response.persisted?
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update runtime function definition',
payload: response.errors)
end
next if response.persisted?

logger.error(message: 'Failed to update runtime function definition',
runtime_id: current_runtime.id,
definition_identifier: runtime_function_definition.identifier,
errors: response.errors.full_messages)

t.rollback_and_return! ServiceResponse.error(message: 'Failed to update runtime function definition',
error_code: :invalid_runtime_function_definition,
details: response.errors)
end

UpdateRuntimeCompatibilityJob.perform_later({ runtime_id: current_runtime.id })

logger.info(message: 'Updated runtime function definitions for runtime', runtime_id: current_runtime.id)

ServiceResponse.success(message: 'Updated runtime function definition', payload: runtime_function_definitions)
end
end
Expand Down
1 change: 1 addition & 0 deletions docs/graphql/enum/errorcodeenum.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Represents the available error responses
| `INVALID_EXTERNAL_IDENTITY` | This external identity is invalid |
| `INVALID_FLOW` | The flow is invalid because of active model errors |
| `INVALID_FLOW_SETTING` | The flow setting is invalid because of active model errors |
| `INVALID_FLOW_TYPE` | The flow type is invalid because of active model errors |
| `INVALID_GENERIC_MAPPER` | The generic mapper is invalid because of active model errors |
| `INVALID_LOGIN_DATA` | Invalid login data provided |
| `INVALID_NAMESPACE_LICENSE` | The namespace license is invalid because of active model errors |
Expand Down
9 changes: 6 additions & 3 deletions spec/requests/grpc/sagittarius/data_type_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
{ code: 'de_DE', content: 'Zahl: ${0}' }
],
rules: [
Tucana::Shared::DefinitionDataTypeRule.create(:number_range, { from: 1, to: 10 })
Tucana::Shared::DefinitionDataTypeRule.create(
:contains_type,
{ data_type_identifier: { generic_key: 'T' } }
)
],
version: {
major: 0,
Expand Down Expand Up @@ -58,8 +61,8 @@
expect(data_type.display_messages.first.code).to eq('de_DE')
expect(data_type.display_messages.first.content).to eq('Zahl: ${0}')
expect(data_type.rules.count).to eq(1)
expect(data_type.rules.first.variant).to eq('number_range')
expect(data_type.rules.first.config).to eq({ 'from' => 1, 'to' => 10, 'steps' => 0 })
expect(data_type.rules.first.variant).to eq('contains_type')
expect(data_type.rules.first.config).to eq({ 'data_type_identifier' => { 'generic_key' => 'T' } })
end

context 'with dependent data types' do
Expand Down