Page 1 of 1

Get List Of Projects

PostPosted: Mon Aug 22, 2011 3:31 pm
by icaoberg
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?

Re: Get List Of Projects

PostPosted: Mon Aug 22, 2011 6:38 pm
by jmoore
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.

Re: Get List Of Projects

PostPosted: Wed May 02, 2012 10:49 pm
by icaoberg
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

Re: Get List Of Projects

PostPosted: Thu May 03, 2012 8:18 am
by jmoore
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.

Re: Get List Of Projects

PostPosted: Tue May 08, 2012 3:38 pm
by wmoore
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 )