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: 2 additions & 0 deletions app/models/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Runtime < ApplicationRecord
has_many :data_type_identifiers, inverse_of: :runtime
has_many :generic_mappers, inverse_of: :runtime

has_many :runtime_function_definitions, inverse_of: :runtime

has_many :flow_types, inverse_of: :runtime

validates :name, presence: true,
Expand Down
2 changes: 2 additions & 0 deletions app/services/error_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ 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' },
data_type_identifier_not_found: { description: 'The data type identifier with the given identifier was not found' },
data_type_not_found: { description: 'The data type with the given identifier was not found' },
invalid_flow_type: { description: 'The flow type is invalid because of active model errors' },

primary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },
Expand Down
51 changes: 41 additions & 10 deletions app/services/namespaces/projects/flows/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ def execute
return ServiceResponse.error(message: 'Missing permission', error_code: :missing_permission)
end

if namespace_project.primary_runtime.nil?
return ServiceResponse.error(
message: 'Project has no primary runtime',
error_code: :no_primary_runtime
)
end

transactional do |t|
settings = []
if params.key?(:flow_settings)
Expand Down Expand Up @@ -83,7 +90,9 @@ def execute
def create_node_function(node_function_id, input_nodes, t)
node_function = input_nodes.find { |n| n.id == node_function_id }

runtime_function_definition = SagittariusSchema.object_from_id(node_function.runtime_function_id)
runtime_function_definition = namespace_project.primary_runtime.runtime_function_definitions.find_by(
id: node_function.runtime_function_id.model_id
)
if runtime_function_definition.nil?
t.rollback_and_return! ServiceResponse.error(
message: 'Invalid runtime function id',
Expand All @@ -93,7 +102,9 @@ def create_node_function(node_function_id, input_nodes, t)

params = []
node_function.parameters.each do |parameter|
runtime_parameter = SagittariusSchema.object_from_id(parameter.runtime_parameter_definition_id)
runtime_parameter = runtime_function_definition.parameters.find_by(
id: parameter.runtime_parameter_definition_id.model_id
)
if runtime_parameter.nil?
t.rollback_and_return! ServiceResponse.error(
message: 'Invalid runtime parameter id',
Expand All @@ -116,11 +127,12 @@ def create_node_function(node_function_id, input_nodes, t)
next
end

reference_value = SagittariusSchema.object_from_id(
parameter.value.reference_value.node_function_id
referenced_node = NodeFunction.joins(:runtime_function).find_by(
id: parameter.value.reference_value.node_function_id.model_id,
runtime_function_definitions: { runtime_id: namespace_project.primary_runtime.id }
)

if reference_value.nil?
if referenced_node.nil?
t.rollback_and_return! ServiceResponse.error(
message: 'Referenced node function not found',
error_code: :referenced_value_not_found
Expand All @@ -130,8 +142,8 @@ def create_node_function(node_function_id, input_nodes, t)
params << NodeParameter.create(
runtime_parameter: runtime_parameter,
reference_value: ReferenceValue.create(
node_function: reference_value,
data_type_identifier: get_data_type_identifier(parameter.value.reference_value.data_type_identifier),
node_function: referenced_node,
data_type_identifier: get_data_type_identifier(parameter.value.reference_value.data_type_identifier, t),
depth: parameter.value.reference_value.depth,
node: parameter.value.reference_value.node,
scope: parameter.value.reference_value.scope,
Expand All @@ -158,11 +170,21 @@ def create_node_function(node_function_id, input_nodes, t)

private

def get_data_type_identifier(identifier)
def get_data_type_identifier(identifier, t)
return DataTypeIdentifier.create(generic_key: identifier.generic_key) if identifier.generic_key.present?

if identifier.generic_type.present?
data_type = SagittariusSchema.object_from_id(identifier.generic_type.data_type_id)
data_type = namespace_project.primary_runtime.data_types.find_by(
id: identifier.generic_type.data_type_id.model_id
)

if data_type.nil?
t.rollback_and_return! ServiceResponse.error(
message: 'Data type not found',
error_code: :data_type_not_found
)
end

mappers = identifier.generic_type.mappers.map do |mapper|
GenericMapper.create(
generic_mapper_id: mapper.generic_mapper_id,
Expand All @@ -175,7 +197,16 @@ def get_data_type_identifier(identifier)

return if identifier.data_type_id.blank?

DataTypeIdentifier.create(data_type: SagittariusSchema.object_from_id(identifier.data_type_id))
data_type = namespace_project.primary_runtime.data_types.find_by(id: identifier.data_type_id.model_id)

if data_type.nil?
t.rollback_and_return! ServiceResponse.error(
message: 'Data type not found',
error_code: :data_type_not_found
)
end

DataTypeIdentifier.create(data_type: data_type)
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions docs/graphql/enum/errorcodeenum.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Represents the available error responses
| `CANNOT_MODIFY_OWN_ADMIN` | Users cannot modify their own admin status |
| `CANNOT_REMOVE_LAST_ADMINISTRATOR` | This action would remove the last administrator |
| `CANNOT_REMOVE_LAST_ADMIN_ABILITY` | This action would remove the last administrative ability |
| `DATA_TYPE_IDENTIFIER_NOT_FOUND` | The data type identifier with the given identifier was not found |
| `DATA_TYPE_NOT_FOUND` | The data type with the given identifier was not found |
| `EMAIL_VERIFICATION_SEND_FAILED` | Failed to send the email verification |
| `EXTERNAL_IDENTITY_DOES_NOT_EXIST` | This external identity does not exist |
| `FAILED_TO_INVALIDATE_OLD_BACKUP_CODES` | The old backup codes could not be deleted |
Expand Down