Understanding the PeopleSoft API Repository

This section provides an overview of the PeopleSoft API Repository and discusses how to access the repository.

The PeopleSoft API Repository enables PeopleCode and third-party integrators to discover the internally available classes, methods, and properties that are provided by PeopleSoft for integration. The repository is useful to third-party integrators who integrate in a generic fashion: middleware providers, testing tool providers, and automated documentation providers.

The PeopleSoft API Repository is nota necessary interface for integrators who integrate at the business-rule level, such as integration with an expense report, and so on. Those integrators should use component interfaces.

The repository describes available PeopleSoft APIs and provides mechanisms to determine the classes that are available in the API, the properties of each class, the methods of a class (along with the required parameters), and information concerning which group a class belongs to (known as a namespace).

The process of determining information about the API is known as discovery. Third-party integrators use information found through discovery to drive generic integration tools.

The repository is divided into namespaces. Each namespace contains a collection of related classes. Example namespaces include "PeopleSoft," "ComponentInterface," "Trees," and "BusinessInterlinks".

A class defines a related set of methods and properties. Using the repository, you can determine the methods and properties that are available and that can be used on any object returned by a call to the PeopleSoft API. An instance of a class is known as an object.

A property is a data item of an object that has both a name and type (string, number, Boolean, and so on are examples of types). Some properties are used for inputting data to a class, some are used for getting data from a class, and some are used for both. Whether a property is used for input or output or both is known as usage.

A method is a function that you can call on an object. Methods have a name and a return type (string, number, Boolean, and so on). Methods also have a collection of arguments that must be set prior to invoking the method. Methods arguments have identical attributes to properties.

This example gets information for the class ABS_HIST from the Namespace component interface and writes it to the file BC.TXT:

This is the complete code sample, followed by the flat file. The next section presents steps that explain each line.

Local ApiObject &MYSESSION;
Local ApiObject &MYCI;
Local string &OutTEXT;
Local File &MYFILE;
 
&MYSESSION = %Session;

&MYFILE = GetFile("CI.txt", "A");
 
&NAMESPACES = &MYSESSION.Repository.Namespaces;
&NAMESPACE = &NAMESPACES.ItemByName("CompIntfc");
 
&OutTEXT = "Namespace = " | &NAMESPACE.Name;
&MYFILE.WriteLine(&OutTEXT);
 
&CLASSES = &NAMESPACE.classes;
&CLASS = &CLASSES.ItemByName("ABS_HIST");
 
&OutTEXT = "  Class: " | &CLASS.Name;
&MYFILE.WriteLine(&OutTEXT);
 
&OutTEXT = "     Methods";
&MYFILE.WriteLine(&OutTEXT);
 
&METHODS = &CLASS.methods;
For &K = 0 To &METHODS.Count - 1
   &METHOD = &METHODS.item(&K);
   &OutTEXT = "             " | &METHOD.name | ":  " | &METHOD.Type

   &MYFILE.WriteLine(&OutTEXT);
   &ARGUMENTS = &METHOD.arguments;
   For &M = 0 To &ARGUMENTS.count - 1
      &ARGUMENT = &ARGUMENTS.item(&M);
      &OutTEXT = "           " | &ARGUMENT.name | ": " | &ARGUMENT.type;
      &MYFILE.WriteLine(&OutTEXT);
   End-For;
End-For;
 
&OutTEXT = "     Properties";
&MYFILE.WriteLine(&OutTEXT);
 
&PROPERTIES = &CLASS.properties;
For &I = 0 To &PROPERTIES.count - 1
   &PROPERTY = &PROPERTIES.item(&I);
   &OutTEXT = "              " | &PROPERTY.name | ": " | &PROPERTY.type;
   &MYFILE.WriteLine(&OutTEXT);
End-For;
&MYFILE.Close();

The previous code produces the following flat file:

Namespace = CompIntfc
  Class: ABS_HIST
     Methods
             Get:  Boolean
             Save:  Boolean
             Cancel:  Boolean
             Find:  ABS_HIST
             GetPropertyByName:  Variant
           Name: String
             SetPropertyByName:  Number
           Name: String
           Value: Variant
             GetPropertyInfoByName:  CompIntfcPropertyInfo
           Name: String
     Properties
              EMPLID: String
              LAST_NAME_SRCH: String
              NAME: String
              ABSENCE_HIST: ABS_HIST_ABSENCE_HISTCollection
              interactiveMode: Boolean
              getHistoryItems: Boolean
              componentName: String
              compIntfcName: String
              stopOnFirstError: Boolean
              propertyInfoCollection: CompIntfcPropertyInfoCollection
              createKeyInfoCollection: CompIntfcPropertyInfoCollection
              getKeyInfoCollection: CompIntfcPropertyInfoCollection
              findKeyInfoCollection: CompIntfcPropertyInfoCollection

The PeopleCode Example Explanation

This procedure goes through the PeopleCode example line by line.

To retrieve information from the API Repository:

  1. Get a session object.

    Before you can access the PeopleSoft API Repository, you have to get a session object. The session controls access to PeopleSoft, provides error tracing, enables you to set the runtime environment, and so on.

    &MYSESSION = %Session;
  2. Open the file.

    As this text will be written to a flat file, the next step is to open the file. If the file is already created, the new text is appended to the end of it. If the file hasn’t been created, the GetFile built-in function creates the file.

    &MYFILE = GetFile("CI.txt", "A");
  3. Get the namespace you want.

    Use the Namespaces property on the repository object to get a collection of available namespaces. We want to discover information about a component interface, so we specify CompIntfc in the ItemByName method to get that namespace. With ItemByName, you must specify a namespace that already exists. You’ll receive a runtime error if you specify one that doesn’t exist.

    &NAMESPACES = &MYSESSION.Repository.Namespaces;
    &NAMESPACE = &NAMESPACES.ItemByName("CompIntfc");
  4. Write the text to the file.

    Because all of the information discovered is being written to a file, the next step is to write text to the file. This code writes the string “Namespace”, followed by the name of the namespace, to the file.

    &OutTEXT = "Namespace = " | &NAMESPACE.Name;
    &MYFILE.WriteLine(&OutTEXT);
  5. Get the class that you want and write text to the file.

    Use the Classes property on the Namespace object to get a collection of all the available classes. We want to discover information about the component interface named ABS_HIST, so we specify that using ItemByName. Then we write that information to the file.

    &CLASSES = &NAMESPACE.classes;
    &CLASS = &CLASSES.ItemByName("ABS_HIST");
     
    &OutTEXT = "  Class: " | &CLASS.Name;
    &MYFILE.WriteLine(&OutTEXT);
  6. Get the methods and arguments, and write the information to the file.

    Use the Methods property on the Class object to get a collection of all the available methods. After you get each method and write the information to the file, loop through and find all of the arguments for the method, then write that information to the file.

    &OutTEXT = "     Methods";
    &MYFILE.WriteLine(&OutTEXT);
     
    &METHODS = &CLASS.methods;
    For &K = 0 To &METHODS.Count - 1
       &METHOD = &METHODS.item(&K);
       &OutTEXT = "             " | &METHOD.name | ":  " | &METHOD.Type;
       &MYFILE.WriteLine(&OutTEXT);
       &ARGUMENTS = &METHOD.arguments;
       For &M = 0 To &ARGUMENTS.count - 1
          &ARGUMENT = &ARGUMENTS.item(&M);
          &OutTEXT = "           " | &ARGUMENT.name | ": " | &ARGUMENT.type;
          &MYFILE.WriteLine(&OutTEXT);
       End-For;
    End-For;
  7. Get the properties and write the information to the file.

    Use the Properties property on the Class object to get a collection of all the available properties. Write each property, with its type, to the file. At the end of the program, close the file.

    &OutTEXT = "     Properties";
    &MYFILE.WriteLine(&OutTEXT);
     
    &PROPERTIES = &CLASS.properties;
    For &I = 0 To &PROPERTIES.count - 1
       &PROPERTY = &PROPERTIES.item(&I);
       &OutTEXT = "              " | &PROPERTY.name | ": " | &PROPERTY.type;
       &MYFILE.WriteLine(&OutTEXT);
    End-For;
    &MYFILE.Close();

This example gets information for the class ABS_HIST from the Namespace component interface.

Private Sub Command1_Click()
    '**************************************************************
    '* TacDemo: Example Repository Usage from Visual Basic
    '*
    '* Copyright (c) 1999 PeopleSoft, Inc.  All rights reserved

    '**************************************************************
    
    ' Declare variables
    Dim oSession As New PeopleSoft_PeopleSoft.Session
    Dim oPSMessages As PSMessageCollection
    Dim oPSMessage As PSMessage
    
    ' Establish a PeopleSoft Session
    nStatus = oSession.Connect(1, "//PSOFTO070698:9001", "PTDMO", "PTDMO", 0)
    
    ' Enable error-handler
    On Error GoTo ErrorHandler
    
    ' Get a Component Interface "shell"
    Dim oNamespaces As NamespaceCollection
    Dim oNamespace As Namespace
    Dim oClasses As ClassInfoCollection
    Dim oClass As ClassInfo
    Dim oMethods As MethodInfoCollection
    Dim oMethod As MethodInfo
    Dim oArguments As PropertyInfoCollection
    Dim oArgument As PropertyInfo
    Dim oProperties As PropertyInfoCollection
    Dim oProperty As PropertyInfo
        
    Set oNamespaces = oSession.Repository.namespaces
    Set oNamespace = oNamespaces.ItemByName("ComponentInterface")
        
    Dim outText As String
    
    outText = "Namespace = " & oNamespace.Name & vbNewLine
    
    Set oClasses = oNamespace.classes
    Set oClass = oClasses.ItemByName("ABS_HIST")
    
    outText = outText & "   Class: " & oClass.Name & vbNewLine
    
    outText = outText & "       Methods" & vbNewLine
 
    Set oMethods = oClass.methods
    For k = 0 To oMethods.Count - 1
        Set oMethod = oMethods.Item(k)        outText = outText & "           " 
& oMethod.Name & ":  " & oMethod.Type & vbNewLine
        Set oArguments = oMethod.arguments
        For m = 0 To oArguments.Count - 1
            Set oArgument = oArguments.Item(m)
            outText = outText & "                 " 
& oArgument.Name & ":  " & oArgument.Type & vbNewLine
        Next
    Next
    
    outText = outText & "       Properties" & vbNewLine
    
    Set oProperties = oClass.properties
    For k = 0 To oProperties.Count - 1
        Set oProperty = oProperties.Item(k)
        outText = outText & "            " & oProperty.Name & ":  " 
& oProperty.Type & vbNewLine
    Next
    
 txtResults = outText
  
' Leave before we encounter the error handler
Exit Sub
 
ErrorHandler:
    If Err.Number = 1001 Then                ' PeopleSoft Error
        Set oPSMessages = oSession.PSMessages
        If oPSMessages.Count > 0 Then
            For i = 1 To oPSMessages.Count
               Set oPSMessage = oPSMessages.Item(i)
               MsgBox (oPSMessage.Text)
            Next i
            oPSMessages.DeleteAll
        Else
            MsgBox ("PS Api Error. No additional information 
available from Session log")
        End If
    Else                                    ' VB Error
        MsgBox ("VB Error: " & Err.Description)
    End If
    
End Sub