Exemple #1
0
def get_all_servicedirs():
    """ Restish return all servicedirs information """

    dao = DAO()
    if request.method == 'GET':

        session = dao.get_session()

        servicedirs_table = dao.get_table("service_dirs")

        the_result = {"service_dirs": []}

        probe_t1 = time.time()
        for servdir in session.query(ServiceDir).order_by(
                servicedirs_table.c.serv_id).options(joinedload('channel')):
            the_result["service_dirs"].append(servdir.jsonize())
        probe_t2 = time.time()

        LOGGER.info("sql request and jsonizing time %f\n" %
                    (probe_t2 - probe_t1))

        session.close()

        return jsonify(the_result)

    elif request.method == 'POST':
        data = request.json
        return jsonify(result=_add_jsonized_products(dao.get_session(), data))
Exemple #2
0
def get_all_servicedirs():
    """ Restish return all servicedirs information """

    dao = DAO()
    if request.method == 'GET':
        
        session = dao.get_session()
        
        servicedirs_table = dao.get_table("service_dirs")
        
        the_result = { "service_dirs" : [] }
        
        probe_t1 = time.time()
        for servdir in session.query(ServiceDir).order_by(servicedirs_table.c.serv_id).options(joinedload('channel')):
            the_result["service_dirs"].append(servdir.jsonize())
        probe_t2 = time.time()
       
        LOGGER.info("sql request and jsonizing time %f\n" %(probe_t2-probe_t1))
        
        session.close()
        
        return jsonify(the_result)
       
    
    elif request.method == 'POST':
        data = request.json
        return jsonify(result=_add_jsonized_products(dao.get_session(), data))
Exemple #3
0
def get_all_channels():
    """ Restish return all channels information """

    dao = DAO()
    if request.method == 'GET':

        session = dao.get_session()

        channel_table = dao.get_table("channels")

        the_channels = {"channels": []}

        for channel in session.query(Channel).order_by(
                channel_table.c.chan_id):
            LOGGER.info("channel = %s" % (channel))
            if channel:
                the_channels["channels"].append(channel.jsonize())

        session.close()

        return jsonify(the_channels)

    elif request.method == 'POST':
        data = request.json
        return jsonify(result=_add_jsonized_products(dao.get_session(), data))
Exemple #4
0
def manager_servicedir_with(name):
    """ Restish get_channels per name """

    dao = DAO()
    if request.method == 'GET':
        # show the user profile for that user
        session = dao.get_session()

        servicedirs_table = dao.get_table("service_dirs")

        the_result = {"service_dirs": []}

        #look for stars in uid and replace them with % for a like sql operation
        if name.find('*'):
            if len(name) == 1:
                #get everything because user asked for *
                for servdir in session.query(ServiceDir).order_by(
                        servicedirs_table.c.serv_id):
                    the_result["service_dirs"].append(servdir.jsonize())
            else:
                #restrict to the wildcard matching string
                name = name.replace('*', '%')
                for servdir in session.query(ServiceDir).filter(
                        ServiceDir.name.like(name)).order_by(
                            servicedirs_table.c.serv_id):
                    the_result["service_dirs"].append(servdir.jsonize())
        else:
            servdir = session.query(ServiceDir).filter_by(name=name).first()
            if servdir:
                the_result["service_dirs"].append(servdir.jsonize())

        return jsonify(the_result)

    elif request.method == 'DELETE':
        session = dao.get_session()
        servdir = session.query(ServiceDir).filter_by(name=name).first()

        if servdir:
            session.delete(servdir)
            session.commit()
            result = {
                "status": "OK",
                "messages": "service_dir %s deleted" % (name)
            }
        else:
            result = {
                "status": "KO",
                "messages": "service_dir %s not in database" % (name)
            }

        return jsonify(result)
Exemple #5
0
def manage_channel_with(name):
    """ Restish get_channels per name """

    dao = DAO()
    if request.method == 'GET':
        # show the user profile for that user

        session = dao.get_session()

        the_result = {"channels": []}

        #look for stars in uid and replace them with % for a like sql operation
        if name.find('*'):
            if len(name) == 1:
                channel_table = dao.get_table("channels")
                #get everything because user asked for *
                for channel in session.query(Channel).order_by(
                        channel_table.c.rodd_id):
                    the_result["channels"].append(channel.jsonize())
            else:
                #restrict to the wildcard matching string
                name = name.replace('*', '%')
                for channel in session.query(Channel).filter(
                        Channel.name.like(name)):
                    the_result["channels"].append(channel.jsonize())
        else:
            channel = session.query(Channel).filter_by(name=name).first()
            if channel:
                the_result["channels"].append(channel.jsonize())

        return jsonify(the_result)

    elif request.method == 'DELETE':
        session = dao.get_session()
        channel = session.query(Channel).filter_by(name=name).first()

        if channel:
            session.delete(channel)
            session.commit()
            result = {
                "status": "OK",
                "messages": ["channel %s deleted" % (name)]
            }
        else:
            result = {
                "status": "KO",
                "messages": ["channel %s not in database" % (name)]
            }

        return jsonify(result)
Exemple #6
0
def manage_product_with(uid):
    """ Restish get_product per uid """

    dao = DAO()
    if request.method == 'GET':
        # show the user profile for that user

        session = dao.get_session()

        the_products = {"products": []}

        #look for stars in uid and replace them with % for a like sql operation
        if uid.find('*'):
            if len(uid) == 1:
                product_table = dao.get_table("products")
                #get everything because user asked for *
                for product in session.query(Product).order_by(
                        product_table.c.rodd_id):
                    the_products["products"].append(product.jsonize())
            else:
                #restrict to the wildcard matching string
                uid = uid.replace('*', '%')
                for product in session.query(Product).filter(
                        Product.internal_id.like(uid)):
                    the_products["products"].append(product.jsonize())
        else:
            product = session.query(Product).filter_by(internal_id=uid).first()
            if product:
                the_products["products"].append(product.jsonize())

        return jsonify(the_products)

    elif request.method == 'DELETE':
        session = dao.get_session()
        product = session.query(Product).filter_by(internal_id=uid).first()

        if product:
            session.delete(product)
            session.commit()
            result = {
                "status": "OK",
                "messages": ["product %s deleted" % (uid)]
            }
        else:
            result = {
                "status": "KO",
                "messages": ["product %s not in database" % (uid)]
            }

        return jsonify(result)
Exemple #7
0
def get_all_products():
    """ Restish return all products information """

    #get products
    dao = DAO()
    if request.method == 'GET':
        session = dao.get_session()

        product_table = dao.get_table("products")

        the_products = {"products": []}

        probe_t1 = time.time()
        res = session.query(Product).order_by(product_table.c.rodd_id).options(
            joinedload('file_infos'))
        probe_t2 = time.time()

        LOGGER.info("#### sql request %f\n" % (probe_t2 - probe_t1))

        probe_t1 = time.time()
        for product in res:
            the_products["products"].append(product.jsonize())

        probe_t2 = time.time()

        LOGGER.info("#### creating products %f\n" % (probe_t2 - probe_t1))

        session.close()
        probe_t1 = time.time()
        json_res = jsonify(the_products)
        probe_t2 = time.time()

        LOGGER.info("#### jsonify %f\n" % (probe_t2 - probe_t1))

        return json_res
    #insert new products
    elif request.method == 'POST':
        data = request.json
        session = dao.get_session()
        res = _add_jsonized_products(session, data)

        LOGGER.info("products = %s" % (res))

        return jsonify(result=res)
    #update existing products: the policy is delete current object and add the new one
    elif request.method == 'PUT':
        data = request.json
        return jsonify(
            result=_update_jsonized_products(dao.get_session(), data))
Exemple #8
0
def get_all_products():
    """ Restish return all products information """
    
    #get products
    dao = DAO()
    if request.method == 'GET':
        session = dao.get_session()
        
        product_table = dao.get_table("products")
        
        the_products = { "products" : [] }
       
        probe_t1 = time.time()
        res = session.query(Product).order_by(product_table.c.rodd_id).options(joinedload('file_infos'))
        probe_t2 = time.time()
       
        LOGGER.info("#### sql request %f\n" %(probe_t2-probe_t1))
        
        probe_t1 = time.time()
        for product in res:
            the_products["products"].append(product.jsonize())
        
        probe_t2 = time.time()
       
        LOGGER.info("#### creating products %f\n" %(probe_t2-probe_t1))
           
        session.close()
        probe_t1 = time.time()
        json_res = jsonify(the_products)
        probe_t2 = time.time()
       
        LOGGER.info("#### jsonify %f\n" %(probe_t2-probe_t1))
        
        return json_res
    #insert new products
    elif request.method == 'POST':
        data = request.json
        session = dao.get_session()
        res     = _add_jsonized_products(session, data)
        
        LOGGER.info("products = %s" %(res))
        
        return jsonify(result=res)
    #update existing products: the policy is delete current object and add the new one
    elif request.method == 'PUT':
        data = request.json
        return jsonify(result=_update_jsonized_products(dao.get_session(), data))
Exemple #9
0
def func_return_jsonised_products():
    """ return a product that has been jsonised """
    
    # query all products
    dao = DAO()
    
    session = dao.get_session()
    
    product_table = dao.get_table("products")
    
    products = { "products" : [] }
    for product in session.query(Product).order_by(product_table.c.rodd_id):
        products["products"].append(product.jsonize())
    
    print("products = %s\n" %(products))
    
    session.close()
Exemple #10
0
def manager_servicedir_with(name):
    """ Restish get_channels per name """
    
    dao = DAO()
    if request.method == 'GET':
        # show the user profile for that user
        session = dao.get_session()
        
        servicedirs_table = dao.get_table("service_dirs")
        
        the_result = { "service_dirs" : [] }
        
        #look for stars in uid and replace them with % for a like sql operation
        if name.find('*'):
            if len(name) == 1:
                #get everything because user asked for *
                for servdir in session.query(ServiceDir).order_by(servicedirs_table.c.serv_id):
                    the_result ["service_dirs"].append(servdir.jsonize())  
            else:
                #restrict to the wildcard matching string
                name = name.replace('*', '%')
                for servdir in session.query(ServiceDir).filter(ServiceDir.name.like(name)).order_by(servicedirs_table.c.serv_id):
                    the_result["service_dirs"].append(servdir.jsonize())   
        else:
            servdir = session.query(ServiceDir).filter_by(name = name).first()
            if servdir:
                the_result["service_dirs"].append(servdir.jsonize())
        
        return jsonify(the_result)
    
    elif request.method == 'DELETE':
        session = dao.get_session()
        servdir = session.query(ServiceDir).filter_by(name = name).first()
        
        if servdir:
            session.delete(servdir)
            session.commit()
            result = { "status" : "OK",
                        "messages"       : "service_dir %s deleted" % (name)
                      }
        else:
            result = { "status" : "KO",
                        "messages"       : "service_dir %s not in database" % (name)
                     }
            
        return jsonify(result)
Exemple #11
0
def manage_channel_with(name):
    """ Restish get_channels per name """
    
    dao = DAO()
    if request.method == 'GET':
        # show the user profile for that user
        
        session = dao.get_session()
        
        the_result = { "channels" : [] }
        
        #look for stars in uid and replace them with % for a like sql operation
        if name.find('*'):
            if len(name) == 1:
                channel_table = dao.get_table("channels")
                #get everything because user asked for *
                for channel in session.query(Channel).order_by(channel_table.c.rodd_id):
                    the_result ["channels"].append(channel.jsonize())  
            else:
                #restrict to the wildcard matching string
                name = name.replace('*', '%')
                for channel in session.query(Channel).filter(Channel.name.like(name)):
                    the_result["channels"].append(channel.jsonize())   
        else:
            channel = session.query(Channel).filter_by(name = name).first()
            if channel:
                the_result["channels"].append(channel.jsonize())
        
        return jsonify(the_result)
    
    elif request.method == 'DELETE':
        session = dao.get_session()
        channel = session.query(Channel).filter_by(name = name).first()
        
        if channel:
            session.delete(channel)
            session.commit()
            result = { "status" : "OK",
                        "messages"       : ["channel %s deleted" % (name)]
                      }
        else:
            result = { "status" : "KO",
                        "messages"       : ["channel %s not in database" % (name)]
                     }
            
        return jsonify(result)
Exemple #12
0
def manage_product_with(uid):
    """ Restish get_product per uid """
    
    dao = DAO()
    if request.method == 'GET':
        # show the user profile for that user
        
        session = dao.get_session()
        
        the_products = { "products" : [] }
        
        #look for stars in uid and replace them with % for a like sql operation
        if uid.find('*'):
            if len(uid) == 1:
                product_table = dao.get_table("products")
                #get everything because user asked for *
                for product in session.query(Product).order_by(product_table.c.rodd_id):
                    the_products["products"].append(product.jsonize())  
            else:
                #restrict to the wildcard matching string
                uid = uid.replace('*', '%')
                for product in session.query(Product).filter(Product.internal_id.like(uid)):
                    the_products["products"].append(product.jsonize())   
        else:
            product = session.query(Product).filter_by(internal_id = uid).first()
            if product:
                the_products["products"].append(product.jsonize())
        
        return jsonify(the_products)
    
    elif request.method == 'DELETE':
        session = dao.get_session()
        product = session.query(Product).filter_by(internal_id = uid).first()
        
        if product:
            session.delete(product)
            session.commit()
            result = { "status" : "OK",
                        "messages"       : ["product %s deleted" % (uid)]
                      }
        else:
            result = { "status" : "KO",
                        "messages"       : ["product %s not in database" % (uid)]
                     }
            
        return jsonify(result)
Exemple #13
0
def func_return_jsonised_products():
    """ return a product that has been jsonised """

    # query all products
    dao = DAO()

    session = dao.get_session()

    product_table = dao.get_table("products")

    products = {"products": []}
    for product in session.query(Product).order_by(product_table.c.rodd_id):
        products["products"].append(product.jsonize())

    print("products = %s\n" % (products))

    session.close()
Exemple #14
0
def func_get_product_index_test():
    
    dao = DAO()
    
    session        = dao.get_session()
    product_table  = dao.get_table("products")
    retrieved_prod = session.query(Product).filter_by(internal_id='TEST:EO:EUM:DAT:METOP:ASCSZRIB').first()
    
    print(retrieved_prod.jsonize())
    
    tuple = retrieved_prod.contains_file('ascat_bufr')
    if tuple:
        grp_list, file = tuple
        
        file.reg_expr = 'alalalla'
        file.size='900KB'
        print(file)
        #session.add(file)
        session.commit()
Exemple #15
0
def func_get_product_index_test():

    dao = DAO()

    session = dao.get_session()
    product_table = dao.get_table("products")
    retrieved_prod = session.query(Product).filter_by(
        internal_id='TEST:EO:EUM:DAT:METOP:ASCSZRIB').first()

    print(retrieved_prod.jsonize())

    tuple = retrieved_prod.contains_file('ascat_bufr')
    if tuple:
        grp_list, file = tuple

        file.reg_expr = 'alalalla'
        file.size = '900KB'
        print(file)
        #session.add(file)
        session.commit()
Exemple #16
0
def get_all_channels():
    """ Restish return all channels information """
    
    dao = DAO()
    if request.method == 'GET':
        
        session = dao.get_session()
        
        channel_table = dao.get_table("channels")
        
        the_channels = { "channels" : [] }
        
        for channel in session.query(Channel).order_by(channel_table.c.chan_id):
            LOGGER.info("channel = %s" %(channel))
            if channel :
                the_channels["channels"].append(channel.jsonize()) 
          
        session.close()
        
        return jsonify(the_channels)
    
    elif request.method == 'POST':
        data = request.json
        return jsonify(result=_add_jsonized_products(dao.get_session(), data))