Skip to content

Commit

Permalink
fixed errormessage dialog and added triple store result detection dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
situx committed Jan 23, 2025
1 parent 89e04f4 commit 29de277
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 7 deletions.
85 changes: 85 additions & 0 deletions dialogs/info/detecttriplestoreresultdialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from qgis.PyQt.QtWidgets import QDialog
from qgis.PyQt.QtWidgets import QStyle
from qgis.PyQt.QtGui import QIcon
from ...util.ui.uiutils import UIUtils
import os
import json
from qgis.PyQt.QtGui import QRegExpValidator
from qgis.PyQt import uic

FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), '../ui/detecttriplestoreresultdialog.ui'))

class DetectTripleStoreResultDialog(QDialog, FORM_CLASS):

def __init__(self,parentdialog,triplestoreconf,triplestorename,triplestorechooser,prefixes,configuration,permanentAdd,capabilities,missingproperties,typeproperty="http://www.w3.org/1999/02/22-rdf-syntax-ns#type",subclassofproperty="http://www.w3.org/2000/01/rdf-schema#subClassOf"):
QDialog.__init__(self,parentdialog)
self.setupUi(self)
self.setWindowTitle("Triple Store Detection Result")
self.setWindowIcon(QIcon(self.style().standardIcon(getattr(QStyle, 'SP_MessageBoxInformation'))))
self.parentdialog=parentdialog
self.permanentAdd=permanentAdd
self.missingproperties=missingproperties
self.triplestoreconf=triplestoreconf
self.triplestorename=triplestorename
self.tripleStoreChooser=triplestorechooser
self.prefixes=prefixes
self.configuration=configuration
self.capabilitiesLabel.setText(capabilities)
if len(self.missingproperties)>0:
self.propertiesMissingLabel.setText("<html><font color=red><b>The plugin could not detect type or subclass properties for this triple store.<br/> Please provide them for the ClassTree View to work properly</font></b></html>")
if "typeproperty" not in self.missingproperties:
self.typePropertyEdit.setText(self.configuration["typeproperty"])
self.typePropertyEdit.setValidator(QRegExpValidator(UIUtils.urlregex, self))
self.typePropertyEdit.textChanged.connect(lambda: UIUtils.check_state(self.typePropertyEdit))
self.typePropertyEdit.textChanged.emit(self.typePropertyEdit.text())
if "subclassproperty" not in self.missingproperties:
self.typePropertyEdit.setText(self.configuration["subclassproperty"])
self.subClassOfEdit.setText(self.configuration["subclassproperty"])
self.subClassOfEdit.setValidator(QRegExpValidator(UIUtils.urlregex, self))
self.subClassOfEdit.textChanged.connect(lambda: UIUtils.check_state(self.subClassOfEdit))
self.subClassOfEdit.textChanged.emit(self.subClassOfEdit.text())
self.geoPropertyEdit.setValidator(QRegExpValidator(UIUtils.urlregex, self))
self.geoPropertyEdit.textChanged.connect(lambda: UIUtils.check_state(self.geoPropertyEdit))
self.geoPropertyEdit.textChanged.emit(self.geoPropertyEdit.text())
self.stackedWidget.show()
else:
self.stackedWidget.hide()
self.addTripleStoreButton.clicked.connect(self.addConfiguration)
self.cancelButton.clicked.connect(self.close)
self.show()


def addConfiguration(self):
if self.missingproperties:
if self.typePropertyEdit.text()=="":
self.configuration["typeproperty"]="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
else:
self.configuration["typeproperty"]=self.typePropertyEdit.text()
if self.subClassOfEdit.text()=="":
self.configuration["subclassproperty"]="http://www.w3.org/2000/01/rdf-schema#subClassOf"
else:
self.configuration["subclassproperty"]=self.subClassOfEdit.text()
if "type" in self.configuration and self.configuration["type"] == "geosparqlendpoint":
self.tripleStoreChooser.addItem(UIUtils.geoendpointicon, self.triplestorename + " [GeoSPARQL Endpoint]")
else:
self.tripleStoreChooser.addItem(UIUtils.linkeddataicon, self.triplestorename + " [SPARQL Endpoint]")
index = len(self.triplestoreconf)
self.triplestoreconf.append({})
self.triplestoreconf[index] = self.configuration
self.addTripleStore = False
self.prefixes.append("")
for prefix in self.configuration["prefixes"]:
self.prefixes[len(self.prefixes) - 1] += "PREFIX " + prefix + ":<" + self.configuration["prefixes"][
prefix] + ">\n"
if self.permanentAdd is not None and self.permanentAdd:
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
f = open(os.path.join(__location__, 'triplestoreconf_personal.json'), "w")
f.write(json.dumps(self.triplestoreconf, indent=2))
f.close()
if self.tripleStoreChooser is not None:
# self.tripleStoreChooser.addItem(self.triplestorename)
self.tripleStoreChooser.setCurrentIndex(self.tripleStoreChooser.count() - 1)
if self.parentdialog is not None:
self.parentdialog.close()
self.close()
164 changes: 164 additions & 0 deletions dialogs/ui/detecttriplestoreresultdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>291</width>
<height>260</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>:/icons/resources/icons/featurecollectionToRDF.png</normaloff>:/icons/resources/icons/featurecollectionToRDF.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0" colspan="2">
<widget class="QStackedWidget" name="stackedWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page_3">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QLineEdit" name="typePropertyEdit">
<property name="placeholderText">
<string>http://www.w3.org/1999/02/22-rdf-syntax-ns#type</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="propertiesMissingLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="typePropertyLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="toolTip">
<string>Select the target conversion vocabulary</string>
</property>
<property name="text">
<string>Type Property:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="subClassOfLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>SubClass Property:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="subClassOfEdit">
<property name="placeholderText">
<string>http://www.w3.org/2000/01/rdf-schema#subClassOf</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="typeHeadingLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Automatic Detection for Properties&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="geoPropertyLabel">
<property name="text">
<string>&lt;b&gt;GeoProperty:&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="geoPropertyEdit">
<property name="placeholderText">
<string>http://www.opengis.net/ont/geosparql#asWKT</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="12" column="1">
<widget class="QPushButton" name="addTripleStoreButton">
<property name="text">
<string>Add Triple Store</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="convertLayerLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Detection Results&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="capabilitiesLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>Dialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>329</x>
<y>149</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>84</y>
</hint>
</hints>
</connection>
</connections>
</ui>
3 changes: 3 additions & 0 deletions dialogs/ui/errormessageboxdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down
7 changes: 3 additions & 4 deletions tasks/query/data/querylayertask.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import json

from ....dialogs.info.errormessagebox import ErrorMessageBox
from ....util.style.styleutils import StyleUtils
from ....util.doc.docconfig import DocConfig
from ....util.layerutils import LayerUtils
from ....util.sparqlutils import SPARQLUtils
from qgis.utils import iface
from qgis.core import Qgis,QgsTask, QgsMessageLog
from qgis.PyQt.QtWidgets import QMessageBox
from qgis.PyQt.QtXml import QDomDocument
from qgis.core import QgsProject, QgsVectorLayer

Expand Down Expand Up @@ -265,14 +264,14 @@ def finished(self, result):
#QgsMessageLog.logMessage('Adding vlayernongeo ' + str(self.vlayernongeo),
# MESSAGE_CATEGORY, Qgis.Info)
if self.geojson is None and self.exception is not None:
msgBox = QMessageBox()
msgBox = ErrorMessageBox("Query Error","")
msgBox.setText("An error occurred while querying: " + str(self.exception))
msgBox.exec()
if self.progress is not None:
self.progress.close()
return
if self.geojson is None and self.nongeojson is None:
msgBox = QMessageBox()
msgBox = ErrorMessageBox("Query Error","")
msgBox.setText("The query yielded no results. Therefore no layer will be created!")
msgBox.exec()
if self.progress is not None:
Expand Down
6 changes: 5 additions & 1 deletion tasks/query/util/detecttriplestoretask.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
import os

from ....dialogs.info.detecttriplestoreresultdialog import DetectTripleStoreResultDialog
from ....dialogs.info.errormessagebox import ErrorMessageBox
from ....util.sparqlutils import SPARQLUtils
from ....util.ui.uiutils import UIUtils
from ....util.graphutils import GraphUtils
from qgis.utils import iface
from qgis.core import Qgis,QgsTask
Expand Down Expand Up @@ -53,6 +53,9 @@ def run(self):
def finished(self, result):
self.progress.close()
if self.gutils.feasibleConfiguration and self.testConfiguration:
DetectTripleStoreResultDialog(self.parentdialog,self.triplestoreconf,self.triplestorename,self.tripleStoreChooser,self.prefixes,self.gutils.configuration,
self.permanentAdd,self.gutils.message,self.gutils.missingproperties).exec()
"""
msgBox = QMessageBox()
msgBox.setStandardButtons(QMessageBox.Yes)
msgBox.addButton(QMessageBox.No)
Expand Down Expand Up @@ -82,6 +85,7 @@ def finished(self, result):
self.tripleStoreChooser.setCurrentIndex(self.tripleStoreChooser.count()-1)
if self.parentdialog is not None:
self.parentdialog.close()
"""
elif self.gutils.feasibleConfiguration:
msgBox = QMessageBox()
msgBox.setText("Automatic Detection Successful")
Expand Down
10 changes: 8 additions & 2 deletions util/graphutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self,testURL):
self.configuration={}
self.testURL=testURL
self.message=""
self.missingproperties=[]

def addDefaultConfigurationParameters(self,triplestorename,triplestoreurl,credentialUserName=None,credentialPassword=None,authmethod=None):
self.configuration = {}
Expand Down Expand Up @@ -80,10 +81,10 @@ def addDefaultConfigurationParameters(self,triplestorename,triplestoreurl,creden

## Creates a String representation of the capabilities of the triple store
def createCapabilityMessage(self,capabilitylist):
capabilitymessage="URL depicts a valid SPARQL Endpoint with the following capabilities: <ul>"
capabilitymessage="A valid SPARQL Endpoint with the following capabilities: <ul>"
for cap in capabilitylist:
capabilitymessage+="<li>"+cap+"</li>"
capabilitymessage+="</ul>Would you like to add this SPARQL endpoint?"
capabilitymessage+="</ul>"
return capabilitymessage

def detectLiteralType(self,configuration,credentialUserName,credentialPassword, authmethod,capabilitylist):
Expand Down Expand Up @@ -372,6 +373,7 @@ def detectTripleStoreConfiguration(self,triplestorename,triplestoreurl,detectnam
if self.testTripleStoreConnection(self.configuration["resource"],self.testQueries["available"],credentialUserName,credentialPassword,authmethod):
capabilitylist=self.detectTripleStoreType(self.configuration,credentialUserName,credentialPassword,authmethod,capabilitylist)
gottype=self.detectLiteralType(self.configuration,credentialUserName,credentialPassword,authmethod,capabilitylist)
rdftype = self.detectTypeProperty(self.configuration["resource"], credentialUserName,credentialPassword, authmethod, self.configuration)
subclassof=self.detectSubClassOfProperty(self.configuration["resource"],credentialUserName, credentialPassword, authmethod,self.configuration)
equivprops=self.detectEquivalentProperties(self.configuration["resource"],credentialUserName, credentialPassword, authmethod,self.configuration)
equivcls=self.detectEquivalentClasses(self.configuration["resource"],credentialUserName, credentialPassword, authmethod,self.configuration)
Expand Down Expand Up @@ -399,6 +401,10 @@ def detectTripleStoreConfiguration(self,triplestorename,triplestoreurl,detectnam
i = i + 1
self.feasibleConfiguration = True
QgsMessageLog.logMessage(str(self.configuration))
if rdftype=="":
self.missingproperties.append("typeproperty")
if subclassof=="":
self.missingproperties.append("subclassproperty")
if self.testTripleStoreConnection(self.configuration["resource"],self.testQueries["hasDCTermsTitleLabel"]):
self.configuration["labelproperty"].append("http://purl.org/dc/terms/title")
if self.testTripleStoreConnection(self.configuration["resource"],self.testQueries["hasSKOSPrefLabel"]):
Expand Down

0 comments on commit 29de277

Please sign in to comment.