-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
175 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import io | ||
import re | ||
|
||
from toolbox.__main__ import run | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import pytest as pytest | ||
|
||
from toolbox.api.datagalaxy_api_attributes import to_bulk_item_attribute | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import logging | ||
from enum import Enum | ||
|
||
import requests as requests | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import logging | ||
import requests as requests | ||
from toolbox.api.datagalaxy_api import DataGalaxyBulkResult, to_bulk_tree | ||
|
||
|
||
class DataGalaxyApiGlossary: | ||
def __init__(self, url: str, access_token: str, workspace: dict): | ||
self.url = url | ||
self.access_token = access_token | ||
self.workspace = workspace | ||
|
||
def list_properties(self, workspace_name: str) -> list: | ||
if not self.workspace["isVersioningEnabled"]: | ||
version_id = self.workspace['defaultVersionId'] | ||
params = {'versionId': version_id, 'includeAttributes': 'true'} | ||
headers = {'Authorization': f"Bearer {self.access_token}"} | ||
response = requests.get(f"{self.url}/properties", params=params, headers=headers) | ||
code = response.status_code | ||
body_json = response.json() | ||
if code == 200: | ||
logging.info( | ||
f'list_properties - {len(body_json["results"])} properties found on ' | ||
f'workspace {workspace_name} :') | ||
result = [] | ||
result = result + body_json['results'] | ||
next_page = body_json["next_page"] | ||
while next_page is not None: | ||
headers = {'Authorization': f"Bearer {self.access_token}"} | ||
response = requests.get(next_page, headers=headers) | ||
body_json = response.json() | ||
next_page = body_json["next_page"] | ||
result = result + body_json['results'] | ||
return result | ||
|
||
if 400 <= code < 500: | ||
raise Exception(body_json['error']) | ||
|
||
raise Exception(f'Unexpected error, code: {code}') | ||
|
||
elif self.workspace["isVersioningEnabled"]: | ||
raise Exception('pour l instant on ne gere pas le versioning') | ||
|
||
def bulk_upsert_property_tree(self, workspace_name: str, properties: list) -> DataGalaxyBulkResult: | ||
# Existing entities are updated and non-existing ones are created. | ||
properties_ok_to_bulk = to_bulk_tree(properties) | ||
logging.info(f'properties_ok_to_bulk: {properties_ok_to_bulk}') | ||
|
||
if not self.workspace["isVersioningEnabled"]: | ||
version_id = self.workspace['defaultVersionId'] | ||
headers = {'Authorization': f"Bearer {self.access_token}"} | ||
response = requests.post(f"{self.url}/properties/bulktree/{version_id}", json=properties_ok_to_bulk, | ||
headers=headers) | ||
code = response.status_code | ||
body_json = response.json() | ||
if 200 <= code < 300: | ||
result = DataGalaxyBulkResult(total=body_json["total"], created=body_json["created"], | ||
deleted=body_json["deleted"], unchanged=body_json["unchanged"], | ||
updated=body_json["updated"]) | ||
logging.info( | ||
f'bulk_upsert_property_tree - {result.total} properties copied on workspace {workspace_name}:' | ||
f'{result.created} were created, {result.updated} were updated, ' | ||
f'{result.deleted} were deleted and {result.unchanged} were unchanged') | ||
return result | ||
|
||
if 400 <= code < 500: | ||
raise Exception(body_json['error']) | ||
|
||
raise Exception(f'Unexpected error, code: {code}') | ||
|
||
elif self.workspace["isVersioningEnabled"]: | ||
raise Exception('pour l instant on ne sait pas si on accepte le versioning') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.