cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing Datalists from WCMQS

simon_white
Champ in-the-making
Champ in-the-making
Hello,

I've got a bunch of information stored in Alfresco Share datalists
(out-of-the-box 'Event' type datalists as it happens) which I want
to use to populate some web page fragments managed by Web Quickstart.

I'm currently using the following method to get data out of the datalists,
which works fine but I feel like I'm missing a trick - datalists are integral
enough to the demonstration websites provided with WCQMS that it feels like there
should be a more direct method of accessing them.

Anyway, what I'm doing is this:

Datalists are just nodes within the repository so I can access them using CMIS. 
The service at /cmis/p/Sites/{siteName}/dataLists/children lists all the datalists,
and I can use a different instantiation of the same service,
/cmis/p/Sites/{siteName}/dataLists/{name}/children to get me the entries in an
individual data list.  This service only provides atom responses by default, so I
use the following ftl template to return a (incomplete but sufficent) JSON response
instead, as this is easier to work with in Javascript webscripts:


<#escape x as jsonUtils.encodeJSONString(x)>
{
  children: [
    <#list results as node>
        {
            author:         "${node.properties.creator!""}",
            id:             "${node.id}",
            name:           "${node.name}",
            created:        "${xmldate(node.properties.created)}",
            title:          "${node.properties['cm:title']!""}",
            updated:        "${xmldate(node.properties.modified)}",
            nodeDetails:    "${node}",
            eventLocation:  "${node.properties['dl:eventLocation']!""}",
            eventStartDate: "${xmldate(node.properties['dl:eventStartDate'])!""}",
            description:    "${node.properties['cm:description']!""}"
        }   
     <#if node_has_next>,</#if>
    </#list>
  ]
}
</#escape>

The last complication is that datalist names are actually system-generated UUIDs. 
The human-readable bit is the title, so we need to look up the UUID from the title in
order to reach our target datascript.

A simplified version of the server-side javascript I'm using in wcmqs, therefore, is:


function getEventListName(title) {
   var conn = remote.connect("alfresco-webscripts");
   var uri = "/cmis/p/Sites/webcontent/dataLists/children?format=json";
   var responseText=conn.get(uri).response;
   var allLists=(eval('(' + responseText + ')')).children;
   for (var i=0; i < allLists.length; i++)   {
      if (allLists[i].title==title) {
         return allLists[i].name;
      }
   }
   throw "No list with the ID: "+list+" could be found";
}

function getEventList(name) {
   var conn = remote.connect("alfresco-webscripts");
   var uri = "/cmis/p/Sites/webcontent/dataLists/"+name+"/children?format=json";
   var events=(eval('(' + conn.get(uri).response + ')')).children;
   return events;
}

model.events=getEventList(getEventListName(args.eventListTitle));

As I say, the above works fine and pushes the relevant events details into the freemarker model for
rendition, but it feels very overworked.

Is there some simple API call that I'm missing here?

Thanks in advance,

Simon
4 REPLIES 4

bremmington
Champ on-the-rise
Champ on-the-rise
I'm impressed. You've clearly done a good deal of work to get this going. There is no specific support for datalists in the WQS API, so you're right to have baked your own solution to this. Although WQS uses a datalist to store comments and contact requests, there was no need to build generic datalist support to provide that functionality, and, to be honest, it didn't actually cross my mind that that would be a useful feature. That's one of the best things about having people like you actually asking these questions - it's hard for us to build the right thing without this kind of feedback Smiley Happy

I'll see if I can make some time to add this kind of functionality in. If you have any code that you're willing/able to send over to me that you think would be appropriate to work into the product then that would be great. Unfortunately I can't promise a particular timescale, but I'll do my best.

simon_white
Champ in-the-making
Champ in-the-making
Thanks for the swift reply Brian.

To be honest, there's a conflict between the use of datalists on the one hand, and articles with custom content models on the other.

That is, if we didn't want to use datalists we could have created a subtype of ws:webasset, given it properties relevant to events, configured the forms service to use it and created events by using 'Create Content' within the document library in Share.  This is obviously the primary route for creating content in WCMQS.

I think there might be a place for datalists, though (which are significantly easier to configure), particularly for populating collections of data in a website that are "content free" (ie. contain only metadata).  Aside from events, exposing things like departmental telephone directories, meeting room bookings, course lists etc to web pages managed by WCMQS would seem to fit better into datalists than the document library.

I'll have a look at the code we've used and maybe knock-out a quick blog entry over the weekend in case there's anything you find useful.

Thanks again,

Simon

simon_white
Champ in-the-making
Champ in-the-making
I did end up blogging about this, over here –> http://ecmsimon.wordpress.com/2011/06/05/accesing-datalists-in-alfresco-web-quickstart

There's not a lot of new information, except I've replaced the rubbish children.get.json.ftl in the forum post with a more generic one

bremmington
Champ on-the-rise
Champ on-the-rise
Fantastic! Thanks very much Smiley Happy