cancel
Showing results for 
Search instead for 
Did you mean: 

Java backed custom Dashlet for Share

yasosaran
Champ in-the-making
Champ in-the-making
Hello,

I am trying to create a java backed custom user dashlet for Alfresco share. This is our requirement. We have a external database were we store our meta data.

We need a webscript/dashlet that would query the external database based the currently logged in user in share and display them in the dashboad just like My Tasks dashlet.

I could successfully develop a (java backed )custom dashlet and add it to dashboard. And it does queries the database and brings the value but with hard coded values.

I am not sure how to get the currently logged (in share)in user's loginid in my custom java code.

Could some one please help me on this. or please let me is it the correct way or should I procees differently on this.

Thanks.
2 REPLIES 2

damiri
Champ in-the-making
Champ in-the-making
Hello yasosaran,

i have created a custom dashlet using java:

1) Comment out the block in ${tomcat}\shared\classes\alfresco\web-extension\custom-slingshot-application-context.xml


  

   <bean id="webframework.searchpath" class="org.alfresco.web.scripts.SearchPath">
      <property name="searchPath">
         <list>
            <ref bean="webframework.remotestore.webscripts" />
            <ref bean="webframework.store.webscripts.custom" />
            <ref bean="webframework.store.webscripts" />
            <ref bean="webscripts.store" />
         </list>
      </property>
   </bean>
  



Remember in web-framework-application-context.xml exists:
   <bean id="webframework.store.webscripts.custom" class="org.alfresco.web.scripts.ClassPathStore">
      <property name="mustExist"><value>false</value></property>
      <property name="classPath"><value>alfresco/web-extension/site-webscripts</value></property>
   </bean>


2) put your desc file in

${tomcat}\webapps\share\WEB-INF\classes\alfresco\web-extension\site-webscripts\org\alfresco\demo\simple.get.desc.xml

<webscript>
  <shortname>The World's Simplest Webscript</shortname>
  <description>Hands back a little bit of JSON</description>
  <family>user-dashlet</family>
  <url>/demo/simple</url>
  <authentication>none</authentication>
</webscript>

3) Modify

${tomcat}\webapps\share\WEB-INF\classes\alfresco\webscript-framework-application-context.xml:

add after

   <!–  Abstract Web Script Implementations –>
   <bean id="webscript" abstract="true"/>

 <bean id="webscript.org.alfresco.demo.simple.get" class="org.alfresco.module.demoscripts.SimpleWebScript" parent="webscript"/>



4) deploy your Java backed Script as jar in WEB-INF/lib

package org.alfresco.module.demoscripts;

import java.io.IOException;
import java.io.Writer;

import org.alfresco.web.scripts.AbstractWebScript;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptResponse;
import org.json.JSONException;
import org.json.JSONObject;

public class SimpleWebScript extends AbstractWebScript {
   public void execute(WebScriptRequest req, WebScriptResponse res)
         throws IOException {
      try {
         // build a json object
         JSONObject obj = new JSONObject();

         // put some data on it
         obj.put("field1", "data1");

         // build a JSON string and send it back
         String jsonString = obj.toString();
         Writer writer = res.getWriter();

         //writer.write(jsonString);
          writer.write("<div class=\"dashlet\">");
          writer.write("<div class=\"title\">SIMPLE WEB SCRIPT</div>");
          writer.write("<div id=\"SIMPLEWEBSCRIPT\" class=\"body scrollableList\">");
          writer.write("<h1>SIMPLE SIMPLE</h1>");
         
          writer.write("</div>");
         
          writer.write("</div>");
                   
      } catch (JSONException e) {
         throw new WebScriptException("Unable to serialize JSON");
      }
   }
   
   
}

damiri
Champ in-the-making
Champ in-the-making
After deploying (refreshing web scripts) you can see this web script at:

http://localhost:8080/share/service/demo/simple

you can add this dashlet to dashboard…

but there is only one problem: dashlet will be not displayed on dashboard - phase render problem??