Cernunnos-Based ImportExport

Using Cernunnos for up3 Import & Export

This page examines the suggestion to use the Cernunnos project for domain-specific XML Import & Export in up3. It looks at the advantages of this approach and contains some detailed technical information and examples.

About Cernunnos

Cernunnos is an open source Java project hosted by Google Code and available under the Apache 2.0 License.

At the heart of Cernunnos is a standard, domain-agnostic contract for behavior: Task. Functionality implemented as a Task may be combined with other Task objects in arbitrary, open-ended ways through XML instrumentation.

The author of this page – Andrew Wills (Deactivated) – is the originator of Cernunnos.

Advantages

The value proposition for using Cernunnos to solve this problem basically comes down to two things:

  1. It would require pretty near the smallest possible incremental investment in custom code; and
  2. Out-of-the-box features of Cernunnos would allow up3 to leverage that investment in flexible, open-ended, and compelling ways.

Or in other words: Small Work, Big Payoff.

Small Work

Using Cernunnos, the only required Java work would be coding a set of Task implementations that stuff data into up3 domain model objects and persist them appropriately. Here's an example – taken from the Working Example attched to this page – of what that might look like for groups:

ImportGroupTask.java
public void perform(TaskRequest req, TaskResponse res) {
		
  Class y = (Class) type.evaluate(req, res);
  String cid = (String) creatorId.evaluate(req, res);
  String sn = (String) serviceName.evaluate(req, res);
  String gn = (String) groupName.evaluate(req, res);
  String desc = (String) description.evaluate(req, res);
		
  try {
    IEntityGroup group = groupService.newGroup(y, sn);
    group.setCreatorID(cid);
    group.setName(gn);
    group.setDescription(desc);
    group.update();
  } catch (Throwable t) {
    String msg = "Unable to import the specified group:" 
        + "\n\t\tTYPE=" + y.getName()
        + "\n\t\tCREATOR_ID=" + cid
        + "\n\t\tSERVICE_NAME=" + sn
        + "\n\t\tGROUP_NAME=" + gn
        + "\n\t\tDESCRIPTION=" + desc;
    throw new RuntimeException(msg, t);
  }
		
}

Big Payoff

Once these Task implementations are written, the out-of-the-box functionality of Cernunnos could handle the rest of the details: reading files, parsing XML, looping nodes, evaluating XPath expressions, etc. Cernunnos can manage these details in the manner currently envisioned – viz. reading and analyzing a domain-specific XML format from the file system. But that's just the beginning: it can also cover these needs in a whole host of supplemental, interesting, and surprising ways! And it can do all these things without modifying the simple Task implementations outlined above.

You could:

  • Import from alternate XML formats, such as standards-based schemas like IMS, etc.
  • Import from alternate data sources, like RDBMS, web services, or files bundled in archives (e.g. .zip, .jar)
  • Pull data, configuration information, or instructions directly from HTTP, FTP, etc. (Subversion anyone?)
  • Schedule imports for off-peak times
  • Send an automated email to notify administrators of the status of the import

The syntax for unlocking these possibilities is simple. Individual schools could easily make this system work in the manner that's best for them.