August 15, 2016

User-Defined Property Types – ATG Repository

One of the best and flexible features provided in ATG Repository is User-Defined Property Types.

Suppose we have an item-descriptor “contact” in which we are storing firstName,lastName and title and we need to concatenate  these three values while displaying in the front end.To implement this,

  1. getPropertyValue method of RepositoryPropertyDescriptor needs  to be overridden to implement the logic.
  2. In the repository definition,the value of property-type attribute  of displayContactName property which is a transient property  is the Qualified class path of the implementation class.

<item-descriptor name="contact"  display-property="displayContactName">
        <property name="displayContactName" data-type="string"
 property-type="" queryable="false" />
        <table name="CONTACT_INFO" id-column-names="CONTACT_ID" type="primary">
            <property name="firstName" column-name="FNAME" data-type="string"  required="true"  />
            <property name="lastName" column-name="LNAME" required="true" />
            <property name="title" column-name="TITLE" required="true" />
public class ContactDisplayName extends RepositoryPropertyDescriptor {
   public Object getPropertyValue(RepositoryItemImpl pItem,Object pValue) {
   //pItem is nothing but contact repository item
   StringBuilder displayName = new StringBuilder();
   //getting the title repository value
   String title =
   //getting the firstName repository value
   String fname = (String)  
   //getting the lastName repository value
   String lname = (String)  
   displayName = displayName.append((String)  
   append (".").append( (String)  
   pItem.getPropertyValue("firstName")).append(" ").
   append((String) pItem.getPropertyValue("lastName"))
   return displayName.toString();

Lets look into another example in which we need to implement a property descriptor class for a transient property.

Suppose we have a repository property lastUpdateUserId for which the value be can be either "System" if the item is updated by the batch job or value of login property of profile if it is updated  by the end user i.e through form handler.

  1. setPropertyValue  method of GSAPropertyDescriptor has to be overridden in Property Descriptor class to implement the logic.
  2. In the repository definition,the value of property-type attribute  of lastUpdateUserId property is  the Qualified class path of the implementation class.

The main advantage is  just by looking at the Property Descriptor class we can easily determine the possible values of the property and easy maintenance of code at single place. Otherwise we would have to call this implementation explicitly wherever we are updating the lastUpdateUserId  property.

<property name="lastUpdateUserId" column-name="LAST_UPDATE_USER_ID"
data-type="string" property-type="com.common.LastUpdateUserIdPropertyDescriptor" /> 
public class LastUpdateUserIdPropertyDescriptor extends GSAPropertyDescriptor {
public void setPropertyValue(final RepositoryItemImpl Item, @SuppressWarnings("unused") final Object pValue) {
        // This profile is the associated profile object for the current thread context/ThreadLocal.
        final Profile profile = (Profile) ServletUtil.getCurrentUserProfile();
        if (profile == null) {
            propertyValue = "System";
        } else if (profile.isTransient()) {
            propertyValue = "Anonymous User - " + profile.getRepositoryId();
        } else {
            propertyValue = profile.getItemDisplayName();
        super.setPropertyValue(pItem, propertyValue);

We can define custom property types for both transient property and persistent properties(properties which are declared inside the <table> tag).To implement custom property types, getPropertyValue and setPropertyValue methods of either RepositoryPropertyDescriptor class  or GSAPropertyDescriptor class has to be overridden

  • If the property is Transient, RepositoryPropertyDescriptor  has to be extended.

  • If the property is non-transient, GSAPropertyDescriptor has to be extended.