def deny_partner_request(request):
    '''
    This is the view function for denying one partner request.
    
    Thread Safety:
    The implementation is not thread safe but it will be used in a thread-safe manner.
    
    @param request: the http request
    @return: the http response
    '''
    CLASS_NAME = 'decision_module.views'
    LOGGER = logging.getLogger(CLASS_NAME)
    # Do logging
    signature = CLASS_NAME + '.deny_partner_request'
    helper.log_entrance(LOGGER, signature, {'request': request})
    
    request_id = request.POST['request_id']
    p = get_request_persistence()
    p.connectionConfig = dbconfig
    req = []
    try:
        p.begin()
        if dbconfig["type"]=='redis':
            req = p.queryRequests('request_id={0}'.format(request_id), None, None)
            if len(req) > 0:
                req = req[0]
            p.updateRequests('status=denied', 'request_id={0}'.format(request_id))
            p.commit()
        else:# MySQL, no other possibilities, otherwise exceptin would be raise before
            req = p.queryRequests('request_id="{0}"'.format(request_id), None, None)
            if len(req) > 0:
                req = req[0]
            p.updateRequests('status="denied"', 'request_id="{0}"'.format(request_id))
            p.commit()
    except:
        p.rollback()
    finally:
        if p.connection:
            p.close()
    
    # Kick off a new thread to handle the request
    try:
        if len(req) == 8:
            req = req[1:]
        if len(req) < 7:
            raise ValueError('Request misses parameters')
        request_id = req[0]
        t = Thread(target=handle_deny_operation, args=([request_id],))
        t.daemon = False
        t.start()
        
    except Exception as e:
        helper.log_exception(LOGGER, signature, e)
    
    # Redirect to /partner_tags
    ret = HttpResponseRedirect('/')
    # Do logging
    helper.log_exit(LOGGER, signature, [ret])
    return ret
def create_partner_request(request):
    '''
    This is the view function for creating one partner request.
    
    Thread Safety:
    The implementation is not thread safe but it will be used in a thread-safe manner.
    
    @param request: the http request
    @return: the http response
    '''
    CLASS_NAME = 'decision_module.views'
    LOGGER = logging.getLogger(CLASS_NAME)
    # Do logging
    signature = CLASS_NAME + '.create_partner_request'
    helper.log_entrance(LOGGER, signature, {'request': request})
    
    # Check posted values
    try:
        check_string('request_id', request.POST['request_id'])
        check_string('study_id', request.POST['study_id'])
        check_string('query', request.POST['query'])
        check_string('expiration_time', request.POST['expiration_time'])
        check_string('cache_available', request.POST['cache_available'])
        if request.POST['cache_available'] == 'true':
            check_string('cache_timestamp', request.POST['cache_timestamp'])
        check_string('status', request.POST['status'])
    except Exception as e:
        helper.log_exception(LOGGER, signature, e)
    
    if dbconfig["type"]=='redis':
        fields = [request.POST['request_id'], request.POST['study_id'], request.POST['query'],
                  request.POST['expiration_time'], request.POST['cache_available'],
                  request.POST['cache_timestamp'], request.POST['status'],]
    else:# MySQL - SQL statements must translate ' to double ', or sql statement is illegal.
        fields = [request.POST['request_id'], request.POST['study_id'], request.POST['query'].replace("'", "''"),
                  request.POST['expiration_time'], request.POST['cache_available'],
                  request.POST['cache_timestamp'], request.POST['status'],]
    p = get_request_persistence()
    p.connectionConfig = dbconfig
    try:
        p.begin()
        p.createRequest(fields)
        p.commit()
    except:
        p.rollback()
    finally:
        if p.connection:
            p.close()
    
    # Redirect to /partner_tags
    # ret = HttpResponseRedirect('/')
    ret = HttpResponse(status=200)
    # Do logging
    helper.log_exit(LOGGER, signature, [ret])
    return ret
def approval_partner_request(request):
    '''
    This is the view function for approval one partner request.
    
    Thread Safety:
    The implementation is not thread safe but it will be used in a thread-safe manner.
    
    @param request: the http request
    @return: the http response
    '''
    CLASS_NAME = 'decision_module.views'
    LOGGER = logging.getLogger(CLASS_NAME)
    # Do logging
    signature = CLASS_NAME + '.approval_partner_request'
    helper.log_entrance(LOGGER, signature, {'request': request})
    
    request_id = request.POST['request_id']
    p = get_request_persistence()
    p.connectionConfig = dbconfig
    req = []
    try:
        p.begin()
        if dbconfig["type"]=='redis':
            req = p.queryRequests('request_id={0}'.format(request_id), None, None)
            if len(req) > 0:
                req = req[0]
            p.updateRequests('status=approved', 'request_id={0}'.format(request_id))
            p.commit()
        else:# MySQL, no other possibilities, otherwise exceptin would be raise before
            req = p.queryRequests('request_id="{0}"'.format(request_id), None, None)
            if len(req) > 0:
                req = req[0]
            p.updateRequests('status="approved"', 'request_id="{0}"'.format(request_id))
            p.commit()
    except:
        p.rollback()
    finally:
        if p.connection:
            p.close()
    
    # Kick off a new thread to handle the request
    try:
        if len(req) == 8:
            req = req[1:]
        if len(req) < 7:
            raise ValueError('Request misses parameters')
        request_id = req[0]
        study_id = req[1]
        query = req[2]
        expiration_time = isodate.parse_datetime(req[3])
        cache_available = 'true' == req[4]
        cache_timestamp = None
        if req[5] and len(req[5]) > 0:
            cache_timestamp = isodate.parse_datetime(req[5])
        
        handler = DataRequestHandler()
        t = Thread(target=handler.handle_data_request, args=(request_id, study_id, query,
                                          expiration_time, cache_available,
                                          cache_timestamp, True))
        t.daemon = False
        t.start()
        
    except Exception as e:
        helper.log_exception(LOGGER, signature, e)
    
    # Redirect to /partner_tags
    ret = HttpResponseRedirect('/')
    # Do logging
    helper.log_exit(LOGGER, signature, [ret])
    return ret
Esempio n. 4
0
def deny_partner_request(request):
    '''
    This is the view function for denying one partner request.
    
    Thread Safety:
    The implementation is not thread safe but it will be used in a thread-safe manner.
    
    @param request: the http request
    @return: the http response
    '''
    CLASS_NAME = 'decision_module.views'
    LOGGER = logging.getLogger(CLASS_NAME)
    # Do logging
    signature = CLASS_NAME + '.deny_partner_request'
    helper.log_entrance(LOGGER, signature, {'request': request})

    request_id = request.POST['request_id']
    p = get_request_persistence()
    p.connectionConfig = dbconfig
    req = []
    try:
        p.begin()
        if dbconfig["type"] == 'redis':
            req = p.queryRequests('request_id={0}'.format(request_id), None,
                                  None)
            if len(req) > 0:
                req = req[0]
            p.updateRequests('status=denied',
                             'request_id={0}'.format(request_id))
            p.commit()
        else:  # MySQL, no other possibilities, otherwise exceptin would be raise before
            req = p.queryRequests('request_id="{0}"'.format(request_id), None,
                                  None)
            if len(req) > 0:
                req = req[0]
            p.updateRequests('status="denied"',
                             'request_id="{0}"'.format(request_id))
            p.commit()
    except:
        p.rollback()
    finally:
        if p.connection:
            p.close()

    # Kick off a new thread to handle the request
    try:
        if len(req) == 8:
            req = req[1:]
        if len(req) < 7:
            raise ValueError('Request misses parameters')
        request_id = req[0]
        t = Thread(target=handle_deny_operation, args=([request_id], ))
        t.daemon = False
        t.start()

    except Exception as e:
        helper.log_exception(LOGGER, signature, e)

    # Redirect to /partner_tags
    ret = HttpResponseRedirect('/')
    # Do logging
    helper.log_exit(LOGGER, signature, [ret])
    return ret
Esempio n. 5
0
def approval_partner_request(request):
    '''
    This is the view function for approval one partner request.
    
    Thread Safety:
    The implementation is not thread safe but it will be used in a thread-safe manner.
    
    @param request: the http request
    @return: the http response
    '''
    CLASS_NAME = 'decision_module.views'
    LOGGER = logging.getLogger(CLASS_NAME)
    # Do logging
    signature = CLASS_NAME + '.approval_partner_request'
    helper.log_entrance(LOGGER, signature, {'request': request})

    request_id = request.POST['request_id']
    p = get_request_persistence()
    p.connectionConfig = dbconfig
    req = []
    try:
        p.begin()
        if dbconfig["type"] == 'redis':
            req = p.queryRequests('request_id={0}'.format(request_id), None,
                                  None)
            if len(req) > 0:
                req = req[0]
            p.updateRequests('status=approved',
                             'request_id={0}'.format(request_id))
            p.commit()
        else:  # MySQL, no other possibilities, otherwise exceptin would be raise before
            req = p.queryRequests('request_id="{0}"'.format(request_id), None,
                                  None)
            if len(req) > 0:
                req = req[0]
            p.updateRequests('status="approved"',
                             'request_id="{0}"'.format(request_id))
            p.commit()
    except:
        p.rollback()
    finally:
        if p.connection:
            p.close()

    # Kick off a new thread to handle the request
    try:
        if len(req) == 8:
            req = req[1:]
        if len(req) < 7:
            raise ValueError('Request misses parameters')
        request_id = req[0]
        study_id = req[1]
        query = req[2]
        expiration_time = isodate.parse_datetime(req[3])
        cache_available = 'true' == req[4]
        cache_timestamp = None
        if req[5] and len(req[5]) > 0:
            cache_timestamp = isodate.parse_datetime(req[5])

        handler = DataRequestHandler()
        t = Thread(target=handler.handle_data_request,
                   args=(request_id, study_id, query, expiration_time,
                         cache_available, cache_timestamp, True))
        t.daemon = False
        t.start()

    except Exception as e:
        helper.log_exception(LOGGER, signature, e)

    # Redirect to /partner_tags
    ret = HttpResponseRedirect('/')
    # Do logging
    helper.log_exit(LOGGER, signature, [ret])
    return ret
Esempio n. 6
0
def create_partner_request(request):
    '''
    This is the view function for creating one partner request.
    
    Thread Safety:
    The implementation is not thread safe but it will be used in a thread-safe manner.
    
    @param request: the http request
    @return: the http response
    '''
    CLASS_NAME = 'decision_module.views'
    LOGGER = logging.getLogger(CLASS_NAME)
    # Do logging
    signature = CLASS_NAME + '.create_partner_request'
    helper.log_entrance(LOGGER, signature, {'request': request})

    # Check posted values
    try:
        check_string('request_id', request.POST['request_id'])
        check_string('study_id', request.POST['study_id'])
        check_string('query', request.POST['query'])
        check_string('expiration_time', request.POST['expiration_time'])
        check_string('cache_available', request.POST['cache_available'])
        if request.POST['cache_available'] == 'true':
            check_string('cache_timestamp', request.POST['cache_timestamp'])
        check_string('status', request.POST['status'])
    except Exception as e:
        helper.log_exception(LOGGER, signature, e)

    if dbconfig["type"] == 'redis':
        fields = [
            request.POST['request_id'],
            request.POST['study_id'],
            request.POST['query'],
            request.POST['expiration_time'],
            request.POST['cache_available'],
            request.POST['cache_timestamp'],
            request.POST['status'],
        ]
    else:  # MySQL - SQL statements must translate ' to double ', or sql statement is illegal.
        fields = [
            request.POST['request_id'],
            request.POST['study_id'],
            request.POST['query'].replace("'", "''"),
            request.POST['expiration_time'],
            request.POST['cache_available'],
            request.POST['cache_timestamp'],
            request.POST['status'],
        ]
    p = get_request_persistence()
    p.connectionConfig = dbconfig
    try:
        p.begin()
        p.createRequest(fields)
        p.commit()
    except:
        p.rollback()
    finally:
        if p.connection:
            p.close()

    # Redirect to /partner_tags
    # ret = HttpResponseRedirect('/')
    ret = HttpResponse(status=200)
    # Do logging
    helper.log_exit(LOGGER, signature, [ret])
    return ret