Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#OBS-I116: fix: Command api and schema fixes #211

Merged
merged 2 commits into from
Jul 25, 2024
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
4 changes: 3 additions & 1 deletion api-service/src/controllers/DatasetCreate/DatasetCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ const getDatasetConnectors = (connectorConfigs: Array<Record<string, any>>): Arr
})
return _.map(uniqueConnectors, (config) => {
return {
id: config.id,
connector_id: config.connector_id,
connector_config: cipherService.encrypt(JSON.stringify(config.connector_config)),
operations_config: config.operations_config
operations_config: config.operations_config,
version: config.version
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
},
"extraction_key": {
"type": "string",
"default": "events",
"minLength": 1
"default": "events"
},
"dedup_config": {
"type": "object",
Expand All @@ -82,8 +81,7 @@
"default": false
},
"dedup_key": {
"type": "string",
"minLength": 1
"type": "string"
}
},
"if": {
Expand Down Expand Up @@ -115,6 +113,11 @@
}
},
"then": {
"properties": {
"extraction_key": {
"minLength": 1
}
},
"required": ["extraction_key", "dedup_config"]
}
},
Expand All @@ -126,8 +129,7 @@
"default": true
},
"dedup_key": {
"type": "string",
"minLength": 1
"type": "string"
}
},
"if": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
"minLength": 1
},
"connector_config": {
"type": "object"
"type": "string"
},
"operations_config": {
"type": "object"
Expand All @@ -402,11 +402,15 @@
"properties": {
"dataset_config": {
"properties": {
"data_key": {
"minLength": 1
"keys_config": {
"properties": {
"data_key": {
"minLength": 1
}
},
"required": ["data_key"]
}
},
"required": ["data_key"]
}
}
}
},
Expand Down
4 changes: 3 additions & 1 deletion api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ const mergeConnectorsConfig = (currConfigs: any, newConfigs: any) => {
return _.unionWith(
_.map(addConfigs, (config) => {
return {
id: config.id,
connector_id: config.connector_id,
connector_config: cipherService.encrypt(JSON.stringify(config.connector_config)),
operations_config: config.operations_config
operations_config: config.operations_config,
version: config.version
}
}),
_.reject(currConfigs, (config) => { return _.includes(removeConfigs, config.connector_id)}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@
"default": true
},
"dedup_key": {
"type": "string",
"minLength": 1
"type": "string"
}
},
"if": {
Expand Down
28 changes: 14 additions & 14 deletions command-service/src/command/db_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ def _insert_datasource_record(self, dataset_id, draft_dataset_id):
return result

def _insert_connector_instances(self, dataset_id, draft_dataset_record):
emptyJson, result = {}
draft_connectors_config_record = draft_dataset_record.connectors_config
emptyJson = {}
result = {}
draft_connectors_config_record = draft_dataset_record.get('connectors_config')
if draft_connectors_config_record is None:
return result

Expand All @@ -196,8 +197,8 @@ def _insert_connector_instances(self, dataset_id, draft_dataset_record):
'{DatasetStatusType.Live.name}',
'{json.dumps(emptyJson)}',
'{json.dumps(emptyJson)}',
'{draft_dataset_record.created_by}',
'{draft_dataset_record.updated_by}',
'{draft_dataset_record.get('created_by')}',
'{draft_dataset_record.get('updated_by')}',
'{current_timestamp}',
'{current_timestamp}',
'{current_timestamp}'
Expand All @@ -206,7 +207,7 @@ def _insert_connector_instances(self, dataset_id, draft_dataset_record):
SET connector_config = '{json.dumps(connector_config.connector_config).replace("'", "''")}',
operations_config = '{json.dumps(connector_config.operations_config).replace("'", "''")}',
data_format = '{connector_config.data_format}',
updated_by = '{draft_dataset_record.updated_by}',
updated_by = '{draft_dataset_record.get('updated_by')}',
updated_date = '{current_timestamp}',
published_date = '{current_timestamp}',
status = '{DatasetStatusType.Live.name}';
Expand All @@ -225,15 +226,15 @@ def _insert_connector_instances(self, dataset_id, draft_dataset_record):
'{connector_config.connector_id}',
'{json.dumps(connector_config.connector_config).replace("'", "''")}',
'{DatasetStatusType.Live.name}',
'{draft_dataset_record.created_by}',
'{draft_dataset_record.updated_by}',
'{draft_dataset_record.get('created_by')}',
'{draft_dataset_record.get('updated_by')}',
'{current_timestamp}',
'{current_timestamp}',
'{current_timestamp}'
)
ON CONFLICT (id) DO UPDATE
SET connector_config = '{json.dumps(connector_config.connector_config).replace("'", "''")}',
updated_by = '{draft_dataset_record.updated_by}',
updated_by = '{draft_dataset_record.get('updated_by')}',
updated_date = '{current_timestamp}',
published_date = '{current_timestamp}',
status = '{DatasetStatusType.Live.name}';
Expand All @@ -247,7 +248,7 @@ def _insert_connector_instances(self, dataset_id, draft_dataset_record):

def _insert_dataset_transformations(self, dataset_id, draft_dataset_record):

draft_dataset_transformations_record = draft_dataset_record.transformations_config
draft_dataset_transformations_record = draft_dataset_record.get('transformations_config')
result = {}
current_timestamp = dt.now()
# Delete existing transformations
Expand All @@ -263,20 +264,19 @@ def _insert_dataset_transformations(self, dataset_id, draft_dataset_record):
)
insert_query = f"""
INSERT INTO dataset_transformations(id, dataset_id, field_key, transformation_function,
status, mode, created_by, updated_by, created_date, updated_date, published_date, metadata)
status, mode, created_by, updated_by, created_date, updated_date, published_date)
VALUES (
'{dataset_id + '_' + transformation.field_key}',
'{dataset_id}',
'{transformation.field_key}',
'{json.dumps(transformation.transformation_function).replace("'", "''")}',
'{DatasetStatusType.Live.name}',
'{transformation.mode}',
'{transformation.created_by}',
'{transformation.updated_by}',
'{current_timestamp}',
'{draft_dataset_record.get('created_by')}',
'{draft_dataset_record.get('updated_by')}',
'{current_timestamp}',
'{current_timestamp}',
'{json.dumps(transformation.metadata).replace("'", "''")}'
'{current_timestamp}'
)
"""
result = self.db_service.execute_upsert(insert_query)
Expand Down
6 changes: 3 additions & 3 deletions command-service/src/model/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class DatasetsDraft:
created_by: str
created_date: datetime
sample_data: dict | None = None
transformations_config: dict | None = None
connectors_config: dict | None = None
transformations_config: list[dict] | None = None
connectors_config: list[dict] | None = None
denorm_config: dict | None = None
tags: list[str] | None = None
updated_by: str | None = None
Expand Down Expand Up @@ -79,7 +79,7 @@ class DatasourcesDraft:
class DatasetConnectorConfigDraft:
id: str
connector_id: str
connector_config: dict
connector_config: str | None
version: str
operations_config: dict | None = None
data_format: str | None = 'json'
Expand Down
Loading