I need to be able to set some metadata in some custom data types. For now, I'm 
just trying to set the value of the 'misc_info' field. The client script is 
put( sys.argv[1], sys.argv[2], { 'update_type' : 'metadata', 'misc_info' : 
'meta data msg' } )
and my API method is as follows. It executes fine, but the values do not show 
on the next show() call.
Disclaimer: Python is still quite new to me, and it's very likely I do not 
understand the metadata model and the way library dataset associates work.

Any clues will be greatly appreaciated!
    def update( self, trans, id,  library_id, payload, **kwd ):
        Sets attributes (metadata) on a library item.
        update_type = None
        if 'update_type' not in payload:
            trans.response.status = 400
            return "Missing required 'update_type' parameter.  Please consult 
the API documentation for help."
            update_type = payload.pop( 'update_type' )
        if update_type not in ( 'metadata' ):
            trans.response.status = 400
            return "Invalid value for 'update_type' parameter ( %s ) specified. 
 Please consult the API documentation for help." % update_type
        content_id = id
        decoded_type_and_id = trans.security.decode_string_id( content_id )
        content_type, decoded_content_id = decoded_type_and_id.split( '.' )
        if content_type not in ( 'file' ):
            trans.response.status = 400
            return "Updates allowed only on files, not directories"
            content = trans.sa_session.query( 
trans.app.model.LibraryDatasetDatasetAssociation ).get( decoded_content_id )
            content = None
        if not content or ( not trans.user_is_admin() and not 
trans.get_current_user_roles(), content, trans.user ) ):
            trans.response.status = 400
            return "Invalid %s id ( %s ) specified." % ( content_type, str( 
content_id ) )

        metadata = content.get_metadata()

        if not metadata:
           metadata = {}

        for name in payload:
            if name not in [ 'name', 'info', 'dbkey' ]:
                setattr( metadata, name, payload[name])

        content.datatype.after_setting_metadata( content )

        return "OK"

John Duddy
Sr. Staff Software Engineer
Illumina, Inc.
9885 Towne Centre Drive
San Diego, CA 92121
Tel: 858-736-3584
E-mail: jdu...@illumina.com<mailto:jdu...@illumina.com>

Please keep all replies on the list by using "reply all"
in your mail client.  To manage your subscriptions to this
and other Galaxy lists, please use the interface at:


Reply via email to