Class BOHierarchyMap

java.lang.Object
com.primavera.integration.util.BOHierarchyMap

public class BOHierarchyMap extends Object
This utility class is used to aid in the building of hierarchies of business objects loaded from the database. The hierarchical business objects (ActivityCode, CostAccount, Document, EPS, FundingSource, OBS, ProjectCode, ResourceCode, Resource, Role, WBS) are usually retrieved from the database in a non-hierarchical order. Using this class can help ensure that the hierarchy is fully loaded.

Add business objects to the map using the addKey() method. When all business objects have been added, you can verify that the hierarchy is complete by calling validateIntegrity(). You can use the getRootKeys() method and recursively call the getKeyChildren() method to quickly traverse the entire hierarchy.

For dealing with incomplete hierarchies, there are getMissingParents(), getOrphans(), and moveOrphansToRoot() methods. An orphan is an object whose parent was specified when addKey was called, but whose parent object itself was never explicitly added.

To visually inspect the hierarchy, use the toString() method.

  • Constructor Details

    • BOHierarchyMap

      public BOHierarchyMap()
      Class constructor
    • BOHierarchyMap

      public BOHierarchyMap(String sName)
      Class constructor specifying a business object class name associated with this map
      Parameters:
      sName - the name of the business object class name associated with this map
  • Method Details

    • size

      public int size()
      Returns the number of key-value mappings in this map.
      Returns:
      int the number of key-value mappings in this map.
    • isEmpty

      public boolean isEmpty()
      Returns true if this map contains no key-value mappings.
      Returns:
      boolean true if this map contains no key-value mappings.
    • clear

      public void clear()
      Removes all mappings from this map.
    • setName

      public void setName(String sName)
      Sets the name of the business object class associated with this map
      Parameters:
      sName - the class name
    • getName

      public String getName()
      Gets the name of the business object class associated with this map
      Returns:
      String the name of the associated business object class
    • addKey

      public void addKey(ObjectId objectId, ObjectId parentObjectId)
      Adds a new key to the map
      Parameters:
      objectId - the object id of the key
      parentObjectId - the object id of the key's parent. This parameter is null for root keys
    • addKey

      public void addKey(ObjectId objectId, ObjectId parentObjectId, Object oValue)
      Adds a new key and its value to the map
      Parameters:
      objectId - the object id of the key
      parentObjectId - the object id of the key's parent. This parameter is null for root keys
      oValue - the value associated with the key, usually the business object reference
    • setValue

      public void setValue(ObjectId objectId, Object o) throws KeyNotFoundException
      Sets the value for a particular key
      Parameters:
      objectId - the object id of the key
      o - the value to be associated with the key
      Throws:
      KeyNotFoundException - if the key does not exist in the map
    • getValue

      public Object getValue(ObjectId objectId) throws KeyNotFoundException
      Gets the value for a particular key
      Parameters:
      objectId - the object id of the key
      Returns:
      Object the value to associated with the key, which can be null
      Throws:
      KeyNotFoundException - if the key does not exist in the map
    • getKeyParent

      public ObjectId getKeyParent(ObjectId objectId) throws KeyNotFoundException
      Gets a key's parent object id
      Parameters:
      objectId - the object id of the key
      Returns:
      Object the object id of the key's parent
      Throws:
      KeyNotFoundException - if the key does not exist in the map
    • getKeyChildren

      public ObjectId[] getKeyChildren(ObjectId objectId) throws KeyNotFoundException
      Gets a key's children object ids
      Parameters:
      objectId - the object id of the key
      Returns:
      Object[] the object ids of the key's children
      Throws:
      KeyNotFoundException - if the key does not exist in the map
    • getRootKeys

      public ObjectId[] getRootKeys()
      Gets the root key(s) in this map. A root key has no parent
      Returns:
      Object[] the object ids of the root key(s)
    • getAllKeys

      public ObjectId[] getAllKeys()
      Gets all keys in this map
      Returns:
      Object[] the object ids of the keys
    • getUniqueValues

      public Set<com.primavera.integration.util.KeyInfo> getUniqueValues()
      Gets all unique values in this map
      Returns:
      Set the set of unique values
    • getMissingParents

      public ObjectId[] getMissingParents()
      Gets ObjectIds of parents that were never added
      Returns:
      Object[] An array of missing parents
    • validateIntegrity

      public void validateIntegrity() throws KeyNotFoundException
      Checks the tree for parents that were never added.
      Throws:
      KeyNotFoundException - if a parent was never added
    • getOrphans

      public ObjectId[] getOrphans()
      Gets ObjectIds of all orphans (keys with parents that were never added)
      Returns:
      Object[] An array of orphan objectIds
    • moveOrphansToRoot

      public void moveOrphansToRoot()
      Moves all orphans (keys with parents that were never added) to the root
    • toString

      public String toString()
      Gets a string representation of this object.
      Overrides:
      toString in class Object
      Returns:
      the String representation of this object