Ejemplo n.º 1
0
def query_handler(request):
    """
    Entry method to handle incoming search queries for hound service.
    Query fields come embedded in request search arguments.
    """
    
    ec = EventComposer()
    
    if request.method == 'GET':
        
        query = request.GET
        
        if 'commit_option' in query:
            
            if (query['commit_option'] == 'info'):
                if 'commit_uri' in query and query['commit_uri'] != '':
                    # Case of retrieving information from a commit
                    print "Case commit.getInfo"

                    params_commit_get_info = {"apiCall": "commit.getInfo",
                        "in_params": (("commitUri", 
                        query['commit_uri'],),)
                        }
                    
                    response = ec.send_recv_metadata(BUS_URL, params_commit_get_info)

                    print("Received: ALERT.Metadata.APICallResponse")
                    
                    data = ec.deserial_metadata('commit.getInfo',
                                StringIO(response))
                else:
                    return HttpResponse("You must provide the commit URI")
                
            elif (query['commit_option'] == 'prod'):
                if 'product' in query and query['product'] != '':
                    # Case of retrieving all commits related to a method
                    # To: Metadata service
                    print "Case commit.getAllForProduct"
                    
                    if 'from_date' in query and query['from_date'] != '':
                        params_commit_get_all_for_product = {"apiCall": "commit.getAllForProduct",
                        "in_params": (("productID", query['product'],),
                                    ("fromDate",query['from_date'],),)
                        }
                        
                    else:
                        params_commit_get_all_for_product = {"apiCall": "commit.getAllForProduct",
                        "in_params": (("productID", query['product'],),)
                        }
                    
                    response = ec.send_recv_metadata(BUS_URL, params_commit_get_all_for_product)

                    print("Received: ALERT.Metadata.APICallResponse")
                    
                    data = ec.deserial_metadata('commit.getAllForProduct',
                            StringIO(response))
                else:
                    return HttpResponse("You must provide a product name.")
                        
        elif ('issue_id' in query and query['issue_id'] != ''):
            
            if ('issue_option' in query and query['issue_option'] != ''):
                if (query['issue_option'] == 'sug'):
                    # Case of suggesting developers for an issue
                    # To: Recommendation service
                    print "Case Recommender.identity.Recommendation"
                    
                    params_devs_recommend = {"issues": ((query['issue_id'],"owl#1"),) 
                                        }
                    
                    response = ec.send_recv_recommender(BUS_URL, params_devs_recommend, 'devs')
                    
                    print("Received: Response from Recommendation service")
                    response = response.replace('encoding="UTF-8"', 'encoding="iso-8859-1"')
                    
                    data = ec.deserial_recommendation('identity.Recommendation',
                            StringIO(response))
                
                elif (query['issue_option'] == 'sim'):
                    # Case of finding related issues
                    # To: KEUI
                    print "Case KEUI-similarThreads"
                    
                    params_similar_threads = {"type": "similarThreads",
                                              "threadId": "-1",
                                              "bugId": query['issue_id'],
                                              "count": 10,
                                              "itemDataSnipLen" : 200,
                                              "includeItemIds": "True",
                                              "includeItemData": "True",
                                              "includeOnlyFirstInThread": "True",                          
                                              "maxCount": 10,
                                              "offset": 0,
                                              "includePeopleData" : "False"
                                              }

                    response = ec.send_recv_keui(BUS_URL, params_similar_threads)
                    response = response.replace('encoding="UTF-8"', 'encoding="iso-8859-1"')
                    data = ec.deserial_keui('similarThreads',
                                    StringIO(response))
                
                elif (query['issue_option'] == 'ext'):
                    # Case of presented extended info about issue
                    # To: Metadata service
                    print "Case issue.getInfo"
                                  
                    params_issue_get_info = {"apiCall": "issue.getInfo",
                                "in_params": (("issueID",query['issue_id'],),)
                                }

                    response = ec.send_recv_metadata(BUS_URL, params_issue_get_info)

                    print("Received: ALERT.Metadata.APICallResponse")
                    response = response.replace('encoding="UTF-8"', 'encoding="iso-8859-1"')
                    data = ec.deserial_metadata('issue.getInfo',
                                    StringIO(response))
     
            else:
                return HttpResponse("You must select an issue option for this particular ID.")
                                        
        elif 'product' in query and query['product'] != '':
            # Case of getting all issues for a product
            # To: Metadata service
            print "Case issue.getAllForProduct"
            
            if 'from_date' in query and query['from_date'] != '':
                params_issue_get_all_for_product = {"apiCall": "issue.getAllForProduct",
                    "in_params": (("productID", query['product'],),
                                    ("fromDate", query['from_date'],),)
                    }
                    
            else:
                params_issue_get_all_for_product = {"apiCall": "issue.getAllForProduct",
                    "in_params": (("productID", query['product'],),)
                    }
            
            response = ec.send_recv_metadata(BUS_URL, params_issue_get_all_for_product)

            print("Received: ALERT.Metadata.APICallResponse")
            
            data = ec.deserial_metadata('issue.getAllForProduct',
                    StringIO(response))
            
        elif 'method_uri' in query and query['method_uri'] != '':
            # Case of getting all issues for a method
            # To: Metadata service
            print "Case issue.getAllForMethod"
            
            #TODO: Handle input for more than one method
            params_issue_get_all_for_method = {"apiCall": "issue.getAllForMethod",
                "in_params": (("methodUri", query['method'],),)
                }
            
            response = ec.send_recv_metadata(BUS_URL, params_issue_get_all_for_method)

            print("Received: ALERT.Metadata.APICallResponse")
            
            data = ec.deserial_metadata('issue.getAllForMethod',
                    StringIO(response))
       
        elif 'keywords' in query and query['keywords'] != '':
            # Case of issues related to keywords
            # To: KEUI
            print "Case KEUI-keywords"
            
            params_issues_for_keywords = {'keywords': (query['keywords'],),
                        "offset": 0, "maxCount": 100, 'resultData': 'itemData',
                        "includeAttachments": 1, 'sortBy': 'dateDesc',
                        'itemDataSnipLen': 200, 'snipMatchKeywords': 1,
                        'keywordMatchOffset': 25, 'includePeopleData':0
                        }
            
            response = ec.send_recv_keui(BUS_URL, params_issues_for_keywords)
            
            data = ec.deserial_keui('issuesForKeywords',
                                    StringIO(response))
            
        elif 'developer' in query and query['developer'] != '':
            # Case of suggest issues for a developer
            # To: Recommendation service
            print "Case Recommender.issuesRecommended"
            
            # Example developer UUID:
            # "ff9dc34d-774e-47ad-9eab-07c46ab3e765ff0df1c4-4c8d-4703-97ea-267d83b4ac08"
            params_issues_recommend = {"identities": (query['developer'],)
                }
            
            response = send_recv_recommender(BUS_URL, params_issues_recommend, 'issues')
            
            data = ec.deserial_recommendation('issue.Recommendation',
                                    StringIO(response))
        
        else:
            # Error: there must be one option selected
            return HttpResponse("Unsupported query petition.</br>"+\
                "You must provide at least a commit_id, issue_id, "+\
                "list of keywords (separated by blank spaces) "+\
                "or developer name for searching.")
                
        return HttpResponse(json.dumps(data), mimetype="application/json")
Ejemplo n.º 2
0
def query_handler(request):
    """
    Entry method to handle incoming search queries for hound service.
    Query fields come embedded in request search arguments.
    """

    ec = EventComposer()

    if request.method == 'GET':

        query = request.GET

        if 'commit_option' in query:

            if (query['commit_option'] == 'info'):
                if 'commit_uri' in query and query['commit_uri'] != '':
                    # Case of retrieving information from a commit
                    print "Case commit.getInfo"

                    params_commit_get_info = {
                        "apiCall": "commit.getInfo",
                        "in_params": ((
                            "commitUri",
                            query['commit_uri'],
                        ), )
                    }

                    response = ec.send_recv_metadata(BUS_URL,
                                                     params_commit_get_info)

                    print("Received: ALERT.Metadata.APICallResponse")

                    data = ec.deserial_metadata('commit.getInfo',
                                                StringIO(response))
                else:
                    return HttpResponse("You must provide the commit URI")

            elif (query['commit_option'] == 'prod'):
                if 'product' in query and query['product'] != '':
                    # Case of retrieving all commits related to a method
                    # To: Metadata service
                    print "Case commit.getAllForProduct"

                    if 'from_date' in query and query['from_date'] != '':
                        params_commit_get_all_for_product = {
                            "apiCall":
                            "commit.getAllForProduct",
                            "in_params": (
                                (
                                    "productID",
                                    query['product'],
                                ),
                                (
                                    "fromDate",
                                    query['from_date'],
                                ),
                            )
                        }

                    else:
                        params_commit_get_all_for_product = {
                            "apiCall": "commit.getAllForProduct",
                            "in_params": ((
                                "productID",
                                query['product'],
                            ), )
                        }

                    response = ec.send_recv_metadata(
                        BUS_URL, params_commit_get_all_for_product)

                    print("Received: ALERT.Metadata.APICallResponse")

                    data = ec.deserial_metadata('commit.getAllForProduct',
                                                StringIO(response))
                else:
                    return HttpResponse("You must provide a product name.")

        elif ('issue_id' in query and query['issue_id'] != ''):

            if ('issue_option' in query and query['issue_option'] != ''):
                if (query['issue_option'] == 'sug'):
                    # Case of suggesting developers for an issue
                    # To: Recommendation service
                    print "Case Recommender.identity.Recommendation"

                    params_devs_recommend = {
                        "issues": ((query['issue_id'], "owl#1"), )
                    }

                    response = ec.send_recv_recommender(
                        BUS_URL, params_devs_recommend, 'devs')

                    print("Received: Response from Recommendation service")
                    response = response.replace('encoding="UTF-8"',
                                                'encoding="iso-8859-1"')

                    data = ec.deserial_recommendation(
                        'identity.Recommendation', StringIO(response))

                elif (query['issue_option'] == 'sim'):
                    # Case of finding related issues
                    # To: KEUI
                    print "Case KEUI-similarThreads"

                    params_similar_threads = {
                        "type": "similarThreads",
                        "threadId": "-1",
                        "bugId": query['issue_id'],
                        "count": 10,
                        "itemDataSnipLen": 200,
                        "includeItemIds": "True",
                        "includeItemData": "True",
                        "includeOnlyFirstInThread": "True",
                        "maxCount": 10,
                        "offset": 0,
                        "includePeopleData": "False"
                    }

                    response = ec.send_recv_keui(BUS_URL,
                                                 params_similar_threads)
                    response = response.replace('encoding="UTF-8"',
                                                'encoding="iso-8859-1"')
                    data = ec.deserial_keui('similarThreads',
                                            StringIO(response))

                elif (query['issue_option'] == 'ext'):
                    # Case of presented extended info about issue
                    # To: Metadata service
                    print "Case issue.getInfo"

                    params_issue_get_info = {
                        "apiCall": "issue.getInfo",
                        "in_params": ((
                            "issueID",
                            query['issue_id'],
                        ), )
                    }

                    response = ec.send_recv_metadata(BUS_URL,
                                                     params_issue_get_info)

                    print("Received: ALERT.Metadata.APICallResponse")
                    response = response.replace('encoding="UTF-8"',
                                                'encoding="iso-8859-1"')
                    data = ec.deserial_metadata('issue.getInfo',
                                                StringIO(response))

            else:
                return HttpResponse(
                    "You must select an issue option for this particular ID.")

        elif 'product' in query and query['product'] != '':
            # Case of getting all issues for a product
            # To: Metadata service
            print "Case issue.getAllForProduct"

            if 'from_date' in query and query['from_date'] != '':
                params_issue_get_all_for_product = {
                    "apiCall":
                    "issue.getAllForProduct",
                    "in_params": (
                        (
                            "productID",
                            query['product'],
                        ),
                        (
                            "fromDate",
                            query['from_date'],
                        ),
                    )
                }

            else:
                params_issue_get_all_for_product = {
                    "apiCall": "issue.getAllForProduct",
                    "in_params": ((
                        "productID",
                        query['product'],
                    ), )
                }

            response = ec.send_recv_metadata(BUS_URL,
                                             params_issue_get_all_for_product)

            print("Received: ALERT.Metadata.APICallResponse")

            data = ec.deserial_metadata('issue.getAllForProduct',
                                        StringIO(response))

        elif 'method_uri' in query and query['method_uri'] != '':
            # Case of getting all issues for a method
            # To: Metadata service
            print "Case issue.getAllForMethod"

            #TODO: Handle input for more than one method
            params_issue_get_all_for_method = {
                "apiCall": "issue.getAllForMethod",
                "in_params": ((
                    "methodUri",
                    query['method'],
                ), )
            }

            response = ec.send_recv_metadata(BUS_URL,
                                             params_issue_get_all_for_method)

            print("Received: ALERT.Metadata.APICallResponse")

            data = ec.deserial_metadata('issue.getAllForMethod',
                                        StringIO(response))

        elif 'keywords' in query and query['keywords'] != '':
            # Case of issues related to keywords
            # To: KEUI
            print "Case KEUI-keywords"

            params_issues_for_keywords = {
                'keywords': (query['keywords'], ),
                "offset": 0,
                "maxCount": 100,
                'resultData': 'itemData',
                "includeAttachments": 1,
                'sortBy': 'dateDesc',
                'itemDataSnipLen': 200,
                'snipMatchKeywords': 1,
                'keywordMatchOffset': 25,
                'includePeopleData': 0
            }

            response = ec.send_recv_keui(BUS_URL, params_issues_for_keywords)

            data = ec.deserial_keui('issuesForKeywords', StringIO(response))

        elif 'developer' in query and query['developer'] != '':
            # Case of suggest issues for a developer
            # To: Recommendation service
            print "Case Recommender.issuesRecommended"

            # Example developer UUID:
            # "ff9dc34d-774e-47ad-9eab-07c46ab3e765ff0df1c4-4c8d-4703-97ea-267d83b4ac08"
            params_issues_recommend = {"identities": (query['developer'], )}

            response = send_recv_recommender(BUS_URL, params_issues_recommend,
                                             'issues')

            data = ec.deserial_recommendation('issue.Recommendation',
                                              StringIO(response))

        else:
            # Error: there must be one option selected
            return HttpResponse("Unsupported query petition.</br>"+\
                "You must provide at least a commit_id, issue_id, "+\
                "list of keywords (separated by blank spaces) "+\
                "or developer name for searching.")

        return HttpResponse(json.dumps(data), mimetype="application/json")
Ejemplo n.º 3
0
def query_test(request):
    """
    Test method for REST API
    http://127.0.0.1:8000/hound/search/query/?issue_id=1&project=kde
    &keywords=hola,adios,tururu&commit_id=123&component=solid
    &start_date=20100901&end_date=20110901
    """
    
    deserial_test = EventComposer()
    
    if request.method == 'GET':
        
        query = request.GET
        
        if 'commit_option' in query:
            
            if (query['commit_option'] == 'info'):
                if 'commit_uri' in query and query['commit_uri'] != '':
                    print "Case commit.getInfo"
                    data = deserial_test.deserial_metadata('commit.getInfo',
                                'templates/events/metadata-commit.getInfo.xml')
                                
                else:
                    return HttpResponse("You must provide the commit URI")
                
            elif (query['commit_option'] == 'prod'):
                if 'product' in query and query['product'] != '':
                    # Case of retrieving all commits related to a method
                    # To: Metadata service
                    print "Case commit.getAllForProduct"
                    data = deserial_test.deserial_metadata('commit.getAllForProduct',
                        'templates/events/metadata-commit.getAllForProduct.xml')
                else:
                    return HttpResponse("You must provide a product name.")
                        
        elif ('issue_id' in query and query['issue_id'] != ''):
            
            if ('issue_option' in query and query['issue_option'] != ''):
                if (query['issue_option'] == 'sug'):
                    # Case of suggesting developers for an issue
                    # To: Recommendation service
                    print "Case Recommender.identity.Recommendation"
                    data = deserial_test.deserial_recommendation('identity.Recommendation',
                            'templates/events/recommender-IdentityRecommendation.xml')
                
                elif (query['issue_option'] == 'sim'):
                    # Case of finding related issues
                    # To: KEUI
                    print "Case KEUI-similarThreads"
                    data = deserial_test.deserial_keui('similarThreads',
                                    'templates/events/KEUI-similarThreads.xml')
                
                elif (query['issue_option'] == 'ext'):
                    # Case of presented extended info about issue
                    # To: Metadata service
                    print "Case issue.getInfo"
                    data = deserial_test.deserial_metadata('issue.getInfo',
                                    'templates/events/metadata-issue.getInfo.xml')
                                   
            else:
                return HttpResponse("You must select an issue option for this particular ID.")
                                        
        elif 'product' in query and query['product'] != '':
            # Case of getting all issues for a product
            # To: Metadata service
            print "Case issue.getAllForProduct"
            data = deserial_test.deserial_metadata('issue.getAllForProduct',
                    'templates/events/metadata-issue.getAllForProduct.xml')
            
        elif 'method_uri' in query and query['method_uri'] != '':
            # Case of getting all issues for a method
            # To: Metadata service
            print "Case issue.getAllForMethod"
            data = deserial_test.deserial_metadata('issue.getAllForMethod',
                    'templates/events/metadata-issue.getAllForMethod.xml')
       
        elif 'keywords' in query and query['keywords'] != '':
            # Case of issues related to keywords
            # To: KEUI
            print "Case KEUI-keywords"
            data = deserial_test.deserial_keui('issuesForKeywords',
                                    'templates/events/KEUI-keywords.xml')
            
        elif 'developer' in query and query['developer'] != '':
            # Case of suggest issues for a developer
            # To: Recommendation service
            print "Case Recommender.issuesRecommended"
            data = deserial_test.deserial_recommendation('issue.Recommendation',
                                    'templates/events/recommender-issuesRecommended.xml')
        
        else:
            # Error: there must be one option selected
            return HttpResponse("Unsupported query petition.</br>"+\
                "You must provide at least a commit_id, issue_id, "+\
                "list of keywords (separated by blank spaces) "+\
                "or developer name for searching.")
                
        return HttpResponse(json.dumps(data), mimetype="application/json")
Ejemplo n.º 4
0
def query_test(request):
    """
    Test method for REST API
    http://127.0.0.1:8000/hound/search/query/?issue_id=1&project=kde
    &keywords=hola,adios,tururu&commit_id=123&component=solid
    &start_date=20100901&end_date=20110901
    """

    deserial_test = EventComposer()

    if request.method == 'GET':

        query = request.GET

        if 'commit_option' in query:

            if (query['commit_option'] == 'info'):
                if 'commit_uri' in query and query['commit_uri'] != '':
                    print "Case commit.getInfo"
                    data = deserial_test.deserial_metadata(
                        'commit.getInfo',
                        'templates/events/metadata-commit.getInfo.xml')

                else:
                    return HttpResponse("You must provide the commit URI")

            elif (query['commit_option'] == 'prod'):
                if 'product' in query and query['product'] != '':
                    # Case of retrieving all commits related to a method
                    # To: Metadata service
                    print "Case commit.getAllForProduct"
                    data = deserial_test.deserial_metadata(
                        'commit.getAllForProduct',
                        'templates/events/metadata-commit.getAllForProduct.xml'
                    )
                else:
                    return HttpResponse("You must provide a product name.")

        elif ('issue_id' in query and query['issue_id'] != ''):

            if ('issue_option' in query and query['issue_option'] != ''):
                if (query['issue_option'] == 'sug'):
                    # Case of suggesting developers for an issue
                    # To: Recommendation service
                    print "Case Recommender.identity.Recommendation"
                    data = deserial_test.deserial_recommendation(
                        'identity.Recommendation',
                        'templates/events/recommender-IdentityRecommendation.xml'
                    )

                elif (query['issue_option'] == 'sim'):
                    # Case of finding related issues
                    # To: KEUI
                    print "Case KEUI-similarThreads"
                    data = deserial_test.deserial_keui(
                        'similarThreads',
                        'templates/events/KEUI-similarThreads.xml')

                elif (query['issue_option'] == 'ext'):
                    # Case of presented extended info about issue
                    # To: Metadata service
                    print "Case issue.getInfo"
                    data = deserial_test.deserial_metadata(
                        'issue.getInfo',
                        'templates/events/metadata-issue.getInfo.xml')

            else:
                return HttpResponse(
                    "You must select an issue option for this particular ID.")

        elif 'product' in query and query['product'] != '':
            # Case of getting all issues for a product
            # To: Metadata service
            print "Case issue.getAllForProduct"
            data = deserial_test.deserial_metadata(
                'issue.getAllForProduct',
                'templates/events/metadata-issue.getAllForProduct.xml')

        elif 'method_uri' in query and query['method_uri'] != '':
            # Case of getting all issues for a method
            # To: Metadata service
            print "Case issue.getAllForMethod"
            data = deserial_test.deserial_metadata(
                'issue.getAllForMethod',
                'templates/events/metadata-issue.getAllForMethod.xml')

        elif 'keywords' in query and query['keywords'] != '':
            # Case of issues related to keywords
            # To: KEUI
            print "Case KEUI-keywords"
            data = deserial_test.deserial_keui(
                'issuesForKeywords', 'templates/events/KEUI-keywords.xml')

        elif 'developer' in query and query['developer'] != '':
            # Case of suggest issues for a developer
            # To: Recommendation service
            print "Case Recommender.issuesRecommended"
            data = deserial_test.deserial_recommendation(
                'issue.Recommendation',
                'templates/events/recommender-issuesRecommended.xml')

        else:
            # Error: there must be one option selected
            return HttpResponse("Unsupported query petition.</br>"+\
                "You must provide at least a commit_id, issue_id, "+\
                "list of keywords (separated by blank spaces) "+\
                "or developer name for searching.")

        return HttpResponse(json.dumps(data), mimetype="application/json")