Page 1 of 1

getting the owner name of a specific image

PostPosted: Tue Jun 14, 2011 12:29 pm
by bhcho
Hi,I'm trying to retrieve the owner's ome ID (or full name) of a specific image.

from my python code,
I retrieve an image object (::omero::model::Image).
from this, I want to retrieve the owner's ome ID (not id number).

i could get the iid by
Code: Select all
img.getDetails().getOwner().getId().getValue()

it gives me just like 303L.

could you tell me how to get the ID (such as 'demo' or 'bk')?

and I would also appreciate if you can tell me how to get the Project and Dataset name (not id number) as well.

Best,
BK

Re: getting the owner name of a specific image

PostPosted: Tue Jun 14, 2011 3:59 pm
by jmoore
Experimenter.id is the primary key in the database. The login name of the user is Experimenter.omeName:

Code: Select all
img.getDetails().getOwner().getOmeName().getValue()


That value may not be loaded, however, depending on how you ran the query which returned the image. In which case you can use another HQL statement or one of the methods on the IAdmin service to load the Experimenter.

Cheers,
~Josh

Re: getting the owner name of a specific image

PostPosted: Mon Jul 11, 2011 11:21 pm
by bhcho
Hi again,

That value may not be loaded, however, depending on how you ran the query which returned the image. In which case you can use another HQL statement or one of the methods on the IAdmin service to load the Experimenter.


like Josh said, I could not get the owner's name because I got image by the following functions

Code: Select all
def getImage( session, iid ):
    """
    Returns an image with the given image id (iid).
    @param session
    @param image id (iid)
    @return image
    """
   
    #create gateway
    gateway = session.createGateway()
   
    if hasImage( session, iid ):
        image = gateway.getImage( iid )
        gateway.close()
        return image
    else:
        print "No image exists with the given iid"
        return []


def hasImage( session, iid ):
   """
   Determines if there is an image in the OMERO database with the given
   image id (iid).
   @params session
   @params image id (iid)
   @return true if image exists, false otherwise
   """

   #create query service
   query = session.getQueryService()

   #create and populate parameter
   params = omero.sys.ParametersI()
   params.addLong( "iid", iid );

   #hql string query
   string = "select count(*) from Image i where i.id = :iid";

   #database query
   result = query.projection( string, params )

   #get answer
   answer = result.pop().pop()._val
   if answer == 0:
       return False
   else:
       return True


could you tell me how to retrieve omeName of the owner of an image, given the image ID?
I dont know how to use HQL nor IAdmin methods.
I'm using python API for OMERO.web interface.

best,
bk

Re: getting the owner name of a specific image

PostPosted: Tue Jul 12, 2011 7:53 am
by wmoore
Hi BK,

If you're using the Blitz Gateway connection in the web framework, then this is easy:

Code: Select all
image = conn.getObject("Image", iId)

print image.getOwnerOmeName()
print image.getOwnerFullName()
print image.getOwner()

# if you know the image is in a single Dataset & Project
print image.getDataset().getId(), image.getDataset().getName()
print image.getProject().getId(), image.getProject().getName()

# if the image is in multiple Datasets and Projects
for d in image.listParents():
    print d.getName()
    for p in d.listParents():
        print "   ", p.getName()


Re: getting the owner name of a specific image

PostPosted: Tue Jul 12, 2011 3:55 pm
by bhcho
we are using the conn by the following code, which is in the views.py for our own app

Code: Select all
@isUserConnected   
def feature_calculation( request, object_type = None, object_ID = None, **kwargs):
    # get connection
    conn = None
    try:
        conn = kwargs["conn"]       
    except:
        logger.error(traceback.format_exc())
        return handlerInternalError("Connection is not available. Please contact your administrator.")
    session = conn.c.sf;


from the conn above, the followings do not seem to work.
Code: Select all
image = conn.getObject("Image", iId)

print image.getOwnerOmeName()
print image.getOwnerFullName()
print image.getOwner()


I tried to use
Code: Select all
conn2 = getBlitzConnection( request )


but it still does not work.

bk

Re: getting the owner name of a specific image

PostPosted: Tue Jul 12, 2011 10:58 pm
by wmoore
Are you using OMERO 4.3 or earlier?

The code I gave you was for 4.3.0 release
Code: Select all
conn.getObject("Image", iId)


If you want 4.2, you need
Code: Select all
conn.getImage(iId)


If not, what error do you get?

Re: getting the owner name of a specific image

PostPosted: Wed Jul 13, 2011 1:56 pm
by bhcho
we are using 4.2.1 and the method you suggested works.
thanks.

bk