Building A SCRUM StoryCards Generator - Part II

A short sample how to create XML using the Groovy MarkupBuilder. In Part I we squeezed raw data out of an Excel sheet containing the SCRUM story cards. The next step is transforming the raw data into an XML representation using the Groovy MarkupBuilder. At the beginning there is raw data:

List<List<Object>> rawData = new ExcelTemplate(data).getRows(HEADERS);

With a little bit of groovy

List<StoryCard> storyCards = new ArrayList<StoryCard>() data.each({
  storyCards.add(it as StoryCard) })

we transform the raw data on the fly into the following regular Java domain object StoryCard

public class StoryCard {

  private final String theme;
  private final String businessValue;
  private final int storyPoints;
  private final String description;

  public StoryCard(String theme, String businessValue, String storyPoints, String description) {
    this.theme = theme;
    this.businessValue = businessValue;
    this.storyPoints = Integer.valueOf(storyPoints);
    this.description = description;
  }
  ...
}

With this List<StoryCards> at hand we can easily convert the data into our preferred XML representation for further processing...

def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
builder.StoryCards {
  for (storyCard in storyCards) {
    builder.StoryCard {
      builder.Story {
        builder.Theme(storyCard.theme)
        builder.BusinessValue(storyCard.businessValue)
        builder.StoryPoints(storyCard.storyPoints)
        builder.Description(storyCard.description)
      }
  }
}

Now we expose the Groovy builder as OSGi service using Spring Dynamic Modules for OSGi(tm) Service Platforms. Besides the usual XML configuration for the storyCardBuilder bean:

<lang:groovy id="storyCardBuilder"
  script-source="classpath:StoryCardBuilderImpl.groovy">
</lang:groovy>

We add an additional spring XML file for OSGi environments to the bundles META-INF/spring folder (following the spring-osgi convention to avoid further configuration in MANIFEST-MF).

<osgi:service id="storyCardBuilder" interface="de.datenkollektiv.scrum.cards.StoryCardBuilder" />

The StoryCardBuilder is a POJI with no dependencies to either Groovy or Spring:

public interface StoryCardBuilder {
  String buildXml(List<List<Object>> data);
}

In the third part we will use Apache FOP and an XSL-FO style sheet to render the PDF. Don't miss Part III...

Building A SCRUM StoryCards Generator - Part I

Building A SCRUM StoryCards Generator - Part II

Building A SCRUM StoryCards Generator - Part III

Building A SCRUM StoryCards Generator - Roundup


Header cover Photo by G. Crescoli