We're Hiring!

getting the owner name of a specific image

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

getting the owner name of a specific image

Postby bhcho » Tue Jun 14, 2011 12:29 pm

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
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: getting the owner name of a specific image

Postby jmoore » Tue Jun 14, 2011 3:59 pm

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
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: getting the owner name of a specific image

Postby bhcho » Mon Jul 11, 2011 11:21 pm

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
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: getting the owner name of a specific image

Postby wmoore » Tue Jul 12, 2011 7:53 am

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()

User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: getting the owner name of a specific image

Postby bhcho » Tue Jul 12, 2011 3:55 pm

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
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: getting the owner name of a specific image

Postby wmoore » Tue Jul 12, 2011 10:58 pm

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?
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: getting the owner name of a specific image

Postby bhcho » Wed Jul 13, 2011 1:56 pm

we are using 4.2.1 and the method you suggested works.
thanks.

bk
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 0 guests