Skip to content

Reverse lookup on EUDAT B2SAFE PIDs fails #124

Open

Description

@chStaiger

B2SAFE changed the PID profile and renamed the PID entry 'CHECKSUM' to 'EUDAT/CHECKSUM'.
The reverse-lookup function however only searches through keys ['URL', 'CHECKSUM']:

rev = dict([('EUDAT/CHECKSUM', '*')])
result = ec.search_handle(**rev)

---------------------------------------------------------------------------
ReverseLookupException                    Traceback (most recent call last)
<ipython-input-8-c654e7e978a0> in <module>()
      1 rev = dict([('EUDAT/CHECKSUM', '*')])
----> 2 result = ec.search_handle(**rev)

/usr/local/lib/python2.7/dist-packages/b2handle-1.1.1-py2.7.egg/b2handle/handleclient.pyc in search_handle(self, URL, prefix, **key_value_pairs)
    969         LOGGER.debug('search_handle...')
    970
--> 971         list_of_handles = self.__searcher.search_handle(URL=URL, prefix=prefix, **key_value_pairs)
    972
    973         return list_of_handles

/usr/local/lib/python2.7/dist-packages/b2handle-1.1.1-py2.7.egg/b2handle/searcher.pyc in search_handle(self, **args)
    241         LOGGER.debug('search_handle...')
    242         if self.__has_search_access:
--> 243             return self.__search_handle(**args)
    244         else:
    245             LOGGER.error(

/usr/local/lib/python2.7/dist-packages/b2handle-1.1.1-py2.7.egg/b2handle/searcher.pyc in __search_handle(self, **args)
    282         list_of_handles = []
    283         LOGGER.debug('search_handle: key-value-pairs: '+str(args))
--> 284         query = self.create_revlookup_query(*fulltext_searchterms, **args)
    285
    286         if query is None:

/usr/local/lib/python2.7/dist-packages/b2handle-1.1.1-py2.7.egg/b2handle/searcher.pyc in create_revlookup_query(self, *fulltext_searchterms, **keyvalue_searchterms)
    390                 msg = 'Cannot search for key "'+key+'". Only searches '+\
    391                     'for keys '+str(allowed_search_keys)+' are implemented.'
--> 392                 raise ReverseLookupException(msg=msg)
    393             else:
    394                 query = query+'&'+key+'='+value

ReverseLookupException: Error during Reverse Lookup: Cannot search for key "EUDAT/CHECKSUM". Only searches for keys ['URL', 'CHECKSUM'] are implemented..

Activity

  1. cookie33 commented on May 1, 2017

    @cookie33

    Hi,

    This is no real issue. Add one line to the credentials file and you are able to search to whatever you like. This is mentioned in: http://eudat-b2safe.github.io/B2HANDLE/handleclient.html?highlight=search#b2handle.handleclient.EUDATHandleClient.search_handle

    The documentation states:

    Note: If allowed search keys are configured, only these are used. If no allowed search keys are specified, all key-value pairs are passed on to the reverse lookup servlet, possibly causing a ReverseLookupException.

  2. cookie33 commented on May 1, 2017

    @cookie33

    The parameter to add is: allowed_search_keys

            :param allowed_search_keys: Optional. The keys that can be used for
                reverse lookup of handles, as a list of strings. Defaults to 'URL'
                and 'CHECKSUM'. If the list is empty, all keys are passed to the
                reverse lookup servlet and exceptions are passed on to the user.
    
  3. chStaiger commented on May 1, 2017

    @chStaiger
    Author

    How do I configure "allowed search keys"?

    I cannot give them as an extra parameter in the standard B2HANDLE v 1.1.1:

    In [5]: b2handle.__version__
    Out[5]: '1.1.1'
    
    In [6]: cred = PIDClientCredentials.load_from_JSON('cred_21.T12995.json')
    
    In [7]: ec = EUDATHandleClient.instantiate_with_credentials(cred)
    
    In [8]: rev = dict([('CHECKSUM', '*')])
    
    In [9]: allowedKeys = ['EUDAT/CHECKSUM', 'TYPE']
    
    In [10]: result = ec.search_handle(**rev, allowedKeys)
      File "<ipython-input-10-1bf44e457d41>", line 1
        result = ec.search_handle(**rev, allowedKeys)
                                       ^
    SyntaxError: invalid syntax
    
  4. cookie33 commented on May 1, 2017

    @cookie33

    The parameter to add is: allowed_search_keys

            :param allowed_search_keys: Optional. The keys that can be used for
                reverse lookup of handles, as a list of strings. Defaults to 'URL'
                and 'CHECKSUM'. If the list is empty, all keys are passed to the
                reverse lookup servlet and exceptions are passed on to the user.
    
  5. cookie33 commented on May 1, 2017

    @cookie33

    For a most easy usage add it to the credentials file.

  6. chStaiger commented on May 1, 2017

    @chStaiger
    Author

    Works now for me. But the documentation does not state how to enable additional keys.
    Can you add a line like this in the documentation of that function:

    You can define the allowed search keys by adding:

    "allowed_search_keys": ["KEY1", "KEY2", ...],
    

    to your credentials file.
    Note that this is not a list with which the predefined keys are extended, but it overwrites the predefined keys.

  7. chStaiger commented on May 1, 2017

    @chStaiger
    Author

    Since the user is allowed to define the search keys, why not make it a real parameter in the function?

  8. TobiasWeigel commented on May 5, 2017

    @TobiasWeigel
    Contributor

    In principle, you are right - since it is the same user who calls a constructor with the allowed_search_keys parameter and then uses the search method, it does not make sense to have this restriction.
    There must have been a specific reason why this peculiar construct ended up in the library, probably related to the way b2handle is used in EUDAT. But to me this is not a concise argument for having this.

    So my vote goes to abandoning the allowed_search_keys parameter. Robert, do you agree?

  9. cookie33 commented on May 8, 2017

    @cookie33

    I am also OK with removing the allowed_search_keys parameter in a next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions