cancel
Showing results for 
Search instead for 
Did you mean: 

CMIS Dashlet

cdowin
Champ in-the-making
Champ in-the-making
Hello everyone.

I'm trying to write a dashlet for Share that runs a CMIS query to get documents out of the repository.  I found this example code from one of the Packt Alfresco books, but I'm running into some errors.  I have successfully loaded up a hello world type of dashlet, so I know everything is going in the correct place and I'm taking the correct steps for refreshing webscripts etc …

Here's my javascript:


var conn = remote.connect("alfresco");
// search cmis search api path
var id = "/api/query";

// get the sites space
var workspace = "/api/path/workspace/SpacesStore/Company Home/Sites";
var sitesspace = conn.get(stringUtils.urlEncodeComponent(workspace));
var sitesspaceentry = atom.toEntry(sitesspace);

// get the children URL which is a cmis feed.
var sitesspacechildren = sitesspaceentry.getLinks("cmis-children").get(0).href;

// get all sites - children of sites space
var sites = conn.get(sitesspacechildren);
var sitesfeed = atom.toFeed(sites);

// gets the entries of the feed - which translate to a site space
var entries = sitesfeed.getEntries();
var size = entries.size();
var sitesspaceid = "";

var sitesdocuments = new Array();
// for each site
for (var i=0; i<size; i++) {
  var site = entries.get(i);
 
  // take the sites id (in alfresco its workspace)
  sitespaceid =  site.getExtension(atom.names.cmis_object).objectId.value;
  var sitename = site.title;
 
  // formulate the query based on sitesid and current user
  // TODO: bug in objecttypeid != 'D/cm_thumbnail' - modify selectString when fixed
  var selectString = "SELECT * FROM Document WHERE IN_TREE( ,\'" + sitespaceid + "\') AND " +
  "(CreatedBy=\'" + user.id + "\' OR LastModifiedBy=\'" + user.id + "\') AND ObjectTypeId = \'document\'";
  var cmisQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><query xmlns:cmis=\"http://www.cmis.org/2008/05\"><statement>" + selectString + "</statement><pageSize>" + 0 + "</pageSize></query>";
 
  // get the documents for the currently active site
  var conn = remote.connect("alfresco");
  var queryResult = conn.post(stringUtils.urlEncodeComponent(id), cmisQuery, "application/cmisquery+xml");
  // sitesdocuments[0] = "{name: " + sitename + ", documents: " + atom.toFeed(queryResult) + "}";
  sitesdocuments[i] = new Object();
  sitesdocuments[i].name=sitename;
  sitesdocuments[i].documents=atom.toFeed(queryResult);
}

//model.results = atom.toFeed(queryResult);
model.sitesdocuments=sitesdocuments;

My template:


<div class="dashlet">
  <div class="title">${msg("title")}</div>
  <div class="body scrollableList">
    <#list sitesdocuments as site>
    <div class="icon">
      ${site.name}
    </div>
    <#assign documents=site.documents>
    <#list documents.entries as entry>
    <div class="detail-list-item">
      <#assign cmis_object=entry.getExtension(atom.names.cmis_object)>     
      <div class="details">
        <h4><a href="${url.context}/page/site/${site.name}/document-details?nodeRef=${cmis_object.versionSeriesId.value}">${cmis_object.name.value}</a></h4>
        ${cmis_object.lastModificationDate.dateValue?datetime}
      </div>
     
    </div>
    </#list>
    </#list>
  </div>
</div>

My XML:


<webscript>
  <shortname>Alfresco Book Site Documents</shortname>
  <description>My Documents Dashlet</description>
  <family>site-dashlet</family>
  <url>/components/dashlets/mydocuments</url>
</webscript>

And finally, the error that I get.  I get this error when I register the dashlet on the page.  This appears in the container where the dashlet would normally show a list of documents.


Web Script Status 500 - Internal Error

The Web Script /share/service/components/dashlets/mydocuments has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   04130005 Failed to load script '/CMIS/mydocuments.get.js (in classpath store file:C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/webscripts)': 04130004 Array index out of range: 0
   
Exception:   java.lang.ArrayIndexOutOfBoundsException - Array index out of range: 0
   
   org.apache.abdera.parser.stax.util.FOMList.get(FOMList.java:83)
   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:597)
   org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155)
   org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
   org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
   org.mozilla.javascript.gen.c12._c0(file:C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/webscripts/CMIS/mydocuments.get.js:11)
   org.mozilla.javascript.gen.c12.call(file:C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/webscripts/CMIS/mydocuments.get.js)
   org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
   org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
   org.mozilla.javascript.gen.c12.call(file:C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/webscripts/CMIS/mydocuments.get.js)
   org.mozilla.javascript.gen.c12.exec(file:C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/webscripts/CMIS/mydocuments.get.js)
   org.alfresco.web.scripts.PresentationScriptProcessor.executeScriptImpl(PresentationScriptProcessor.java:314)
   org.alfresco.web.scripts.PresentationScriptProcessor.executeScript(PresentationScriptProcessor.java:189)
   org.alfresco.web.scripts.AbstractWebScript.executeScript(AbstractWebScript.java:819)
   org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:90)
   org.alfresco.web.scripts.PresentationContainer.executeScript(PresentationContainer.java:64)
   org.alfresco.web.scripts.LocalWebScriptRuntimeContainer.executeScript(LocalWebScriptRuntimeContainer.java:192)
   org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:306)
   org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:183)
   org.alfresco.web.scripts.WebScriptProcessor.executeBody(WebScriptProcessor.java:329)
   org.alfresco.web.framework.render.AbstractProcessor.execute(AbstractProcessor.java:85)
   org.alfresco.web.framework.render.RenderHelper.processComponent(RenderHelper.java:348)
   org.alfresco.web.framework.render.RenderUtil.renderRawComponent(RenderUtil.java:451)
   org.alfresco.web.framework.render.RenderUtil.renderRawComponent(RenderUtil.java:434)
   org.alfresco.web.framework.render.bean.ComponentRenderer.body(ComponentRenderer.java:135)
   org.alfresco.web.framework.render.RenderUtil.renderRegionComponents(RenderUtil.java:328)
   org.alfresco.web.site.taglib.RegionIncludeTag.doStartTag(RegionIncludeTag.java:43)
   org.alfresco.tools.TagUtil.execute(TagUtil.java:147)
   org.alfresco.tools.TagUtil.execute(TagUtil.java:81)
   org.alfresco.web.scripts.FreemarkerTagSupportDirective.executeTag(FreemarkerTagSupportDirective.java:89)
   org.alfresco.web.scripts.GenericFreemarkerTagDirective.execute(GenericFreemarkerTagDirective.java:127)
   freemarker.core.Environment.visit(Environment.java:261)
   freemarker.core.UnifiedCall.accept(UnifiedCall.java:126)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.MixedContent.accept(MixedContent.java:92)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.Environment.process(Environment.java:188)
   freemarker.template.Template.process(Template.java:237)
   org.alfresco.web.scripts.PresentationTemplateProcessor.process(PresentationTemplateProcessor.java:185)
   org.alfresco.web.scripts.FreemarkerProcessor.executeBody(FreemarkerProcessor.java:266)
   org.alfresco.web.framework.render.AbstractProcessor.execute(AbstractProcessor.java:85)
   org.alfresco.web.framework.render.RenderHelper.processRenderable(RenderHelper.java:284)
   org.alfresco.web.framework.render.bean.ChromeRenderer.body(ChromeRenderer.java:60)
   org.alfresco.web.framework.render.AbstractRenderer.render(AbstractRenderer.java:105)
   org.alfresco.web.framework.render.bean.RegionRenderer.body(RegionRenderer.java:134)
   org.alfresco.web.framework.render.AbstractRenderer.render(AbstractRenderer.java:105)
   org.alfresco.web.framework.render.RenderUtil.startRegionRenderer(RenderUtil.java:273)
   org.alfresco.web.framework.render.RenderUtil.renderRegion(RenderUtil.java:213)
   org.alfresco.web.framework.render.PresentationUtil.renderRegion(PresentationUtil.java:125)
   org.alfresco.web.site.taglib.RegionTag.doStartTag(RegionTag.java:109)
   org.alfresco.tools.TagUtil.execute(TagUtil.java:147)
   org.alfresco.tools.TagUtil.execute(TagUtil.java:81)
   org.alfresco.web.scripts.FreemarkerTagSupportDirective.executeTag(FreemarkerTagSupportDirective.java:89)
   org.alfresco.web.scripts.RegionFreemarkerTagDirective.execute(RegionFreemarkerTagDirective.java:128)
   freemarker.core.Environment.visit(Environment.java:261)
   freemarker.core.UnifiedCall.accept(UnifiedCall.java:126)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
   freemarker.core.Environment.visit(Environment.java:415)
   freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.MixedContent.accept(MixedContent.java:92)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
   freemarker.core.Environment.visit(Environment.java:415)
   freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.MixedContent.accept(MixedContent.java:92)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.Macro$Context.runMacro(Macro.java:164)
   freemarker.core.Environment.visit(Environment.java:601)
   freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.IfBlock.accept(IfBlock.java:82)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.Macro$Context.runMacro(Macro.java:164)
   freemarker.core.Environment.visit(Environment.java:601)
   freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.MixedContent.accept(MixedContent.java:92)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.Environment.visit(Environment.java:393)
   freemarker.core.BodyInstruction.accept(BodyInstruction.java:93)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.MixedContent.accept(MixedContent.java:92)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.Macro$Context.runMacro(Macro.java:164)
   freemarker.core.Environment.visit(Environment.java:601)
   freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.MixedContent.accept(MixedContent.java:92)
   freemarker.core.Environment.visit(Environment.java:208)
   freemarker.core.Environment.process(Environment.java:188)
   freemarker.template.Template.process(Template.java:237)
   org.alfresco.web.scripts.PresentationTemplateProcessor.process(PresentationTemplateProcessor.java:185)
   org.alfresco.web.scripts.FreemarkerProcessor.executeBody(FreemarkerProcessor.java:266)
   org.alfresco.web.framework.render.AbstractProcessor.execute(AbstractProcessor.java:85)
   org.alfresco.web.framework.render.RenderHelper.processTemplate(RenderHelper.java:423)
   org.alfresco.web.framework.render.bean.TemplateInstanceRenderer.body(TemplateInstanceRenderer.java:140)
   org.alfresco.web.framework.render.AbstractRenderer.render(AbstractRenderer.java:105)
   org.alfresco.web.framework.render.bean.PageRenderer.body(PageRenderer.java:81)
   org.alfresco.web.framework.render.AbstractRenderer.render(AbstractRenderer.java:105)
   org.alfresco.web.framework.render.RenderUtil.startPageRenderer(RenderUtil.java:144)
   org.alfresco.web.framework.render.RenderUtil.renderPage(RenderUtil.java:117)
   org.alfresco.web.framework.render.PresentationUtil.renderPage(PresentationUtil.java:86)
   org.alfresco.web.site.servlet.DispatcherServlet.dispatchPage(DispatcherServlet.java:512)
   org.alfresco.web.site.servlet.DispatcherServlet.dispatch(DispatcherServlet.java:389)
   org.alfresco.web.site.servlet.DispatcherServlet.service(DispatcherServlet.java:165)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   java.lang.Thread.run(Thread.java:619)
   
Exception:   org.alfresco.web.scripts.WebScriptException - 04130004 Array index out of range: 0
   
   org.alfresco.web.scripts.PresentationScriptProcessor.executeScriptImpl(PresentationScriptProcessor.java:320)
   
Exception:   org.alfresco.web.scripts.WebScriptException - 04130005 Failed to load script '/CMIS/mydocuments.get.js (in classpath store file:C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/webscripts)': 04130004 Array index out of range: 0
   
   org.alfresco.web.scripts.PresentationScriptProcessor.executeScript(PresentationScriptProcessor.java:193)
   
Server:   Alfresco Enterprise v3.2.0 (304) schema 3,400
Time:   May 13, 2010 3:51:29 PM
   
Diagnostics:   Inspect Web Script (CMIS/mydocuments.get)

Any help is appreciated.  Thanks in advance!
2 REPLIES 2

icrew
Champ in-the-making
Champ in-the-making
For what it's worth, I ran into the same trouble.  I filed a bug about it at https://issues.alfresco.com/jira/browse/ALF-8785

If anyone else has managed to get this resolved, I'd love to know–this'd be quite useful for us.

Thanks.

ryans
Champ in-the-making
Champ in-the-making
bump … curious about this too