Skip to content

Commit 457223f

Browse files
committed
Enhance flow creation and validation process with new data types and settings
1 parent b03d787 commit 457223f

File tree

11 files changed

+539
-34
lines changed

11 files changed

+539
-34
lines changed

app/graphql/mutations/namespaces/projects/flows/create.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ class Create < BaseMutation
1515
argument :flow, Types::Input::FlowInputType
1616

1717
def resolve(project_id:, flow:, **params)
18-
create_params = {}
19-
20-
2118
project = SagittariusSchema.object_from_id(project_id)
2219

2320
if project.nil?
@@ -30,11 +27,27 @@ def resolve(project_id:, flow:, **params)
3027
return error('Invalid input type id')
3128
end
3229

30+
return_type = SagittariusSchema.object_from_id(flow.return_type)
31+
if return_type.nil?
32+
return error('Invalid return type id')
33+
end
3334

35+
flow_type = SagittariusSchema.object_from_id(flow.flow_type)
36+
if flow_type.nil?
37+
return error('Invalid flow type id')
38+
end
3439

35-
36-
37-
40+
Namespaces::Projects::Flows::CreateService.new(
41+
create_authentication(context[:current_user]),
42+
namespace_project: project,
43+
params: {
44+
return_type: return_type,
45+
input_type: input_type,
46+
flow_type: flow_type,
47+
starting_node: params[:starting_node],
48+
settings: params[:settings] || [],
49+
}
50+
).execute.to_mutation_response(success_key: :flow);
3851
end
3952

4053
def error(message)

app/graphql/types/input/data_type_identifier_input_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Input
55
class DataTypeIdentifierInputType < Types::BaseInputObject
66
description 'Input type for data type identifier'
77

8-
argument :data_type_identifier, String, required: false,
8+
argument :data_type_id, Types::GlobalIdType[::DataTypeIdentifier], required: false,
99
description: 'Data type ID'
1010
argument :generic_key, String, required: false,
1111
description: 'Generic key value'

app/graphql/types/input/flow_setting_input_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class FlowSettingInputType < Types::BaseInputObject
66
description 'Input type for flow settings'
77

88
argument :flow_setting_id, String, required: true,
9-
description: 'The identifier of the flow setting'
9+
description: 'The identifier (not database id) of the flow setting'
1010

1111
argument :object, GraphQL::Types::JSON, required: true,
1212
description: 'The value of the flow setting'

app/graphql/types/input/generic_mapper_input_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class GenericMapperInputType < Types::BaseInputObject
88
argument :source, Types::Input::DataTypeIdentifierInputType, required: true,
99
description: 'The source data type identifier for the mapper'
1010

11-
argument :target, Types::Input::DataTypeIdentifierInputType, required: true,
11+
argument :target, String, required: true,
1212
description: 'The target data type identifier for the mapper'
1313
end
1414
end

app/graphql/types/input/generic_type_input_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Input
55
class GenericTypeInputType < Types::BaseInputObject
66
description 'Input type for generic type operations.'
77

8-
argument :data_type, Types::Input::DataTypeTypeInput, required: true, description: 'The data type associated with this generic type.'
8+
argument :data_type_id, Types::GlobaIdType[::DataType], required: true, description: 'The data type associated with this generic type.'
99
argument :generic_mappers, [Types::Input::GenericMapperInputType], required: true,
1010
description: 'The mappers associated with this generic type.'
1111

app/services/namespaces/projects/flows/create_service.rb

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ def execute
2020
end
2121

2222
transactional do |t|
23+
settings = []
24+
params[:settings].each do |graphql_setting|
25+
setting = FlowSetting.new(flow_setting_id: graphql_setting.flow_setting_id, object: graphql_setting.object)
26+
unless setting.valid?
27+
t.rollback_and_return! ServiceResponse.error(
28+
message: 'Invalid flow setting',
29+
payload: setting.errors
30+
)
31+
settings << setting
32+
end
33+
end
34+
params[:settings] = settings
35+
36+
node = create_node_function(params[:starting_node], t)
37+
params[:starting_node] = node
38+
2339
flow = Flow.create(project: namespace_project, **params)
2440
unless flow.persisted?
2541
t.rollback_and_return! ServiceResponse.error(
@@ -50,6 +66,86 @@ def execute
5066
ServiceResponse.success(message: 'Created new project', payload: flow)
5167
end
5268
end
69+
70+
def create_node_function(node_function, t)
71+
runtime_function_definition = SagittariusSchema.object_from_id(node_function.runtime_function_id)
72+
if runtime_function_definition.nil?
73+
t.rollback_and_return! ServiceResponse.error(
74+
message: 'Invalid runtime function id',
75+
payload: :invalid_runtime_function_id
76+
)
77+
end
78+
79+
params = []
80+
node_function.parameters.each do |parameter|
81+
runtime_parameter = SagittariusSchema.object_from_id(parameter.runtime_parameter_definition_id)
82+
if runtime_parameter.nil?
83+
t.rollback_and_return! ServiceResponse.error(
84+
message: 'Invalid runtime parameter id',
85+
payload: :invalid_runtime_parameter_id
86+
)
87+
end
88+
if parameter.literal_value.present?
89+
params << NodeParameter.create(
90+
runtime_parameter: runtime_parameter,
91+
literal_value: parameter.literal_value,
92+
)
93+
next
94+
end
95+
if parameter.function_value.present?
96+
params << NodeParameter.create(
97+
runtime_parameter: runtime_parameter,
98+
function_value: create_node_function(parameter.function_value, t),
99+
)
100+
next
101+
end
102+
if parameter.reference_value.present?
103+
identifier = parameter.reference_value.data_type_identifier
104+
105+
ReferenceValue.create(
106+
reference_value_id: parameter.reference_value.reference_value_id,
107+
data_type_identifier: get_data_type_identifier(identifier),
108+
)
109+
end
110+
111+
end
112+
113+
next_node = nil
114+
if node_function.next_node.present?
115+
next_node = create_node_function(node_function.next_node, t)
116+
end
117+
118+
119+
NodeFunction.create(
120+
next_node: next_node,
121+
runtime_function_definition: runtime_function_definition,
122+
parameters: params
123+
)
124+
end
125+
126+
private
127+
128+
def get_data_type_identifier(identifier)
129+
if identifier.generic_key.present?
130+
return DataTypeIdentifier.create(generic_key: identifier.generic_key)
131+
end
132+
133+
if identifier.generic_type.present?
134+
data_type = SagittariusSchema.object_from_id(identifier.generic_type.data_type_id)
135+
mappers = identifier.generic_type.mappers.map do |mapper|
136+
GenericMapper.create(
137+
generic_mapper_id: mapper.generic_mapper_id,
138+
source: mapper.source,
139+
target: mapper.target
140+
)
141+
end
142+
return DataTypeIdentifier.create(generic_type: GenericType.create(data_type: data_type, mappers: mappers))
143+
end
144+
145+
if identifier.data_type_id.present?
146+
return DataTypeIdentifier.create(data_type: SagittariusSchema.object_from_id(identifier.data_type_id))
147+
end
148+
end
53149
end
54150
end
55151
end

app/services/namespaces/projects/flows/validation/data_type/data_type_validation_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initialize(current_authentication, flow, data_type)
1818
end
1919

2020
def execute
21-
logger.debug("Validating data type: #{data_type.name} for flow: #{flow.name}")
21+
logger.debug("Validating data type: #{data_type.name} for flow: #{flow.id}")
2222

2323
transactional do |t|
2424
if data_type.invalid?

app/services/namespaces/projects/flows/validation/node_function/node_function_parameter_validation_service.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ def execute
4141
flow,
4242
parameter.reference_value
4343
).execute
44+
return
45+
end
46+
if parameter.function_value.present?
47+
logger.debug("Validating function value: #{parameter.function_value.id} for node parameter: #{parameter.id}")
48+
NodeFunctionValidationService.new(
49+
current_authentication,
50+
flow,
51+
parameter.function_value
52+
).execute
4453
end
4554
end
4655
end

app/services/namespaces/projects/flows/validation/validation_service.rb

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,30 @@ def execute
2727
# ---
2828
# Input Type Validation
2929
# ---
30-
Namespaces::Projects::Flows::Validation::DataTypeValidationService(
31-
current_authentication,
32-
flow,
33-
flow.input_type
34-
).execute
30+
if flow.input_type.present?
31+
Namespaces::Projects::Flows::Validation::DataType::DataTypeValidationService.new(
32+
current_authentication,
33+
flow,
34+
flow.input_type
35+
).execute
36+
end
3537

3638
# ---
3739
# Return Type Validation
3840
# ---
39-
Namespaces::Projects::Flows::Validation::DataTypeValidationService(
40-
current_authentication,
41-
flow,
42-
flow.return_type
43-
).execute
41+
if flow.return_type.present?
42+
Namespaces::Projects::Flows::Validation::DataType::DataTypeValidationService.new(
43+
current_authentication,
44+
flow,
45+
flow.return_type
46+
).execute
47+
end
4448

4549
# ---
4650
# Setting
4751
# ---
4852
flow.flow_settings.each do |setting|
49-
Namespaces::Projects::Flows::Validation::FlowSettingValidationService(
53+
Namespaces::Projects::Flows::Validation::FlowSettingValidationService.new(
5054
current_authentication,
5155
flow,
5256
setting
@@ -56,12 +60,21 @@ def execute
5660
# ---
5761
# Starting node
5862
# ---
59-
Namespaces::Projects::Flows::Validation::NodeFunctionValidationService(
63+
Namespaces::Projects::Flows::Validation::NodeFunction::NodeFunctionValidationService.new(
6064
current_authentication,
6165
flow,
6266
flow.starting_node
6367
).execute
6468

69+
# ---
70+
# Flow Type
71+
# ---
72+
FlowTypeValidationService.new(
73+
current_authentication,
74+
flow,
75+
flow.flow_type
76+
).execute
77+
6578
ServiceResponse.success(message: 'Validation service executed successfully', payload: flow)
6679
end
6780
end

0 commit comments

Comments
 (0)