ooiservices/app/uframe/assets.py
def create_asset():
    """ Create a new asset, the return will be uframe asset format (not ooi-ui-services format).
    Cache ('asset_list') is updated with new asset
    Either a success or an error message.
    Login required.
    """
    debug = False
    try:
        data = json.loads(request.data)
        if valid_create_asset_request_data(data):
            if debug: print '\n debug validated required fields...'

        url = current_app.config['UFRAME_ASSETS_URL'] + '/%s' % 'assets'
        if 'lastModifiedTimestamp' in data:
            del data['lastModifiedTimestamp']
        if 'asset_class' in data:
            data['@class'] = data.pop('asset_class')

        # Create asset in uframe
        response = requests.post(url, data=json.dumps(data), headers=_uframe_headers())

        if response.status_code == 201:
            json_response = json.loads(response.text)
            data['assetId'] = json_response['id']
            data['tense'] = 'NEW'
            data_list = [data]
            try:
                compiled_data, _ = _compile_assets(data_list)
            except Exception:
                raise

            if not compiled_data or compiled_data is None:
                raise Exception('_compile_assets returned empty or None result.')

            # Update asset cache ('asset_list')
            asset_cache = cache.get('asset_list')
            if asset_cache:
                cache.delete('asset_list')
                asset_cache.append(compiled_data[0])
                cache.set('asset_list', asset_cache, timeout=CACHE_TIMEOUT)
        else:
            return bad_request('Failed to create asset!')

        return response.text, response.status_code

    except ConnectionError:
        message = 'ConnectionError during create asset.'
        current_app.logger.info(message)
        return bad_request(message)
    except Timeout:
        message = 'Timeout during during create asset.'
        current_app.logger.info(message)
        return bad_request(message)
    except Exception as err:
        message = str(err)
        current_app.logger.info(message)
        return bad_request(message)
 Create a new asset, the return will be uframe asset format (not ooi-ui-services format).
    Cache ('asset_list') is updated with new asset
    Either a success or an error message.
    Login required.
    
Create a new asset, the return will be uframe asset format (not ooi-ui-services format).
Cache ('asset_list') is updated with new asset
Either a success or an error message.
Login required.
Create a new asset the return will be uframe asset format ( not ooi - ui - services format ) . Cache ( ' asset_list ' ) is updated with new asset Either a success or an error message . Login required .
def create_asset():
    debug = False
    try:
        data = json.loads(request.data)
        if valid_create_asset_request_data(data):
            if debug: print '\n debug validated required fields...'
        url = current_app.config['UFRAME_ASSETS_URL'] + '/%s' % 'assets'
        if 'lastModifiedTimestamp' in data:
            del data['lastModifiedTimestamp']
        if 'asset_class' in data:
            data['@class'] = data.pop('asset_class')
        response = requests.post(url, data=json.dumps(data), headers=_uframe_headers())
        if response.status_code == 201:
            json_response = json.loads(response.text)
            data['assetId'] = json_response['id']
            data['tense'] = 'NEW'
            data_list = [data]
            try:
                compiled_data, _ = _compile_assets(data_list)
            except Exception:
                raise
            if not compiled_data or compiled_data is None:
                raise Exception('_compile_assets returned empty or None result.')
            asset_cache = cache.get('asset_list')
            if asset_cache:
                cache.delete('asset_list')
                asset_cache.append(compiled_data[0])
                cache.set('asset_list', asset_cache, timeout=CACHE_TIMEOUT)
        else:
            return bad_request('Failed to create asset!')
        return response.text, response.status_code
    except ConnectionError:
        message = 'ConnectionError during create asset.'
        current_app.logger.info(message)
        return bad_request(message)
    except Timeout:
        message = 'Timeout during during create asset.'
        current_app.logger.info(message)
        return bad_request(message)
    except Exception as err:
        message = str(err)
        current_app.logger.info(message)
        return bad_request(message)
def create_asset ( ) : debug = False try : data = json . loads ( request . data ) if valid_create_asset_request_data ( data ) : if debug : print '\n debug validated required fields...' url = current_app . config [ 'UFRAME_ASSETS_URL' ] + '/%s' % 'assets' if 'lastModifiedTimestamp' in data : del data [ 'lastModifiedTimestamp' ] if 'asset_class' in data : data [ '@class' ] = data . pop ( 'asset_class' ) response = requests . post ( url , data = json . dumps ( data ) , headers = _uframe_headers ( ) ) if response . status_code == 201 : json_response = json . loads ( response . text ) data [ 'assetId' ] = json_response [ 'id' ] data [ 'tense' ] = 'NEW' data_list = [ data ] try : compiled_data , _ = _compile_assets ( data_list ) except Exception : raise if not compiled_data or compiled_data is None : raise Exception ( '_compile_assets returned empty or None result.' ) asset_cache = cache . get ( 'asset_list' ) if asset_cache : cache . delete ( 'asset_list' ) asset_cache . append ( compiled_data [ 0 ] ) cache . set ( 'asset_list' , asset_cache , timeout = CACHE_TIMEOUT ) else : return bad_request ( 'Failed to create asset!' ) return response . text , response . status_code except ConnectionError : message = 'ConnectionError during create asset.' current_app . logger . info ( message ) return bad_request ( message ) except Timeout : message = 'Timeout during during create asset.' current_app . logger . info ( message ) return bad_request ( message ) except Exception as err : message = str ( err ) current_app . logger . info ( message ) return bad_request ( message )
Create a new asset, the return will be uframe asset format (not ooi-ui-services format).
Create a new asset the return will be uframe asset format ( not ooi - ui - services format ) .
""" Create a new asset, the return will be uframe asset format (not ooi-ui-services format).
    Cache ('asset_list') is updated with new asset
    Either a success or an error message.
    Login required.
    """ # Create asset in uframe # Update asset cache ('asset_list')