Repository: hydroshare/hydroshare

Issue:
Incorrect RDF/XML entry for raster aggregation spatial reference
**Description of the bug**
The rdf/xml of the spatial reference entry in a geographic raster aggregation is written incorrectly with an extra rdflib BNode.  Hsclient is unable to parse it, resulting in null value.

Steps to reproduce the bug:
1. Go to an aggregation rdf/xml
2. Right click on the aggregation
3. Click Download zipped
4. Open the _meta.xml file and compare the structure of spatial reference compared to spatial coverage.

**Expected behavior**
The rdf/xml of spatial reference should be the same structure as spatial coverage.



Discussion:

Resolving patch:
diff --git a/hs_geo_raster_resource/models.py b/hs_geo_raster_resource/models.py
--- a/hs_geo_raster_resource/models.py
+++ b/hs_geo_raster_resource/models.py
@@ -1,4 +1,5 @@
 import json
+import parser
 
 from django.contrib.contenttypes.fields import GenericRelation
 from django.db import models
@@ -114,24 +115,25 @@ def remove(cls, element_id):
     def rdf_triples(self, subject, graph):
         original_coverage = BNode()
         graph.add((subject, HSTERMS.spatialReference, original_coverage))
-        value = BNode()
-        graph.add((original_coverage, HSTERMS.box, value))
+        graph.add((original_coverage, RDF.type, HSTERMS.box))
         value_string = "; ".join(["=".join([key, str(val)]) for key, val in self.value.items()])
-        graph.add((value, RDF.value, Literal(value_string)))
+        graph.add((original_coverage, RDF.value, Literal(value_string)))
 
     @classmethod
     def ingest_rdf(cls, graph, subject, content_object):
-        spatial_object = graph.value(subject=subject, predicate=HSTERMS.spatialReference)
-        box_object = graph.value(subject=spatial_object, predicate=HSTERMS.box)
-        value_str = graph.value(subject=box_object, predicate=RDF.value)
-        if value_str:
-            value_str = value_str.value
-            value_dict = {}
-            for key_value in value_str.split(";"):
-                key_value = key_value.strip()
-                k, v = key_value.split("=")
-                value_dict[k] = v
-            OriginalCoverage.create(value=value_dict, content_object=content_object)
+        for _, _, cov in graph.triples((subject, cls.get_class_term(), None)):
+            rdf_type = graph.value(subject=cov, predicate=RDF.type)
+            value_str = graph.value(subject=cov, predicate=RDF.value)
+            rdf_type = rdf_type.split('/')[-1]
+            if value_str:
+                value_dict = {}
+                for key_value in value_str.split(";"):
+                    key_value = key_value.strip()
+                    k, v = key_value.split("=")
+                    if k in ['start', 'end']:
+                        v = parser.parse(v).strftime("%Y/%m/%d")
+                    value_dict[k] = v
+                OriginalCoverage.create(type=rdf_type, value=value_dict, content_object=content_object)
 
     @classmethod
     def get_html_form(cls, resource, element=None, allow_edit=True, file_type=False):


Test patch:
diff --git a/hs_core/tests/data/test_resource_metadata_files/logan_meta.xml b/hs_core/tests/data/test_resource_metadata_files/logan_meta.xml
--- a/hs_core/tests/data/test_resource_metadata_files/logan_meta.xml
+++ b/hs_core/tests/data/test_resource_metadata_files/logan_meta.xml
@@ -17,13 +17,9 @@
     </hsterms:BandInformation>
     <dc:title>logan1</dc:title>
     <hsterms:spatialReference>
-      <rdf:Description>
-        <hsterms:box>
-          <rdf:Description>
-            <rdf:value>northlimit=4655492.446916306; southlimit=4648592.446916306; eastlimit=452174.01909127034; westlimit=445574.01909127034; projection=NAD83 / UTM zone 12N; units=meter; projection_string=PROJCS["NAD83 / UTM zone 12N",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4269"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-111],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","26912"]]; datum=North_American_Datum_1983</rdf:value>
-          </rdf:Description>
-        </hsterms:box>
-      </rdf:Description>
+      <hsterms:box>
+        <rdf:value>northlimit=4655492.446916306; southlimit=4648592.446916306; eastlimit=452174.01909127034; westlimit=445574.01909127034; projection=NAD83 / UTM zone 12N; units=meter; projection_string=PROJCS["NAD83 / UTM zone 12N",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4269"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-111],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","26912"]]; datum=North_American_Datum_1983</rdf:value>
+      </hsterms:box>
     </hsterms:spatialReference>
     <dc:coverage>
       <dcterms:box>