Re: [basedb-devel] Setting active project via API

2010-01-08 Thread Woodbridge, Mark R
I have added a servlet to the BASE webapp that does the following:

SessionControl sc = 
Application.newSessionControl("net.sf.basedb.clients.web", 
request.getRemoteAddr(), null);
sc.login(username, password, null, false);
DbControl dc = sc.newDbControl();
sc.setActiveProject(Project.getById(dc, projectId));
dc.close();

response.sendRedirect(String.format("/base/views/experiments/index.jsp?ID=%s&cmd=ViewItem&item_id=%s",
 sc.getId(), experimentId));

Haven't done much testing, but seems to work so far. I'm passing in the project 
ID because an experiment can be shared with more than one project (as 
previously discussed).

I could make more of an effort to avoid creating unnecessary sessions, but not 
sure if this is worthwhile. Presumably I could avoid passing the user's 
password by putting the root password in the servlet and impersonating the real 
user.

Thanks for all the help,

Mark.



From: basedb-devel-boun...@lists.sourceforge.net 
[basedb-devel-boun...@lists.sourceforge.net] On Behalf Of Bob MacCallum 
[r.maccal...@imperial.ac.uk]
Sent: 08 January 2010 14:48
To: lefev...@yahoo.com; BASE dev
Subject: Re: [basedb-devel] Setting active project via API

A long time ago now, I remember having problems with experiments/projects.
You would think it would be enough to add "Everyone" group to the project
and then it would be visible, but as others have pointed out, the project
has to be active before the expt is visible.

We decided to just share all project items to Everyone and be done with it(*).
You might get the granularity you need by sharing to groups instead.

(* thanks to the BASE developers, we got a much increased max items limit in
list view to make this easy to do)

Olivier Lefevre writes:
 > >> Disregarding that, do you have any ideas about how to
 > >> link directly to an Experiment without getting the
 > >> 'permission denied' error caused by the wrong project
 > >> being selected?
 > >
 > > You can't link directly. You need to set the active
 > > project first.
 >
 > ?? AFAIK this is the first time this comes up. Why isn't
 > it enough to be logged and to have permission to view
 > the experiments in questions. Direct links to experiments
 > are possible: they have the form
 > http://localhost:8080/base2/views/experiments/index.jsp?ID=xxx&cmd=ViewItem&item_id=nnn
 >
 > -- O.L.
 >
 >
 > --
 > This SF.Net email is sponsored by the Verizon Developer Community
 > Take advantage of Verizon's best-in-class app development support
 > A streamlined, 14 day to market process makes app distribution fast and easy
 > Join now and get one step closer to millions of Verizon customers
 > http://p.sf.net/sfu/verizon-dev2dev
 > ___
 > basedb-devel mailing list
 > basedb-devel@lists.sourceforge.net
 > https://lists.sourceforge.net/lists/listinfo/basedb-devel

--
Bob MacCallum | VectorBase Developer | Kafatos/Christophides Groups |
Division of Cell and Molecular Biology | Imperial College London |
Phone +442075941945 | Email r.maccal...@imperial.ac.uk

--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel

--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel


Re: [basedb-devel] Setting active project via API

2010-01-08 Thread Bob MacCallum

A long time ago now, I remember having problems with experiments/projects.
You would think it would be enough to add "Everyone" group to the project
and then it would be visible, but as others have pointed out, the project
has to be active before the expt is visible.

We decided to just share all project items to Everyone and be done with it(*).
You might get the granularity you need by sharing to groups instead.

(* thanks to the BASE developers, we got a much increased max items limit in
list view to make this easy to do)

Olivier Lefevre writes:
 > >> Disregarding that, do you have any ideas about how to
 > >> link directly to an Experiment without getting the 
 > >> 'permission denied' error caused by the wrong project 
 > >> being selected? 
 > > 
 > > You can't link directly. You need to set the active 
 > > project first.
 > 
 > ?? AFAIK this is the first time this comes up. Why isn't
 > it enough to be logged and to have permission to view 
 > the experiments in questions. Direct links to experiments
 > are possible: they have the form
 > http://localhost:8080/base2/views/experiments/index.jsp?ID=xxx&cmd=ViewItem&item_id=nnn
 > 
 > -- O.L.
 > 
 > 
 > --
 > This SF.Net email is sponsored by the Verizon Developer Community
 > Take advantage of Verizon's best-in-class app development support
 > A streamlined, 14 day to market process makes app distribution fast and easy
 > Join now and get one step closer to millions of Verizon customers
 > http://p.sf.net/sfu/verizon-dev2dev 
 > ___
 > basedb-devel mailing list
 > basedb-devel@lists.sourceforge.net
 > https://lists.sourceforge.net/lists/listinfo/basedb-devel

-- 
Bob MacCallum | VectorBase Developer | Kafatos/Christophides Groups |
Division of Cell and Molecular Biology | Imperial College London |
Phone +442075941945 | Email r.maccal...@imperial.ac.uk

--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel


Re: [basedb-devel] Setting active project via API

2010-01-07 Thread Nicklas Nordborg
Olivier Lefevre wrote:
>>> Disregarding that, do you have any ideas about how to
>>> link directly to an Experiment without getting the 
>>> 'permission denied' error caused by the wrong project 
>>> being selected? 
>> You can't link directly. You need to set the active 
>> project first.
> 
> ?? AFAIK this is the first time this comes up. Why isn't
> it enough to be logged and to have permission to view 
> the experiments in questions. Direct links to experiments
> are possible: they have the form
> http://localhost:8080/base2/views/experiments/index.jsp?ID=xxx&cmd=ViewItem&item_id=nnn

The permissions for a user a linked with the active project. Switching 
projects is more or less at the same level as logging out and then back 
as another user.

The direct link offers no possibility to switch user nor any possibility 
to switch project. Both of these things has to be done before the view 
page is being accessed.

/Nicklas

--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel


Re: [basedb-devel] Setting active project via API

2010-01-07 Thread Olivier Lefevre
>> Disregarding that, do you have any ideas about how to
>> link directly to an Experiment without getting the 
>> 'permission denied' error caused by the wrong project 
>> being selected? 
> 
> You can't link directly. You need to set the active 
> project first.

?? AFAIK this is the first time this comes up. Why isn't
it enough to be logged and to have permission to view 
the experiments in questions. Direct links to experiments
are possible: they have the form
http://localhost:8080/base2/views/experiments/index.jsp?ID=xxx&cmd=ViewItem&item_id=nnn

-- O.L.


--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel


Re: [basedb-devel] Setting active project via API

2010-01-07 Thread Nicklas Nordborg
Woodbridge, Mark R wrote:
  > I have tried adding a new servlet to the existing BASE web.xml file
> but I got a strange error that seemed to imply that BASE defines its
> own ClassLoader. 

Not in this context, but Tomcat does. 
http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html


 > Have you ever seen a problem like this?

Like what?


 > I'm not
> clear on the best way to invoke code that uses the native API. Using
> the webservices API is easy because you just need the relevant jars.
> 
> Disregarding that, do you have any ideas about how to link directly
> to an Experiment without getting the 'permission denied' error caused
> by the wrong project being selected? 

You can't link directly. You need to set the active project first. To do 
this you need code that is living in the BASE web application that calls 
SessionControl.setActiveProject(). You could for example create a 
servlet that takes four parameters: login, password, project ID and 
experiment ID. Then something rougly like this:

// Create a new session and login
SessionControl sc = Application.newSessionControl();
sc.login(login, password, );

// Then, active the project
Project p = Project.getById(...);
sc.setActiveProject(p);

// redirect to the experiment page
response.sendRedirect();

 > I'm assuming it would actually
> be possible to write a servlet that automatically authenticates the
> user, sets the active project, then redirects to the experiment? I'm
> not sure of the best approach...

Neither am I... you'll need to fill in a lot of blanks in the "code" 
above. The example above creates a new session every time. If you need 
something different, you'll probably need to mange the session id's in 
your own application and add that as a parameter to the servlet as well. 
The servlet should then first check for an existing session before 
creating a new one: Application.getSessionControl(...);

/Nicklas

--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel


Re: [basedb-devel] Setting active project via API

2010-01-07 Thread Woodbridge, Mark R
Ok. I assumed session ids could be re-used because the SessionClient 
constructor allows you to pass one in. That explains why my approach isn't 
working.

I have tried adding a new servlet to the existing BASE web.xml file but I got a 
strange error that seemed to imply that BASE defines its own ClassLoader. Have 
you ever seen a problem like this? I'm not clear on the best way to invoke code 
that uses the native API. Using the webservices API is easy because you just 
need the relevant jars.

Disregarding that, do you have any ideas about how to link directly to an 
Experiment without getting the 'permission denied' error caused by the wrong 
project being selected? I'm assuming it would actually be possible to write a 
servlet that automatically authenticates the user, sets the active project, 
then redirects to the experiment? I'm not sure of the best approach...

Mark.

-Original Message-
From: basedb-devel-boun...@lists.sourceforge.net 
[mailto:basedb-devel-boun...@lists.sourceforge.net] On Behalf Of Nicklas 
Nordborg
Sent: 07 January 2010 16:37
To: BASE dev
Subject: Re: [basedb-devel] Setting active project via API

Woodbridge, Mark R wrote:
> Thanks Nicklas.
> 
> I know this issue has come up on the mailing list a couple of times,
> but I'm not sure what the solution is. As I said, I'm linking
> directly to Experiments in BASE from my Flex application. I'm doing
> this by doing an HTTP POST to /login.jsp with a redirect to
> views/experiments/index.jsp?cmd=ViewItem&item_id=...&ID=...
> 
> This works fine but there are a couple of problems. The first is that
> I call /login.jsp every time I link to an experiment. I'm using the
> same ID every time to avoid creating a new session. Is this the
> correct thing to do?

No you can't reuse the same ID. It has to be unique for per user 
session. Strange things will happen if there are multiple sessions using 
the same ID.

> The second problem is this issue with the active project. What is the
> correct way to ensure that the link works i.e. avoiding linking to an
> Experiment that isn't shared with the 'active' project? I have tried
> the following:
> 
> 1. Generate a session ID 2. Use the webservices API to set the active
> project for this sessionID 3. Post to /login.jsp using this sessionID
> 
> 
> But this doesn't seem to work. Is there a way to link directly to an
> Experiment, ignoring whatever Project is currently active? Any help
> would be gratefully received.

No this will not work. From the BASE point of view your web service 
application is the client. The session ID it uses to set the active 
project can't be transfered to another client (eg. a web browser).

You'll need to add code to the BASE web server application. Eg. add your 
own servlets, JSP:s, web services, etc. that does the hard work for you 
using the BASE core API directly. I don't think it can be done by using 
the current web service API or by calling the JSP scripts.

/Nicklas

--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel

--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel


Re: [basedb-devel] Setting active project via API

2010-01-07 Thread Nicklas Nordborg
Woodbridge, Mark R wrote:
> Thanks Nicklas.
> 
> I know this issue has come up on the mailing list a couple of times,
> but I'm not sure what the solution is. As I said, I'm linking
> directly to Experiments in BASE from my Flex application. I'm doing
> this by doing an HTTP POST to /login.jsp with a redirect to
> views/experiments/index.jsp?cmd=ViewItem&item_id=...&ID=...
> 
> This works fine but there are a couple of problems. The first is that
> I call /login.jsp every time I link to an experiment. I'm using the
> same ID every time to avoid creating a new session. Is this the
> correct thing to do?

No you can't reuse the same ID. It has to be unique for per user 
session. Strange things will happen if there are multiple sessions using 
the same ID.

> The second problem is this issue with the active project. What is the
> correct way to ensure that the link works i.e. avoiding linking to an
> Experiment that isn't shared with the 'active' project? I have tried
> the following:
> 
> 1. Generate a session ID 2. Use the webservices API to set the active
> project for this sessionID 3. Post to /login.jsp using this sessionID
> 
> 
> But this doesn't seem to work. Is there a way to link directly to an
> Experiment, ignoring whatever Project is currently active? Any help
> would be gratefully received.

No this will not work. From the BASE point of view your web service 
application is the client. The session ID it uses to set the active 
project can't be transfered to another client (eg. a web browser).

You'll need to add code to the BASE web server application. Eg. add your 
own servlets, JSP:s, web services, etc. that does the hard work for you 
using the BASE core API directly. I don't think it can be done by using 
the current web service API or by calling the JSP scripts.

/Nicklas

--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel


Re: [basedb-devel] Setting active project via API

2010-01-07 Thread Woodbridge, Mark R
Thanks Nicklas.

I know this issue has come up on the mailing list a couple of times, but I'm 
not sure what the solution is. As I said, I'm linking directly to Experiments 
in BASE from my Flex application. I'm doing this by doing an HTTP POST to 
/login.jsp with a redirect to 
views/experiments/index.jsp?cmd=ViewItem&item_id=...&ID=...

This works fine but there are a couple of problems. The first is that I call 
/login.jsp every time I link to an experiment. I'm using the same ID every time 
to avoid creating a new session. Is this the correct thing to do?

The second problem is this issue with the active project. What is the correct 
way to ensure that the link works i.e. avoiding linking to an Experiment that 
isn't shared with the 'active' project? I have tried the following:

1. Generate a session ID
2. Use the webservices API to set the active project for this sessionID
3. Post to /login.jsp using this sessionID

But this doesn't seem to work. Is there a way to link directly to an 
Experiment, ignoring whatever Project is currently active? Any help would be 
gratefully received.

Mark.


-Original Message-
From: basedb-devel-boun...@lists.sourceforge.net 
[mailto:basedb-devel-boun...@lists.sourceforge.net] On Behalf Of Nicklas 
Nordborg
Sent: 07 January 2010 07:31
To: BASE dev
Subject: Re: [basedb-devel] Setting active project via API

Woodbridge, Mark R wrote:
> Hi,
> 
>  
> 
> I'm linking to experiments in BASE from another web application. This 
> works fine, including automatically logging in, as long as the 
> experiment belongs to the user's active project. I'd like to ensure that 
> the correct project is activated before the user clicks on the link. 
> Does anyone know if I can get the relevant project id from an experiment 
> id? There doesn't seem to be an ExperimentInfo.getProject() method.

There is no such method since an experiment can belong to more than one 
project. The web service API has very limited functionality. The 
functionality that currently exists was implemented to support some 
specific use cases (mainly related to downloading data files) for a 
project that we participated in.

Using the regular BASE API you can find the projects by putting the 
experiment in a collection and then using a multi-permissions object:

Collection experiments = ...
MultiPermissions mp = new MultiPermissions(experiments);
ItemQuery q = mp.getProjects();
List project = q.list(dc);

The code is a bit awkward, but for some reason the obvious approach, 
Experiment.getProjectKey().getProjects(), is missing.

/Nicklas

--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel

--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel


Re: [basedb-devel] Setting active project via API

2010-01-06 Thread Nicklas Nordborg
Woodbridge, Mark R wrote:
> Hi,
> 
>  
> 
> I’m linking to experiments in BASE from another web application. This 
> works fine, including automatically logging in, as long as the 
> experiment belongs to the user’s active project. I’d like to ensure that 
> the correct project is activated before the user clicks on the link. 
> Does anyone know if I can get the relevant project id from an experiment 
> id? There doesn’t seem to be an ExperimentInfo.getProject() method.

There is no such method since an experiment can belong to more than one 
project. The web service API has very limited functionality. The 
functionality that currently exists was implemented to support some 
specific use cases (mainly related to downloading data files) for a 
project that we participated in.

Using the regular BASE API you can find the projects by putting the 
experiment in a collection and then using a multi-permissions object:

Collection experiments = ...
MultiPermissions mp = new MultiPermissions(experiments);
ItemQuery q = mp.getProjects();
List project = q.list(dc);

The code is a bit awkward, but for some reason the obvious approach, 
Experiment.getProjectKey().getProjects(), is missing.

/Nicklas

--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel


[basedb-devel] Setting active project via API

2010-01-04 Thread Woodbridge, Mark R
Hi,

I'm linking to experiments in BASE from another web application. This works 
fine, including automatically logging in, as long as the experiment belongs to 
the user's active project. I'd like to ensure that the correct project is 
activated before the user clicks on the link. Does anyone know if I can get the 
relevant project id from an experiment id? There doesn't seem to be an 
ExperimentInfo.getProject() method.

Many thanks,

Mark.

--
Mark Woodbridge
CISBIC Data Management
Imperial College London
--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev ___
basedb-devel mailing list
basedb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/basedb-devel