Exemplo n.º 1
0
def default_search_func(search_dict):
    """
    Defaults to calling the data broker's search function

    Parameters
    ----------
    search_dict : dict
        The search_dict gets unpacked into the databroker's search function

    Returns
    -------
    search_results: list
        The results from the data broker's search function

    Raises
    ------
    ImportError
        Raised if the metadatastore cannot be found
    ValueError
        Raised if the search dictionary is empty
    """
    logger.info("default_search_func() in broker_query_example.py")
    print(search_dict)
    # check to see if the dictionary is empty
    if len(search_dict) == 0:
        logger.error("search_dict has no keys. Raising a value error")
        raise ValueError("The search_dict input parameter has no keys")
    print(search_dict)
    logger.info("search_dict")
    try:
        from metadataStore.userapi.commands import search
        logger.info("Search command from metadataStore.userapi.commands "
                    "imported successfully")
    except ImportError:
        #todo add logging statement about import error
        logger.info("The data broker cannot be found, returning an empty "
                    "search")
        return _defaults["empty_search"]

    result=search(**search_dict)
    print(result)
    return result
Exemplo n.º 2
0
    def compute(self):
        query = None
        if self.has_input("query_dict"):
            query = self.get_input("query_dict")
            return_only_one = False
        if self.has_input("unique_query_dict"):
            query = self.get_input("unique_query_dict")
            return_only_one = True

        if query is None:
            logger.debug("no search dictionary was passed in, search "
                         "cannot proceed")
            return
        logger.debug("broker_query: {0}".format(query))
        data = self.get_input("is_returning_data")
        query["data"] = data
        result = search(**query)
        if return_only_one:
            keys = list(result)
            result = result[keys[0]]
        self.set_output("query_result", result)
        logger.debug("result: {0}".format(list(result)))
Exemplo n.º 3
0
 def gen_tree():
     query = {"owner": "edill", "data": True}
     return search(**query)
Exemplo n.º 4
0
 def gen_tree():
     query = {"owner": "edill", "data": True}
     return search(**query)