atg.repository
Class RepositoryUtils

java.lang.Object
  extended by atg.repository.RepositoryUtils

public class RepositoryUtils
extends java.lang.Object

This utility class is home to methods that can be used to operate against repositories, repository items and properties.


Nested Class Summary
static interface RepositoryUtils.RepositoryPropertyCallback
          Return repository property callback.
static class RepositoryUtils.Service
          A generic service to expose the repository callbacks to Nucleus.
 
Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Constructor Summary
RepositoryUtils()
           
 
Method Summary
protected static void addItemDescriptors(RepositoryItemDescriptor pDescriptor, java.util.Collection pItemDescriptors)
          This method determines if the RepositoryItemDescriptor has any subtypes (if its a RepositoryItemDescriptorContainer) and then adds all subtype item-descriptors and the item-descriptor passed to this method to the collection of item-descriptors passed to this method.
static void addRepositoryPropertyCallback(RepositoryUtils.RepositoryPropertyCallback pCallback)
          Add the specified repository property callback.
static boolean anyReferencesToItem(RepositoryItem pItem)
          Query whether any cross-references to a repository item exist within the repository that contains that item.
static java.lang.String buildUriForRepositoryItem(java.lang.String pRepositoryName, java.lang.String pItemDescriptorName, java.lang.String pRepositoryId)
          Return a JNDI "atgrep:" URI given a repository name, an item descriptor, and a repository ID.
static MutableRepositoryItem cloneItem(RepositoryItem pSource, boolean pDeepCopy, java.util.Map pPropExceptions, java.util.Map pExcludedProperties, MutableRepository pDestRepository, java.lang.String pId)
          Create a copy of a RepositoryItem in a repository without adding the item.
static MutableRepositoryItem cloneItem(RepositoryItem pSource, boolean pDeepCopy, java.util.Map pPropExceptions, MutableRepository pDestRepository, java.lang.String pId)
          Create a copy of a RepositoryItem in a repository without adding the item.
static java.lang.String convertValueToString(DynamicPropertyDescriptor pPropDesc, java.lang.Object pValue)
          Converts an Object value with an optional property descriptor to a string value, which gets returned.
static java.util.Collection<RepositoryItemDescriptor> getAllSubtypeItemDescriptors(atg.repository.RepositoryItemDescriptorContainer pItemDescriptor)
          Returns a collection of item-descriptors that are subtypes of the item-descriptor passed to this method.
static RepositoryItemDescriptor getBaseItemDescriptor(RepositoryItemDescriptor pItemDesc)
          Return the base item descriptor, if one exists.
static java.lang.String getItemDescriptorDisplayName(RepositoryItemDescriptor pItemDesc)
          Get the localized display name of the item descriptor.
static java.lang.String getItemDisplayPropertyName(RepositoryItemDescriptor pDesc)
          Get the name of the display property for the given item descriptor, translating it using FirstWithLocale, if applicable and returning null if the property is not queryable.
static java.lang.String getItemDisplayPropertyName(RepositoryItemDescriptor pDesc, boolean pMustBeQueryable)
          Get the name of the display property for the given item descriptor, translating it using FirstWithLocale, if applicable.
static java.lang.String getItemDisplayPropertyPath(RepositoryItemDescriptor pDesc)
          Get the DynamicBeans path of the display name property for the given item descriptor.
static MutableRepositoryItem getMutableRepositoryItem(MutableRepository pRepository, java.lang.String pItemId, java.lang.String pItemType)
          Get a mutable repository item based on the repository, item ID and item type provided.
static MutableRepositoryItem getMutableRepositoryItem(RepositoryItem pItem)
          Get a mutable version of the repository item provided.
static RepositoryItemDescriptor getParentItemDescriptor(RepositoryItemDescriptor pItemDesc)
          Return the parent item descriptor, if any.
static java.lang.String getUriForRepositoryItem(RepositoryItem pItem)
          Return a JNDI "atgrep:" URI given a repository item.
static boolean isTypeOfItemDesc(RepositoryItemDescriptor pItemDesc, RepositoryItemDescriptor pSuper)
          Returns whether pItemDesc is a subtype (or equal to) pSuper.
static boolean isTypeOfItemDesc(RepositoryItem pItem, RepositoryItemDescriptor pSuper)
          Returns whether pItem is of the same type, or a subtype, of pSuper
static boolean isTypeOfItemDesc(RepositoryItem pItem, java.lang.String pSuperDescriptorName)
          Returns whether pItem is of the same type, or a subtype, of the type identified by pSuperDescriptorName
static void notifyGetPropertyValue(java.lang.String pPropertyName, RepositoryItem pItem)
          Notify on fetching property value.
static void notifySetPropertyValue(java.lang.String pPropertyName, MutableRepositoryItem pItem, java.lang.Object pValue)
          Notify on fetching setting value.
static java.lang.String printPropertyMap(java.util.Map pPropertyMap)
          Prints a map with the key as the PropertyDescriptor and the value as the property value
static void removeReferencesToItem(RepositoryItem pItem)
          Removes any references to a given from others items in its repository.
static boolean removeRepositoryPropertyCallback(RepositoryUtils.RepositoryPropertyCallback pCallback)
          Remove the specified repository property callback.
static RepositoryItemDescriptor unwrapItemDescriptor(RepositoryItemDescriptor pDesc)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

RepositoryUtils

public RepositoryUtils()
Method Detail

addItemDescriptors

protected static void addItemDescriptors(RepositoryItemDescriptor pDescriptor,
                                         java.util.Collection pItemDescriptors)
                                  throws RepositoryException
This method determines if the RepositoryItemDescriptor has any subtypes (if its a RepositoryItemDescriptorContainer) and then adds all subtype item-descriptors and the item-descriptor passed to this method to the collection of item-descriptors passed to this method.

Parameters:
pDescriptor - the item-descriptor that should be checked for subtypes and then added to the itemDescriptors collection
pItemDescriptors - a collection of item-descriptors
Throws:
RepositoryException

getAllSubtypeItemDescriptors

public static java.util.Collection<RepositoryItemDescriptor> getAllSubtypeItemDescriptors(atg.repository.RepositoryItemDescriptorContainer pItemDescriptor)
                                                                                   throws RepositoryException
Returns a collection of item-descriptors that are subtypes of the item-descriptor passed to this method. For example, if there is an address item that has two subtypes; home and business this method will return the home and business item-descriptors.

Additionally, if any of those item-descriptors themselves have subtype descriptors, those will be returned in the Collection as well. For example, if the home address subtype had a subtype, this would appear in the Collection as well.

Parameters:
pItemDescriptor - item-descriptor to discover subtypes for. If there are no subtypes associated with the item-descriptor passed, then null will be returned
Returns:
collection subtype item-descriptors
Throws:
RepositoryException

cloneItem

public static MutableRepositoryItem cloneItem(RepositoryItem pSource,
                                              boolean pDeepCopy,
                                              java.util.Map pPropExceptions,
                                              java.util.Map pExcludedProperties,
                                              MutableRepository pDestRepository,
                                              java.lang.String pId)
                                       throws RepositoryException,
                                              DuplicateIdException
Create a copy of a RepositoryItem in a repository without adding the item. Can specify a default copy mode of deep or shallow as well as a list of property name exceptions to this mode.

Parameters:
pSource - Item to copy.
pDeepCopy - The mode of the copy. If true, default to a deep copy of the item and its properties. Otherwise, default to a shallow copy, only getting references of child RepositoryItems. Note that shallow coping will only work if the source and destination and repositories are the same.
pPropExceptions - Hierarchical map of property name exceptions to the above mode. Keys are property names while values are null or another Map if the property is an item. For example, if you clone a product using pDeepCopy=true, you could add the key "parentCategory" with a null value into pPropExceptions to cause a shallow copy of the product.parentCategory. Alternatively, you could add the key "parentCategory" but set the value to another map of exceptions that included the key/value pair "keywords"/null to do a deep copy of product.parentCategory but a shallow copy of the product.parentCategory.keywords. Optional.
pExcludedProperties - Properties to exclude from clone. Keys are item-type names and the values are collections of property names to exclude. Optional.
pDestRepository - Repository to copy the item to. If source and destination repositories are the same, properties that are items will be cloned to the repository of the source item-property. Optional - If null, copy to source repository.
pId - Id to use in copy of item. Optional - if null, a unique Id will automatically be generated.
Throws:
RepositoryException - Thrown if the item could not be created.
DuplicateIdException - Thrown if the specified Id is already in use.

cloneItem

public static MutableRepositoryItem cloneItem(RepositoryItem pSource,
                                              boolean pDeepCopy,
                                              java.util.Map pPropExceptions,
                                              MutableRepository pDestRepository,
                                              java.lang.String pId)
                                       throws RepositoryException,
                                              DuplicateIdException
Create a copy of a RepositoryItem in a repository without adding the item. Can specify a default copy mode of deep or shallow as well as a list of property name exceptions to this mode.

Parameters:
pSource - Item to copy.
pDeepCopy - The mode of the copy. If true, default to a deep copy of the item and its properties. Otherwise, default to a shallow copy, only getting references of child RepositoryItems. Note that shallow coping will only work if the source and destination and repositories are the same.
pPropExceptions - Hierarchical map of property name exceptions to the above mode. Keys are property names while values are null or another Map if the property is an item. For example, if you clone a product using pDeepCopy=true, you could add the key "parentCategory" with a null value into pPropExceptions to cause a shallow copy of the product.parentCategory. Alternatively, you could add the key "parentCategory" but set the value to another map of exceptions that included the key/value pair "keywords"/null to do a deep copy of product.parentCategory but a shallow copy of the product.parentCategory.keywords. Optional.
pDestRepository - Repository to copy the item to. If source and destination repositories are the same, properties that are items will be cloned to the repository of the source item-property. Optional - If null, copy to source repository.
pId - Id to use in copy of item. Optional - if null, a unique Id will automatically be generated.
Throws:
RepositoryException - Thrown if the item could not be created.
DuplicateIdException - Thrown if the specified Id is already in use.

anyReferencesToItem

public static boolean anyReferencesToItem(RepositoryItem pItem)
                                   throws RepositoryException
Query whether any cross-references to a repository item exist within the repository that contains that item. This method can only detect references through queryable properties.

Calling this method will generate multiple repository queries per call, one for each property descriptor that might refer to pItem. For example, if pItem's type is "contact-info", one query will be performed for each property descriptor whose type is either contact-info or any multi-valued type that might contain a list of items of type contact-info. (The queries will each fetch at most one item from the repository, so the effect on the repository's cache should be minimal.)

Parameters:
pItem - Any repository item.
Returns:
true if any other item in pItem's repository refers to pItem
Throws:
RepositoryException

removeReferencesToItem

public static void removeReferencesToItem(RepositoryItem pItem)
                                   throws RepositoryException
Removes any references to a given from others items in its repository. This method can only remove references in queryable properties.

Calling this method will generate multiple repository queries per call, one for each property descriptor that might refer to pItem. For example, if pItem's type is "contact-info", one query will be performed for each property descriptor whose type is either contact-info or any multi-valued type that might contain a list of items of type contact-info.

Parameters:
pItem - Any repository item.
Throws:
RepositoryException

getMutableRepositoryItem

public static MutableRepositoryItem getMutableRepositoryItem(RepositoryItem pItem)
                                                      throws RepositoryException
Get a mutable version of the repository item provided.

Parameters:
pItem - the repository item
pRepository - the mutable repository where the item resides
Returns:
MutableRepositoryItem a mutable version of the repository item
Throws:
RepositoryException - on repository error

getMutableRepositoryItem

public static MutableRepositoryItem getMutableRepositoryItem(MutableRepository pRepository,
                                                             java.lang.String pItemId,
                                                             java.lang.String pItemType)
                                                      throws RepositoryException
Get a mutable repository item based on the repository, item ID and item type provided.

Parameters:
pRepository - - the mutable repository where the item resides
pItemId - - the repository item's id
pItemType - - the repository item's type
Returns:
MutableRepositoryItem - a mutable version of the repository item
Throws:
- - RepositoryException on repository error
RepositoryException

printPropertyMap

public static java.lang.String printPropertyMap(java.util.Map pPropertyMap)
Prints a map with the key as the PropertyDescriptor and the value as the property value


convertValueToString

public static java.lang.String convertValueToString(DynamicPropertyDescriptor pPropDesc,
                                                    java.lang.Object pValue)
Converts an Object value with an optional property descriptor to a string value, which gets returned.


getUriForRepositoryItem

public static java.lang.String getUriForRepositoryItem(RepositoryItem pItem)
                                                throws RepositoryException
Return a JNDI "atgrep:" URI given a repository item.

Parameters:
pItem - the repository item
Throws:
RepositoryException

buildUriForRepositoryItem

public static java.lang.String buildUriForRepositoryItem(java.lang.String pRepositoryName,
                                                         java.lang.String pItemDescriptorName,
                                                         java.lang.String pRepositoryId)
                                                  throws RepositoryException
Return a JNDI "atgrep:" URI given a repository name, an item descriptor, and a repository ID.

Parameters:
pRepositoryName - the repository name
pItemDescriptor - the item descriptor name
pRepositoryId - the repository id
Throws:
RepositoryException

isTypeOfItemDesc

public static boolean isTypeOfItemDesc(RepositoryItemDescriptor pItemDesc,
                                       RepositoryItemDescriptor pSuper)
Returns whether pItemDesc is a subtype (or equal to) pSuper.

Parameters:
pItemDesc - The (presumably child) item descripor
pSuper - The item descriptor to test for parent-hood.
Returns:
true if pItemDesc is a subtype (or equal to) pSuper, return false otherwise.

isTypeOfItemDesc

public static boolean isTypeOfItemDesc(RepositoryItem pItem,
                                       RepositoryItemDescriptor pSuper)
                                throws RepositoryException
Returns whether pItem is of the same type, or a subtype, of pSuper

Parameters:
pItem - The (presumably child) item
pSuper - The item descriptor to test for parent-hood.
Returns:
true if pItemDesc is a subtype (or equal to) pSuper, return false otherwise.
Throws:
RepositoryException

isTypeOfItemDesc

public static boolean isTypeOfItemDesc(RepositoryItem pItem,
                                       java.lang.String pSuperDescriptorName)
                                throws RepositoryException
Returns whether pItem is of the same type, or a subtype, of the type identified by pSuperDescriptorName

Parameters:
pItem - The (presumably child) item
pSuperDescriptorName - The item descriptor name to test for parent-hood.
Returns:
true if pItemDesc is a subtype (or equal to) the type identified by pSuperDescriptorName, return false otherwise.
Throws:
RepositoryException

getParentItemDescriptor

public static RepositoryItemDescriptor getParentItemDescriptor(RepositoryItemDescriptor pItemDesc)
Return the parent item descriptor, if any. Returns null unless pItemDesc represents a sub-type.


getBaseItemDescriptor

public static RepositoryItemDescriptor getBaseItemDescriptor(RepositoryItemDescriptor pItemDesc)
Return the base item descriptor, if one exists. Otherwise returns pItemDesc;


getItemDescriptorDisplayName

public static java.lang.String getItemDescriptorDisplayName(RepositoryItemDescriptor pItemDesc)
Get the localized display name of the item descriptor. If there is no display name, then fall back to the item descriptor name.


getItemDisplayPropertyPath

public static java.lang.String getItemDisplayPropertyPath(RepositoryItemDescriptor pDesc)
                                                   throws RepositoryException
Get the DynamicBeans path of the display name property for the given item descriptor. If the type of the item descriptor's display property is a repository item itself, then use that item type's display name (e.g., for PromotionClaimable items, the display name property is a reference to a promotion item).

Throws:
RepositoryException

getItemDisplayPropertyName

public static java.lang.String getItemDisplayPropertyName(RepositoryItemDescriptor pDesc)
                                                   throws RepositoryException
Get the name of the display property for the given item descriptor, translating it using FirstWithLocale, if applicable and returning null if the property is not queryable.

Throws:
RepositoryException

getItemDisplayPropertyName

public static java.lang.String getItemDisplayPropertyName(RepositoryItemDescriptor pDesc,
                                                          boolean pMustBeQueryable)
                                                   throws RepositoryException
Get the name of the display property for the given item descriptor, translating it using FirstWithLocale, if applicable.

Parameters:
pDesc - the RepositoryItemDescriptor for which to get the display name property
pMustBeQueryable - if true, return null if the property is not queryable
Throws:
RepositoryException

unwrapItemDescriptor

public static RepositoryItemDescriptor unwrapItemDescriptor(RepositoryItemDescriptor pDesc)
                                                     throws RepositoryException
Throws:
RepositoryException

notifySetPropertyValue

public static void notifySetPropertyValue(java.lang.String pPropertyName,
                                          MutableRepositoryItem pItem,
                                          java.lang.Object pValue)
Notify on fetching setting value. This method should only be called by repository implementations. Note that invocation of this method does not mean that setting the property value succeeded.


notifyGetPropertyValue

public static void notifyGetPropertyValue(java.lang.String pPropertyName,
                                          RepositoryItem pItem)
Notify on fetching property value. This method should only be called by repository implementations. Note that invocation of this method does not mean that the repository value was fetched successfull.

Parameters:
pPropertyName - the property descriptor for the item.
pItem - the item whose property value is being fetched.

addRepositoryPropertyCallback

public static void addRepositoryPropertyCallback(RepositoryUtils.RepositoryPropertyCallback pCallback)
Add the specified repository property callback.


removeRepositoryPropertyCallback

public static boolean removeRepositoryPropertyCallback(RepositoryUtils.RepositoryPropertyCallback pCallback)
Remove the specified repository property callback.