We're Hiring!

Get List Of Projects

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.

Get List Of Projects

Postby icaoberg » Mon Aug 22, 2011 3:31 pm

Using the API I can get the projects associated with a user, given
Code: Select all
projects=gateway.getProjects([],False)


In my case, the list of projects contains the projects in which the user is the owner and the projects this user can "see". Is there a way to only retrieve a list of the projects the user has ownership?
icaoberg
 
Posts: 145
Joined: Fri Sep 17, 2010 9:05 pm
Location: Pittsburgh, PA

Re: Get List Of Projects

Postby jmoore » Mon Aug 22, 2011 6:38 pm

Hi Ivan,

Hopefully something like the following will help:
Code: Select all
In [8]: service = client.sf.getQueryService()

In [9]: service.projection("select p.id from Project p where p.details.owner.id = :id", omero.sys.ParametersI().addId(0))
...
In [10]: me = client.sf.getAdminService().getEventContext().userId

In [11]: service.projection("select p.id from Project p where p.details.owner.id = :id", omero.sys.ParametersI().addId(me))
Out[11]:
[[object #0 (::omero::RLong)
{
    _val = 201
}],
[object #0 (::omero::RLong)
{
    _val = 202
}]]

In [12]: omero.rtypes.unwrap(service.projection("select p.id from Project p where p.details.owner.id = :id", omero.sys.ParametersI().addId(me)))
Out[12]: [[201L], [202L]]


Cheers,
~Josh.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Get List Of Projects

Postby icaoberg » Wed May 02, 2012 10:49 pm

i am trying to retrieve a list of projects using the code

Code: Select all
execfile( 'login.py' )
query = conn.getQueryService()
me = conn.getAdminService().getEventContext().userId
string = "select p.id from Project p where p.details.owner.id = :id"
params = omero.sys.ParametersI().addId(me)
prids = omero.rtypes.unwrap(query.projection(string,params))


but then prids is empty. i don't understand what i am doing wrong. sorry for the confusion
icaoberg
 
Posts: 145
Joined: Fri Sep 17, 2010 9:05 pm
Location: Pittsburgh, PA

Re: Get List Of Projects

Postby jmoore » Thu May 03, 2012 8:18 am

Could you be logged into the wrong group? What do you see if you try:

Code: Select all
bin/omero hql --admin "select p.id, p.details.owner.id, p.details.group.id from Project p"


~J.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Get List Of Projects

Postby wmoore » Tue May 08, 2012 3:38 pm

There is a "listProjects()" method on the Blitz Gateway that can optionally take an experimenter ID.

If no ID is supplied then it lists Projects belonging to the current user.

Code: Select all
for p in conn.listProjects():    # returns a generator
    print p.getName()      # p is a ProjectWrapper
    print p._obj               # gets the underlying omero.model object

expId = 123
pgen = conn.listProjects(expId)   # filter by experimenter
projects = list( pgen )
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest