Server-Side Critique COM Component Tasks

An agent of the Event Service (which is part of Microsoft Exchange Server 5.5) contains server-side script that is triggered by folder events. In the CML/LitCrit application, this script instantiates the server-side Critique COM component and then calls its methods to perform messaging and database tasks.

Note  The Critique COM component runs on the Microsoft Exchange Server computer. This may or may not be the same computer on which SQL Server is installed.

One purpose of the Critique component is to keep the SQL Server FmLib database synchronized with the contents of the LitCrit public folder. This and other goals are accomplished by the following tasks:

Route Critique to Administrator

A person posts a critique of the IPM.Post.EnhancedLitCrit message class (see IPM.Post.EnhancedLitCrit Message Class) to the public folder, using Microsoft Outlook. The Folder_OnMessageCreated event on the public folder fires, and resulting agent script causes the server-side Critique component to write information to the FmLib SQL Server database.

This event's script first determines whether the critique exists. To do this, it reads the value of the critique number from the Critique table in the database. The first time a critique is posted to the public folder (before approval), the critique number is blank. The critique number is the primary key (generated automatically by SQL Server) in the Critique table. It is also written to a hidden field in the Outlook form when the form is updated in the public folder.

The application now needs to determine the critique submitter's borrowerNo, a number assigned to a user in the borrower table of the FmLib database when the user checks out a library item. This borrowerNo is written to the Critique table when a record of a newly submitted critique is added to the table. (It is not necessary to determine a borrowerNo if the submitter of this critique already exists in the borrower table.) To obtain a borrowerNo from the borrower table, the Critique object's BorrowerInfo method is called to invoke the GetInfoFromTable method of the Search COM component. If this attempt to retrieve a borrowerNo fails, the UpdateInfoFromExchange method of the Search COM component is called. If the borrower is not listed in the Microsoft Exchange Server directory, this call returns NULL, and the borrower can neither submit critiques nor borrow library items.

If the critique is new, script calls the Critique.AddRecord method to store the new critique's properties (including a critique number) in the Critique table.

If the critique is not new (it has a critique number), script calls the Critique.UpdateRecord method to write changed critique properties to the Critique table.

Whether or not the critique is new, agent script uses CDO to copy critique data onto a new form with the IPM.Post.ToApprover message class, and then to route it to the administrator for approval. (For more information on this process from the approver's point of view, see Approving or Rejecting a Critique.)

Handle the Approved or Rejected Critique

After the administrator responds to the critique, script copies the critique's properties onto a new form of the IPM.Post.FromApprover message class. This form is routed back to the LitCrit public folder, which triggers another Folder_OnMessageCreated event.

Just as in the Route Critique to Administrator task, this event's script first determines whether the critique exists. An approved or rejected critique is not a new critique.

Before taking further action, the script next checks whether the critique has been approved. If the critique's IsApproved bit is False (it was rejected), the event script calls the Critique.DeleteRecord method to delete the critique's record from the database. If the IsApproved bit is True, the critique remains in the folder, and the event script calls the Critique.UpdateRecord method to write data from the approved critique to the Critique table in the FmLib SQL Server database.

After the critique is posted, a trigger on the Critique table in the FmLib database reads the overall_rating given to this library title, and uses it to recalculate the average overall rating for this title, which it stores in the title table.

If the administrator clicks Approve Critique, the script notifies the borrower that the critique has been accepted. Similarly, if the administrator clicks Reject Critique, the script notifies the borrower that the critique has been rejected.

Delete a Critique

When a person deletes a critique from the public folder, the folder event Folder_OnMessageDeleted fires. This event triggers script that calls the Critique.DeleteRecord method to delete the critique's record from the FmLib database. When a critique is deleted, a trigger on the Critique table in the FmLib database deletes the overall_rating given to this library title and recalculates the average overall rating for this title, which it stores in the title table.

Update a Critique

An updated critique must be approved as if it were a new critique. For this reason, the "Update a Critique" task is identical to Route Critique to Administrator, except that the original critique is deleted. (As the changed critique is posted to the public folder, a Folder_OnMessageCreated event is triggered; which causes the critique's new values to be written to the FmLib database.)