Understanding The Personify API
Understanding The Personify API
Understanding The Personify API
January 2009
TMA Resources 1919 Gallows Road Suite 400 Vienna, VA 22182 www.tmaresources.com
Copyright Information
2009 TMA Resources, Inc. All rights reserved. Produced in the United States of America. All material contained in this documentation is the confidential and proprietary property of TMA Resources, Inc. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form by any means, electronic or otherwise, without the written permission of the publisher, TMA Resources, Inc. All trademarks, service marks, and trade names referenced in this material are the property of their respective owners. TIMSS and Personify are registered trademarks of TMA Resources, Inc. Microsoft, Windows, SQL Server, .NET, and Notepad are registered trademarks of Microsoft Corporation. Group 1, CODE-1, and Universal Coder are registered trademarks of Group 1 Software, Inc. Crystal Reports is a registered trademark of Business Objects SA. EXPOCAD is a registered trademark of Applied Computer Technology, Inc. NetAdvantage is a registered trademark of Infragistics, Inc. Firefox is a registered trademark of Mozilla Corporation. Payflow Pro is a registered trademark of PayPal. CyberSource is a registered trademark of CyberSource Corporation. Intel is a registered trademark of Intel Corporation. Wells Fargo is a registered trademark of Wells Fargo. Lyris ListManager is a registered trademark of Lyris Technologies, Inc. BusinessObjects and WebIntelligence are a registered trademark of Business Objects SA.
Table of Contents
Personify API Overview...................................................................................... 1
Goals for the API ........................................................................................................ 1 Library Hierarchy ........................................................................................................ 2
ii
iii
Library Hierarchy
Library Hierarchy
To support development and customization, the API library is built in layers, providing increasing levels of specialization. In practice, the library is delivered as two distinct compiled binaries: TimssAPIBase.dll The core and generated code. TimssAPI.dll The base code. Currently, code for all subsystems is included in the binaries. This scheme must be modified to support proper packaging and deployment of the final product. Customer Generated Layer Base Layer Generated Layer Core Layer
The Core, Generated, and Base layers can only be modified by TMA Resources programmers (the Professional Services team can also not modify these layers). The Customer Generated Layer can be modified by TMA Resources customers by using the Database Designer in Personify. The Database Designer contains the definitions for the tables and columns added by the end user. For more information on the Database Designer see the Personify Studio Tools User Guide.
Library Hierarchy
Application
The Application class is the primary class in the API. The Application class handles all communications with the data access layer, manages the individual API layers, and provides authentication, authorization, state management, and caching services. The class is implemented as a single instance, meaning there can only be one instance of an Application object for a given application domain (i.e., an instance of a Personify client application).
BusinessObjectCollection
The BusinsessObjectCollection class is the base class for all API Collections. A BusinessObjectCollection is analogous to a Table in a relational database. The BusinessObjectCollection class has properties and methods to manage fetching the appropriate data from the database, caching retrieved data, caching related data, reading table schema information, and inserting and deleting items from the collection.
BusinessObject
The BusinessObject class is the base class for all Item types in the API. A BusinessObject is analogous to a Row in a relational database. The BusinessObject class provides property access to the individual columns in the underlying row and standard business logic for
validating property values, generating appropriate SQL statements to update the row in the database, and navigating to related collections and items.
performs the actual authentication. It selects the appropriate data from the SEC_USER and SEC_GROUP_MEMBER tables and instantiates the PersonifyIdentity object. If authentication is successful (i.e., a record is retrieved from the SEC_USER table), the IsAuthenticated flag in the PersonifyIdentity interface is set to TRUE. The IPrincipal interface requires a read-only property, Roles(), which is a string array listing the roles in which the particular user can participate. For the PersonifyPrincipal object, the ORG_ID, ORG_UNIT_ID, and USER_GROUP columns combine from SEC_GROUP_MEMBER to create the entries in the Roles() array. For example, a user who is a member of the Admin user group in the NSSWP organizations NSSWP org unit and is a member of the CALLCENTER group in the NSSWPs FNDTN org unit, has two entries in the Roles() array: NSSWP/NSSWP/ADMIN and NSSWP/FNDTN/CALLCENTER. The Connect method sets System.Threading.Thread.CurrentPrincipal to the newly created PersonifyPrincipal object.
Authorization
User Authorization
Every call to the data access layer is authorized by the application object. Authorization is implemented in the application objects AuthCheck() method. AuthCheck looks at the current threads identity object to ensure the IsAuthenticated flag is TRUE. It then uses the OrgId and OrgUnitId properties from the current context to find an entry in the current threads Principal.Roles() collection. If an entry is found, the request is authorized. As long as the user is a member of any group for the Organization/OrgUnit they wish to access, the request will pass.
Caching
The API Core implements a variety of caching mechanisms to improve performance.
Type Cache
The Type Cache maintains a list of resolved API types (BusinessObjectCollections and BusinessObjects). It is implemented as a HashTable, keyed by the shortened API type name (the API Namespace and Class name, without the library prefix). As API types are resolved,
they are added to the Type Cache, improving the performance of the API by reducing the need to search through the various API layers to find the most derived object type. The cache exists for the life of the application and items are never automatically cleared from it, however, the cache does have a Clear() method to allow it to be reset programmatically.
Schema Cache
The Schema Cache maintains the SQL table schemas for each API collection. It is implemented as a Dataset that contains a DataTable for each referenced table. When a new collection is instantiated, it first looks for its table schema in the Schema Cache and if not found, the collection executes a SELECT * FROM table name WHERE 1=2 statement in order to receive an empty table definition from the database. It then stores these results in the Schema Cache. The cache exists for the life of the application and items are never automatically cleared from it, however, the cache does have a Clear() method to allow it to be reset programmatically. The table schema is fetched from the database at runtime, rather than simply relying on the schema information from generated code. This allows accessing customer columns on any table in the database without having to re-generate or re-compile the code.
Codes Cache
The Codes Cache stores data for classes that implement the ICode interface. These are lists containing name/value (or code/description) pairs and support enumeration and validation of code type properties. The cache is implemented as a HashTable, keyed by the individual codes GetHashKey() function. Each ICode class is responsible for implementing the appropriate GetHashkey() function that uniquely distinguishes its list from any other code list. The cache exists for the life of the application and items are never automatically cleared from it, however, the cache does have a Clear() method to allow it to be reset programmatically.
ORDER_MASTER table to hold the order master data. When the BillToCustomer is referenced, since no customer data has yet been retrieved, a select statement is executed to retrieve customer data from the database. This data is stored in the CUSTOMER table of the OrderMasters collections dataset. When the ShipToCustomer property is referenced, since the customer ID points to the same customer, no data is retrieved from the database. The ShipToCustomer object is pointed to the same underlying row as the BillToCustomer.
The AccessToken is described in the Data Access Authorization section of this document. The RequestSet object is a collection of RequestItem objects. A RequestItem object is an object that implements the IRequestItem interface. It embodies a SQL statement. The following classes implement IRequestItem:
Class BaseRequest DeleteRequest InsertRequest NextIdRequest Description Base class for request items. Executes a DELETE statement. Executes an INSERT statement. Executes the AppNextNumber stored procedure to receive an auto numbered column value. Issues a SELECT COUNT(*) statement. Issues a SELECT statement. Executes a generic SQL statement. Executes a SELECT*FROM table name WHERE 1=2 to get an empty table schema. Used to check CONCURRENCY_ID column value.
Since the data access methods accept a RequestSet object, multiple independent requests can be bundled together and sent to the data access layer as a batch. The data access layer executes each RequestItem in the RequestSet and records the results in a results dataset. For GetData() calls, the data access layer creates a table in the results dataset for each RequestItem. For SaveData() calls, the data access layer creates a table in the
results dataset called Results in which it stores the status, number or rows effected, and response message for each request. The results dataset is returned to the API core as a ResultSet object. The ResultSet object is an object that implements the IResultSet interface. The ResultSet is a wrapper from the .NET dataset and has two methods: Pack(oDataset As Dataset) and Unpack() As Dataset. The data access layer calls Pack() to store the results dataset in the ResultSet and the API Core calls Unpack() to retrieve the results dataset from the ResultSet. This wrapper provides a way to change the serialization mechanism used to pass data back to the API and to dynamically change serialization strategies depending on the details of a particular network architecture.
Instantiating a Collection
Instantiation of new collections is handled by one of the overloaded GetCollection() methods of the Application object. The GetCollection methods handle finding the most derived collection type and calling the collections constructor.
Our programmers never directly call New() on an API collection type, they use Application.GetCollection(). Calling New() means you instantiate a collection from a particular layer of the API, whereas GetCollection() ensures that an instance of the most derived type is returned. GetCollection first looks at the Type Cache to see if an object of the request type is already instantiated. If so, a new object of that type is instantiated and returned. If not, the code searches for the appropriate type to return. The code to search for an API type uses the entries in the <APILibraries> section of the app.config file. Each entry in this section specifies an assembly that contains API objects. The assemblies are searched in order until an object matching the specified criteria is found. Once found, the type is added to the type cache and returned. This mechanism allows you to have any number of layers in the API, implement partial layers in multiple assemblies, and add/remove layers by modifying the app.config file.
FillMode flag on the collection is set to OnDemand. In this case the select clause only includes the columns that participate in the primary key of the table. Refer to <<FillMode>> for more information about the OnDemand fill mode. The FROM clause: This is always From (table name) using the collections Schema.TableName property. All joins are handled in the WHERE clause. The WHERE clause: This is built by combining a variety of sources: Any filter criteria set by adding items to the collections FILTER property. Any filter criteria passed as a parameter to the fill method. If this collection is not a top-level collection (i.e., it has a ParentObject), the relationship that joins the parent to the child is added to the WHERE clause. Any values in the Application.Context dictionary that have the UseInQuery flag = TRUE and have a matching column name in the collection are added to the WHERE clause. The ORDER BY clause: if the SortProperty has been set on the collection, its column value is added as an ORDER BY clause to the select statement. 2. Check the local cache. Once the select statement has been constructed, the fill method determines if there is already data in the local dataset that matches the criteria (See Collection-Level Data Cache on page 6). If the local dataset contains rows that match the selection criteria, that data is used to fill the collection and no call is made to the data access layer.
The check for local data uses the Select() method of the DataTable class, which does not support all possible SQL predicates. Any query that contains a BETWEEN, LIKE, or IN clause is not supported by the DataTable.Select() method and cannot be cached in the current implementation. Queries containing these predicates always issue a select statement against the database, regardless of whether or not data has already been retrieved. 3. Fetch the data from the database. If there is no data in the local cache, or the selection criteria cannot be cached, a call is made to the Application.GetData() method, which constructs the AccessToken and RequestSet objects, passes the request to the DataAccess GetData() method, and unpacks the returned ResultSet into a Dataset. This data is then merged into the collections dataset. 4. Convert data rows to BusinessObjects. Once the rows have been retrieved, either from cache or from a call to the database, the Fill() method calls FillList(), which creates an appropriately typed BusinessObject for each row in the results and adds that BusinessObject to the collections underlying list. The BusinessObjects are created by calling the Application.GetAPIItem() method for
the type specified by the collections ItemType property. this ensures that the mostderived item type for that collection is the one that is created. This also means that the type of collection you are working with and the type of item it contains may by implemented in different layers of the API. For example, the Customer object may be overridden in a user layer, while the Customers collection has not been. In this case, you would have a collection of type Personify.API.Generated.CustomerInfo.Customer, but each item in the collection would be of type Personify.API.User.CustomerInfo.Customer.
The BusinessObject is a wrapper that provides strongly-typed properties and business logic for an individual data row. The actual data for the business object is maintained in the data row and is pointed to via the BusinessObjects SourceRow() property.
To implement complex default value logic, our programmers override the SetDefaults() method, call MyBase.SetDefaults(), then implement the logic. This method is automatically called when a new object is created, but may also be called programmatically from a property set routine when a property change will result in a change in default values.
10
NewKey This method ensures that the BusinessObject has a unique primary key. It takes an optional Boolean parameter (TemporaryKey), which tells the routine whether to create a temporary key or the final primary key for the object. Temporary keys are used to minimize the number of round-trips to the database when creating objects. For integer and decimal columns, the code starts with the maximum value for an integer, then continually subtracts 1 from that value until it finds a value that is not already in use in the collection. For string columns, the logic is the same, but the numeric value is padded with 9s and converted to a string. This is done to minimize the possibility of key clashes with data that is already in the database and may be added to the collection by subsequent Fill() calls. When a TemporaryKey is created the HasTemporaryKey property of the BusinessObject is set to TRUE. Final keys are set by calling the AppNextNumber() stored procedure in the database for any properties of the primary key marked as AutoNumbered. This happens automatically when saving any object where the HasTemporaryKey is set.
Formatting Rules
Capitalization Specifies that the property value should be converted to upper, lower, or proper case and whether to always perform the conversion or only when the existing value is null. String Padding Specifies a character, padding direction, and length. Used primarily from numeric columns that are really strings (i.e., OrderNumber).
Validation Rules
Minimum and Maximum Value Applied to numeric values. An exception is thrown if the specified value falls outside the specified range. Minimum and Maximum Length For string properties, if the values length is less than the minimum an exception is thrown. If it is longer than the maximum, the value is truncated. Regular Expression Matching For string properties, if the string does not match the regular expression, an exception is thrown. Date Range For date properties, specifies that a date may be in the Past, Present, and/ or Future. An exception is thrown if the specified date fails the rule.
11
Code List Validation used for ICode type properties when the Validate() flag is TRUE. If the value specified does not match a code from the ICodes list, the value is ignored.
12
13
Sorting Collections
Collection sorting is accomplished by using one of the collections overloaded Sor() methods. Sort() can be called with a property name and optional sort direction, an array of property names, or an array of PropertyInfo objects. If the collection is already filled with data, the sort method re-sorts the items in the collection using the specified criteria. the sort criteria is also included as an ORDER BY clause when the collection is filled from the database. Specifying the sort criteria before filling the collection off loads the work of sorting the collection to the database server.
14
Filters are used to determine what data to select from the database.
This creates a select statement with the appropriate WHERE clauses to join CUSTOMER to CUS_ADDRESS and CUS_ADDRESS to CUS_ADDRESS_DETAIL, as well as the specified search criteria. Executing the SearchObjects Search() method fills the SearchObjects Results() dataset with the selected rows. The SearchObjects GetObjectKey() method can then be used to choose a particular row from the results and can be used to fill a collection.
15
16
17
NOLOAD The UI does not automatically load the API model files. You must specify the model files to load using the menu option. WSROOT Identifies the root directory of the developers workspace. This should be the working directory that is mapped to the VSS root ($/) project.
18
Personify
Personify
The Personify element is the root of the API Model. Parent Nodes None Child Nodes ObjectModel User Interface Navigation only. There is no UI to directly edit this element.
ObjectModel
The ObjectModel element is the root element for all information related to generating code. Parent Nodes Personify Child Nodes DataTypes, Namespaces User Interface Navigation only. There is no UI to directly edit this element.
DataTypes
The DataTypes element contains a collection of DataType elements. Parent Nodes ObjectModel Child Nodes DataType User Interface Navigation only. There is no UI to directly edit this element.
DataType
Defines a common data type for use by properties in the API. The initial list of data types is derived from the date types defined in the SQL server. Data types do not directly produce any generated code. They are specify a reusable set of attributes and facets for value properties in the API. Parent Nodes DataTypes Child Nodes CapitalizationFacet, StringPaddingFacet, RegexValidationFacet, DateFacet User Interface:
Field Name SQL Name Name of the data type. Name of the type define in the SQL Server. Description
19
Namespaces
Field Base Type Default Value Min Length Max Length Min Value Max Value
Description API data type that is the basis for this type. Default value for the data type. For String based types, the minimum length of the string. For String base types, the maximum length of the string. For Numeric types, the minimum value of the number. For Numeric types, the maximum value of the number.
Namespaces
The Namespaces element contains a collection of Namespace elements. Parent Nodes ObjectModel Child Nodes Namespace User Interface Navigation only, there is no UI to directly edit this element.
Namespace
The Namespace element defines a Namespace in the API and corresponds directly to the Subsystems defined for Personify. Parent Nodes Namespaces Child Nodes Collection, Item, Exception, ValidationIssue User Interface:
Field Name Abbreviation License Key Name of the namespace. Subsystem abbreviation for the namespace. Holds information for enforcing licensing restrictions for API modules. Description
Collection
Defines an API Collection class. A Collection class corresponds to a table in the SQL server and inherits from Core.BusinessObjectCollection. For every Collection element, there is a matching Item element that defines the individual column properties for the table. Parent Nodes Namespace Child Nodes Properties, Methods, Events
20
Item
User Interface:
Field Name Item Type Interface Name Item Interface Table Name Access Caption Description Read Only Description The name of the API Collection class. The name of the API Item class that corresponds with this collection. The name of the API Interface for this class is always the same as the Collection class name (with the letter I prefixed). The name of the API Interface for this class is always the same as the Item Type name (with the letter I prefixed). The name of the SQL server table that this collection represents. The access modifier for the generated collection class: Public, Friend, Protected, or Private. Defaults to Public. English caption for the class. Description of the class. Specified whether items in the collection may be modified. This flag controls the _DisableAdd, _DisableEdit, and _DisableRemove flags on the base BusinessObjectCollection. Intended to indicate whether this collection may be instantiated as a standalone object, or only as the child of another object. At this time, all collection types may be standalone and this flag is not referenced. Intended to indicate that this collection is the primary collection (first-order object) of its namespace. Useful for dynamically generating user interface code, but not currently referenced anywhere. Specifies that this collection is to be included in the generated code.
Top-Level Collection
Publish
Item
Defines an Item class for the API. An item class corresponds to a Row in a SQL Server table and inherits from Core.BusinessObject. Parent Nodes Namespace Child Nodes Properties, Methods, Events
21
Properties
User Interface:
Field Name Collection Type Interface Name Collection Name Table Name Description Name of the API Item class. Name of the corresponding collection class for the item. Name of the API Interface for the item. Name of the API Interface for this items collection type. Name of the SQL Server table for which this item represents a single row.
Properties
A collection of Property elements. Parent Nodes Collection, Item Child Nodes Property User Interface Navigation only, there is no UI to directly edit this element.
Property
This represents a property on a class in the API. There are four kinds of properties that can be represented in the model: 1. Value Properties Value properties correspond directly to Columns in the SQL Server database. They represent simple data elements. Value property definitions may include one or more facets that supply additional formatting or validation rules for the property. Currently the available facets are CapitalizationFacet, StringPaddingFacet, RegexValidationFacet, and DateFacet..
Field Name API Type Access Column Name Caption SQL Type Description Default Value The name of the property. API (VB) data type of the value. Object access to the property. The SQL Server column name corresponding to the property. The generic caption name for the property. SQL Server data type for the column. A brief description, for documentation purposes, of the property. The default value for the property. Description
22
Property
Field Read-Only
Description This specifies that the property should be generated as a ReadOnly property. The API does not expose a means of setting the property. This specifies that the value may not be changed when the object is in the Inserted state. Inserted means that the item has been created and added to the collection, but the collection has not yet been committed to the database. This flag does not generate a ReadOnly property; a property set statement is still created when this value is True, but the logic in the core prevents changes to this property when in Inserted mode.
Read-Only on Insert
Read-Only on Update
This specifies that the value may not be changed after the original object has been committed to the database. This provides the ability to create Write-Once properties. This specifies that this property is required. All non-nullable columns in SQL Server are marked as Required. This specifies a unique constraint for this property within its collection. When this flag is checked, the core checks to ensure any value entered into this property does not already exist in the underlying table. This indicates that this property is part of the tables primary key and, if so, its position in the key. The first column in the tables primary key should have a value of 1. A value of 0 means that this property is not part of the key. For key properties, this specifies that the column is to be automatically numbered (using the APP_NEXT_NUMBER table). For string properties, this specifies the minimum and maximum length of the string. For numeric properties, this specifies the minimum and maximum value of the number. Displays whether the work on this API property is Completed, In Progress, or Pending.
Key Position
Auto Numbered Length: Min and Max Value: Min and Max Development Status
2. Code Properties Code properties correspond to Columns in a table, but they include information about the enumerated (lookup) values for that column. This is used for
23
Property
columns that implement the ICode interface. A code property must have a CodeInfo child node that defines the parameters for the ICode object.
Field Name API Type Access Column Name Caption SQL Type Description Default Value Code Type The name of the property. API (VB) data type of the value. Object access to the property. The SQL Server column name corresponding to the property. The generic caption name for the property. SQL Server data type for the column. A brief description, for documentation purposes, of the property. The default value for the property. This identifies the Code Class (i.e., the class that implements the ICode interface) that handles the code. The code type is the return type for this property. This specifies that the property should be generated as a ReadOnly property. The API does not expose a means of setting the property. This specifies that this property is required. All non-nullable columns in SQL Server are marked as Required. This indicates that this property is part of the tables primary key and, if so, its position in the key. The first column in the tables primary key should have a value of 1. A value of 0 means that this property is not part of the key. For key properties, this specifies that the column is to be automatically numbered (using the APP_NEXT_NUMBER table). Displays whether the work on this API property is Completed, In Progress, or Pending. Description
Read-Only
3. List Properties List properties correspond to relationships between tables in the database. For example, the CUSTOMER CUS_DEMOGRAPHIC relationship in the database is represented by the Demographics property of the Customer object in the API. A list property definition must have a Relationship child node that defines the relationship.
Field Name Access The name of the property. Object access to the property. Description
24
Property
Field Caption Description Target Namespace Target Collection Min Cardinality Max Cardinality Cascade Insert Cascade Delete
Description The generic caption name for the property. A brief description, for documentation purposes, of the property. Namespace of the API object that this property references. Class name of the collection type that this property references. The minimum number of items that this property refers to. If this is not required, enter 0. The maximum number of items that this property refers to. If there is no limit, enter 0. Indicates that a new item should be created when the parent is created. Indicates that the items referenced by the property should be deleted when the parent is deleted.
25
Property
Description Defines the relationship (i.e., the foreign-key) from this object to the target. This table has four columns: SourceProperty The name of the parent object. TargetProperty The name of the property of the child object. IsJoinKey Specifies that the Source/Target pair is part of the foreign-key relationship. Values that have IsJoinKey set are used by the Core to create the inner join clauses needed to fill collections. ValuePropagationRule Specifies the rule to use for copying property values from parent to child when inserting or updating the parent. Options are: Always Overwrites the value in the child object with the value in the parent object. IfNull Copies the value from the parent to the child only if the value is null on the child object. IfSame Copies the value from the parent to the child only when the value on the child is the same as the original value on the parent. IfNullOrSame Copies the value from the parent to the child if the value is null on the child object or if the value on the child is the same as the original value on the parent. Never Does not copy values from the parent to the child.
For properties that are part of the join key, the value propagation rule must be Always (i.e., being part of the join key means that the values must match between parent and child and any changes to the parent are reflected in the child). Other properties that are not part of the join key may be specified on the relationship. For example, the OrgId column. The OrgId column is not part of the tables key, but when set on a parent object, you want the value to be reflected on all child objects.
26
CapitalizationFacet
4. Transient Properties A transient property provides a means to reference calculated or derived information at runtime through a property statement. Transient properties are not stored in the database.
Field Name Member Name Return Type Default Value Access Caption Description ReadOnly The name of the property. The name for the private member variable that is generated to hold this propertys value. The data type of the property. The default value for the property. Object access to the property. The generic caption name for the property. A brief description, for documentation purposes, of the property. This specifies that the property should be generated as a ReadOnly property. The API does not expose a means of setting the property. Determines whether the propertys calculated information can be overridden. Description
Overridable
CapitalizationFacet
A CapitalizationFacet specifies capitalization rules for string-based, value properties. Parent Node Property Child Nodes None User Interface:
Field Capitalize Description Specifies how to capitalize the string: Preserve Take no action on the string. Upper Convert to upper case. Proper Convert to property (i.e., Name) case. Lower Convert to lower case. Specifies how the capitalization rule is applied. Always The rule is always applied. One Time The rule is only applied when the property value is changed to a different string (not just a different case of the string).
Apply Rule
27
StringPaddingFacet
StringPaddingFacet
Applies a padding character, with an optional prefix, to the string value using the max length specified on the string property. For example, if the OrderNumber property has a padding character of 0, a prefix of 1, and a direction of left, when the value 1234 is entered for an order number, the value will be converted to 1000000001234. Parent Nodes Property Child Nodes None
RegexValidationFacet
Specifies a regular expression that must be matched when setting the propertys value. If the new value does not match the expression, an exception is thrown. Parent Nodes Property Child Nodes None
DateFacet
Applies to value properties that are based on the Date data type. This facet provides runtime checking of a date value relative to the current date. For example, this could be used to require that a BirthDate property not be able to be set to a future date. Parent Nodes Property Child Nodes None
Methods
A collection of Method elements. Parent Nodes Collection, Item Child Nodes Method User Interface Navigation only, there is no UI to edit in this element.
Method
This element allows you to specify a method to generate on the class. The code generator uses the information to create an empty Sub or Function in the generated class. Actual implementation of the method must be done by overriding the method in the base layer. Parent Nodes Methods Child Nodes Parameters
28
Parameters
User Interface:
Field Name Return Type Access Overloaded Description The name of the method. The data type returned by the method. If none is specified the method is generated as a Sub rather than a Function. Code access to the method. Specifies whether or not there is overloaded parameter sets for this method.
Parameters
This element represents a set of parameters that are passed to a method or event. It is used to generate the method signature for methods and events. Parent Nodes Method, Event Child Nodes Parameter User Interface:
Field Name Type Optional Default Value Description The name of the parameter. The data type of the parameter. Indicates an optional parameter. Defines the default value for optional parameters.
29
Collection Interface
Collection Interface
This is a typical interface created for the AbstractAuthors BusinessObjectCollection:
Public Interface IAbstractAuthors Inherits Personify.API.Core.IBusinessObjectCollection Default Shadows ReadOnly Property Item(ByVal nIndex As Integer) As IAbstractAuthor Function CreateNew() As IAbstractAuthor Shadows Function AddNew() As IAbstractAuthor Shadows Function Add(ByVal Item As IAbstractAuthor) As Integer Shadows Sub Remove(ByVal Item As IAbstractAuthor) Overloads Sub Fill(By Val AbstractId As Long,_By Val MasterCustomerId As String, ByVal SubCustomerId As Integer) End Interface
Item Interface
This interface is created for the AbstractAuthor BusinessObject:
Public Interface IAbstractAuthor Inherits Personify.API.Core.IBusinessObject Property Property Property Property Property Property Property Property Property Property Property Property ReadOnly ReadOnly ReadOnly ReadOnly ReadOnly AbstractId() As Long MasterCustomerId() As String SubCustomerId() As Integer RoleCode() As Personify.API.Core.ICode RoleSinceDate() As Date ListingOrder() As Decimal Honorarium() As Decimal Comments() As String AllowToPublishFlag() As Boolean AllowToRecordFlag() As Boolean AllowToPhotographFlag() As Boolean AllowToInterviewFlag() As Boolean Property AddedBy() As String Property AddedOn() As Date Property ChangedBy() As String Property ChangedOn() As Date Property ConcurrencyId() As Long
30
Item Interface
31
32
Fill
This method fills a collection (for example, fetching data from the database table). This function is overloaded to facilitate data fetching with almost any condition (for example, fetching all orders created on July 1, 2008):
Dim mColOrderMasters as New Timss.TimssAPI.Order.OrderMasters(AppCOntext) Dim oFilter as new Timss.ApiBase.TimssFilter oFilter.Add(order_date, 07-01-2008) mColOrdermasters.fill(nothing, oFilter)
33
Programming Tasks
Programming Tasks
The following highlights the tasks that are performed by the developer for each API collection/object.
Value Properties
Each value property on an object should be reviewed to determine that it has the correct data type, has the correct default, min and max values, and that its required and autonumber flags are correctly set.
34
Programming Tasks
Code Properties
Each code property on an object should be reviewed to determine that it has been configured correctly. For codes that are read from the APP_CODE table, this means checking that the Subsystem and Type parameters on the code set to their correct values and that the Option1/2/3 parameters are referenced if they are used for that code.
List Properties
Each list property on an object should be reviewed to ensure that the cardinality is set correctly, that it is returning the correct API type, and that the join key is set up correctly. For zero-to-one or one-to-one relationships, the return type of the list property should be the interface name of the related properties item type. For zero-to-many or one-to-many relationships, the return type should be the interface name of the collection type for the related property. For example, the relationship of Customer to Demographics is one-tomany, therefore the property should return a type of Personify.API.CustomerInfo.CustomerDemographics. The relationship of Customer to Employer is one-to-one, therefore the property should return a type of Personify.API.CustomerInfo.ICustomer.
35
Programming Tasks
of the object. If multiple properties are involved, the code that calculates the member should be placed in a separate function. This function is then called from each of the properties set methods. Many methods should be callable independently of the standard interface methods. An indicator of this is whether or not the existing user interface has a button to perform the methods action. Methods such as CalculateShipping(), CalculateTax(), RecalculateOrder(), etc. are such methods. These should be marked as Public and Overridable, so that they can be called independently of the standard interface and their behavior may be overridden by a subsequent API layer.
36
Consumer
Customer
Validation Issue
37
38
Use of AutoResponses
The core Application object has an AutoResponses property containing a collection of automatic issue responses. It is the responsibility of the consumer to populate the collection of autoresponses.
39
If the issue is an Error condition, the program will most likely not be able to continue. If the issue is a Question (i.e., a prompt to the consumer), the process may continue with a default response to the issue or exit the process and re-evaluate the issue when next called.
40
Classes
Classes
AutoResponsesCollection
The AutoResponsesCollection class contains a list of automatic responses to validation issues. The collection is loaded and referenced by the API Core Application object. The collection is implemented as a hash table that is keyed by API item type/issue type. For example, an auto-response fro the product out of stock issue that is coded in the base OrderInfo namespace is keyed in the hash table as OrderInfo.OrderMaster/ OrderInfo.ProductOutOfStockIssue. It is the responsibility of the consumer to load the autoresponses collection with the appropriate responses for that collection. The API developer may check for an auto response using the HasResponse and GetResponse methods.
Example
From within the OrderInfo.OrderMasters collection, the following call determines if an auto response exists for the ProductOutOfStockIssue.
Global.App.AutoResponses.HasResponse(Me.ItemType, GetType (ProductOutOfStockIssue)
Methods
Name Add Remove HasResponse GetResponse Description Adds an auto response to the collection. Removes the response from the collection. Returns TRUE if the requested response exists in the collection. Returns the StandardResponseType value of the response. If the response does not exist in the collection StandardResponseType, NONE is returned.
IssueBase
The IssueBase class is the base class for all validation issues.
41
Classes
Properties
Name Caption Description A short descriptive caption for the issue. This is used by UI programs as a dialog title when displaying the issue. If not overridden, the caption defaults to the Severity of the issue. A string that uniquely identifies the issue within an issues collection. The issue base class requires that the key be passed on the constructor. Inherited classes may automatically generate this key as appropriate. For example, the InformationMessageIssue in the Core generates a GUID for the key and combines the class name and additional key, if applicable, to arrive at the Unique key for the issue.
Key
It is up to the API developer to determine if an issue needs an additional key. If the additional key is passes to the constructor, it is included as part of the Key. Message This is the text message displayed for the issue. Overloaded constructors on IssueBase allow this to be specified as either a string message or as a MessageId number. Both constructors also take a number of issue parameters as well, allowing this message to be used as a format string. In addition, an inherited issue class may choose to override the message property so that more complex logic may be implemented to show a more appropriate message. The reference property provides a place for the creator of the issue to store contextual information about the issue. For example, if the issue is a question about a particular product, the API developer may choose to store the product object in the reference property. This way, when the question is answered, the API developer can take action against the stored product value. The response property returns the Responses.SelectedResponses property. This supports legacy validation issue code. This is a Boolean data type indicating whether a response is required for the issue. The severity of the issue. See IssueSeverityEnum for a list of values.
Reference
Response
ResponseRequired Severity
42
Classes
Description This property indicates whether a response has been received from the consumer of the API for the issue. This returns the GUID of the parent object of the object that raised the validation issue. When identical issues exist in the same object, this property allows the user to obtain the AdditionalKey associated with the issue.
IssueEventArgs
The IssueEventArgs class is used when the IssueAdded event is raised from the IssueCollection class. These events are intended to be used by the consumer to react to the raising of validation issues.
Properties
Name Issue Description The issue that was added to the collection
IssueResponse
The Issue Response class represents a single response to the issue.
Properties
Name Description Description The text description of the response. This is the string that displays to the end user in an interactive application when the issue provides a choice of responses. The value for the description may be set using a string or message ID. Shared property that returns an empty response. The reference property provides a place where the creator of the issue can store contextual information about the response. For example, if an issue is asking the consumer to choose between a list of alternate products, the API developer may choose to store the ProductId of each choice in the Reference property. Converts the Value property, which is a string, to one of the value in StandardResponseEnum. If the Value property cannot be converted into a StandardResponseEnum, then StandardResponseEnum.None is returned.
Empty Reference
StandardResponseValue
43
Classes
Name Value
Description The sting value of the response. This value is determined by the API developer when the issue is created. The developer may use the StandardRespons values (i.e., OK, Cancel, Yes, No, etc.) or any other sting value (i.e., a product code, customer ID, etc.).
IssueResponsesCollection
The IssueResponsesCollection contains a list of IssueResponse objects. It is typically referenced via the Responses property of an Issue object.
Properties
Name Item Description Returns a single IssueResponse object from the collection using either the responses string value, the StandardResponseEnum value, or the numeric index of the item within the collection. Returns the response that was chosen by the consumer. If no choice has been made SelectedResponse returns Nothing. Returns the response marked as the default response for the issue. Returns TRUE if the consumer has responded to the issue.
Methods
Name Add Remove Contains IndexOf Description Adds a new response to the collection. Removes the response from the collection. Returns TRUE if the collection contains the specified response. Returns the integer index of the response within the collection. If the response is not found, it returns a negative number.
IssuesCollection
The IssuesCollection is a collection of validation issues. The IssuesCollection class is referenced from the within a BusinessObject or BusinessObjectCollection by referencing the ValidationIssues property of the object. There is only one IssuesCollection for each top-
44
Classes
level API collection. Each member of the top-level collection, all of its child collections, and all of their items point to the root-level ValidationIssues collection.
Properties
Name Item Description Returns an individual issue from the collection either via the issues key or the numeric index of the issue within the collection. Set to TRUE by default. When this is set to FALSE, the ValidationIssueEvent will not be raised. This can be used to make the UI ignore the event when the issue is generated by the API.
TriggerValidaitonIssueEvent
Methods
Name Assert Description Accepts a conditional expression and an issue. If the condition is TRUE the issue is added to the collection. If the condition is FALSE the issue is removed from the collection. Shortcut method that removes all issues from the collection that do not require a response. This adds a new issue to the collection. By default, when an issue is added, the Add method checks the AutoResponses collection determine if there are any auto responses for the issue. If there is, the Add method sets the selected response on the issue to the appropriate value before adding it to the collection. If the auto response value is Ignore, the Add method ignores the issue and does not add it to the collection. Removes the issue from the collection. Removes all of the issues from the collection. Returns TRUE if the specified issue is in the collection. Returns the number of issues in the collection that have a severity of ERROR. The default save method checks this value before attempting to save a collection. If the ErrorCount > 0, the save method does not attempt to save the collection. Returns the numeric index of the issue within the collection. If the issue is not found, IndexOf returns a negative number.
IndexOf
45
Classes
Events
Name IssueRaised Description This event occurs whenever a new issue is added to the collection. It is used by the consumer to react to new validation issues. This event occurs when the issues collection is cleared. It is used by the consumer to display the list of current outstanding issues.
IssuesReset
IIssue
This is the interface implemented by all validation issues. This interface is implemented by IssueBase.
Properties
Name Caption Description A short descriptive caption for the issue. This is used by UI programs as a dialog title when displaying the issue. If not overridden, the caption defaults to the Severity of the issue. A string that uniquely identifies the issue within an issues collection. The issue base class requires that the key be passed on the constructor. Inherited classes may automatically generate this key as appropriate. For example, the InformationMessageIssue in the Core generates a GUID for the key and combines the class name and additional key, if applicable, to arrive at the Unique key for the issue.
Key
It is up to the API developer to determine if an issue needs an additional key. If the additional key is passes to the constructor, it is included as part of the Key. Message This is the text message displayed for the issue. Overloaded constructors on IssueBase allow this to be specified as either a string message or as a MessageId number. Both constructors also take a number of issue parameters as well, allowing this message to be used as a format string. In addition, an inherited issue class may choose to override the message property so that more complex logic may be implemented to show a more appropriate message.
46
Classes
Name Reference
Description The reference property provides a place for the creator of the issue to store contextual information about the issue. For example, if the issue is a question about a particular product, the API developer may choose to store the product object in the reference property. This way, when the question is answered, the API developer can take action against the stored product value. The response property returns the Responses.SelectedResponses property. This supports legacy validation issue code. This is a Boolean data type indicating whether a response is required for the issue. The severity of the issue. See IssueSeverityEnum for a list of values. This property indicates whether a response has been received from the consumer of the API for the issue. This returns the GUID of the parent object of the object that raised the validation issue. When identical issues exist in the same object, this property allows the user to obtain the AdditionalKey associated with the issue.
Response
IIssuesCollection
The interface implementedd by the IssuesCollection class.
Properties
Name Item
Description Returns an individual issue from the collection either via the issues key or the numeric index of the issue within the collection. Set to TRUE by default. When this is set to FALSE, the ValidationIssueEvent will not be raised. This can be used to make the UI ignore the event when the issue is generated by the API.
TriggerValidaitonIssueEvent
47
Classes
Methods
Name Assert Description Accepts a conditional expression and an issue. If the condition is TRUE the issue is added to the collection. If the condition is FALSE the issue is removed from the collection. Shortcut method that removes all issues from the collection that do not require a response. This adds a new issue to the collection. By default, when an issue is added, the Add method checks the AutoResponses collection determine if there are any auto responses for the issue. If there is, the Add method sets the selected response on the issue to the appropriate value before adding it to the collection. If the auto response value is Ignore, the Add method ignores the issue and does not add it to the collection. Removes the issue from the collection. Removes all of the issues from the collection. Returns TRUE if the specified issue is in the collection. Returns the number of issues in the collection that have a severity of ERROR. The default save method checks this value before attempting to save a collection. If the ErrorCount > 0, the save method does not attempt to save the collection. Returns the numeric index of the issue within the collection. If the issue is not found, IndexOf returns a negative number.
IndexOf
Events
Name IssueRaised Description This event occurs whenever a new issue is added to the collection. It is used by the consumer to react to new validation issues. This event occurs when the issues collection is cleared. It is used by the consumer to display the list of current outstanding issues.
IssuesReset
48
Classes
IssueSeverityEnum
The IssueSeverityEnum identifies the severity of the issue.
Name Information Warning Description The is extra information provided to the consumer and is only used if no response is necessary. Warns the consumer about a particular action. Similar to Information, but allows the consumer to display the message differently. Used when a response from the consumer is needed. Identifies the issue as an error. Errors may or may not include responses. If a BusinessOjects issues collection contains error issues, the save method does not attempt to save the object.
Question Error
StandardIssueResponseEnum
The StandardIssueResponseEnum represents a list of standard responses to issues. An issue may or may not use the standard responses, or may use a combination of standard and custom responses. It is the responsibility of the API developer to determine the correct set of responses for a particular issue. Valid values are: Cancel Continue Ignore No None OK Retry Yes
49
Classes
PropertyMissingIssue
This issue is raised when an object requires a property value, but that value has not been set. The Reference property of the issue contains the object that is missing the property and the issue provides a property name property as well.
BusinessObjectPropertyMissingIssue
This issue is similar to the PropertyMissingIssue, except that the Reference property is strongly typed to an IBusinessObject object. The name of the missing property is stored in the issue as well. This issue is raised by the core Validate() methods when checking that all required properties on a business object are set.
InvalidPropertyValueIssue
This issue is raised when a consumer attempts to set a property to a value that is not valid for that property. This may be a violation of the minimum or maximum length of a string, the minimum or maximum value for a number, a setting outside of a specified date range, etc. The issue is raised by the various Property Setter methods in the core BusinessObject.
YesNoIssue
This is a generic issue that automatically adds the YES and NO responses to its responses collection. This issue is not used by the core, but is available for the base layer developers to inherit from.
DuplicateObjectIssue
This issue identifies that a duplicate object has been detected. It is raised by the DuplicateCheck() process in the Core.
50
Classes
This section is only a sampling of validation issues and is not intended to cover every validation issue in Personify. The following examples describe the a sampling of validation issues handled by Personify. Each validation issue is a specific class designed and coded in the API.Base.<Namespace>.<ValidationIssue Class> by the API developer to handle different business scenarios. For example, Order related validation issues are coded in OrderValidationIssues.vb within the OrderInfo namespace as shown below:
51
Classes
If you have to extend the base functionality and a new Issue of response type is required to be added for the order entry process, you can add the new class in the following namespace of your Customer Layer.
All validation issues class names should end with Issue. It is not a mandatory requirement, but helps in identifying an Issue class among other objects when using context sensitive help.
The namespace definition is not required in the code if you set up the root namespace in the project properties.
52
ProductOutofStockIssue
When is this issue thrown?
The ProductOutOfStockIssue is raised when a product is selected on an order detail line. The OrderDetail object is responsible for raising the issue. The constructor for the issue class requires only a product ID and product name. The product ID is used for the Reference property and the product name is used as a parameter for constructing the message. The class determines the unique key for the issue and contains constants defined for all of the messages that it needs. The class also contains a CanBackOrder property and an AddAlternateProduct method. These are used by the OrderDetail object to control the behavior of the ProductOutOfStockIssue.
53
response is added to the responses collection specifying the appropriate message and using the ID of the alternate product as the value for the response.
54
55
product ID and product name on the constructor. It then sets the CanBackOrder flag to true, and adds three alternate products.
56
InvalidDateRangeIssue
InvalidDateRangeIssue is an issue class that reports an invalid date range. The issue accepts an Owner object, a StartDate, and EndDate on the constructor. It uses the Owner object to create a unique key for the issue an stores the StartDate and EndDate in private variables. The class does not set a message string in the constructor, rather, it overrides the message property and returns one of three messages depending on the contents of the StartDate and EndDate properties.
57
58
SegmentWithMembersDisabledIssue
When is this issue thrown?
This validation issue is raised when the user attempts to disable a segment definition for which there are existing members.
SegmentChangeWithMembersIssue
When is this issue thrown?
This issue is thrown when the user attempts to change a Segment Definition for which there are existing members.
UpdateSubCustomerStatusToReflectMasterCustomerStatusIssue
This validation issue updates the Customer Status Code of Sub Customer when the master record is being updated.
59
MarkAddressAsBillToORShipToIssue
This validation issue alerts the user of a potential duplicate primary customer address and updates of the customers Primary Address flag depending on the users response.
CreateMultipleLinksToPrimaryAddressIssue
When is this issue thrown?
This validation issue is thrown when a user creates a new address and attempts to link that address to another customer.
60
EmailExistAsPrimaryForAnotherCustomerIssue
When is this issue thrown?
This issue is raised when a user creates a new primary email address for a customer, attempts to save the record, and the email address is already being used as the primary email address for another customer record.
PrimaryEmployerAlreadyExistsIssue
This validation issue alerts the user to the fact that the customer already has a primary employer on record and updates the primary employer flag based upon the users response.
PrimaryContactAlreadyExistsIssue
This validation issue alerts the user to the existence of a primary contact relationship for the customer and updates the primary contact flag of the customers relationship depending on the users response.
61
DuplicateCustomerMatchesFoundIssue
This validation issue alerts the user of a potential duplicate customer match based on criteria set up for the application to match a duplicate customers and contains a list of the possible duplicate customer records. The user can choose to continue with the customers creation or select one of the identified duplicates.
62