Project

General

Profile

« Previous | Next » 

Revision 61524

fixed problem to extract correct identifier in case of multiple ones

View differences:

modules/dli-api/branches/ES_7/v3/responseModel.py
62 62
    result:List[ScholixType] = []
63 63

  
64 64

  
65
def get_scholix_resource(item):
65
def get_scholix_resource(item, pid=None):
66 66
    title = ''
67 67
    if 'title' in item:
68 68
        title = item.title
......
71 71
            title = title[1:-1]
72 72
    identifier = [dict(ID=x.identifier, IDScheme=x.schema, IDURL=x.url) for x in
73 73
                  item.identifier]
74
    identifier = identifier[0]
74

  
75
    if pid!= None:
76
        items = [x for x in identifier if pid == x["ID"]]
77
        if len(items) >0:
78
            identifier = items[0]
79
        else:
80
            identifier = identifier[0]
81
    else:
82
        identifier = identifier[0]
75 83
    creator = []
76 84
    if 'creator' in item and item.creator is not None:        
77 85
        creator = [dict(Name=x.name) for x in item.creator]
......
90 98
    return resource
91 99

  
92 100

  
93
def convert_response(response):
101
def convert_response(response, sourcePid=None, targetPid=None):
94 102
    now = datetime.now()
95 103
    log = logging.getLogger("scholexplorer")
96 104
    start = time()
......
106 114
        current_item['RelationshipType'] = dict(Name=rel_sub_type, SubType=item.relationship.name,
107 115
                                                SubTypeSchema=item.relationship.schema)
108 116

  
109
        current_item['source'] = get_scholix_resource(item.source)
110
        current_item['target'] = get_scholix_resource(item.target)
117
        current_item['source'] = get_scholix_resource(item.source, sourcePid)
118
        current_item['target'] = get_scholix_resource(item.target, targetPid)
111 119

  
112 120
        yield current_item
113 121
    end = time()
114 122
    log.debug("response converted in {} ms".format(end-start))
115 123

  
116
def create_response(response, current_page):
124
def create_response(response, current_page, sourcePid=None,targetPid=None):
117 125
    log = logging.getLogger("scholexplorer")    
118 126
    if current_page > 9999:
119 127
        raise HTTPException(status_code=400,detail="MAX NUMBER OF PAGE REACHED")
......
123 131
    
124 132
    result = {'totalLinks': response.hits.total.value, 'currentPage': current_page /100,
125 133
              'totalPages': 1 + response.hits.total.value / 100, 'result': []}
126
    result['result'] = convert_response(response)
134
    result['result'] = convert_response(response, sourcePid, targetPid)
127 135
    end = time()
128 136

  
129 137
    log.debug("response created in {} ms".format(end-start))
modules/dli-api/branches/ES_7/v3/api_v3.py
68 68
      
69 69
        return create_response(s.links(provider = linkProvider, s_pid=sourcePid, t_pid=targetPid, s_publisher=sourcePublisher,
70 70
                                           t_publisher=targetPublisher, s_pid_type=sourcePidType,
71
                                           t_pid_type=targetPidType, page=m_page, target_Type=targetType, source_Type=sourceType),m_page)    
71
                                           t_pid_type=targetPidType, page=m_page, target_Type=targetType, source_Type=sourceType),m_page, sourcePid,targetPid)    
72 72
        

Also available in: Unified diff