Conditional Operation Example

Purpose

This example illustrates how to use an event handler to implement an entity operation which incorporates pattern-matching and conditional logic.

The NYU (New York University) library system, Bobcat provides a "search by author name" function which generates a recordset output. In the model this recordset is the Authors recordset on the BrowsingAuthors entity.

An author search is performed by entering the string A= followed by the author name. The author name is entered using the author's last name (surname, family name), a comma (",") character, followed by the author's first (given) name, followed by the Return key. For example:

		A=shakespeare, william
	

The Bobcat system responds by displaying a set of records. The closest match for the search term appears on a line below a record with the index value set to ">>>". Entering the index number of the following line displays the authors for that book. The entity reached by entering the index number will be either:

This operation automatically navigates to the appropriate title display entity for the author name marked in the recordset, but only if the author name searched for matches the author name in the recordset.

Implementation

This example attaches an operation event handler to the model's BrowsingAuthors.ToTitlesByAuthor operation. The event handler reads the search command from the BrowsingAuthors.Author attribute, and attempts to match that term with the record marked by the Bobcat system using a combination of pattern matching and recordset searching.

Model Design

The model used is a VT terminal model which requires a connection to the Bobcat system to exercise the event handler.

Execution using the Design Tool

The NYU library is no longer availible for public use. The model can still be viewed in offline mode in the Design Tool. The following is a walk through of the host application to aid in understanding the model.

To use the built-in author search operation,

  1. Either select the SearchAuthors operation or the BrowsingAuthors entity. This will provide a default author search (for the American writer "Mark Twain").
  2. When the BrowsingAuthors entity is displayed, perform the ToTitlesByAuthor operation, which will display the titles of books written by Mark Twain.

To search for other authors, return to the Search entity, enter an author search command, and press the Enter key. Verify that if the name you enter does not match an author in the library's catalog that the ToTitlesByAuthor event handler will throw an exception.

To observe what happens when an author has only a single work in the catalog, enter the command "a=Tynemouth, John" and execute the SearchAuthors operation. Then perform the ToTitlesByAuthor operation. Notice that it displays only a single book, rather than a list of books.

Synthetic Operation Example

Purpose

This example illustrates how to use an event handler which rewrites host application input, making it appear that the host command structure is simpler than it really is. This same technique can be used to do data scrubbing (correction of erroneous entries).

This example also uses the NYU library catalog system, Bobcat. In this case we would like to create a screen-based rejuvenation application which allows entering a search term, and then choosing how to search using a control on the web page.

Recall that the Bobcat command structure is rather different. To perform different kinds of searches, you must first enter a search command followed by a search term. We would like to allow the user to enter just a search term, and then choose the search method desired. Doing this (with the simple rejuvenation web application structure) requires erasing and re-entering data that the user has already entered.

Implementation

Two operation event handlers are provided, one to handle a request to "search by author" and the other to handle requests to "search by keyword". Each operates in the same way:

  1. Do the default model operation. This provides a default search term in the Design Tool.
  2. Delegate to another (shared) class method which does the command replacement.

The shared class method, SearchCommand.rewrite(), examines the input provided by the user and decides whether or not the input already constitutes the correct search command. (That is, if a search by author is needed, and the search term already starts with the string "A=", the command does not need rewriting.) If the command must be changed, the original input is erased and replaced with the correct search command.

Model Design

The model's Search entity has two operations which are not "hidden": SearchAuthors and SearchKeywords. Each provides a default search term in the Design Tool, and each is attached to an event handler. The destinations of the operations include the entities which might be reached as a result of performing a search.

Execution using the Design Tool

The NYU library is no longer availible for public use. The model can still be viewed in offline mode in the Design Tool. The following is a walk through of the host application to aid in understanding the model.

  1. Start the Design Tool, load the model, connect to the NYU library catalog system, and execute the login commands. This will login to the catalog system and navigate to the home entity, Search.
  2. Enter an author name of the form "last name, first name" Execute the SearchAuthors operation. Notice how the search term you enter is first erased and then rewritten with the prefix "A=".
  3. Enter a single keyword and execute the SearchKeywords operation. Notice that if you don't start the keyword term with the characters "W=" that the search term entered will be replaced with the proper search code.