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

Update create template #216 #217

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Move old metadata versions to folder [(#209)](https://github.com/OpenEnergyPlatform/oemetadata/pull/209)
- Update JSON schema from (draft-07) to (Draft 2020-12) [(#212)](https://github.com/OpenEnergyPlatform/oemetadata/pull/212)
- Update all tests [(#212)](https://github.com/OpenEnergyPlatform/oemetadata/pull/212)
- Update create template [(#217)](https://github.com/OpenEnergyPlatform/oemetadata/pull/217)

### Removed
- [(#)]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,45 @@ def test_oemetadata_schema_should_validate_oemetadata_template():
except ValidationError as e:
print("Cannot validate OEMetadata Template with Schema (v2.0)!", e)

def find_and_replace_key(data, target_key, new_value):
if isinstance(data, dict):
for key, value in data.items():
if key == target_key:
data[key] = new_value
return True # Return True if replacement is successful
elif isinstance(value, (dict, list)):
if find_and_replace_key(value, target_key, new_value):
return True # Return True if replacement occurs in nested structure
elif isinstance(data, list):
for item in data:
if find_and_replace_key(item, target_key, new_value):
return True
return False # Return False if key not found

def replace_key_in_json(file_path, target_key, new_value):
# Open and read the JSON file
with open(file_path, 'r') as file:
data = json.load(file)

# Perform the key replacement
if find_and_replace_key(data, target_key, new_value):
# Save the updated JSON data back to the file
with open(file_path, 'w') as file:
json.dump(data, file, indent=4)
print(f"Updated '{target_key}' to '{new_value}' in {file_path}")
else:
print(f"Key '{target_key}' not found in JSON file.")


if __name__ == "__main__":
logger.info("Generation started.")
main()
replace_key_in_json(TEMPLATE_PATH, 'boundingBox', [0, 0, 0, 0])
replace_key_in_json(TEMPLATE_PATH, 'metadataVersion', 'OEMetadata-2.0.1')
replace_key_in_json(TEMPLATE_PATH, 'metadataLicense', {
"name": "CC0-1.0",
"title": "Creative Commons Zero v1.0 Universal",
"path": "https://creativecommons.org/publicdomain/zero/1.0"
})
test_oemetadata_schema_should_validate_oemetadata_template()
logger.info("Generation ended.")
334 changes: 167 additions & 167 deletions metadata/v20/v20/template.json
Original file line number Diff line number Diff line change
@@ -1,178 +1,178 @@
{
"name": "",
"title": "",
"description": "",
"id": "",
"resources": [
{
"@id": "",
"@context": "",
"name": "",
"topics": [
""
],
"title": "",
"path": "",
"description": "",
"languages": [
""
],
"subject": [
"name": "",
"title": "",
"description": "",
"id": "",
"resources": [
{
"name": "",
"path": ""
}
],
"keywords": [
""
],
"publicationDate": "",
"embargoPeriod": {
"start": "",
"end": "",
"isActive": false
},
"context": {
"title": "",
"homepage": "",
"documentation": "",
"sourceCode": "",
"publisher": "",
"publisherLogo": "",
"contact": "",
"fundingAgency": "",
"fundingAgencyLogo": "",
"grantNo": ""
},
"spatial": {
"location": {
"address": "",
"@id": "",
"latitude": "",
"longitude": ""
},
"extent": {
"name": "",
"@id": "",
"resolutionValue": "",
"resolutionUnit": "",
"boundingBox": [
13.08825,
52.33859,
13.76104,
52.6754
],
"crs": ""
}
},
"temporal": {
"referenceDate": "",
"timeseries": [
{
"start": "",
"end": "",
"resolution": "",
"alignment": "",
"aggregationType": ""
}
]
},
"sources": [
{
"title": "",
"authors": [
""
],
"description": "",
"publicationYear": "",
"path": "",
"licenses": [
{
"name": "",
"title": "",
"path": "",
"instruction": "",
"attribution": "",
"copyrightStatement": ""
}
]
}
],
"licenses": [
{
"name": "",
"title": "",
"path": "",
"instruction": "",
"attribution": ""
}
],
"contributors": [
{
"title": "",
"path": "",
"organization": "",
"roles": [
""
],
"date": "",
"object": "",
"comment": ""
}
],
"type": "",
"format": "",
"encoding": "",
"schema": {
"fields": [
{
"@id": "",
"@context": "",
"name": "",
"topics": [
""
],
"title": "",
"path": "",
"description": "",
"type": "",
"nullable": false,
"unit": "",
"isAbout": [
{
"name": "",
"path": ""
}
"languages": [
""
],
"valueReference": [
{
"value": "",
"name": "",
"path": ""
}
]
}
],
"primaryKey": [
""
],
"foreignKeys": [
{
"fields": [
""
"subject": [
{
"name": "",
"path": ""
}
],
"reference": {
"resource": "",
"fields": [
"keywords": [
""
]
],
"publicationDate": "",
"embargoPeriod": {
"start": "",
"end": "",
"isActive": false
},
"context": {
"title": "",
"homepage": "",
"documentation": "",
"sourceCode": "",
"publisher": "",
"publisherLogo": "",
"contact": "",
"fundingAgency": "",
"fundingAgencyLogo": "",
"grantNo": ""
},
"spatial": {
"location": {
"address": "",
"@id": "",
"latitude": "",
"longitude": ""
},
"extent": {
"name": "",
"@id": "",
"resolutionValue": "",
"resolutionUnit": "",
"boundingBox": [
0,
0,
0,
0
],
"crs": ""
}
},
"temporal": {
"referenceDate": "",
"timeseries": [
{
"start": "",
"end": "",
"resolution": "",
"alignment": "",
"aggregationType": ""
}
]
},
"sources": [
{
"title": "",
"authors": [
""
],
"description": "",
"publicationYear": "",
"path": "",
"licenses": [
{
"name": "",
"title": "",
"path": "",
"instruction": "",
"attribution": "",
"copyrightStatement": ""
}
]
}
],
"licenses": [
{
"name": "",
"title": "",
"path": "",
"instruction": "",
"attribution": ""
}
],
"contributors": [
{
"title": "",
"path": "",
"organization": "",
"roles": [
""
],
"date": "",
"object": "",
"comment": ""
}
],
"type": "",
"format": "",
"encoding": "",
"schema": {
"fields": [
{
"name": "",
"description": "",
"type": "",
"nullable": false,
"unit": "",
"isAbout": [
{
"name": "",
"path": ""
}
],
"valueReference": [
{
"value": "",
"name": "",
"path": ""
}
]
}
],
"primaryKey": [
""
],
"foreignKeys": [
{
"fields": [
""
],
"reference": {
"resource": "",
"fields": [
""
]
}
}
]
},
"dialect": {
"delimiter": "",
"decimalSeparator": ""
},
"review": {
"path": "",
"badge": ""
}
}
]
},
"dialect": {
"delimiter": "",
"decimalSeparator": ""
},
"review": {
"path": "",
"badge": ""
}
}
],
}
],
"metaMetadata": {
"metadataVersion": "OEMetadata-2.0.1",
"metadataLicense": {
Expand Down
Loading