Beispiel #1
0
 def find_by_field(self,
                   subpath,
                   field_path,
                   value,
                   resolved=False,
                   deprecated=False):
     if not subpath.startswith('/'):
         subpath = u"/{}".format(subpath)
     path = "{path}{subpath}/?&filter={{\"op\":\"eq\",\"path\":\"{field_path}\",\"value\":{value}}}&{deprecated}".format(
         path=self.path,
         subpath=subpath,
         field_path=field_path,
         deprecated="deprecated={}".format(deprecated)
         if deprecated is not None else '',
         value=u"\"{}\"".format(value) if isinstance(value,
                                                     (str,
                                                      unicode)) else value)
     if resolved:
         path += "&fields=all"
     result = self._http_client.get(path)
     if result is not None:
         results = [SearchResult(r) for r in result["results"]]
         if resolved:
             results = [self._wrap_with_entity(r) for r in results]
         return SearchResultList(result["total"], results, result["links"])
     return None
Beispiel #2
0
 def list_by_full_path(self, path):
     path = path.decode("string_escape")
     resolved = "fields=all" in path
     result = self._http_client.get(path)
     if result is not None:
         results = [SearchResult(r) for r in result["results"]]
         if resolved:
             results = [self._wrap_with_entity(r) for r in results]
         return SearchResultList(result["total"], results, result["links"])
     return None
Beispiel #3
0
 def retrieve_all_results(self, x: SearchResultList) -> Optional[List[Union[SearchResult, Instance]]]:
     results = x.results
     next_page = x.get_next_link()
     while next_page:
         y = self.client.instances.list_by_full_path(next_page)
         next_page = y.get_next_link()
         results.extend(y.results)
     try:
         assert(len(results) == x.total)
     except AssertionError:
         print("<error>", (f"Retrieved item count ({len(results)}) and "
                           f"result count ({x.total}) are different!"))
         return None
     return results
Beispiel #4
0
 def list_by_full_path(self, path, deprecated=False):
     path = decode_escapes(path)
     resolved = "fields=all" in path
     deprecated = "deprecated={}".format(
         deprecated) if deprecated is not None else ''
     path = "{path}&{deprecated}".format(
         path=path, deprecated=deprecated
     ) if '?' in path else "{path}?{deprecated}".format(
         path=path, deprecated=deprecated)
     result = self._http_client.get(path)
     if result is not None:
         results = [SearchResult(r) for r in result["results"]]
         if resolved:
             results = [self._wrap_with_entity(r) for r in results]
         return SearchResultList(result["total"], results, result["links"])
     return None
Beispiel #5
0
 def retrieve_all_results(
         self, x: SearchResultList
 ) -> Optional[List[Union[SearchResult, Instance]]]:
     results = x.results
     next_page = x.get_next_link()
     while next_page:
         y = self.client.instances.list_by_full_path(next_page)
         next_page = y.get_next_link()
         results.extend(y.results)
     try:
         assert (len(results) == x.total)
     except AssertionError:
         print("<error>", (f"Retrieved item count ({len(results)}) and "
                           f"result count ({x.total}) are different!"))
         return None
     return results
Beispiel #6
0
 def fulltext_search(self, value, subpath=None, resolved=False, deprecated=False):
     if subpath is not None and not subpath.startswith('/'):
         subpath = u"/{}".format(subpath)
     else:
         subpath=""
     path = "{path}{subpath}/?&q={query}&{deprecated}".format(path=self.path,
         subpath=subpath,
         query = value,
         deprecated="deprecated={}".format(deprecated) if deprecated is not None else ''
     )
     if resolved:
         path += "&fields=all"
     result = self._http_client.get(path)
     if result is not None:
         results = [SearchResult(r) for r in result["results"]]
         if resolved:
             results = [self._wrap_with_entity(r) for r in results]
         return SearchResultList(result["total"], results, result["links"])
     return None