[Building Sakai] How to get site id

David Horwitz David.Horwitz at uct.ac.za
Tue Jun 23 05:24:30 PDT 2009


Hi, 

Remember if Toolplacement will only work if your code is part of a tool placed on a page (hence the name).If  your code is not running as part of tool logic (for instance in a webservice or quartz job) You need to use another way to figure out the context.  Often you can do this as part of the object hierarchy your dealing with: 

foo.getFooContainer.getContext(). 

Regards 

David

>>> "Diego del Blanco Orobitg" <diego.delblanco at setival.com> 6/23/2009 1:32 PM >>>
Hi Steve!!!

I use ToolManager as follows:


import org.sakaiproject.tool.cover.ToolManager;
public class ReivenListBean {
....

   private String getCurrentSiteId(){
  System.out.println(" ----------- ReivenListBean.getCurrentSiteId ------");
  String currentSiteId = null;
        Placement thisPlacement = ToolManager.getCurrentPlacement();
  if (thisPlacement!=null){
   System.out.println(" > toolManager.currentPlacement---> NOT NULL");
   if(thisPlacement != null)
    currentSiteId = thisPlacement.getContext();
  }else{
   System.out.println(" > toolManager.currentPlacement ---> NULL");
  }
     return currentSiteId;
   }
  
....  
}

But I also have tried doing the same as
http://bugs.sakaiproject.org/confluence/display/BOOT/Using+the+ToolManager+S
ervice suggests with the same result.

Thank you very much in advance.

-----Mensaje original-----
De: Steve Swinsburg [mailto:s.swinsburg at lancaster.ac.uk]
Enviado el: martes, 23 de junio de 2009 13:07
Para: Diego del Blanco Orobitg
CC: Sakai Dev Mailing List
Asunto: Re: [Building Sakai] How to get site id

Is theToolManager dependency injected correctly? How are you injecting 
it? Via Spring directly (setting up your impl as a bean and setting it 
as a property etc) or getting it from the ComponentManager? Post your 
relevant injection code.

cheers,
Steve

---
Steve Swinsburg
Portal Systems Developer
Centre for e-Science
Lancaster University
Lancaster
LA1 4YT

email: s.swinsburg at lancaster.ac.uk
phone: +44 (0) 1524 594870







On 23 Jun 2009, at 11:21, Diego del Blanco Orobitg wrote:

> Dear all,
>
> I'm developing a new Sakai tool to be able to import IMS QTI and IMS 
> CP to
> Samigo, Mneme and Melete, respectively, through these three tools 
> Services
> to do that.
>
> The problem I have is that toolManager.getCurrentPlacement is null 
> and,
> thus, I cannot get siteId to know which is the current site I am 
> visiting.
> This makes Samigo, Mneme and Melete services not to know to which 
> site they
> have to associate imported files. And, thus, import process fails.
> As far as I know, the only way to get Site Id is through
> toolManager.getCurrentPlacement().getContext(), but I cannot get it 
> in this
> way. Do you know if there is any? I also have used
> PortalService.getCurrentSiteId() but this function is based in the 
> former
> and thus, it doesn't work either.
>
> As Stephen Marquard has suggested me "getCurrentPlacement() is 
> usable when
> it is called by code running in
> the context of a /portal/tool/toolid/... http request. Outside that 
> (for
> example in service code called by some other process,
> e.g. a maintenance thread or webservice) it's not set or meaningful.
> Generally service code should not rely on getCurrentPlacement() as 
> this
> breaks the SOA paradigm (i.e. it makes the service code only usable 
> from the
> tool UI code)". Considering this pointing, I've tried to get
> toolManager.getCurrentPlacement().getContext() from one of the beans 
> of my
> tool, instead to leave Samigo Services to do it for my tool and...I'm
> getting the same NPE!!!.
>
> The following scriptlet is inside one of my tool's bean:
>    if (ToolManager.getCurrentPlacement()!=null){
>     System.out.println(" > toolManager.currentPlacement---> NOT 
> NULL");
>    }else{
>     System.out.println(" > toolManager.currentPlacement ---> NULL");
>    }
> And I get
>
>> toolManager.currentPlacement ---> NULL
>
> I really don't know why!!!!. I have analyzed the link to my tool in 
> Sakai
> main page, to see which pattern it follows and be able to check if 
> it is
> valid for a tool or not. And here you have what I've found:
> Site-info
> <!-- start Tool Body -->
> <div class="portletMainWrap">
> <iframe name="Main9bd95d6ax328fx4a14xb2c0xfbbaf22a6145"
> id="Main9bd95d6ax328fx4a14xb2c0xfbbaf22a6145"
> title="Informaci&#243;n del sitio "
> class ="portletMainIframe"
> height="50"
> width="100%"
> frameborder="0"
> marginwidth="0"
> marginheight="0"
> scrolling="auto"
>
>
src="http://localhost:8080/portal/tool/9bd95d6a-328f-4a14-b2c0-fbbaf22a6145?
> panel=Main">
> </iframe>
> </div>
> <!-- end Tool Body -->
> My Tool
>
> <!-- start Tool Body -->
> <div class="portletMainWrap">
> <iframe name="Maine4759e5axcc51x44dcxb9b2x9be7f28ee6ca"
> id="Maine4759e5axcc51x44dcxb9b2x9be7f28ee6ca"
> title="Reiven Content "
> class ="portletMainIframe"
> height="50"
> width="100%"
> frameborder="0"
> marginwidth="0"
> marginheight="0"
> scrolling="auto"
>
>
src="http://localhost:8080/portal/tool/e4759e5a-cc51-44dc-b9b2-9be7f28ee6ca?
> panel=Main">
> </iframe>
> </div>
> <!-- end Tool Body -->
> That is, the request is very similar to the one generated for other 
> sakai
> tools (site-info, in this case). So, why 
> ToolManager.getCurrentPlacement()
> is not usable here? Is any other way of getting Site id?
>
> I really don't know if it is a problem of tool configuration or if I 
> am
> missing some libraries.
>
> Thank you very much in advance.
>
> -- Kind regards,
>       Diego
>
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>
> TO UNSUBSCRIBE: send email to
sakai-dev-unsubscribe at collab.sakaiproject.org
>  with a subject of "unsubscribe"


_______________________________________________
sakai-dev mailing list
sakai-dev at collab.sakaiproject.org
http://collab.sakaiproject.org/mailman/listinfo/sakai-dev

TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"


 
______________________________________________________________________________________________ 

UNIVERSITY OF CAPE TOWN 

This e-mail is subject to the UCT ICT policies and e-mail disclaimer published on our website at http://www.uct.ac.za/about/policies/emaildisclaimer/ or obtainable from +27 21 650 4500. This e-mail is intended only for the person(s) to whom it is addressed. If the e-mail has reached you in error, please notify the author. If you are not the intended recipient of the e-mail you may not use, disclose, copy, redirect or print the content. If this e-mail is not related to the business of UCT it is sent by the sender in the sender's individual capacity.

_____________________________________________________________________________________________________
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20090623/f5951b9a/attachment.html 


More information about the sakai-dev mailing list