Skip to content

Commit 0a8253e

Browse files
authored
Merge pull request #45 from OpenEnergyPlatform/release-v0.3.3
Release v0.3.3
2 parents 9bd8bcf + b28b0b9 commit 0a8253e

7 files changed

+92
-33
lines changed

CHANGELOG.md

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is inpired from [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
@@ -26,119 +27,163 @@ Template:
2627
### Removed
2728
- basic description [#PR/#Issue/#Commit]
2829
```
30+
2931
## [Unreleased] - 20XX-MM-DD
3032

3133
### Added
3234

35+
-
36+
3337
### Changed
3438

39+
-
40+
3541
### Removed
3642

3743
______________________________________________________________________
44+
45+
## [v0.3.3] - 2024-04-15
46+
47+
### Added
48+
49+
- New settings module [#44](https://github.com/OpenEnergyPlatform/oem2orm/pull/44)
50+
51+
### Changed
52+
53+
- Improve logging and error messages [table creation, data upload, metadata registration](#38)
54+
- Fix error if field type is None
55+
- Update oep host url [#44](https://github.com/OpenEnergyPlatform/oem2orm/pull/44)
56+
57+
______________________________________________________________________
58+
3859
## [0.3.2] - 2022-11-29
3960

4061
### Added
62+
4163
- token can be passed as parameter (to support usage in APIs)
4264

4365
### Changed
66+
4467
- Error is raised if schema does not exist
4568
- Metadata compilance checks now inculue optinal jsonschema validation for metadata (PR#32)
4669
- MetadataError is thrown if uploading metadata to OEP fails
4770

4871
______________________________________________________________________
72+
4973
## [0.3.1] - 2022-10-24
5074

5175
### Changed
76+
5277
- fix module not installed error after pip install and import of oem2orm PR(#26)
5378

5479
______________________________________________________________________
80+
5581
## [0.3.0] - 2022-10-24
5682

5783
### Added
84+
5885
- Option to create tables from OEM JSON instead of file
5986
- New module to check if metadata is oep compliant. Can check (omi's 1 parse 2 compile) oemetadata v1.5 and v1.4 (PR#23)
6087
- Add PYPI release workflow to automate python package releases for pypi test and pypi official (PR#22)
6188

6289
### Changed
90+
6391
- omi_validateMD was outdated and now runs the new oep compliance checks.
6492

6593
______________________________________________________________________
94+
6695
## [0.2.7] - 2021-03-11
6796

6897
### Added
98+
6999
- enable console usage [PR#8]
70-
- new package requirement "omi"
71-
- support for sqlachemy "numeric" data type
100+
- new package requirement "omi"
101+
- support for sqlachemy "numeric" data type
72102

73103
### Changed
104+
74105
- fix missing dependency that made pip install fail [ISSUE#1;PR#8]
75106

76107
### Removed
77-
- console script, remove table delete
108+
109+
- console script, remove table delete
78110

79111
______________________________________________________________________
112+
80113
## [0.2.6] - 2020-09-23
81114

82115
### Added
116+
83117
- support for datatypes "hstore" and "decimal"
84118
- provide new example files that work with oem2orm
85119

86120
______________________________________________________________________
121+
87122
## [0.2.5] - 2020-08-06
88123

89124
### Changed
125+
90126
- fix installation error caused by jmespath package dependency
91127

92128
______________________________________________________________________
129+
93130
## [0.2.4] - 2020-07-20
94131

95132
### Added
133+
96134
- Support to setup the OEP API-URL
97135
- Metadata Up- and download are supported
98136
- Save downloaded metadata to file
99137
- Validate metadata using OMI parser v1.4.0
100138

101139
### Changed
140+
102141
- change functions names
103142

104143
______________________________________________________________________
144+
105145
## [0.2.3] - 2020-06-02
106146

107147
### Added
148+
108149
- provide a minimal working example as jupyter notebook tutorial
109-
- New OEP-API related functions: Prepare the oemetadata string to send to api
150+
- New OEP-API related functions: Prepare the oemetadata string to send to api
110151
- Simple User Input function to set the OEP-API-Token
111152

112153
### Changed
154+
113155
- Update README
114156
- include OEP public schema (whitelist) check
115157
- Spatial types from Geoalchemy2 do not set a spatial_index anymore
116158

117159
______________________________________________________________________
160+
118161
## [0.2.2] - 2020-06-02
119162

120163
### Added
164+
121165
- new function: setting up a logger
122166

123167
### Changed
168+
124169
- add missing input parameter
125170
- extended description in changelog
126-
- Fix logging
171+
- Fix logging
127172

128173
______________________________________________________________________
174+
129175
## [0.2.0] - 2020-05-27
130176

131177
### Added
178+
132179
- new function: delete tables from DB now possible
133-
- new function: select the oem data folder
180+
- new function: select the oem data folder
134181
- new function: tables are collected and ordered by fk (increase usability)
135182

136183
### Changed
184+
137185
- added docstrings
138186

139187
### Removed
140-
- the user is no longer required to use a for loop in the main function to collect tables
141-
142-
143-
144188

189+
- the user is no longer required to use a for loop in the main function to collect tables

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ see [Pipx-Documentation](https://pypa.github.io/pipx/) for further information.
1818

1919
## Usage:
2020

21-
This tool is part of the open-energy-metadata (OEM) integration into the [OEP](https://openenergy-platform.org/).
21+
This tool is part of the open-energy-metadata (OEM) integration into the [OEP](https://openenergyplatform.org/).
2222
To use this tool with the OEP API you need to be signed up to the OEP since
2323
you need to provide an API-Token.
2424

oem2orm/oep_oedialect_oem2orm.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from oem2orm.postgresql_types import TYPES
2121
from oem2orm.oep_compliance import run_metadata_checks
22+
from oem2orm.settings import OEP_URL, OEP_API_URL
2223

2324
# prepare connection string to connect via oep API
2425
CONNECTION_STRING = "{engine}://{user}:{token}@{host}"
@@ -38,22 +39,22 @@ class MetadataError(Exception):
3839
pass
3940

4041

41-
def setup_logger():
42+
def setup_logger(logger_level: str = "Yes"):
4243
"""
4344
Easy logging setup depending on user input. Provides a logger for INFO level logging.
4445
:return: logging.INFO or none
4546
"""
46-
logger_level = input("Display logging information[Yes] or [No]:")
47+
4748
if re.fullmatch("[Yy]es", logger_level):
48-
print("logging activated")
49+
print("Logging activated")
4950
return logging.basicConfig(
5051
format="%(levelname)s:%(message)s", level=logging.INFO
5152
)
5253
elif re.fullmatch("[Nn]o", logger_level):
5354
pass
5455

5556

56-
def setup_db_connection(engine="postgresql+oedialect", host="openenergy-platform.org"):
57+
def setup_db_connection(engine="postgresql+oedialect", host=OEP_URL):
5758
"""
5859
Create SQLAlchemy connection to Database API with Username and Token.
5960
Default is the OEP RESTful-API.
@@ -81,9 +82,8 @@ def setup_db_connection(engine="postgresql+oedialect", host="openenergy-platform
8182

8283
def setupApiAction(schema, table, token=None):
8384
API_ACTION = namedtuple("API_Action", ["dest_url", "headers"])
84-
OEP_URL = "https://openenergy-platform.org"
8585

86-
url = OEP_URL + "/api/v0/schema/{schema}/tables/{table}/meta/".format(
86+
url = OEP_API_URL + "schema/{schema}/tables/{table}/meta/".format(
8787
schema=schema, table=table
8888
)
8989

@@ -107,8 +107,10 @@ def create_tables(db: DB, tables: List[sa.Table]):
107107
:return: none
108108
"""
109109
for table in tables:
110+
logging.info(f"Working on table: {table}")
110111
if not db.engine.dialect.has_schema(db.engine, table.schema):
111-
error_msg = f'The provided database schema: "{table.schema}" does not exist. Please use an existing schema'
112+
error_msg = f'The provided database schema: "{table.schema}" does not exist. Please use an existing ' \
113+
f'schema from the `name` column from: {OEP_URL}/dataedit/schemas'
112114
logging.info(error_msg)
113115
raise DatabaseError(error_msg)
114116
else:
@@ -117,7 +119,7 @@ def create_tables(db: DB, tables: List[sa.Table]):
117119
table.create(checkfirst=True)
118120
logging.info(f"Created table {table.name}")
119121
except oedialect.engine.ConnectionException as ce:
120-
error_msg = f'Error when uploading table "{table.name}".'
122+
error_msg = f'Error when uploading table "{table.name}". Reason: {ce}.'
121123
logging.error(error_msg)
122124
raise DatabaseError(error_msg) from ce
123125
except sa.exc.ProgrammingError as pe:
@@ -203,7 +205,7 @@ def create_tables_from_metadata_file(
203205
# Get column type:
204206
try:
205207
column_type = TYPES[field["type"]]
206-
except KeyError:
208+
except (KeyError, ValueError):
207209
raise MetadataError(
208210
"Unknown column type", field, field["type"], metadata_file
209211
)
@@ -268,7 +270,7 @@ def check_oep_api_schema_whitelist(oem_schema):
268270
return True
269271
else:
270272
logging.info(
271-
"The OEP-API does not allow to write un-reviewed data to another schema then model_draft or sandbox"
273+
"The OEP-API does not allow to write un-reviewed data to another schema then 'model_draft' or 'sandbox'"
272274
)
273275
return False
274276

@@ -314,7 +316,7 @@ def collect_tables_from_oem(db: DB, oem_folder_path):
314316

315317

316318
def load_json(filepath):
317-
logging.info("reading %s" % filepath)
319+
logging.info("Reading metadata: %s" % filepath)
318320
with open(filepath, "rb") as f:
319321
return json.load(f)
320322

@@ -373,18 +375,26 @@ def api_updateMdOnTable(metadata, token=None):
373375
schema = getTableSchemaNameFromOEM(metadata)[0]
374376
table = getTableSchemaNameFromOEM(metadata)[1]
375377

376-
logging.info("UPDATE METADATA")
378+
logging.info(f"Update metadata on table: {table}")
377379
api_action = setupApiAction(schema, table, token)
378380
resp = requests.post(api_action.dest_url, json=metadata, headers=api_action.headers)
379381
if resp.status_code == 200:
380-
logging.info(" ok.")
381-
logging.info(api_action.dest_url)
382+
logging.info(f"METADATA SUCCESSFULLY UPDATED: {table}")
383+
logging.info(f"Link to updated metadata on OEP: {api_action.dest_url}")
382384
else:
383-
error_msg = resp.json()
384-
logging.info(error_msg)
385-
logging.info("HTTP status code: ")
386-
logging.info(resp.status_code)
387-
raise MetadataError(f"Uploading of metadata failed. Response from OEP: {error_msg}")
385+
oep_err_msg_header = re.search("<h3>(.*)</h3>", resp.text).group(1)
386+
err_message = (
387+
f"Uploading of metadata failed. HTTPS response from OEP: {resp.status_code}, Message: {oep_err_msg_header}, URL: {resp.url}"
388+
""
389+
)
390+
if not resp.text.startswith("{"):
391+
raise MetadataError(
392+
f"The response text doesn't seem to be a json: {resp.text[:40]}..... \n\n Please check "
393+
f"that the table is already created on the OEP! \n {err_message}"
394+
)
395+
else:
396+
# in case a json is returned and there is a json error
397+
raise MetadataError(err_message, resp.json())
388398

389399

390400
def api_downloadMd(schema, table, token=None):

oem2orm/postgresql_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class DatabaseTypes:
4040
}
4141

4242
def __getitem__(self, item):
43+
if item is None:
44+
raise ValueError("Field type is 'None'.")
4345
if item.split(" ")[-1] == "array":
4446
db_type = self.types[item[:-6]]
4547
return psql.ARRAY(db_type)

oem2orm/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sqlalchemy
22
psycopg2-binary
33
jmespath
44
GeoAlchemy2
5-
oedialect
5+
oedialect==0.1.1
66
geopandas
77
pandas
88
omi

oem2orm/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
OEP_URL = "openenergy-platform.org"
2+
OEP_API_URL = "https://openenergy-platform.org/api/v0/"

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setuptools.setup(
1010
name="oem2orm",
11-
version="0.3.2",
11+
version="0.3.3",
1212
author="henhuy, jh-RLI",
1313
author_email="Hendrik.Huyskens@rl-institut.de",
1414
description="SQLAlchemy module to generate ORM, read from data model (oedatamodel) in open-energy-metadata JSON format",
@@ -28,7 +28,7 @@
2828
"Operating System :: OS Independent",
2929
],
3030
python_requires='>=3.6',
31-
install_requires=['sqlalchemy==1.3.14', 'oedialect', 'requests', 'jmespath', 'omi', 'click'], # Optional
31+
install_requires=['sqlalchemy==1.3.14', 'oedialect==1.1', 'requests', 'jmespath', 'omi', 'click'], # Optional
3232
project_urls={ # Optional
3333
'Bug Reports': 'https://github.com/OpenEnergyPlatform/oem2orm/issues',
3434
'Source': 'https://github.com/OpenEnergyPlatform/oem2orm/tree/develop/oem2orm',

0 commit comments

Comments
 (0)