Skip to content

Commit

Permalink
RSL metadata download fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristjan committed Sep 2, 2021
1 parent e069b61 commit c61e739
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
28 changes: 23 additions & 5 deletions OPDM/OPDM_SOAP_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, server, username="", password="", debug=False, verify=False):

self.debug = debug
self.history = HistoryPlugin()
self.API_VERSION = "0.0.8" # TODO - Get the version from versioneer
self.API_VERSION = "0.0.11" # TODO - Get the version from versioneer

service_wsdl = '{}/cxf/OPDMSoapInterface?wsdl'.format(server)
auth_wsdl = '{}/cxf/OPDMSoapInterface/SoapAuthentication?wsdl'.format(server)
Expand Down Expand Up @@ -156,7 +156,7 @@ class Operations:
</sm:part>
</sm:Query>"""

GetContentResult = """<?xml version="1.0" encoding="UTF-8"?>
GetContentResult_Profile = """<?xml version="1.0" encoding="UTF-8"?>
<sm:GetContent xmlns="http://entsoe.eu/opde/ServiceModel/1/0"
xmlns:sm="http://entsoe.eu/opde/ServiceModel/1/0"
xmlns:opde="http://entsoe.eu/opde/ObjectModel/1/0"
Expand All @@ -169,6 +169,19 @@ class Operations:
</sm:part>
</sm:GetContent>"""

GetContentResult_OPDMObject = """<?xml version="1.0" encoding="UTF-8"?>
<sm:GetContent xmlns="http://entsoe.eu/opde/ServiceModel/1/0"
xmlns:sm="http://entsoe.eu/opde/ServiceModel/1/0"
xmlns:opde="http://entsoe.eu/opde/ObjectModel/1/0"
xmlns:opdm="http://entsoe.eu/opdm/ObjectModel/1/0">
<sm:part name="identifier" type="opde:ShortMetaData">
<sm:part name="content-return-mode">{return_mode}</sm:part><!-- PAYLOAD or FILE -->
<opdm:OPDMObject>
<opde:Id>{mRID}</opde:Id>
</opdm:OPDMObject>
</sm:part>
</sm:GetContent>"""

PublicationsSubscriptionList = """<?xml version="1.0" encoding="UTF-8"?>
<sm:PublicationsSubscriptionList xmlns:sm="http://entsoe.eu/opde/ServiceModel/1/0">
<sm:part name="listType">AVAILABLE_PUBLICATIONS</sm:part>
Expand Down Expand Up @@ -310,10 +323,12 @@ def query_profile(self, metadata_dict):

return query_id, result

def get_content(self, content_id, return_payload=False):
def get_content(self, content_id, return_payload=False, object_type="file"):
"""Downloads single file from OPDM Service Provider to OPDM Client local storage,
to get the file binary as a response of set return_payload to True
supported object_types = [file, model]
Returns a dictionary with metadata and filename or content, to get the filename or content use:
result['sm:GetContentResult']['sm:part'][1]['opdm:Profile']['opde:Content']
"""
Expand All @@ -324,13 +339,16 @@ def get_content(self, content_id, return_payload=False):

logger.debug(f"Return mode: {return_mode}")

get_content_result = self.Operations.GetContentResult.format(mRID=content_id, return_mode=return_mode)
object_types = {"file": self.Operations.GetContentResult_Profile,
"model": self.Operations.GetContentResult_OPDMObject}

get_content_result = object_types[object_type].format(mRID=content_id, return_mode=return_mode)

result = xmltodict.parse(etree.tostring(self.execute_operation(get_content_result.encode())), xml_attribs=False)

if type(result['sm:GetContentResult']['sm:part']) == list:
logger.info("File downloaded")
logger.debug(result['sm:GetContentResult']['sm:part'][1]['opdm:Profile']['opde:Content'])
#logger.debug(result['sm:GetContentResult']['sm:part'][1]['opdm:Profile']['opde:Content'])

else:
logger.error("File download failed")
Expand Down
4 changes: 2 additions & 2 deletions examples/install_latest_RSL.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
if latest_RSL["version"] != installed_RSL:

# Download latest RSL
response = service.get_content(latest_RSL["id"])
print(f"Downloaded {response['sm:GetContentResult']['sm:part'][1]['opdm:Profile']['pmd:fileName']}")
response = service.get_content(latest_RSL["id"], object_type="model")
print(f"Downloaded {response['sm:GetContentResult']['sm:part'][1]['opdm:OPDMObject']['pmd:fileName']}")

# Install latest RSL
response = service.install_ruleset(latest_RSL["version"])
Expand Down

0 comments on commit c61e739

Please sign in to comment.