[Building Sakai] How to get site id

Diego del Blanco Orobitg diego.delblanco at setival.com
Tue Jun 23 03:21:21 PDT 2009


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



More information about the sakai-dev mailing list