Project

General

Profile

« Previous | Next » 

Revision 58542

fixed npe

View differences:

modules/dli-service-portal/branches/ES_7/eu/dnetlib/es_connector.py
5 5
from elasticsearch_dsl import *
6 6
import logging
7 7
from eu.dnetlib.util import get_index_properties
8
import traceback
8 9

  
9 10
import os
10 11
from os import path
......
198 199
            s = s[start:end]
199 200
        response = s.execute()
200 201

  
201
        print (response.hits.total)
202
        
202 203

  
203 204
        hits = []
204 205

  
205 206
        for index_result in response.hits:
206 207
            input_source = index_result.__dict__['_d_']
208
            
207 209
            fixed_titles = []
208 210

  
209 211
            for ids in input_source.get('localIdentifier', []):
......
268 270
            return
269 271
        relSource = relation.get('source')
270 272
        collectedFrom = relSource.get('collectedFrom',[])
271
        for coll in collectedFrom:
272
            for d in source['datasources']:
273
                if d['datasourceName'] == coll['provider']['name']:
274
                    d['provisionMode'] = coll['provisionMode']
273
        if collectedFrom is not None:
274
            for coll in collectedFrom:
275
                for d in source['datasources']:
276
                    if d['datasourceName'] == coll['provider']['name']:
277
                        d['provisionMode'] = coll['provisionMode']
275 278
        return source
276 279

  
277 280
    def item_by_id(self, id, type=None, start=None):
278 281
        try:
279
            res = self.client.get(index=self.index_name+"_object", id=id)
282
            res = self.client.get(index=self.index_name+"_object",doc_type="_all", id=id, _source=True)
280 283
            hits = []
281 284
            input_source = res['_source']
282 285
            fixed_titles = []
......
324 327
                             related_unknown=related_unknown))
325 328

  
326 329
            return DLIESResponse(total=1, hits=hits)
327
        except Exception as e:
330
        except Exception as e:            
328 331
            log.error("Error on getting item ")
329
            log.error(e)
332
            log.error(e)            
330 333
            #log.error("on line %i" % sys.exc_info)
331 334
            return DLIESResponse()
modules/dli-service-portal/branches/ES_7/main.py
66 66
    return dict(result=connector.get_main_page_stats())
67 67

  
68 68
@app.post('/api/queryPid/')
69
def query_pid(*, pid:str= Form(...)):   
70
    print (pid) 
69
def query_pid(*, pid:str= Form(...)):       
71 70
    connector = DLIESConnector()    
72 71
    return dict(result=connector.query_by_id(pid))
73 72

  
......
80 79
    if filter:
81 80
        filter_key = filter
82 81
    if action == 'query' and query is not None:
83
        print(query)
82
        
84 83
        connector = DLIESConnector()
85 84
        try:
86 85
            result = connector.simple_query(query, start=start, user_filter=filter_key)

Also available in: Unified diff