Skip to content

Commit

Permalink
Merge pull request #63 from Open-EO/ngnann
Browse files Browse the repository at this point in the history
Ngnann
  • Loading branch information
bgoesswe authored Oct 31, 2019
2 parents 48b0ca0 + 0bc8668 commit ec56441
Show file tree
Hide file tree
Showing 11 changed files with 1,638 additions and 426 deletions.
Binary file added display_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added execute_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 90 additions & 14 deletions models/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@ def connect(self, url, username=None, password=None) -> bool:
self.token = token.json()["access_token"]
else:
return False

# disconnect
elif username and password == None:
token_dis = requests.get(self._url)
if token_dis.status_code == 200:
return False
else:
return False

return True

def get_header(self):
"""
Returns the header (used for a request) with e.g. the authentication token.
:return: header: Dict
"""

if self.token:
return {'Authorization': 'Bearer {}'.format(self.token)}
else:
Expand Down Expand Up @@ -120,29 +128,72 @@ def job_info(self, job_id):
"""
Returns information about a created job.
:param: job_id: Identifier of the job
:return: jobs: Strings containing details about the created jobs.
:return: job_info_id: Strings containing details about the created jobs.
"""
requested_info = "/jobs/{}".format(job_id)
get_info = self.get(requested_info, stream=True)
json = get_info.json()
job_info = get_info.json()

title = job_info['title']
description = job_info['description']
submission = job_info['submitted']
cost = job_info['costs']
processes = []
# Data & Extents & Processes
for key in job_info['process_graph'].keys():
if "load_collection" in key:
data_set = job_info['process_graph'][key]['arguments']['id']
temporal_extent = job_info['process_graph'][key]['arguments']['spatial_extent']
spatial_extent = job_info['process_graph'][key]['arguments']['temporal_extent']
processes.append(key)
job_info_id = "Title: {}. \nDescription: {}. \nSubmission Date: {} \nData: {}. \nProcess(es): {}. \nSpatial Extent: {}.\nTemporal Extent: {}. \nCost: {}."\
.format(title, description, submission, data_set, processes, spatial_extent, temporal_extent, cost)\
.replace("'", "").replace("[", "").replace("]", "").replace("{", "").replace("}", "")
return job_info_id

title = json['title']
description = json['description']
process_graph = json['process_graph']
cost = json['costs']
def service_info(self, service_id):
"""
Returns information about a created service.
:param: service_id: Identifier of the service
:return: service_info_id: Strings containing details about the created service.
"""
requested_info = "/services/{}".format(service_id)
get_info = self.get(requested_info, stream=True)
service_info = get_info.json()

title = service_info['title']
description = service_info['description']
submission = service_info['submitted']
type = service_info['type']
cost = service_info['costs']
processes = []
# Data & Extents & Processes
for key in json['process_graph'].keys():
for key in service_info['process_graph'].keys():
if "load_collection" in key:
data_set = json['process_graph'][key]['arguments']['id']
temporal_extent = json['process_graph'][key]['arguments']['spatial_extent']
spatial_extent = json['process_graph'][key]['arguments']['temporal_extent']
data_set = service_info['process_graph'][key]['arguments']['id']
temporal_extent = service_info['process_graph'][key]['arguments']['spatial_extent']
spatial_extent = service_info['process_graph'][key]['arguments']['temporal_extent']
processes.append(key)
service_info_id = "Title: {}. \nDescription: {}. \nSubmission Date: {} \nType: {} \nData: {}. \nProcess(es): {}. \nSpatial Extent: {}.\nTemporal Extent: {}. \nCost: {}." \
.format(title, description, submission, type, data_set, processes, spatial_extent, temporal_extent, cost) \
.replace("'", "").replace("[", "").replace("]", "").replace("{", "").replace("}", "")
return service_info_id

job_info = "Title: {}. \nDescription: {}. \nData: {}. \nProcess(es): {}. \nSpatial Extent: {}. \nTemporal Extent: {}. \nCost: {}.".\
format(title, description, data_set, processes, spatial_extent, temporal_extent, cost).replace("'", "").replace("[", "").replace("]", "").replace("{", "").replace("}", "")
def pg_info_job(self, job_id):
requested_info = "/jobs/{}".format(job_id)
get_info = self.get(requested_info, stream=True)
job_info = get_info.json()
process_graph_job = job_info['process_graph']
return process_graph_job

def pg_info_service(self, service_id):
requested_info = "/services/{}".format(service_id)
get_info = self.get(requested_info, stream=True)
service_info = get_info.json()
process_graph_service = service_info['process_graph']
# return process_graph_service

return job_info, process_graph
return service_info

def job_result_url(self, job_id):
"""
Expand Down Expand Up @@ -216,6 +267,24 @@ def job_create(self, process_graph):

return job_status

def service_create(self, process_graph):
"""
Sends the process graph to the backend and creates a new job.
:param: process_graph: Dict, Process Graph of the new job
:return: status: String, Status of the job creation
"""
pg = {
"process_graph": process_graph
}
#print(process_graph)

service_status = self.post("/jobs", postdata=pg)

#if job_status.status_code == 201:
# return job_status

return service_status

def post(self, path, postdata):
"""
Makes a RESTful POST request to the back end.
Expand All @@ -238,12 +307,19 @@ def delete(self, path):
auth = self.get_auth()
return requests.delete(self._url+path, headers=auth_header, auth=auth)


def delete_job(self, job_id):
path = "/jobs/{}".format(job_id)
auth_header = self.get_header()
auth = self.get_auth()
return requests.delete(self._url+path, headers=auth_header, auth=auth)

def delete_service(self, service_id):
path = "/services/{}".format(service_id)
auth_header = self.get_header()
auth = self.get_auth()
return requests.delete(self._url+path, headers=auth_header, auth=auth)

def patch(self, path):
"""
Makes a RESTful PATCH request to the back end.
Expand Down
6 changes: 1 addition & 5 deletions models/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from qgis.PyQt.QtCore import QFileInfo
from qgis.core import QgsProject


class Result():

def __init__(self, path=None):
Expand All @@ -26,7 +25,4 @@ def display(self):

else:
print
"Unable to read basename and file path - Your string is probably invalid"



"Unable to read basename and file path - Your string is probably invalid"
Binary file added openEO_plugin_header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions openeo_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from qgis.PyQt.QtWidgets import QAction
from PyQt5.QtGui import QIcon
from qgis.PyQt import QtWidgets
from PyQt5.QtCore import Qt

# Initialize Qt resources from file resources.py
from .resources import *
Expand Down Expand Up @@ -182,6 +183,11 @@ def run(self):
self.dlg.refreshButton.setIcon(QIcon(os.path.join(os.path.dirname(__file__), 'reload_icon.png')))
self.dlg.deleteButton.setIcon(QIcon(os.path.join(os.path.dirname(__file__), 'delete_job.png')))
self.dlg.deleteFinalButton.setIcon(QIcon(os.path.join(os.path.dirname(__file__), 'deleteFinalBtn.png')))
self.dlg.refreshButton_service.setIcon(QIcon(os.path.join(os.path.dirname(__file__), 'reload_icon.png')))
self.dlg.deleteButton_service.setIcon(QIcon(os.path.join(os.path.dirname(__file__), 'delete_job.png')))
self.dlg.deleteFinalButton_service.setIcon(QIcon(os.path.join(os.path.dirname(__file__), 'deleteFinalBtn.png')))
self.dlg.operationManualBtn.setIcon(QIcon(os.path.join(os.path.dirname(__file__), 'user_manual_icon.png')))
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)

# show the dialog
self.dlg.show()
Expand Down
Loading

0 comments on commit ec56441

Please sign in to comment.