Showing posts with label ATG-Repository. Show all posts
Showing posts with label ATG-Repository. Show all posts

Sunday, April 20, 2014

Item Caches and Query Caches : ATG Repository



Each item descriptor in a SQL repository has its own separate item cache and query cache. This lets you size and flush caches separately for separate item types. The item cache holds property values for repository items. It is indexed by the repository item IDs. The query cache holds the repository IDs of items that match particular queries in the cache.


For example, suppose you have a query like this:


color = red AND size = XXL

If query caching is enabled, the first time this query is issued, the result set is retrieved from the database and stored in the query cache. Then, the next time this same query is issued, the SQL repository can retrieve the result set from the cache, rather than needing to access the database.

The item caches hold the values of repository items. Repository queries are performed in two passes, using two separate SELECT statements. The first statement gathers the IDs of the repository items that match that query. The SQL repository then examines the result set from the first SELECT statement and finds any items that already exist in the item cache. A second SELECT statement retrieves from the database any items that are not in the item cache.

Query caching is turned off by default. If items in your repository are updated frequently, or if repeated queries are not common, you may not receive enough benefit from a query cache to justify the minor amount of overhead in maintaining the cache.


Invalidate the item caches for every item descriptor in a repository:


RepositoryImpl rep = getRepository();
  String[] descriptorNames = getItemDescriptorNames();

// iterate over all the descriptors

for (int i=0; i<descriptorNames.length; i++) {
    String name = descriptorNames[i];
    ItemDescriptorImpl d = (ItemDescriptorImpl)rep.getItemDescriptor(name);
    d.invalidateItemCache();
}


Cache Timeout:


if you set item-expire-timeout to 1000 milliseconds, the SQL repository will reload those properties after they have been in the cache for 1 second. If you set query-expire-timeout to 1000 milliseconds, the SQL repository re-executes the query after that entry has been in the query cache for 1 second.

To use the item-expire-timeout and query-expire-timeout attributes, set the value (in milliseconds) in the item-descriptor tag.


For example:


<item-descriptor name="order" cache-mode="simple"
      item-expire-timeout="180000"
      query-expire-timeout="180000">
...
</item-descriptor>
 



Wednesday, January 16, 2013

Moving Properties to a Different Database Table : ATG



This is an example of what can go wrong if you do not understand how the Dynamo Application Framework combines XML files. Suppose you extend the userProfile.xml definition file with your own file in the localconfig configuration layer. You want to use the receiveEmail property that appears in the standard user profile repository definition, but you want this property to be stored in the my_user table, rather than the dps_user table. The receiveEmail property is defined in the standard profile repository definition like this:

<!-- DPS userProfile.xml -->
  <item-descriptor name="user" ...>
    <table name="dps_user" ...>
...
      <property category="Email" name="receiveEmail" data-type="enumerated"
                default="yes" column-name="receive_email"
                display-name="Receive email">
        <attribute name="useCodeForValue" value="false"/>
        <option value="yes" code="1"/>
        <option value="no" code="0"/>
      </property>...
    </table>
  </item-descriptor>


To replace this property with a similar property that is stored in the my_user table rather than the dps_user table, you might try to define this property in a /atg/userprofiling/userProfile.xml file in your application module or your localconfig directory, using the xml-combine="replace" directive, like this:

Bad Example 1:


<!-- my userProfile.xml -->
  <item-descriptor name="user" ...>
    <table name="my_user" ...>
      <property category="Email" name="receiveEmail" data-type="enumerated"
                default="yes" column-name="receive_email"
                display-name="Receive email" xml-combine="replace">
        <attribute name="useCodeForValue" value="false"/>
        <option value="yes" code="1"/>
        <option value="no" code="0"/>
      </property>
    </table>
  </item-descriptor>

This approach won’t work. In the Personalization module’s userProfile.xml, the receiveEmail property is defined under the dps_user table. But in the second userProfile.xml file, that property is defined under the my_user table. XML combination operates recursively starting from the outermost tags and working inwards. In this case, the <table> tags are matched by name. Since the table names dps_user and my_user don’t match, these two <table> tags are not combined. And since the <table> tags don’t match, the tags inside the <table> tags will not match up against each other. When the two userProfile.xml files are combined, you end up with two properties in the user item descriptor, each with the same property name: receiveEmail. So you end up with:


Bad Example 2:



<item-descriptor name="user" ...>
  <table name="dps_user" ...>
    <property name="receiveEmail" ... />
  </table>
  <table name="my_user" ...>
    <property name="receiveEmail" ... />
  </table>
</item-descriptor>

Since the resulting user item descriptor has two properties named receiveEmail, errors result.

To fix this is easy. Use the xml-combine="remove" directive in the dps_user table, rather than the xml-combine="replace" directive in the my_user table, as in this example:

Perfect Example:


<item-descriptor name="user" ...>
  <table name="dps_user" ...>
    <property name="receiveEmail" xml-combine="remove" />
  </table>
  <table name="my_user" ...>
    <property category="Email" name="receiveEmail" data-type="enumerated"
              default="yes" column-name="receive_email"
              display-name="Receive email" xml-combine="replace">
       <attribute name="useCodeForValue" value="false"/>
       <option value="yes" code="1"/>
       <option value="no" code="0"/>
    </property>
  </table>
</item-descriptor>


The xml-combine="remove" directive ensures that the old receiveEmail property is eliminated from the profile repository definition.

Tuesday, September 4, 2012

Functions of startSQLRepository: ATG


startSQLRepository Functions:


startSQLRepository, reads a repository definition from an XML file or DOM and


1. Verifies your XML is correctly formed and compliant with the DTD.

2. Parses and processes optional operation tags like <add-item>, <remove-item>, and <query-  
    items>. These tags provide a means for adding, removing, updating items in your SQL  \
    repository.

3. Generates SQL statements required to create appropriate table structure in database when you
    use the –outputSQL flag.

4. Returns results of <query-items> and <print-item> requests in the form of <add-item> tags.
    This allows you to easily copy and paste the results into another XML template, so you can add
    the items to another repository.

5. Imports and exports items and item descriptors


Using the startSQLRepository Script


Use one of the startSQLRepository scripts included in the <ATGdir>/home/bin directory:

If your template contains <table> tags, you must also make sure that:


1. the database accessed by your repository is running

2. the database contains the appropriate tables

3. you have appropriate database access authorization to perform any import or create database
    operations

you need to make sure that repository IDs in the source repository do not collide with repository IDs in the target repository. Make sure that both the source database and target database already contain IdSpaces. The IdSpaces in the source database and target database must have the same names. Furthermore, the name of the IdSpaces used by each item descriptor should be the same in the source repository for the export and the target repository for the import. If you do this, then the import operation reserves all the IDs it encounters for repository items it creates in the target database.

ID Generators should be happen and it will create idspaces.xml,


The startSQLRepository scripts use the following syntax:


startSQLRepository <arguments> [file name.xml]


For example, to load an XML template whose CONFIGPATH name is /atg/test.xml in a repository with a Nucleus address of /atg/userprofiling/ProfileAdapterRepository:

startSQLRepository -m DPS
   –repository /atg/userprofiling/ProfileAdapterRepository /atg/test.xml

Note that the repository template file name you provide is a reference to a CONFIGPATH location, and not a pathname in your file system. For example, you can put a file in your localconfig directory and refer to it as /<your-file>. You can also use a file with the same name as your repository’s existing definition file and then omit the file name argument from the startSQLRepository command. The startSQLRepository script uses XML file combination to combine all files with the same name into a single repository definition

if you include the following file at <ATGdir>/home/localconfig/atg/userprofiling/userProfile.xml and run the startSQLRepository script, it will print all profiles in your Profile Repository:

<gsa-template>
  <print-item item-descriptor="user"/>
</gsa-template>

You can use the startSQLRepository script together with the test operation tags described earlier in this chapter to quickly test a query, or add, update, remove, or print an item.

Exporting & Importing Data from SOLID : ATG


Exporting the CustomProject Data from SOLID:


Make sure that either there are no connection pool properties files, or that they are pointing to the CustomProject SOLID database. Start the SOLID database and use the commands below (on one line, with no line breaks) to export the demo data to an XML file called all.xml.

Command:


1. bin/startSQLRepository -m CustomProject -exportRepositories all all.xml

2. bin/startSQLRepository -m SampleProject -exportRepositories all all.xml


Importing the CustomProject Data to Your Database:


Your connection pool properties file must be pointing to the new target database. All Dynamo supported databases can import all.xml.

Oracle users: Before importing the CustomProject data, set the useSetCharacterStream property of all SQL repository components to true so that non-8859 characters are displayed correctly. You can set this property in your localconfig/GLOBAL.properties file: useSetCharacterStream=true

From the command line, go to the <ATGdir>/home directory. Use the commands below (on one line, with no line breaks) to import the data contained in all.xml to your target database. Your connection pool properties file must be pointing to the new target database.

Command:


1. bin/startSQLRepository -m CustomProject -import all.xml

2. bin/startSQLRepository -m  SampleProject -import all.xml


You can add your own project instead of CustomProject.

Friday, June 8, 2012

Parameterized Query Example : ATG

The following is an example of how you might use a parameterized query. Note that error handling is not dealt with in these examples.

Suppose you wanted to create a Query like this:

firstName  = 'Jerry'

Then, you want to change that to

firstName = 'Phil'

Query Example without Parameters


The first example shows how you would need to do this without the use of parameters:

// Get the repository through our made up getRepository( ) call
Repository rep = getRepository();
RepositoryItemDescriptor desc = rep.getItemDescriptor("user");
RepositoryView view = desc.getRepositoryView();
QueryBuilder qb = view.getQueryBuilder();

// Build our first Query
// firstName = 'Jerry'
QueryExpression firstNameProp = qb.createPropertyQueryExpression("firstName");
QueryExpression jerryValue = qb.createConstantQueryExpression
(new String("Jerry"));
Query firstNameQuery = qb.createComparisonQuery(firstNameProp, jerryValue,
 QueryBuilder.EQUALS);

// Execute our first Query
RepositoryItem[] jerryItems = view.executeQuery(firstNameQuery);

// Set up our second Query now
QueryExpression philValue = qb.createConstantQueryExpression(new String("Phil"));
firstNameQuery = qb.createComparisonQuery(firstNameProp, philValue,
QueryBuilder.EQUALS);

// Execute our second Query
RepositoryItem[] philItems = view.executeQuery(firstNameQuery);



Query Example with Parameters


With the use of parameters in your queries, you can create a reusable Query as in the example that follows. Note that the view used is a ParameterSupportView instead of a RepositoryView:

// Get the repository through our made up getRepository( ) call
Repository rep = getRepository();
RepositoryItemDescriptor desc = rep.getItemDescriptor("user");
// Our RepositoryView is a ParameterSupportView this time, so we know it supports
// parameters in Queries
// Note – this assumes we have advanced knowledge that this view is an instance of
// a ParameterSupportView
ParameterSupportView view = (ParameterSupportView)desc.getRepositoryView();
QueryBuilder qb = view.getQueryBuilder();

// Builder our first Query up
// firstName = 'Jerry'
QueryExpression firstNameProp = qb.createPropertyQueryExpression("firstName");
QueryExpression parameterValue = qb.createParameterQueryExpression();
Query firstNameQuery = qb.createComparisonQuery
                       (firstNameProp, parameterValue, QueryBuilder.EQUALS);

// Execute our first Query
Object[] args = new Object[1];
args[0] = new String("Jerry");
RepositoryItem[] jerryItems = view.executeQuery(firstNameQuery, args);

// Set up our second Query now
args[0] = new String("Phil");
RepositoryItem[] philItems = view.executeQuery(firstNameQuery, args);


In the first example, we have to create a new constant QueryExpression if we want to change the name from Jerry to Phil. This means we must also create a new instance of a comparison Query to use the new QueryExpression. In the second example, we can increase efficiency by creating just one Query object, and changing the value of the name we want in an Object array that is passed to the executeQuery method. This also allows you to cache a Query in your internal application (above the query cache layer), and pass in varying parameter values at execution time.

Repository Query Examples

The examples in this section demonstrate how to perform some simple repository queries. In the Repository API, all queries are performed using Query or QueryExpression objects. A QueryExpression is a building block you can use to create simple or complex queries. A Query is a repository query that can be executed. A Query can also be used as a building block to create queries that are more complicated.

The following example supposes we have an item descriptor named user with an integer property named userType. This is how we might perform a simple query to find users whose userType property is 2.


import atg.repository.*;

MutableRepository pRepository =
  (MutableRepository)ServletUtil.getCurrentRequest().resolveName
  ("/atg/userprofiling/ProfileAdapterRepository");

    // Queries are created using QueryBuilders and executed by
    // RepositoryViews. A Query is defined in the context of a
    // specific item descriptor and thus must be built and executed with
    // the right QueryBuilder and RepositoryView.

    RepositoryItemDescriptor userDesc = pRepository.getItemDescriptor("user");
    RepositoryView userView = userDesc.getRepositoryView();
    QueryBuilder userBuilder = userView.getQueryBuilder();

    // create a QueryExpression that represents the property userType
    QueryExpression userType =
      userBuilder.createPropertyQueryExpression("userType");

    // create a QueryExpression that represents the constant 2
    QueryExpression two =
      userBuilder.createConstantQueryExpression(new Integer(2));

    // now we build our query: userType = 2
    Query userTypeIsTwo =
      userBuilder.createComparisonQuery(userType, two, QueryBuilder.EQUALS);

    // finally, execute the query and get the results
    RepositoryItem[] answer = userView.executeQuery(userTypeIsTwo);

    System.out.println("running query: userType = 2");
    if (answer == null)
      {
        System.out.println("no items were found");
      }
    else
      {
        for (int i=0; i<answer.length; i++)
          System.out.println("id: " + answer[i].getRepositoryId());
      }



Let’s expand the preceding example with a slightly more complicated query. The next code fragment builds on the preceding fragment to create the query userType < 2 AND login STARTS WITH "j":



import atg.repository.*;

MutableRepository pRepository =
  (MutableRepository)ServletUtil.getCurrentRequest().resolveName
  ("/atg/userprofiling/ProfileAdapterRepository");

    // reuse the building blocks we have to create
    // the "userType < 2" query
    Query userTypeLTTwo =
      userBuilder.createComparisonQuery(userType, two, QueryBuilder.LESS_THAN);

    // create the "login STARTS WITH j" query
    QueryExpression login =
      userBuilder.createPropertyQueryExpression("login");

    QueryExpression j =
      userBuilder.createConstantQueryExpression("j");

    //Note that we could make this query case-insensitive by adding another
    //parameter to the createPatternMatchQuery, with a value of true
    Query startsWithJ =
      userBuilder.createPatternMatchQuery(login, j, QueryBuilder.STARTS_WITH);


    // now AND the two pieces together. You can AND together as many
    // Query pieces as you like: we only have two in our example
    Query[] pieces = { userTypeLTTwo, startsWithJ };
    Query andQuery = userBuilder.createAndQuery(pieces);

    // execute the query and get the results
    answer = userView.executeQuery(andQuery);

    System.out.println("running query: userType < 2 AND login STARTS WITH j");
    if (answer == null)
      {
        System.out.println("no items were found");
      }
    else
      {
       for (int i=0; i<answer.length; i++)
          {
           RepositoryItem item = answer[i];
           String id = item.getRepositoryId();
           String l = (String)item.getPropertyValue("login");
           Integer a = (Integer)item.getPropertyValue("userType");
           System.out.println("item: " + id + ", login=" + l + ", userType=" + a);
          }
      }

   }

Sunday, March 25, 2012

ATG Cache Flushing


You can flush (invalidate) the caches for an item descriptor or an entire SQL repository, using the following methods. Note that first, you must cast your atg.repository.RepositoryItemDescriptor to an atg.repository.ItemDescriptorImpl. If you are using distributed cache mode, use the Cache Invalidator, as described in the Cache Invalidation Service section below.

The methods in atg.repository.ItemDescriptorImpl are:

These methods also have versions that accept a boolean parameter that indicates whether the cache should be changed globally, or just for the local cache. These methods are:

removeItemFromCache(id, boolean pGlobal)
invalidateCaches(boolean pGlobal)
invalidateItemCache(boolean pGlobal)

If this global parameter is true, the invalidation occurs across the cluster. Otherwise, the invalidation occurs only in the local ATG instance.


The removeItemFromCache method, when given a true value, will use one of two mechanisms to distribute the invalidation event:

1.If the item descriptor uses distributed cache mode, it uses the event server to send the invalidation event.

2.Otherwise, it uses the GSAInvalidatorService to send the event.

The invalidateCaches and invalidateItemCache methods, when given true for the global parameter, will always use the GSAInvalidatorService. If this service is not enabled, a warning is logged and the cache is only invalidated locally.

This method in atg.repository.RepositoryImpl affects all caches in the repository:


invalidateCaches()
Invalidates all caches in this repository.



You can cast your repository to these classes and call these methods from there. You can both flush items of a specific kind, items and queries of a specific kind or a specific item with these methods.

For example, here is how you might use the invalidateItemCache() method to invalidate the item caches for every item descriptor in a repository:

RepositoryImpl rep = getRepository();
  String[] descriptorNames = getItemDescriptorNames();
// iterate over all the descriptors
for (int i=0; i<descriptorNames.length; i++) {
    String name = descriptorNames[i];
    ItemDescriptorImpl d = (ItemDescriptorImpl)rep.getItemDescriptor(name);
    d.invalidateItemCache();
}

Wednesday, March 7, 2012

Composite Repositories : ATG


All ATG repositories provide a means for representing information in a data store as Java objects. The composite repository lets you use more than one data store as the source for a single repository. The composite repository consolidates all data sources in a single data model, making the data model flexible enough to support the addition of new data sources. Additionally, the composite repository allows all properties in each composite repository item to be queryable. Thus, from the point of view of your ATG application, the composite repository presents a consistent view of your data, regardless of which underlying data store the data may reside in.

The composite repository is a repository that unifies multiple data sources. Its purpose is to make any number of repositories appear in an ATG application as a single repository. The composite repository defines a mapping between item descriptors and properties as they appear to facilities that use the composite repository and item descriptors and properties of the data models that comprise the composite data model. A composite repository is composed of any number of composite item descriptors. Each item descriptor can draw on different data models from different repositories, and map underlying data model attributes in different ways.


Use Example

Suppose you maintain profile data both in an SQL database and an LDAP directory. ATG’s profile repository ships with a user composite item descriptor comprised of just one primary item descriptor and no contributing item descriptors. The primary item descriptor is the user item descriptor. You can add to the composite item descriptor the user item descriptor from the LDAP repository as a contributing item descriptor. If there are any property name collisions between the SQL repository and the LDAP repository, you can resolve them by mapping the properties explicitly to different names in the composite repository configuration. After you’ve done this, your ATG applications can view both LDAP profile information and SQL database profile information as properties of composite items in the composite user item descriptor.

Primary and Contributing Item Descriptors

Each composite item descriptor is composed of any number of contributing item descriptors. One of these contributing item descriptors must be designated as the primary item descriptor. The primary item descriptor’s main purpose is to provide the ID space for the composite item descriptor. The composite item descriptor can incorporate any number of contributing item descriptors, which contribute properties to the composite repository items.

Each contributing item has one or more relationships to the primary item. These relationships are defined in the contributing item descriptor. Each relationship defines a unique ID attribute in the primary item descriptor, as well as a unique ID attribute in the contributing item descriptor. The attribute can be the repository item ID or a unique property. A contributing item is linked to a primary item if the value of its unique ID attribute matches the value of the primary item’s unique ID attribute. If multiple relationships are defined, they are AND’d together.

For example, suppose you have a contributing item descriptor that defines two relationships to the primary item descriptor. One says that a primary item’s firstName property must match the contributing item’s userFirstName property and the other says that the primary item’s lastName property must match the contributing item’s userLastName. These two relationships together mean that a user’s first names and last names must each match for two items to be related. This is useful in situations where no one property uniquely identifies a user. See link-via-property for an example of defining a relationship with two or more properties.

Item Inheritance and Composite Repositories

A composite repository can handle item descriptor inheritance only for its primary item descriptors. For example, suppose you have a user composite item descriptor. Its primary item descriptor is named person and is part of an LDAP repository. The contributing item descriptor is named user and is part of an SQL repository. The user item descriptor has a subtype named broker. The composite items have access to the properties of the person item descriptor and the user item descriptor, but not to properties that exist only in the broker item descriptor.

Transient Properties and Composite Repositories

An LDAP repository does not support transient properties. Therefore, if you want to use transient properties in your composite item descriptor, the transient properties must be derived from an SQL repository or other repository that does support transient properties.

Non-Serializable Items and Composite Repositories

An LDAP repository item is not serializable. Therefore, if you have a property that derives from an LDAP repository item, you should mark the property as not serializable by setting the serialize attribute to false:

<property name="propName" >
   ...
    <attribute name="serialize" value="false"/>
   ...
</property>

Property Derivation

The properties in a composite item descriptor are determined as follows:

1.If configured to do so, all properties from the primary and contributing item descriptors are combined into the composite item descriptor, with each property retaining its property name and property type.

2.Any properties marked as excluded are removed from the composite item descriptor. See Excluding Properties.

3.All property mappings are performed. This means that a primary or contributing property that is to be mapped gets renamed in the composite item descriptor. See Property Mappings.

4.If there are any two properties in the composite item descriptor that have the same name, an error results. The composite repository requires that all composite property names map explicitly to only one primary or contributing property.

Configuring a Composite Repository

1.Design the composite repository. Pick what item types you want to represent in your composite repository’s composite item descriptors

2,Specify the primary item descriptor. This is where the composite repository item’s repository item IDs come from

3.Specify any contributing item descriptors you need to supplement the primary item descriptor.

4.Resolve any property name collisions between properties in the primary item descriptor and the contributing item descriptors. See Property Mappings.

5.Determine whether you want to use static or dynamic linking for properties whose types are repository items. See Link Methods.

6.Determine what item creation policy you want the composite repository to implement. See Creating Composite and Contributing Items.

7.Determine whether there are any properties in your primary or contributing item descriptors that you want to exclude from the composite item descriptor. See Excluding Properties.

8.Create and configure a CompositeRepository component. See Configuring the Composite Repository Component.

Property Mappings

The composite repository requires that all composite property names map explicitly to only one primary or contributing property. If primary or contributing item descriptors contain one or more properties with the same name, you must exclude one of the properties (see Excluding Properties) or map it to another name.

You can map a property with the mapped-property-name attribute in an item descriptor’s property tag. For example, given two contributing item descriptors, where each has a login property, you can map one of the properties to a different name like this:

<property name="ldapLogin" ... mapped-property-name="login"/>

In this example, the name attribute specifies the property name in the composite item descriptor and the mapped-property-name attribute specifies the name of the property in the primary or contributing item descriptor to which this property maps.

Excluding Properties

Sometimes you may not want to expose absolutely every property from the underlying primary and contributing item descriptors in the composite item descriptor. You can configure the item descriptor to exclude those contributing properties that are not desired. You do this by setting a property tag’s exclude attribute to true:

<property name="password ... exclude="true"/>

Link Methods

The link-method attribute determines what happens when the composite repository needs to get a property value that belongs to a contributing repository item. For example, a process might call:

CompositeItem.getPropertyValue("ldapFirstName");

where ldapFirstName is a property of a contributing repository item in an LDAP repository. The CompositeItem that is being asked for the property needs to look for this contributing item. If it can find it, it retrieves the property value and acts according to the value of the link-method attribute: static or dynamic.

Static link method

If link-method is set to static, the contributing item is stored in a member variable of that composite repository item. The next time a property is requested from that same item, it retrieves it from this variable instead of finding it again from the underlying contributing repository. This saves some computational effort and results in faster property retrieval.

If the value of the property or properties used to link to the underlying contributing item changes, the data in the member variable is stale. This occurs only if a linking property in the underlying data store changes. For example, if you link to a contributing item descriptor using a login property, static linking can result in stale data only if the login property changes in an underlying repository.

Dynamic link method

If link-method attribute is set to dynamic, the composite repository queries the underlying repository for the contributing item every time a property is requested from it. This might result in slower performance, but it also means that data is never out of sync at the repository level.

Methods compared

Dynamic link mode might seem like the most technically correct implementation, because the data model is guaranteed to reflect the latest information. Because dynamic link mode requires a query each time information is needed from a composite item, it can impair performance. Usually, the information that links items rarely changes. Static linking is generally provides correct data model linking.



composite-repository-template

The composite-repository-template tag encloses the whole composite repository definition. The composite-repository-template tag encloses a <header> tag and one or more <item-descriptor> tags:

header (Composite Repository)

item-descriptor (Composite Repository)

Example

<composite-repository-template>
  <header>
...
  </header>
  <item-descriptor name="..." />
...
  </item-descriptor>
</composite-repository-template>

header (Composite Repository)

The <header> tag provides information that can help you manage the creation and modification of repository definition files.

For example, the header of your template might look like this:

<header>
  <name>Catalog Template</name>
  <author>Neal Stephenson</author>
  <author>Emily Dickinson</author>
  <version>$Id: catalog.xml,v 1.10 2000/12/24 03:34:26 hm Exp $</version>
  <description>Template for the store catalog</description>
</header>


item-descriptor (Composite Repository)

The item-descriptor tag defines a composite item descriptor.


<item-descriptor name="compositeUser" default="true"
         display-property="fooProperty"
         display-name-resource="itemDescriptorUser">
   <attribute name="resourceBundle"
              value="atg.userprofiling.CompositeProfileTemplateResources"
              data-type="string"/>
   <primary-item-descriptor.../>
   <contributing-item-descriptor.../>
...
</item-descriptor>

1.A primary-item-descriptor tag can enclose one or more property tags.
2.The contributing-item-descriptor has the same attributes as the primary-item-descriptor tag. See primary-item-descriptor and contributing-item-descriptor attributes.



Sample Composite Repository Definition File

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE scenario-manager-configuration
     PUBLIC "-//Art Technology Group, Inc.//DTD Scenario Manager//EN"
     'http://www.atg.com/dtds/composite-repository/composite-repository_1.0.dtd'>


<!-- composite repository definition -->
<composite-repository-template>


  <!-- Header similar to GSA DTD -->
  <header>
    <!-- name of this document -->
    <name>A sample Composite Repository template</name>
    <!-- author of this document -->
    <author>Graham Mather</author>
    <!-- version of this document -->
    <version>$Change: 226591 $$DateTime: 2002/01/22 15:50:56 $$Author: gm $
    </version>
  </header>

  <!-- composite item descriptor definition -->
  <!-- name: name of the composite item descriptor -->
  <!-- default: is this the composite repository's default item descriptor? -->
  <!-- display-property: the property used when display items of this type -->
  <!-- display-name-resource: resource which defines the display name -->
  <item-descriptor name="compositeUser" default="true"
    display-property="fooProperty"
    display-name-resource="itemDescriptorUser">


    <!-- resource bundle from whence this item descriptor's resources come -->
    <attribute name="resourceBundle"
               value="atg.userprofiling.CompositeProfileTemplateResources"
               data-type="string"/>
    <!-- icon for items of this type -->
    <attribute name="icon" value="userIcon" data-type="string"/>
    <!-- "basics" category sort priority -->
    <attribute name="categoryBasicsPriority" value="10" data-type="int"/>


    <!-- primary view definition -->
      <!-- name: the name of the primary view, as it appears internally to the
      composite repository.  The primary view and all composite views must have
      unique internal view names -->
      <!-- repository-nucleus-name: the nucleus path of the repository in which
      the primary view resides -->
      <!-- repository-item-descriptor-name: the name of the view in the given
      repository which acts as the primary item descriptor for this composite item
      descriptor -->
      <!-- all-properties-propagate: if true, composite repository attempts to
      make all properties in the primary item descriptor available in the
      composite item descriptor.  Default is false  -->
      <!-- all-properties-queryable: if true, all properties in the view are
      queryable unless otherwise specified.  If false, all properties are not
      queryable unless otherwise specified. default is true -->
    <primary-item-descriptor name="user"
      repository-nucleus-name="/atg/userprofiling/ProfileAdapterRepository"
      repository-item-descriptor-name="user"
      all-properties-propagate="true"
      all-properties-queryable="true">


      <!--
      Can also contain explicit property mappings and explicit property exclusions
      -->


      <property mapped-property-name="lastName" exclude="true"/>
      <property mapped-property-name="email" exclude="true"/>


    </primary-item-descriptor>


    <!-- contributing view definition -->
    <!-- name: the name of this contributing view, as it appears to the composite
    repository -->
    <!-- repository-nucleus-name: the nucleus path of the repository in which the
    primary view resides -->
    <!-- repository-item-descriptor-name: the name of the view in the given
    repository which acts as the primary item descriptor for this composite item
    descriptor -->
    <!-- all-properties-propagate: if true, composite repository attempts to make
    all properties in the primary item descriptor available in the composite item
    descriptor.  Default is false  -->
    <!-- all-properties-queryable: if true, all properties in the view are
    queryable unless otherwise specified.  If false, all properties are not
    queryable unless otherwise specified. default is true -->


    <contributing-item-descriptor name="UserProfile-LDAP"
      repository-nucleus-name="/atg/adapter/ldap/LDAPRepository"
      repository-item-descriptor-name="user"
      all-properties-propagate="true"
      all-properties-queryable="true">




    <!-- explicit property mapping
    sometimes it's advantageous to explicitly map a property in a composite view
    to a particular property in either the primary or a contributing view.
    For example, perhaps two contributing views have properties with the same
    name. This gets around the "no contributing views with same property names"
    rule.
    -->


    <!-- name: name of this composite property -->
    <!-- mappedPropertyName: the property to which this property maps -->
    <!-- queryable: property queryable flag -->
    <!-- required:  property required flag-->
    <!-- expert: property expert flag -->
    <!-- hidden: property hidden flag -->
    <!-- readable: property readable flag -->
    <!-- writable: property writable flag -->
    <!-- category-resource: resource for category name -->
    <!-- display-name-resource: resource for display name -->
    <property name="ldapFirstName" mapped-property-name="firstName"
    queryable="false" required="false" expert="false"
    hidden="false" readable="true" writable="true"
    category-resource="categoryBasics"
    display-name-resource="ldapFirstName">


      <!-- bundle for this property's resources -->
      <attribute name="resourceBundle"
      value="atg.userprofiling.CompositeProfileTemplateResources"
      data-type="string"/>
      <!-- flag for ui being able to write this property -->
      <attribute name="uiwritable" value="true" data-type="boolean"/>
      <!-- maximum length for this property -->
      <attribute name="maxLength" value="32" data-type="int"/>
      <!-- does this property's value have to be unique? -->
      <attribute name="unique" value="true" data-type="boolean"/>
      <!-- sort priority -->
      <attribute name="propertySortPriority" value="10" data-type="int"/>


    </property>


    <!-- explicit property exclusion
    Sometimes users will not want to expose absolutely every property from
    the underlying primary and contributing views in the composite view. An
    explicit property removal allows the user to make the composite view
    contain only those contributing properties that are desired.
    -->
    <property mapped-property-name="login" exclude="true"/>
    <property mapped-property-name="password" exclude="true"/>
    <property mapped-property-name="id" exclude="true"/>


    <!--
    2) a composite view's property names are determined thusly:

       a) If all-properties-propagate is true, all properties from the primary and
       contributing views are combined into the composite view, retaining their
       property names, property types, and any metadata they may have defined.

       b) All property exclusions are performed.  This means that any properties
       to be excluded are removed from the composite view.

       c) All property mappings are performed.  This means that a primary or
       contributing property that is to be mapped gets renamed in the composite
       view.

       d) If there are any two properties in the composite view that have the same
       name, error.  The composite repository requires that all composite property
       names map explicitly to only one primary or contributing property.

      -->

      <!-- the primary view link describes how items in the contributing view are
       linked to items in the primary view.  For each primary-contributing
       relationship, the user picks a unique id attribute for the primary and the
       contributing view. The attribute can be either the repository id of the
      item or a uniquely-valued property of the item (e.g. login).  A primary item
      is linked to a contributing item if its unique id attribute value matches
      the unique id attribute value of the contributing item. There must be at
      least one primary view link, but there is primary view link limit.  -->

      <!-- example: this primary view link defines a relationship where an item in
      the primary view is linked to an item in this contributing view if the
      contributing item has a repository id which is the same as the primary
      item's id.
-->

<!--
      <primary-item-descriptor-link>
        <link-via-id/>
      </primary-item-descriptor-link>
-->

      <!-- OR:

      This primary view link defines a relationship where a primary view item is
      linked to an item in this contributing view if the value of the primary
      item's "login" property matches the value of the contributing item's
      "userLoginName" property.
      -->

      <primary-item-descriptor-link>
        <link-via-property primary="login" contributing="login"/>
      </primary-item-descriptor-link>

      <!-- OR:

      This primary view link defines a relationship where a primary view item is
      linked to an item in this contributing view if the value of the primary
      item's "firstName" property matches the value of the contributing item's
      "userFirstName" property AND the value of the primary item's "lastName"
       property matches the value of the contributing item's "userLastName"
       property.  This is useful in the case where no one property in the primary
       view or the contributing view is uniquely valued. The relationships are
       ANDed together

      <primary-item-descriptor-link>
        <link-via-property primary="firstName" contributing="userFirstName"/>
        <link-via-property primary="lastName" contributing="userLastName"/>
      </primary-item-descriptor-link>

      -->


    </contributing-item-descriptor>


  </item-descriptor>

Repository Loader Manifest : ATG


If the content root in the file system for your repository contains a large number of files, the FileSystemMonitorService might require a long time to identify which files and folders to load into the repository, and for the LoaderManager and ContentHandlers to convert the files and folders into repository items. You can reduce processing overhead by creating a Repository Loader manifest file that identifies in advance the files and folders to load.

For example, the following Repository Loader manifest file adds five files:

<manifest>
  <add>/main/Dynamo/RL/sample-data/user001.xml</add>
  <add>/main/Dynamo/RL/sample-data/user002.xml</add>
  <add>/main/Dynamo/RL/sample-data/user003.xml</add>
  <add>/main/Dynamo/RL/sample-data/user004.xml</add>
  <add>/main/Dynamo/RL/sample-data/user005.xml</add>
</manifest>

Elements in a Repository Loader manifest file are handled in order of appearance, so one element should not depend on a later element. For example, a content repository requires a folder hierarchy; so a content item should not precede the folder that contains it.

Document Type Definition

The Repository Loader manifest file is an XML file that conforms to the following DTD:

<!--
====================================================================
rl-manifest_1.0.dtd - document type for Repository Loader manifests
Version: $Id: //product/DAS/main/Java/atg/dtds/rl/rl-manifest_1.0.dtd#1 $
$Change: 286550 $
====================================================================
-->


<!-- A single manifest composed of any number of add, update, remove tags -->
<!ELEMENT manifest (add | update | remove)*>
<!ATTLIST manifest num-elements CDATA #IMPLIED>
<!ELEMENT add (#PCDATA)>
<!ATTLIST add type-mapping CDATA #IMPLIED>
<!ELEMENT update (#PCDATA)>
<!ATTLIST update type-mapping CDATA #IMPLIED>
<!ELEMENT remove (#PCDATA)>
<!ATTLIST remove type-mapping CDATA #IMPLIED>

Thursday, January 26, 2012

Designing the Catalog Repository : A Simple Overview


If you are designing a multi-locale site with catalog repository content, you can set up your catalog repository in one of two ways. You can create a separate repository for each language or with a single repository for all languages.

A catalog repository is similar to other SQL repositories. There are three main parts:

The database schema on your SQL database server.

The repository component, which is of class atg.adapter.gsa.GSARepository.

The repository definition file, which is an XML file that defines the relationship between the SQL database and the Dynamo repository component.

This section discusses the pros and cons of single and multiple repository configurations. The option you choose dictates how you must set up your database tables. If you have a repository for each locale, you should also have database tables that contain different product information for each locale. If you have a single repository, you can separate your database tables so that the locale-specific properties of each product are stored in multi-valued tables that hold many different language versions of the same information. When you are designing your catalog repository, consider the following pros and cons of each design:

Multiple Repositories

Create a separate content repository for each language. This requires separate targeting rules for each locale, in which each rule references the appropriate language repository. This is the simpler of the two methods.

Pros: Separate targeting rules let you target different pieces of content to different locales. For example, site visitors from Japan may not be interested in the same style of jeans as site visitors from the US.

Also, administration of multiple repositories is easier than a single repository, because you can have a catalog administrator for each language who has access only to the appropriate repository.

Cons: You must maintain multiple copies of each item in the repository, since each item is duplicated in each locale-specific repository. In addition, storing separate values for each locale-sensitive takes up a lot of space in the database.

One Repository

Configure a single repository for all languages and include a language attribute in each repository item. This method requires you to develop logic that uses the RequestLocale’s localeString property to get the property values corresponding to the proper locale.

Pros: You can maintain only one copy of each repository item. These items draw their locale-specific attributes from a multi-valued table in the database.

Cons: This configuration is more difficult to administer because data for every language is in one repository. You cannot separate products that are Japanese-specific, for example.

You have to store most languages other than English in UNICODE format, which takes up 2 bytes per character, instead of ASCII, which only requires one byte per character. If you are using separate repositories, you can use ASCII and UNICODE where appropriate, but if you have a single repository you must store all data in UNICODE. This takes up more space in the database.

There are more database joins in a single repository because of the large number of multi-value tables. This slows Dynamo operation. The reduced performance may be imperceptible, but using multi-value tables does increase the load on the database.

Wednesday, January 25, 2012

Extending the Repository for Internationalization


To aid in internationalization, ATG Commerce includes a feature that allows you to specify alternate text for some catalog items using derived properties. You can add a derivation property to any property in the catalog, then specify alternatives to use in each catalog. For example, you could specify different display text to appear in different languages for the same catalog item.

The following example shows how to expand the displayName property to include English and German versions. As provided in ATG Commerce, displayName looks like this:

<item-descriptor name="sku"
  <table name="dcs_sku" type="primary" id-column="sku_id">
    <property name="displayName" column-name="display_name" data-type="string"/>
  </table>
</item-descriptor>

First, create two new properties, one for the English display name (reusing the column above) and one for the German display name (this requires a new table).

We start off with the name of the item descriptor containing the property:

<item-descriptor name="sku">

Remove the old definition of displayName. In order for the XML combination to work, do this inside the correct table tag:

<table name="dcs_sku" type="primary" id-column="sku_id">
  <property name="displayName" xml-combine="remove"/>

To reuse the column name for the English display name (this way the English values do not need to be copied anywhere), define the English display name in the same table tag, then close the table:

  <property name="displayName_en" column-name="dislpay_name" data-type="string">
    <attribute name="locale" value="en"/>
  </property>
</table>

Notice there is an attribute called “locale” on this property. The derivation method uses this to determine the correct value.

Now define the German version. It looks similar to the English version above (with a different “locale” attribute). Define a new table for this:

<table name="dcs_sku_de" type="auxiliary" id-column="sku_id">
  <property name="displayName_de" column-name="display_name" data-type="string">
    <attribute name="locale" value="de"/>
  </property>
</table>

Next, define the derived property. Giving it the same name as the previously English property (“displayName”) means that JSP code that references this does not have to be rewritten:

<property name="displayName data-type="string">
  <derivation user-method="atg.commerce.util.FirstWithLocale">
    <expression>displayName_en</expression>
    <expression>displayName_de</expression>
  </derivation>
    <attribute name="derivationAttribute" value="locale"/>
    <attribute name="keyService" value="/atg/userprofiling/LocaleService"/>
    <attribute name="keySubProperty" value="locale"/>
    <attribute name="defaultKey" value="en"/>
</property>

The <derivation> tag uses a custom derivation method called FirstWithLocale, a subclass of FirstWithAttribute. It performs the following actions:

1.Gets the repository key service

2.Calls RepositoryKeyService.getRepositoryKey, which returns the user’s current locale as the key.

3.Compares this key to each expression’s <locale> value.

4.Returns the first property whose attribute matches.

The locale is searched in a locale-specific way. For example, if locale=fr_FR_EURO, it first looks for a property where the locale attribute is fr_FR_EURO, then look for “fr_FR”, and finally look for “fr.”

There is also a defaultKey, which keyService uses if the if the value with the real key is null. In other words, if the real key is “de_DE” and we are looking for displayName, but displayName_de is null, then return displayName_en instead (assuming its locale is “en” and the defaultKey is “en” or “en_US”).

Using a defaultKey may slow performance. If no default key is defined, it is not used. If the default key is the same as the current key, there are no performance implications. In all other cases, there is an extra clause on all search terms.

The complete XML looks like this:

<item-descriptor name="sku">
   <table name="dcs_sku" type="primary" id-column="sku_id">
     <property name="displayName" xml-combine="remove"/>
     <property name="displayName_en" column-name="dislpay_name"
          data-type="string">
      <attribute name="locale" value="en"/>
    </property>
  </table>

  <table name="dcs_sku_de" type="auxiliary" id-column="sku_id">
    <property name="displayName_de" column-name="display_name" data-type="string">
       <attribute name="locale" value="de"/>
     </property>
  </table>


  <property name="displayName data-type="string">
    <derivation user-method="atg.commerce.util.FirstWithLocale">
      <expression>displayName_en</expression>
      <expression>displayName_de</expression>
    </derivation>
    <attribute name="keyService" value="/atg/userprofiling/LocaleService"/>
    <attribute name="defaultKey" value="en_US"/>
  </property>
   </item-descriptor>

Popular Posts