[GRASS-SVN] r67611 - in grass-addons/grass7/gui/wxpython/wx.metadata: config mdlib

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 19 12:33:26 PST 2016


Author: krejcmat
Date: 2016-01-19 12:33:26 -0800 (Tue, 19 Jan 2016)
New Revision: 67611

Added:
   grass-addons/grass7/gui/wxpython/wx.metadata/config/record_metadata_gmd.html
Modified:
   grass-addons/grass7/gui/wxpython/wx.metadata/config/connections_resources.xml
   grass-addons/grass7/gui/wxpython/wx.metadata/config/record_metadata_dc.html
   grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py
   grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py
Log:
addons g.gui.cswbrowser: workaround for browsing CSW which returns records based on ISO schema http://schemas.opengis.net/csw/2.0.2/

Modified: grass-addons/grass7/gui/wxpython/wx.metadata/config/connections_resources.xml
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.metadata/config/connections_resources.xml	2016-01-19 09:11:17 UTC (rev 67610)
+++ grass-addons/grass7/gui/wxpython/wx.metadata/config/connections_resources.xml	2016-01-19 20:33:26 UTC (rev 67611)
@@ -14,4 +14,7 @@
     <csw name="UK Location Catalogue Publishing Service" url="http://csw.data.gov.uk/geonetwork/srv/en/csw" />
     <csw name="UNEP GRID-Geneva Metadata Catalog" url="http://metadata.grid.unep.ch:8080/geonetwork/srv/eng/csw" />
     <csw name="USA: Data.gov CSW" url="http://catalog.data.gov/csw-all" />
-<csw name="localhost" url="http://localhost:8000/" /><csw name="den" url="http://www.geodata-info.dk/registrant/srv/en/csw" /></qgsCSWConnections>
\ No newline at end of file
+    <csw name="localhost" url="http://localhost:8000/" />
+    <csw name="INSPIRE Geoportal Discovery Service(workaround for GMD)" url="http://data.jrc.ec.europa.eu/catalogue/service" />
+    <csw name="den" url="http://www.geodata-info.dk/registrant/srv/en/csw" />
+</qgsCSWConnections>
\ No newline at end of file

Modified: grass-addons/grass7/gui/wxpython/wx.metadata/config/record_metadata_dc.html
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.metadata/config/record_metadata_dc.html	2016-01-19 09:11:17 UTC (rev 67610)
+++ grass-addons/grass7/gui/wxpython/wx.metadata/config/record_metadata_dc.html	2016-01-19 20:33:26 UTC (rev 67611)
@@ -21,12 +21,14 @@
     <h3>{{ gettext('Record Metadata') }} (<a href="{{ obj.xml_url }}">{{ gettext('View XML') }}</a>)</h3>
 </header>
 <section id="record-metadata">
+     <table>
+         <tr>
+              <td>{{ gettext('Identifier') }}</td>
+              <td>{{ obj.identifier }}</td>
+        </tr>
+    </table>
     <table>
         <tr>
-            <td>{{ gettext('Identifier') }}</td>
-            <td>{{ obj.identifier }}</td>
-        </tr>
-        <tr>
             <td>{{ gettext('Title') }}</td>
             <td>{{ obj.title }}</td>
         </tr>
@@ -51,10 +53,6 @@
             <td>{{ obj.publisher}}</td>
         </tr>
         <tr>
-            <td>{{ gettext('Contributor') }}</td>
-            <td>{{ obj.contributor}}</td>
-        </tr>
-        <tr>
             <td>{{ gettext('Modified') }}</td>
             <td>{{ obj.modified }}</td>
         </tr>

Added: grass-addons/grass7/gui/wxpython/wx.metadata/config/record_metadata_gmd.html
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.metadata/config/record_metadata_gmd.html	                        (rev 0)
+++ grass-addons/grass7/gui/wxpython/wx.metadata/config/record_metadata_gmd.html	2016-01-19 20:33:26 UTC (rev 67611)
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html lang="{{ language }}">
+<head>
+    <meta charset="utf-8"/>
+    <title>{{ gettext('Record Metadata') }}</title>
+    <style type="text/css">
+        body, h3 {
+            background-color: #ffffff;
+            font-family: arial, verdana, sans-serif;
+            text-align: left;
+            float: left;
+        }
+
+        header {
+            display: inline-block;
+        }
+    </style>
+</head>
+<body>
+<header>
+    <h3>{{ gettext('Record Metadata') }}</h3>
+</header>
+<section id="record-metadata">
+     <table>
+         <tr>
+            <td>{{ gettext('Identifier') }}</td>
+            <td>{{ obj.identifier }}</td>
+        </tr>
+    </table>
+    <table>
+        <tr>
+            <td>{{ gettext('Title') }}</td>
+            <td>{{ obj.identification.title }}</td>
+        </tr>
+        <tr>
+            <td>{{ gettext('Abstract') }}</td>
+            <td>{{ obj.identification.abstract }}</td>
+        </tr>
+        <tr>
+        {% for co in obj.identification.contact -%}
+            <tr>
+                <td>{{ gettext('Responsible party:') }}</td>
+                <tr><td>{{ gettext(' -organisation') }}</td><td>{{ co.organization }}</td></tr>
+                <tr><td>{{ gettext(' -email') }}</td><td>{{ co.email }}</td></tr>
+                <tr><td>{{ gettext(' -role') }}</td><td>{{ co.role }}</td></tr>
+            </tr>
+        {% endfor -%}
+        </tr>
+        <tr>
+            <td>{{ gettext('Language') }}</td>
+            <td>{{ obj.languagecode }}</td>
+        </tr>
+        <tr>
+            {% for rc in obj.identification.uselimitation -%}
+                <td>{{ gettext('Use limitation') }}</td>
+                <td> {{ rc }}</td>
+            {% endfor -%}
+        </tr>
+        <tr>
+            {% for oc in obj.identification.otherconstraints -%}
+                <td>{{ gettext('Other constraint') }}</td>
+                <td>{{ oc }}</td>
+            {% endfor -%}
+        </tr>
+        <tr>
+            {% for ac in obj.identification.accessconstraints -%}
+                <td>{{ gettext('Access constraints') }}</td>
+                <td> {{ ac }}</td>
+            {% endfor -%}
+        </tr>
+        <tr>
+            <td>{{ gettext('Bounding Box') }}</td>
+            <td>{{ [obj.identification.extent.boundingBox.minx, obj.identification.extent.boundingBox.miny, obj.identification.extent.boundingBox.maxx, obj.identification.extent.boundingBox.maxy]|join(',') }}</td>
+        </tr>
+    </table>
+</section>
+<section id="links">
+    <h4>Links</h4>
+    <ul>
+        {% for (cod,code) in zip(obj.identification.uricode,obj.identification.uricodespace) %}
+
+        <li><a href="{{ cod }}">{{ cod if cod not in [None, 'None', ''] else
+            gettext('Access Link') }}</a></li>
+        {% endfor %}
+    </ul>
+</section>
+</body>
+</html>

Modified: grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py	2016-01-19 09:11:17 UTC (rev 67610)
+++ grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py	2016-01-19 20:33:26 UTC (rev 67611)
@@ -41,7 +41,7 @@
 from grass.script import parse_key_val
 
 
-class ConstraintsBulder(wx.Panel):
+class ConstraintsBuilder(wx.Panel):
     def __init__(self, parent, settings=''):
         wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
         self.label = wx.StaticText(self, -1, label="Manual for creating constraints:\n\
@@ -93,6 +93,8 @@
         self.constraintsAdvanced = False
         self.idResults = []
         self.constString = ''
+        self.outpoutschema='dc'
+        self.warns=True
         sizeConst = 55
         self.splitterBrowser = SplitterWindow(self, style=wx.SP_3D | wx.SP_LIVE_UPDATE | wx.SP_BORDER)
         self.context = StaticContext()
@@ -210,7 +212,7 @@
                                       pos=wx.DefaultPosition)
 
             self.geDialog.SetSize((500, 500))
-            self.constrPnl = ConstraintsBulder(self.geDialog, self.constString)
+            self.constrPnl = ConstraintsBuilder(self.geDialog, self.constString)
             self.constrPnl.applyBtt.Bind(wx.EVT_BUTTON, self.OnSetAdvancedConstraints)
             self.constrPnl.cancelBtt.Bind(wx.EVT_BUTTON, self._destroyDialog)
             dbSizer = wx.BoxSizer(wx.VERTICAL)
@@ -271,7 +273,8 @@
         f.close()
         if yesNo(self, 'Do you want to open <request> in default browser', 'Open file'):
             open_url(path)
-        self.htmlView.SetPage((renderXML(self.context, self.catalog.request)))
+        else:
+            self.htmlView.SetPage((renderXML(self.context, self.catalog.request)))
 
     def OnShowResponse(self, evt):
         #response_html = encodeString(highlight_xml(self.context, self.catalog.response,False))
@@ -282,10 +285,12 @@
         f.close()
         if yesNo(self, 'Do you want to open <response> in default browser', 'Open file'):
             open_url(path)
-        self.htmlView.SetPage((renderXML(self.context, self.catalog.response)))
+        else:
+            self.htmlView.SetPage((renderXML(self.context, self.catalog.response)))
 
     def OnRecord(self, evt):
         """show record metadata"""
+
         self.refreshServiceButt()
         curr = 0
         idx = self.resultList.GetNextItem(curr, wx.LIST_NEXT_ALL,
@@ -293,36 +298,68 @@
         if not idx:
             return
 
-        identifier = self.get_item_data(idx, 'identifier')
-        try:
+        if self.outpoutschema == 'gmd':
+            startfr=self.startfrom+idx+1
+
+            #identifier = self.get_item_data(idx, 'identifier')
             cat = CatalogueServiceWeb(self.catalog_url, timeout=self.timeout)
-            cat.getrecordbyid(
-                [self.catalog.records[identifier].identifier])
-        except ExceptionReport, err:
-            GWarning('Error getting response: %s' % err)
-            return
-        except KeyError, err:
-            GWarning('Record parsing error, unable to locate record identifier')
-            return
 
-        record = cat.records[identifier]
-        record.xml_url = cat.request
+            try:
+               cat.getrecords2(constraints=self.constraints,
+                             maxrecords=1,
+                             startposition=startfr,
+                             outputschema='http://www.isotc211.org/2005/gmd')
+            except ExceptionReport, err:
+                GWarning('Error getting response: %s' % err)
+                return
+            except KeyError, err:
+                GWarning('Record parsing error, unable to locate record identifier')
+                return
 
-        if self.catalog:
-            path = 'record_metadata_dc.html'
-            metadata = render_template('en', self.context,
-                                       record,
-                                       path)
+            if self.catalog:
+                md=cat.records.values()[0]
+                path = 'record_metadata_gmd.html'
+                metadata = render_template('en', self.context,md,path)
 
-        try:
-            record = self.catalog.records[identifier]
-        except KeyError, err:
-            GWarning('@!Record parsing error, unable to locate record identifier')
-            return
+            #try:
+            #    record = self.catalog.records[identifier]
+            #except KeyError, err:
+            #    GWarning('@!Record parsing error, unable to locate record identifier')
+            #    return
 
-        self.htmlView.SetPage(metadata)
-        self.findServices(record, idx)
+            self.htmlView.SetPage(metadata)
+            #self.findServices(record, idx)
 
+        else:
+            identifier = self.get_item_data(idx, 'identifier')
+            cat = CatalogueServiceWeb(self.catalog_url, timeout=self.timeout)
+            try:
+               cat.getrecordbyid([self.catalog.records[identifier].identifier])
+            except ExceptionReport, err:
+                GWarning('Error getting response: %s' % err)
+                return
+            except KeyError, err:
+                GWarning('Record parsing error, unable to locate record identifier')
+                return
+
+            record = cat.records[identifier]
+            record.xml_url = cat.request
+
+            if self.catalog:
+                path = 'record_metadata_dc.html'
+                metadata = render_template('en', self.context,
+                                           record,
+                                           path)
+
+            try:
+                record = self.catalog.records[identifier]
+            except KeyError, err:
+                GWarning('@!Record parsing error, unable to locate record identifier')
+                return
+
+            self.htmlView.SetPage(metadata)
+            self.findServices(record, idx)
+
     def findServices(self, record, item):
         """scan record for WMS/WMTS|WFS|WCS endpoints"""
         links = record.uris + record.references
@@ -415,6 +452,7 @@
             self.bttAddWcs.Enable()
 
     def OnNavigate(self, evt):
+
         name = evt.GetEventObject().GetLabel()
         if name == '<<':
             self.startfrom = 0
@@ -438,10 +476,16 @@
                     return
 
         self.loadConstraints()
+
         try:
-            self.catalog.getrecords2(constraints=self.constraints,
-                                     maxrecords=self.maxrecords,
-                                     startposition=self.startfrom, esn='full')
+            if self.outpoutschema == 'gmd':
+                self.catalog.getrecords2(constraints=self.constraints,
+                                         maxrecords=self.maxrecords, esn='full',startposition=self.startfrom,
+                                         outputschema='http://www.isotc211.org/2005/gmd')
+            else:
+                self.catalog.getrecords2(constraints=self.constraints,
+                                         maxrecords=self.maxrecords,
+                                         startposition=self.startfrom, esn='full')
         except ExceptionReport, err:
             GWarning('Search error: %s' % err)
             return
@@ -449,6 +493,10 @@
             GWarning('Connection error: %s' % err)
             return
 
+        if self.outpoutschema == 'gmd':
+            self.displyResultsGMD()
+            return
+
         self.displyResults()
 
     def OnSetCatalog(self, evt):
@@ -645,7 +693,7 @@
             self.constraints.append(BBox(bbox))
 
         # (a && b)
-        # build request
+        # build requestprint
         if not self._get_csw():
             return
 
@@ -654,17 +702,42 @@
         try:
             self.catalog.getrecords2(constraints=self.constraints,
                                      maxrecords=self.maxrecords, esn='full')
+            self.outpoutschema='dc'
         except ExceptionReport, err:
             GError('Search error: %s' % err)
             return
         except Exception, err:
             GError('Connection error: %s' % err)
             return
+        #work around for GMD records
+        if len(self.catalog.records)==0 and self.catalog.results['matches'] != 0:
+            try:
+                self.catalog.getrecords2(constraints=self.constraints,
+                                         maxrecords=self.maxrecords, esn='full',
+                                         outputschema='http://www.isotc211.org/2005/gmd')
+                self.outpoutschema='gmd'
+                if self.warns:
+                    GWarning("Endopoint of service is not setup properly. Server returns ISO metadata(http://www.isotc211.org/2005/gmd) instead of CSW records(http://schemas.opengis.net/csw/2.0.2/record.xsd). CSW browser may work incorrectly.")
+                    self.warns=False
+
+            except ExceptionReport, err:
+                GError('Search error: %s' % err)
+                return
+            except Exception, err:
+                GError('Connection error: %s' % err)
+                return
+
         if self.catalog.results['matches'] == 0:
             self.findResNumLbl.SetLabel('0 results')
             self.refreshNavigationButt(True)
             return
+
         self.refreshNavigationButt(True)
+        #parsing for another html template(GMD)
+        if self.outpoutschema == 'gmd':
+            self.displyResultsGMD()
+            return
+
         self.displyResults()
 
     def get_item_data(self, index, field):
@@ -695,6 +768,34 @@
                 d[index]['link'] = value
             self.idResults.insert(index, d)
 
+    def displyResultsGMD(self):
+        self.refreshResultList()
+        position = self.catalog.results['returned'] + self.startfrom
+        msg = 'Showing %s - %s of %s result(s)' % (self.startfrom + 1,
+                                                   position,
+                                                   self.catalog.results['matches'])
+
+        self.findResNumLbl.SetLabel(msg)
+        index = 0
+        for rec in self.catalog.records:
+
+            if self.catalog.records[rec].identification.identtype:
+                item = wx.ListItem()
+                self.resultList.InsertStringItem(index, normalize_text(self.catalog.records[rec].identification.identtype))
+            else:
+                self.resultList.SetStringItem(index, 0, 'unknown')
+            if self.catalog.records[rec].identification.title:
+                self.resultList.SetStringItem(index, 1, normalize_text(self.catalog.records[rec].identification.title))
+
+            if self.catalog.records[rec].identification.title:
+                self.set_item_data(index, 'identifier',
+                                   self.catalog.records[rec].identification.title)
+            if index % 2:
+                self.resultList.SetItemBackgroundColour(index, "LIGHT GREY")
+            index += 1
+
+        self.Fit()
+
     def displyResults(self):
         """display search results"""
 
@@ -878,11 +979,25 @@
         self.serviceInfoBtt.Bind(wx.EVT_BUTTON, self.onServiceInfo)
 
         self.textMetadata.Bind(EVT_HTML_LINK_CLICKED, self.onHtmlLinkClicked)
+        self.textMetadata.Bind(wx.EVT_KEY_DOWN, self.OnHtmlKeyDown)
+
         self._layout()
 
-    def GetUrl(self):
-        return self.catalog_url
+    def OnHtmlKeyDown(self,event):
+        if self._is_copy(event):
+            self._add_selection_to_clipboard()
+        self.textMetadata.Parent.OnKey(event)
+        event.Skip()
 
+    def _is_copy(self, event):
+        return event.GetKeyCode() == ord('C') and event.CmdDown()
+
+    def _add_selection_to_clipboard(self):
+        wx.TheClipboard.Open()
+        wx.TheClipboard.SetData(wx.TextDataObject(self.textMetadata.SelectionToText()))
+        wx.TheClipboard.Close()
+
+
     def onNewconnection(self, evt=None, cancel=False):
         if self.newBtt.GetLabel() == "New":
             self.newBtt.SetLabel('Save')
@@ -905,7 +1020,6 @@
             self.stBoxConnections1Sizer.Add(self.connUrlNewLabel, 1, wx.EXPAND)
             self.stBoxConnections1Sizer.Add(self.connUrlNew, 1, wx.EXPAND)
 
-
         else:
             # test validity of connection
             url = self.connUrlNew.GetValue()

Modified: grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py	2016-01-19 09:11:17 UTC (rev 67610)
+++ grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py	2016-01-19 20:33:26 UTC (rev 67611)
@@ -47,6 +47,8 @@
 
     env = Environment(extensions=['jinja2.ext.i18n'],
                       loader=FileSystemLoader(context.confDirPath))
+    env.globals.update(zip=zip)
+
     env.install_gettext_callables(gettext, ngettext, newstyle=True)
 
     template_file = template



More information about the grass-commit mailing list