You are currently on IBM Systems Media’s archival website. Click here to view our new website.

IBM i > DEVELOPER > GENERAL

Exploring ATK

Using the open-source ATK framework could be a boon for i Web developers.


We’d like to do something a little different and introduce you to some new software we think will interest i professionals involved in Web development. The ATK framework is an open-source initiative that originated with the folks at ibuildings. Like most open-source initiatives, ATK is free, but ibuildings offers a full range of fee-based support services for those who need more than community support. We’ve been playing with ATK recently as part of our explorations in the PHP world. You can read about it at the ATK Framework Web page so we won't dwell on the details and history. Suffice it to say that ATK is designed to produce applications quickly, easily and with minimum coding.

 

Perhaps before we dig deeper, we should explain “framework” for readers unfamiliar with the term, at least in the formal computing sense. According to Wikipedia, it’s “a reusable design for a software system (or subsystem). A software framework may include support programs, code libraries, a scripting language, or other software to help develop and glue together the different components of a software project....”

Most practical framework implementations are based in object-oriented (OO) languages such as Java and C++. This probably explains why we don't see full-blown frameworks in the RPG world—they’d be very difficult to implement. As we've noted in the past, as a couple of “failed Java programmers,” we find PHP an appealing language for our Web applications, and PHP's OO extensions have led to the development of several PHP-based frameworks such as the popular Cake and Zend frameworks.

You have multiple approaches within the frameworks world. Some are component frameworks, basically standardized libraries you can use to help you to build an application. In our RPG-centric world, the closest we come to this is with task-specific API libraries such as CGIDEV2 and Scott Klement's HTTPAPI. But it’s a weak comparison. Others are referred to as full-stack frameworks, since they define the complete application. We really have no comparison here, unless you count cloning programs—and that really would be a stretch.

ATK is a full-stack framework, but it’s a new breed—a special-purpose business framework. In other words, it works from the assumption that most functions within a business application are similar and therefore it can build the bulk of the application for you simply by being pointed at the relevant database(s). You’re then required only to code those pieces unique to your specific application. This approach is nicely summed up by the three tenets of ATK's philosophy: minimize coding, don't repeat yourself and keep it simple. It also lends rise to ATK’s advertising slogan: “An application in 10 lines of code.”

An ATK Example

Now that we’ve introduced the basic ideas behind ATK, let's look at a brief example:

An ATK application consists of a number of modules. These aren’t modules in the compiled ILE sense, but there’s a parallel since an ATK module is represented by a source member. As part of our overall application, we need to build a module that lets us view, search and update a simple product table in our database.

Figure 1 shows the data-entry panel we’ll be building. The red asterisks by some entries indicate the columns that must be entered. Notice that in the entry panel, ATK has generated a pull-down list for the Category column, which is based on the Category table. We’ll see the mechanics of how that was done in a moment. Immediately below the data-entry panel, you can see the top section of the companion “subfile” display, which lists the rows currently in the table. Among the other standard built-in features, the subfile can be sorted on any of its columns; each row can be viewed, edited or deleted; and you’ll find a basic search capability based on the description column.

If all of that weren't enough, behind the “Extended” link under the search button is the capability to search based on any of the columns in the product table in multiple ways. Last but not least, you might also notice that we have the capability to export the entire table as a CSV file (the “Export” link in the subfile). Not a bad set of capabilities for what’s effectively only 11 lines of code! And in case you find that hard to believe, here they are:

(A) class product extends atkNode
    {
    public function __construct()
    {
(B) parent::__construct("product", NF_EXPORT);

(C) $this->add(new atkAttribute("id", AF_UNIQUE|AF_PRIMARY));

(D) $this->add(new atkManyToOneRelation("category", "jon.category", AF_OBLIGATORY));

(C) $this->add(new atkAttribute("description", AF_OBLIGATORY|AF_SEARCHABLE));
    $this->add(new atkAttribute("quantity"));
    $this->add(new atkAttribute("costPrice"));
    $this->add(new atkAttribute("sellPrice"));

(E) $this->setOrder("id");

(F) $this->setTable("product");
    }

  }

Since ATK is OO based, the syntax may look a little odd to some of you, but if you think of it as a series of procedure calls (technically they’re method calls), it becomes simple to understand. For example, the reference “$this->add(new atkAttribute(“quantity”));” simply says to add a new entry box to the form ($this) based on the database column “quantity.” Like many other OO-based functions in PHP (e.g., Web services and XML support), you don't need to fully understand the OO features to take advantage of what others have built. That said, let's take a more detailed look at the code.

(A) The class and function definitions are standard. The only thing we need to do here that’s specific to our application is to identify the name of our module (product).

(B) Once again a standard line, but in this case in addition to naming our module, we’ve also specified the attribute NF_EXPORT. That's was all it took to add the CSV export capability to the application.

(C) The series of operations here identify the individual columns in the database table we wish to use in the module. We identify the column names (e.g., “id” and “category”) and define any specific attributes that we require them to have. In the case of the “id” column, we specified that it is the table's primary key (AF_PRIMARY) and must be unique (AF_UNIQUE). You can also see how we arranged for “description” to be a searchable column (AF_SEARCHABLE) and how “category” and “description” were defined as compulsory entries (AF_OBLIGATORY).

(D) Remember we said we'd tell you how we arranged to have a pull-down list for the category entry? This is it. We simply tell ATK that there’s a many-to-one relationship between products and categories (i.e., there are many products in each category) and we then identify that the column “category” is the relevant key. We also must name the module that describes the category information. We won't show you all the details of that module here—it’s remarkably similar to this one. But we’ll show you one relevant line from that module:

$this->setDescriptorTemplate("[name]");

This line is what causes ATK to use the category “name” column and not the category code itself as the pull-down content.

(E) This next line simply specifies that the key “id” is used to provide the default sequencing for the subfile list. It could have been omitted in this case but we wanted to demonstrate that the sequence was easily controllable.

(F) Last but not least, we identify the actual database table that we’re going to be using in this module (product).

That's it! Well, OK, not quite. We must do a couple of other tiny (and we really do mean tiny) things, each of which normally takes one line of code in a configuration file. One registers the new module as part of the application and the other adds an appropriate entry to the menu bar.

Obviously, a lot more work is involved in producing a complete working application, but nevertheless it’s interesting to see just how much you can get “out of the box” with very little effort. We’d also be failing in our duty to you if we didn’t point out some of the shortcomings with ATK. While an active user community supports the product, and you’ll find some good demonstration applications, overall the documentation and instructional materials are definitely lacking. The ATK team is aware and is working hard to remedy the problem.

We certainly intend to continue to investigate ATK's capabilities in the coming months to see what else it can do for us. We're also waiting to see what develops with the ATK offshoot i7, an IBM i specific version (i.e., DB2 enabled, among other things). Good news right? Yes—but sadly the documentation is only available in Dutch at the moment. You may want to keep an eye on the Dutch i7 Web site to see what emerges.

Beyond i7, one upcoming feature of IBM i that will impact the utility of ATK in our community is the introduction of the DB2 storage engine for MySQL. Since most ATK applications use MySQL, this new storage engine offers the prospect of building ATK applications that utilize DB2 data even if i7 doesn’t make the leap to English in a meaningful timeframe.

So take a good look at ATK. It’ll be well worth your time.

 

Jon Paris is a technical editor with IBM Systems Magazine and co-owner of Partner400.

Susan Gantner is a technical editor with IBM Systems Magazine and co-owner of Partner400.



Advertisement

Advertisement

2019 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

Are You Multilingual?

Rational enables development in multiplatform environments

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
IBMi News Sign Up Today! Past News Letters