예제 #1
0
 def convert_solr_json(self, solr_json):
     """ Converst the solr jsont """
     ok_show_debug = True
     if 'solr' in self.act_responses:
         return solr_json
     if 'context' in self.act_responses \
        or 'geo-facet' in self.act_responses \
        or 'geo-project' in self.act_responses \
        or 'geo-record' in self.act_responses:
         search_context_obj = SearchContext()
         self.json_ld['@context'] = search_context_obj.id
     if 'metadata' in self.act_responses:
         self.json_ld['id'] = self.make_id()
         self.json_ld['label'] = self.label
         self.json_ld['dcmi:modified'] = self.get_modified_datetime(
             solr_json)
         self.json_ld['dcmi:created'] = self.get_created_datetime(solr_json)
         self.add_paging_json(solr_json)
         self.add_filters_json()
         self.add_text_fields()
     # now process numeric + date fields, facets will
     # only be added if 'facet' in self.act_response
     self.add_numeric_fields(solr_json)
     self.add_date_fields(solr_json)
     # now check for form-use-life chronology
     # note! Do this first to set time bounds for geo-features
     # needs to be done, even if facet results are not displayed
     self.make_form_use_life_chronotiles(solr_json)
     if 'geo-facet' in self.act_responses:
         # now check for discovery geotiles
         self.make_discovery_geotiles(solr_json)
     if 'geo-project' in self.act_responses:
         # now check for project geojson
         self.make_project_geojson(solr_json)
     # now process regular facets.
     # they will only be added to the response if
     # 'facet' in self.act_response
     self.make_facets(solr_json)
     if 'geo-record' in self.act_responses \
        or 'nongeo-record' in self.act_responses:
         # now add the result information
         geojson_recs_obj = GeoJsonRecords(self.request_dict_json)
         geojson_recs_obj.entities = self.entities
         geojson_recs_obj.min_date = self.min_date
         geojson_recs_obj.max_date = self.max_date
         geojson_recs_obj.flatten_rec_attributes = self.flatten_rec_attributes
         geojson_recs_obj.rec_attributes = self.rec_attributes
         geojson_recs_obj.make_records_from_solr(solr_json)
         if len(geojson_recs_obj.geojson_recs) > 0 \
            and 'geo-record' in self.act_responses:
             self.json_ld['type'] = 'FeatureCollection'
             if 'features' not in self.json_ld:
                 self.json_ld['features'] = []
             self.json_ld['features'] += geojson_recs_obj.geojson_recs
         if len(geojson_recs_obj.non_geo_recs) > 0 \
            and 'nongeo-record' in self.act_responses:
             self.json_ld[
                 'oc-api:has-results'] = geojson_recs_obj.non_geo_recs
     if 'uuid' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         uuids = solr_uuids.make_uuids_from_solr(solr_json)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:uuids'] = uuids
         else:
             # just return a simple list
             self.json_ld = uuids
             ok_show_debug = False
     if 'uri' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         uris = solr_uuids.make_uris_from_solr(solr_json)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:has-results'] = uris
         else:
             # just return a simple list
             self.json_ld = uris
             ok_show_debug = False
     elif 'uri-meta' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         solr_uuids.min_date = self.min_date
         solr_uuids.max_date = self.max_date
         solr_uuids.entities = self.entities
         solr_uuids.flatten_rec_attributes = self.flatten_rec_attributes
         solr_uuids.rec_attributes = self.rec_attributes
         uris = solr_uuids.make_uris_from_solr(solr_json, False)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:has-results'] = uris
         else:
             # just return a simple list
             self.json_ld = uris
             ok_show_debug = False
     if settings.DEBUG and ok_show_debug:
         self.json_ld['request'] = self.request_dict
         # self.json_ld['request'] = self.request_dict
         self.json_ld['solr'] = solr_json
     return self.json_ld
예제 #2
0
 def convert_solr_json(self, solr_json):
     """ Converst the solr jsont """
     ok_show_debug = True
     if 'solr' in self.act_responses:
         return solr_json
     if 'context' in self.act_responses \
        or 'geo-facet' in self.act_responses \
        or 'geo-project' in self.act_responses \
        or 'geo-record' in self.act_responses:
         search_context_obj = SearchContext()
         self.json_ld['@context'] = search_context_obj.id
     if 'metadata' in self.act_responses:
         self.json_ld['id'] = self.make_id()
         self.json_ld['label'] = self.label
         self.json_ld['dcmi:modified'] = self.get_modified_datetime(solr_json)
         self.json_ld['dcmi:created'] = self.get_created_datetime(solr_json)
         self.add_paging_json(solr_json)
         self.add_filters_json()
         self.add_text_fields()
     # now process numeric + date fields, facets will
     # only be added if 'facet' in self.act_response
     self.add_numeric_fields(solr_json)
     self.add_date_fields(solr_json)
     # now check for form-use-life chronology
     # note! Do this first to set time bounds for geo-features
     # needs to be done, even if facet results are not displayed
     self.make_form_use_life_chronotiles(solr_json)
     if 'geo-facet' in self.act_responses:
         # now check for discovery geotiles
         self.make_discovery_geotiles(solr_json)
     if 'geo-project' in self.act_responses:
         # now check for project geojson
         self.make_project_geojson(solr_json)
     # now process regular facets.
     # they will only be added to the response if
     # 'facet' in self.act_response
     self.make_facets(solr_json)
     if 'geo-record' in self.act_responses \
        or 'nongeo-record' in self.act_responses:
         # now add the result information
         geojson_recs_obj = GeoJsonRecords(self.request_dict_json)
         geojson_recs_obj.entities = self.entities
         geojson_recs_obj.min_date = self.min_date
         geojson_recs_obj.max_date = self.max_date
         geojson_recs_obj.flatten_rec_attributes = self.flatten_rec_attributes
         geojson_recs_obj.rec_attributes = self.rec_attributes
         geojson_recs_obj.make_records_from_solr(solr_json)
         if len(geojson_recs_obj.geojson_recs) > 0 \
            and 'geo-record' in self.act_responses:
             self.json_ld['type'] = 'FeatureCollection'
             if 'features' not in self.json_ld:
                 self.json_ld['features'] = []
             self.json_ld['features'] += geojson_recs_obj.geojson_recs
         if len(geojson_recs_obj.non_geo_recs) > 0 \
            and 'nongeo-record' in self.act_responses:
             self.json_ld['oc-api:has-results'] = geojson_recs_obj.non_geo_recs
     if 'uuid' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         uuids = solr_uuids.make_uuids_from_solr(solr_json)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:uuids'] = uuids
         else:
             # just return a simple list
             self.json_ld = uuids
             ok_show_debug = False
     if 'uri' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         uris = solr_uuids.make_uris_from_solr(solr_json)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:has-results'] = uris
         else:
             # just return a simple list
             self.json_ld = uris
             ok_show_debug = False
     elif 'uri-meta' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         solr_uuids.min_date = self.min_date
         solr_uuids.max_date = self.max_date
         solr_uuids.entities = self.entities
         solr_uuids.flatten_rec_attributes = self.flatten_rec_attributes
         solr_uuids.rec_attributes = self.rec_attributes
         uris = solr_uuids.make_uris_from_solr(solr_json,
                                               False)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:has-results'] = uris
         else:
             # just return a simple list
             self.json_ld = uris
             ok_show_debug = False
     if settings.DEBUG and ok_show_debug:
         self.json_ld['request'] = self.request_dict
         # self.json_ld['request'] = self.request_dict
         self.json_ld['solr'] = solr_json
     return self.json_ld