Repository: hydroshare/hydroshare

Issue:
Failed to create geographic feature resource
The files are from this resource https://www.hydroshare.org/resource/822fe5a7a83a49668c77a85179c3a7ee/. 

The error is shown as below. Thanks for looking into this issue 
![v1 ao3 o6x3ete23yl1nw](https://cloud.githubusercontent.com/assets/5016511/20231562/19a9d520-a820-11e6-9373-81cf529504b8.png)



Discussion:

Resolving patch:
diff --git a/hs_geographic_feature_resource/parse_lib.py b/hs_geographic_feature_resource/parse_lib.py
--- a/hs_geographic_feature_resource/parse_lib.py
+++ b/hs_geographic_feature_resource/parse_lib.py
@@ -9,6 +9,9 @@
     #  Python 3
     from html.parser import HTMLParser
 
+from hs_core.models import Title
+
+
 UNKNOWN_STR = "unknown"
 
 
@@ -156,27 +159,36 @@ def parse_shp_xml(shp_xml_full_path):
         if os.path.isfile(shp_xml_full_path):
             with open(shp_xml_full_path) as fd:
                 xml_dict = xmltodict.parse(fd.read())
-                if 'metadata' in xml_dict:
-                    if 'dataIdInfo' in xml_dict['metadata']:
-                        dataIdInfo_dict = xml_dict['metadata']['dataIdInfo']
-                        if 'idAbs' in dataIdInfo_dict:
-                            description_value = clean_text(dataIdInfo_dict['idAbs'])
-                            description = {'description': {'abstract': description_value}}
-                            metadata.append(description)
-                        if 'idPurp' in xml_dict['metadata']['dataIdInfo']:
-                            title_value = clean_text(dataIdInfo_dict['idPurp'])
-                            title = {'title': {'value': title_value}}
-                            metadata.append(title)
-                        if 'searchKeys' in dataIdInfo_dict:
-                            searchKeys_dict = dataIdInfo_dict['searchKeys']
-                            if 'keyword' in searchKeys_dict:
-                                keyword_list = []
-                                if type(searchKeys_dict["keyword"]) is list:
-                                    keyword_list += searchKeys_dict["keyword"]
-                                else:
-                                    keyword_list.append(searchKeys_dict["keyword"])
-                                for k in keyword_list:
-                                    metadata.append({'subject': {'value': k}})
+
+                dataIdInfo_dict = xml_dict['metadata']['dataIdInfo']
+                if 'idCitation' in dataIdInfo_dict:
+                    if 'resTitle' in dataIdInfo_dict['idCitation']:
+                        if '#text' in dataIdInfo_dict['idCitation']['resTitle']:
+                            title_value = dataIdInfo_dict['idCitation']['resTitle']['#text']
+                        else:
+                            title_value = dataIdInfo_dict['idCitation']['resTitle']
+
+                        title_max_length = Title._meta.get_field('value').max_length
+                        if len(title_value) > title_max_length:
+                            title_value = title_value[:title_max_length-1]
+                        title = {'title': {'value': title_value}}
+                        metadata.append(title)
+
+                if 'idAbs' in dataIdInfo_dict:
+                    description_value = clean_text(dataIdInfo_dict['idAbs'])
+                    description = {'description': {'abstract': description_value}}
+                    metadata.append(description)
+
+                if 'searchKeys' in dataIdInfo_dict:
+                    searchKeys_dict = dataIdInfo_dict['searchKeys']
+                    if 'keyword' in searchKeys_dict:
+                        keyword_list = []
+                        if type(searchKeys_dict["keyword"]) is list:
+                            keyword_list += searchKeys_dict["keyword"]
+                        else:
+                            keyword_list.append(searchKeys_dict["keyword"])
+                        for k in keyword_list:
+                            metadata.append({'subject': {'value': k}})
 
     except Exception:
         # Catch any exception silently and return an empty list


Test patch:
diff --git a/hs_geographic_feature_resource/tests/test_geo_feature.py b/hs_geographic_feature_resource/tests/test_geo_feature.py
--- a/hs_geographic_feature_resource/tests/test_geo_feature.py
+++ b/hs_geographic_feature_resource/tests/test_geo_feature.py
@@ -593,7 +593,7 @@ def test_read_shp_xml(self):
                       resGeoFeature2.metadata.description.abstract)
 
         # test title
-        self.assertIn("Ponds and wetlands impounded by beaver dams as of 1940",
+        self.assertIn("beaver_ponds_1940",
                       resGeoFeature2.metadata.title.value)
 
         # test keywords