Reporting Status (Aspire 2)

From wiki.searchtechnologies.com
Jump to: navigation, search

For Information on Aspire 3.1 Click Here

If you want to report status for your component on the Component's Admin page, you'll need to do two things:

  1. Override the getStatus() method in your component.
    • This adds data to the AspireObject data returned to the web browser for your component
  2. Add the appropriate XSLT transform code to show the status on the admin page.
    • This transforms the XML returned by getStatus() into HTML which is then displayed nicely in the web browser

So, the sequence is roughly this:

 Admin Console -> Component -> getStatus() -> (AsireObject) -> Admin Console -> Browser -> XSL Transform -> (HTML)

getStatus()

You can override the default getStatus() method in your component to display additional status on the administration page for your component.

The template for your status page should look like this:

 public AspireObject getStatus() throws AspireException
 {
   // addDerivedStatus adds a tag into which your status will be stored
   AspireObject status = addDerivedStatus("myStatus", super.getStatus());
   
   // The "status" variable is now "pushed" into the sub-element ("myStatus" in the example above).
   // This means that you can add new attributes and elements to the tag directly, for example:
   
   status.setAttribute("attA", "Attribute A");  // Adds an attribute to my status tag
   status.add("elementB", "Element B content");  // add a new element with content
   
   // Note:  You can also use status.push() to add a new parent <tag> and then start adding children into that
   
   status.popAll();
   
   return status;
 }

Testing getStatus()

In order to test your new getStatus() code, do the following:

  1. Deploy your new component.
  2. Update the component code in Aspire.
  3. Startup Aspire.
  4. Go to the Admin page for your component.
  5. Do "View Source" on your web browser.
    • (Note: Works in old version of IE and Firefox. In IE 9 you'll need to use the developer tools to see the original data transferred from the server.)

You should now see the XML status including the new tags that your getStatus() method added to your component.

It is this XML data which will be transformed into XHTML for display by the "status.xsl" transform (see below).

As an example, the getStatus() code above should return the following example XML (note the "<myStatus>" element below):

 <status application="/aspire" component="/FeedOneExample/MyComponent" server="http://localhost:50505">
  <component description="..." factoryName="aspire-my-component" implementation="com.searchtechnologies.aspire.Components.MyComponent" name="/FeedOneExample/MyComponent" subType="default">
    <config/>
    <myStatus attA="Attribute A">            <<<<<<<<<<<NEW<<<<<<<<<<<
      <elementB>Element B content</elementB>
    </myStatus>
  </component>
  
 </status>

XSL Transform

Every component has an XSL transform for displaying status, stored in:

In Eclipse:

  • src/main/resources/resources/{full component class name}/status.xsl

For example:

  • src/main/resources/resources/com.searchtechnologies.aspire.docprocessing.fetchurl.FetchURLStage/status.xsl

The headers and footers of the admin page will come from templates which are available from the Aspire Application, including things like "common.xsl", "component-manager.xsl", "utilities.js", etc.

In order to include your new status, you'll need to add XSLT commands to status.xsl to copy the data from your new XML tag (as reported by the component) into XHTML tags for presentation.

The XPath to your new status will be: /status/component/{new tag}

For example: /status/component/myStatus/@attA --> Get the contents of attribute A

A sample XSTL fragment might look like this:

<p/>
Test of getting attribute:  <xslt:value-of select="/status/component/myStatus/@attA"/>
<p/>
Test of getting element:  <xslt:value-of select="/status/component/myStatus/elementB"/>

And then, once you redeploy your component, your new status should appear on the admin page.

Example of how your code might look inside of status.xsl:

 <?xml version="1.0"?>
 <xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:import href="/aspire/files/common.xsl"/>
   <xsl:import href="/aspire/files/component-manager.xsl"/>
   <xsl:output indent="yes" method="html" />
   
   <xsl:template match="/">
    <html>
      <script src="/aspire/files/js/JSON.js" />
      <script src="/aspire/files/js/JSONError.js" />
      <script src="/aspire/files/js/utilities.js" />
      <head>
        <title>Fetch URL Stage Status - <xsl:value-of select="/status/component/@name"/></title>
      </head>
      <body>
        <xsl:call-template name="header"/>
        <table>
          <tr>
            <td>
              <img border="1">
                <xsl:attribute name="src"><xsl:value-of
                  select="concat(/status/@application,/status/@component)" />/files/images.jpeg</xsl:attribute>
              </img>
            </td>
            <td>
              <h2 style="margin-left:2em">Fetch URL Stage:  <xsl:value-of select="/status/component/@name"/></h2>
            </td>
          </tr>
        </table>
       <p/>
        
        <xsl:variable name="component" select="/status/component"/>
        <xsl:variable name="compMgr" select="/status/component/componentManager"/>
        
        <!-- HERE HERE HERE HERE -->
        <p/>
        Test of getting attribute:  <xslt:value-of select="/status/component/myStatus/@attA"/>
        <p/>
        Test of getting element:  <xslt:value-of select="/status/component/myStatus/elementB"/>
        
        <p />
        <hr width="50%" />
        <xsl:call-template name="componentDetail"/>
      </body>
    </html>
   </xsl:template>
  
  </xsl:stylesheet>