Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
situx committed Jan 31, 2025
2 parents d7a7a24 + c60bea8 commit 9b30c6c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
14 changes: 1 addition & 13 deletions dialogs/conf/triplestoredialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,7 @@ def __init__(self,triplestoreconf,prefixes,prefixstore,comboBox):
self.prefixstore=prefixstore
self.comboBox=comboBox
self.prefixes=prefixes
for item in triplestoreconf:
if "resource" in item and "type" in item["resource"] and item["resource"]["type"]=="file":
self.tripleStoreChooser.addItem(UIUtils.rdffileicon,
item["name"] + " [File]")
elif "type" in item:
if item["type"] == "geosparqlendpoint":
self.tripleStoreChooser.addItem(UIUtils.geoendpointicon, item["name"]+ " [GeoSPARQL Endpoint]")
elif item["type"]=="sparqlendpoint":
self.tripleStoreChooser.addItem(UIUtils.linkeddataicon,item["name"] + " [SPARQL Endpoint]")
elif item["type"]=="file":
self.tripleStoreChooser.addItem(UIUtils.rdffileicon,item["name"] + " [File]")
else:
self.tripleStoreChooser.addItem(item["name"]+" ["+str(item["type"])+"]")
UIUtils.createTripleStoreCBox(self.tripleStoreChooser,triplestoreconf)
self.tripleStoreChooser.currentIndexChanged.connect(self.loadTripleStoreConfig)
self.tripleStoreChooser.view().setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.geometryVariableComboBox.currentIndexChanged.connect(self.switchQueryVariableInput)
Expand Down
13 changes: 9 additions & 4 deletions sparql_unicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,11 @@ def saveTripleStoreConfig(self):
with open(os.path.join(__location__, 'conf/triplestoreconf_personal.json'), 'w') as myfile:
myfile.write(json.dumps(self.triplestoreconf, indent=2))

def syncTripleStoreConfig(self,combobox):
def syncTripleStoreConfig(self,combobox=None,dlg=None):
self.qlayerinstance = TripleStoreRepositorySyncTask(
"Syncing triplestore conf with repository",combobox, self.triplestoreconf)
"Syncing triplestore conf with repository",self.dlg,combobox, self.triplestoreconf)
QgsApplication.taskManager().addTask(self.qlayerinstance)
self.triplestoreconf=self.qlayerinstance.triplestoreconf

## Restores the triple store configuration file with the version delivered with the SPARQLUnicorn QGIS plugin.
# @param self The object pointer.
Expand Down Expand Up @@ -315,16 +316,20 @@ def run(self):
"""Run method that performs all the real work"""
# Create the dialog with elements (after translation) and keep reference
# Only create GUI ONCE in callback, so that it will only load when the plugin is started
if self.first_start == True:
self.first_start=True
if self.first_start:
self.first_start = False
self.manageTripleStoreConfFiles()
QgsMessageLog.logMessage('Started task "{}"'.format(str(len(self.triplestoreconf))), "SPARQL Unicorn",
Qgis.Info)
QgsMessageLog.logMessage('Started task "{}"'.format(str(len(self.triplestoreconf))), "SPARQL Unicorn", Qgis.Info)
self.dlg = SPARQLunicornDialog(self.languagemap,self.triplestoreconf, self.prefixes, self.addVocabConf, self.autocomplete,
self.prefixstore, self.savedQueriesJSON, self)
self.dlg.comboBox.clear()
UIUtils.createLanguageSelectionCBox(self.dlg.queryResultLanguageCBox,self.languagemap)
UIUtils.createTripleStoreCBox(self.dlg.comboBox,self.triplestoreconf)
self.syncTripleStoreConfig(self.dlg.comboBox,self.dlg)
self.dlg.comboBox.setCurrentIndex(0)
self.syncTripleStoreConfig(self.dlg.comboBox)
self.dlg.oauthTestButton.hide()
self.dlg.oauthTestButton.clicked.connect(lambda: LoginWindowDialog(self).exec())
self.dlg.tabchanged(self.dlg.tabWidget.currentIndex())
Expand Down
14 changes: 8 additions & 6 deletions tasks/query/util/triplestorereposynctask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
class TripleStoreRepositorySyncTask(QgsTask):


def __init__(self, description,combobox,triplestoreconf,removeOldConfig=False,triplestorerepourl=None):
def __init__(self, description,dlg,combobox,triplestoreconf,removeOldConfig=False,triplestorerepourl=None):
super().__init__(description, QgsTask.CanCancel)
self.exception = None
self.triplestoreconf=triplestoreconf
self.dlg=dlg
self.combobox=combobox
self.triplestorerepourl = triplestorerepourl
self.removeOldConfig=removeOldConfig
Expand All @@ -27,8 +28,7 @@ def run(self):
QgsMessageLog.logMessage('Started task "{}"'.format(str(self.triplestorerepourl)), MESSAGE_CATEGORY, Qgis.Info)
try:
self.results = json.loads(requests.get(self.triplestorerepourl).text)
#QgsMessageLog.logMessage('Started task "{}"'.format(str(self.results)), MESSAGE_CATEGORY,
# Qgis.Info)
QgsMessageLog.logMessage('Started task "{}"'.format(str(len(self.results))), MESSAGE_CATEGORY,Qgis.Info)
return True
except Exception as e:
self.exception=e
Expand All @@ -39,6 +39,8 @@ def finished(self, result):
QgsMessageLog.logMessage("An error occured while accessing the triple store repository:\n" + str(self.exception), MESSAGE_CATEGORY,Qgis.Info)
ErrorMessageBox("Error syncing triple stores","An error occured while accessing the triple store repository:\n" + str(self.exception)).exec()
if self.results is not None:
triplestoreconf=ConfigUtils.updateTripleStoreConf(self.triplestoreconf,self.results,self.removeOldConfig)
self.combobox.clear()
UIUtils.createTripleStoreCBox(self.combobox, triplestoreconf)
QgsMessageLog.logMessage("Updating triplestoreconf:",MESSAGE_CATEGORY, Qgis.Info)
self.dlg.triplestoreconf=ConfigUtils.updateTripleStoreConf(self.triplestoreconf,self.results,self.removeOldConfig)
if self.dlg.comboBox is not None:
self.dlg.comboBox.clear()
UIUtils.createTripleStoreCBox(self.dlg.comboBox, self.triplestoreconf)
13 changes: 13 additions & 0 deletions util/conf/configutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def updateTripleStoreConf(triplestoreconf,newtriplestoreconf,removeold=False):
seentriplestores[conf["resource"]["url"]]=True
urltoindex[conf["resource"]["url"]]=str(counter)
counter+=1
elif "resource" in conf and conf["resource"]["type"]=="file" and conf["resource"]["url"].startswith("http"):
triplestoreconfindex[conf["resource"]["url"]]=conf
seentriplestores[conf["resource"]["url"]]=True
urltoindex[conf["resource"]["url"]]=str(counter)
counter+=1
QgsMessageLog.logMessage('TripleStoreConfIndex' + str(triplestoreconfindex), MESSAGE_CATEGORY, Qgis.Info)
for nconf in newtriplestoreconf:
QgsMessageLog.logMessage('NCONF ' + str(nconf), MESSAGE_CATEGORY, Qgis.Info)
Expand All @@ -71,6 +76,14 @@ def updateTripleStoreConf(triplestoreconf,newtriplestoreconf,removeold=False):
else:
QgsMessageLog.logMessage('Found new conf for ' + str(nconf["resource"]["url"]), MESSAGE_CATEGORY,Qgis.Info)
triplestoreconf.append(nconf)
if "resource" in nconf and nconf["resource"]["type"] == "file" and nconf["resource"]["url"].startswith("http"):
if nconf["resource"]["url"] in triplestoreconfindex:
QgsMessageLog.logMessage('Updating conf for ' + str(nconf["resource"]["url"]), MESSAGE_CATEGORY, Qgis.Info)
triplestoreconfindex[nconf["resource"]["url"]]=nconf
del seentriplestores[nconf["resource"]["url"]]
else:
QgsMessageLog.logMessage('Found new conf for ' + str(nconf["resource"]["url"]), MESSAGE_CATEGORY,Qgis.Info)
triplestoreconf.append(nconf)
if removeold:
for ts in seentriplestores:
if ts in urltoindex:
Expand Down
9 changes: 8 additions & 1 deletion util/ui/uiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ def createTripleStoreCBox(cbox,triplestoreconf):
item += " --> "
for mandvar in triplestore["mandatoryvariables"]:
item += "?" + mandvar + " "
if "type" in triplestore and triplestore["type"] == "geosparqlendpoint":
isfile=False
if "resource" in triplestore and "type" in triplestore["resource"] and triplestore["resource"]["type"]=="file":
if triplestore["resource"]["url"].startswith("http"):
item += " [URIResource]"
else:
item += " [File]"
cbox.addItem(UIUtils.rdffileicon, item)
elif "type" in triplestore and triplestore["type"] == "geosparqlendpoint":
item += " [GeoSPARQL Endpoint]"
cbox.addItem(UIUtils.geoendpointicon, item)
elif "type" in triplestore and triplestore["type"] == "sparqlendpoint":
Expand Down

0 comments on commit 9b30c6c

Please sign in to comment.