feedGenerator() from query


A bit confused on how to generate an rss feed using the built in
plugin, with data from a query... What would be best practice on this
in a cb app? Do I have to convert my query to a structure... :-\

anyone doing this?

I just started looking at this today. I don't have the answers yet,
but when I do I'd like to create a tut for it. Please let me know if
you get any details!

sound good, working hard as ever on it... Let you know whats up!

Did you read the docs?




thanks Ernst...

I couldn't find those for the life of me... I'll I found was this

thanks soo much on that documentation, it's been a huge help!! however
Im getting this error from the feedGenerator() plugin:

Error Type: java.lang.IllegalArgumentException : [N/A]
Error Messages: [Table (rows 5 columns ID, TITLE, DESCRIPTION,
CREATEDON, ispermalink): [ID: coldfusion.sql.QueryColumn@ca2d82]
[TITLE: coldfusion.sql.QueryColumn@171e893] [DESCRIPTION:
coldfusion.sql.QueryColumn@15c4c43] [CREATEDON:
coldfusion.sql.QueryColumn@92ca95] [ispermalink:
coldfusion.sql.QueryColumn@13237fd] ] is not indexable by link

I'm not sure where to track this down!?? I haven't been able to get my
query to populate items. The structure is working out fine...

any thoughts?

thanks in advance.

Just to be clear,

The docs you read are for the new plugins in development, not what is on 2.6.3, although the approaches are similar.

Hi Luis,

thank again, for everything! you rule!

but have you came across that issue? Are there in particular fields I
need in the table, I've done the mapping method to most of my fields?

Sorry man, I have not tried it out as you pointed it, been rather busy. Hopefully I can be more available next week. However, the mappings should take care of translating the query to what you need to generate. Can you post some more code and maybe some of the other guys can review it.

alright, I've added a 'link' key to my map, which has gotten me
further. I believe the link key is mandatory along with the
guid_permalink Luis added in the docs... However I'm getting an even
more intuitive (NOT) error now!!

Error Type: Expression : [N/A]
Error Messages: cannot convert the value "
http://localhost:8501/appnew/index.cfm/headlines_feed/rss This feed is
for internal blah blah blah en-us Thu, 26 Mar 2009 20:14:02 GMT Thu,
26 Mar 2009 20:14:02 GMT ColdBox Feed Generator - 1.0 2009-03-23
00:00:00.0 Mon, 23 Mar 2009 06:00:00 GMT http://localhost:8501/appnew/index.cfm/headlines_feed/rss
This feed is for internal blah blah blah en-us Thu, 26 Mar 2009
20:14:02 GMT Thu, 26 Mar 2009 20:14:02 GMT ColdBox Feed Generator -
1.0 2009-03-23 00:00:00.0 Mon, 23 Mar 2009 06:00:00 GMT
Extra Information Dump [N/A]

but here is my feeditems methods to generate items...

<cffunction name="generateItems" access="public" returntype="query"
    <cfset var returnQuery = ""/>
  <cfset var permalinkArray = arrayNew(1)/>
    <cfset var i = 1 />

  <!--- Query the headlines and save results to a variable --->
    <cfset returnQuery = instance.DataMgr.getRecords('headlines') />

      <!--- If the database query fails we create an empty query --->
      <cfcatch type="Database">
        <cfset returnQuery = QueryNew("id","VarChar")/>

  <!--- Create a new permalink cell, one for each query record --->
    <cfloop from="1" to="#returnQuery.RecordCount#" index="i">
        <cfset permalinkArray[i] = "false"/>
    <!--- Merge the permalink cells into the query --->
    <cfset QueryAddColumn(returnQuery, 'ispermalink', permalinkArray)/

    <cfreturn returnQuery/>

<!--- Map database column names to feed item elements --->
  <cffunction name="mapItems" access="public" returntype="struct"
    <cfset var returnMap = StructNew()/>

  <cfset returnMap.link = "updatedAt" />
        <cfset returnMap.description = "description"/>
  <cfset returnMap.title = "title"/>
  <cfset returnMap.pubDate= "createdOn"/>
  <cfset returnMap.guid_permalink= "ispermalink"/>
  <cfset returnMap.guid_string = "id"/>

    <cfreturn returnMap/>

Also here is my generate action in my handler...

<!--- Create Feed --->
  <cffunction name="generate" output="false" returntype="void">
     <cfargument name="event" type="any">
     <cfset var rc = event.getCollection()/>
     <!--- feed structure --->
     <cfset rc.feed = structNew()/>

     <!--- metadata --->
     <cfset rc.feed["Title"] = "My Title"/>
     <cfset rc.feed["Description"] = "This feed is for internal blah
blah blah"/>
     <cfset rc.feed["Link"] = #event.buildLink('headlines_feed/rss')# /

     <!--- Item's data --->
     <cfset rc.feed["items"] = instance.feeditems.generateItems()/>
     <!--- Process and compile the feed --->
     <cfset rc.compileFeed = getPlugin('feedGenerator').createFeed
bu_headlines_feed.xml' )/>
     <!-- view --->
     <cfset event.setView('generate_headlines_rss')/>

any progress Accelero?

thanks in advance.

alright I got it!

make sure you modify your feeditems model to incorporate the link
element. Also in my generateFeed view, change the expression to check
if the return of the generate action is valid xml rather than
boolean... like so...

<cfif isXML(rc.compileFeed)>
  <h2>Congratulations the feed was successfully updated</h2>
  <h2>There was a problem updating the feed</h2>

however, since this is more a utility function, Im probably gonna
remove the view altogether and just generate my feed whenever the db
is modified.

Not sure if this by coldbox practice or not. but works for me! thanks
again Luis (or whomever) for the docs!

That is it. As with Salomoko I could only find
http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbRSS as well so
this helped tremendously.

The vwDisplayFeed doesn't work if you have the sidebar turned on in
your config. :slight_smile:

Thank you very much!!

If you want to disable the sidebar for a specific event, you could use:
<cfset event.setProxyRequest()>

PS You should thank Luis for making the docs....

Cool - thanks for that bit.

I will be sure to send my praises Luis' way, but thank you for
pointing out that documentation.

I am running into another issue that I can't seem to get resolved with
this process.

After creating the mapping that looks like ...
<cffunction name="mapItems" access="public" returntype="struct"
    <cfset var returnMap = StructNew() />
    <cfset returnMap.guid_string = "NewsID"/>
    <cfset returnMap.guid_permaLink = "ispermalink"/>
    <cfset returnMap.category_tag = "RegionNumber" />
    <cfset returnMap.description = "Summary"/>
    <cfset returnMap.title = "Title"/>
    <cfset returnMap.link = "URL"/>
    <cfset returnMap.pubDate = "DatePublished"/>
  <cfreturn returnMap />

which dumps ...
GUID_PERMALINK ispermalink
PUBDATE DatePublished

I get ...
"Element GUID_PERMALINK is undefined in FI." from line 1094 in coldbox

Do you know of any issues that may cause this? IThe dump shows the
ispermalink is there and if I dump the query that is being mapped the
column of ispermalink are all "false".

Any help would be appreciated.