com.ptc.windchill.esi.migrate
Class TargetFactory

java.lang.Object
  extended bycom.ptc.windchill.esi.migrate.TargetFactory

public class TargetFactory
extends Object

Utility class for creating and retrieving ESITarget instances during the migration of RTP Organizations (ERBOrganization) to ESI Targets. NOTE: The 'system' attribute of ESITarget will be set to the object ID ('ida2a2') of the ERBOrganization entry.


Field Summary
protected static String ID_PREFIX
           
protected static String ID_SEPARATOR
           
protected static String ORG_CLASS_NAME
           
protected static Class TARGET_CLASS
           
protected static Hashtable targetIdCache
           
protected static Hashtable targetSystemCache
           
protected static ESITargetUtility tgtUtility
           
 
Constructor Summary
TargetFactory()
           
 
Method Summary
protected static void addToCache(ESITarget target)
          Adds the supplied target to the Target cache using the target's corresponding organization identity as the key.
static boolean completeMigration(ESITarget target)
          Finalizes the migration activity for the supplied ESI Target.
static ESITarget createTargetFromOrg(String name, String description, long id)
          Creates an ESITarget object from the supplied ERBOrganization values.
protected static long decodeId(String name)
          Decodes the supplied name and returns only the id portion.
protected static String decodeName(String name)
          Decodes the supplied name and returns only the name portion.
protected static String encodeId(long id)
          Encodes the supplied identity such that it can be appended with a name for storing or can be used for searching using the SQL LIKE operator.
protected static String encodeName(String name, long id)
          Encodes the supplied name and identity into a single string value.
protected static boolean equals(Object o1, Object o2)
          Determines if the two references are equal, taking null into account.
protected static ESITarget findInCache(long id)
          Finds the target that corresponds to the supplied organization identity.
protected static ESITarget findInCache(String system)
          Finds the target that corresponds to the supplied system value.
static ESITarget getTargetBySystem(String system)
          Returns the ESI Target having the supplied system value.
static ESITarget getTargetForOrg(long id)
          Returns the ESITarget that was created for the corresponding ERBOrganization identity value.
static ESITarget getTargetForOrg(ObjectIdentifier objectId)
          Returns the ESITarget that was created for the corresponding ERBOrganization ObjectIdentifier value.
static ESITarget getTargetForOrg(String orgName, String erpSystem)
          Returns the corresponding ESI Target for the ERBOrganization identified by the supplied values.
static QueryResult getTargetsInMigration()
          Queries those ESI Target objects that are partially migrated.
protected static QueryResult getTargetsWithNameLike(String likeValue)
          Returns a query result of those targets that have a name matching (i.e., SQL LIKE) the supplied value.
static boolean hasTargetForOrg(String name, String description, long id)
          Determines if an ESITarget object has been created for the supplied ERBOrganization values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORG_CLASS_NAME

protected static String ORG_CLASS_NAME

TARGET_CLASS

protected static Class TARGET_CLASS

ID_PREFIX

protected static String ID_PREFIX

ID_SEPARATOR

protected static String ID_SEPARATOR

tgtUtility

protected static ESITargetUtility tgtUtility

targetIdCache

protected static Hashtable targetIdCache

targetSystemCache

protected static Hashtable targetSystemCache
Constructor Detail

TargetFactory

public TargetFactory()
Method Detail

addToCache

protected static void addToCache(ESITarget target)
Adds the supplied target to the Target cache using the target's corresponding organization identity as the key.

Parameters:
target - - the target

findInCache

protected static ESITarget findInCache(long id)
Finds the target that corresponds to the supplied organization identity. Returns null if the target is not in the cache.

Parameters:
id - - the identity of the ERBOrganization
Returns:
the corresponding target, or null if not cached.

findInCache

protected static ESITarget findInCache(String system)
Finds the target that corresponds to the supplied system value. Returns null if the target is not in the cache.

Parameters:
system - - the unique id of the target ERP system/org.
Returns:
the corresponding target, or null if not cached.

encodeId

protected static String encodeId(long id)
Encodes the supplied identity such that it can be appended with a name for storing or can be used for searching using the SQL LIKE operator.

Parameters:
id - - the identity of the ERBOrganization
Returns:
the encoded Id

encodeName

protected static String encodeName(String name,
                                   long id)
Encodes the supplied name and identity into a single string value.

Parameters:
name - - the name of the organzation
id - - the identity of the ERBOrganization
Returns:
the encoded string

decodeId

protected static long decodeId(String name)
Decodes the supplied name and returns only the id portion. If the name is not encoded, this method returns ZERO.

Parameters:
name - - the encoded name
Returns:
the decoded id

decodeName

protected static String decodeName(String name)
Decodes the supplied name and returns only the name portion. If the name is not encoded, this method returns the original string.

Parameters:
name - - the encoded name
Returns:
the decoded name

createTargetFromOrg

public static ESITarget createTargetFromOrg(String name,
                                            String description,
                                            long id)
                                     throws UniquenessException,
                                            WTException
Creates an ESITarget object from the supplied ERBOrganization values.

Parameters:
name - - the name of the organzation
description - - the description of the organization
id - - the identity of the ERBOrganization
Returns:
the newly created target
Throws:
UniquenessException
WTException

hasTargetForOrg

public static boolean hasTargetForOrg(String name,
                                      String description,
                                      long id)
                               throws WTException
Determines if an ESITarget object has been created for the supplied ERBOrganization values. Returns false if there is no target, or the the target's values do not match the supplied values.

Parameters:
name - - the name of the organzation
description - - the description of the organization
id - - the identity of the ERBOrganization
Returns:
true if there is a corresponding target that matches the supplied ERBOrganization values.
Throws:
WTException

getTargetsWithNameLike

protected static QueryResult getTargetsWithNameLike(String likeValue)
                                             throws WTException
Returns a query result of those targets that have a name matching (i.e., SQL LIKE) the supplied value.

Parameters:
likeValue - - the name of the organzation
Returns:
the matching targets
Throws:
WTException

getTargetForOrg

public static ESITarget getTargetForOrg(long id)
                                 throws WTException,
                                        ESINoSuchTargetException
Returns the ESITarget that was created for the corresponding ERBOrganization identity value.

Parameters:
id - - the identity of the ERBOrganization
Returns:
the corresponding target
Throws:
WTException
ESINoSuchTargetException - if no corresponding target is found

getTargetForOrg

public static ESITarget getTargetForOrg(ObjectIdentifier objectId)
                                 throws WTException,
                                        ESINoSuchTargetException
Returns the ESITarget that was created for the corresponding ERBOrganization ObjectIdentifier value.

Parameters:
objectId - - the identifier of the ERBOrganization object
Returns:
the corresponding target
Throws:
WTException
ESINoSuchTargetException - if no corresponding target is found

getTargetForOrg

public static ESITarget getTargetForOrg(String orgName,
                                        String erpSystem)
                                 throws WTException,
                                        ESINoSuchTargetException
Returns the corresponding ESI Target for the ERBOrganization identified by the supplied values. requires: - RTP Organization migration must be completed.

Parameters:
orgName - - the 'orgName' column value of ERBOrganization
erpSystem - - the 'erpSystem' column value of ERBOrganization
Returns:
the corresponding ESITarget object
Throws:
ESINoSuchTargetException - if no corresponding target is found
WTException

getTargetBySystem

public static ESITarget getTargetBySystem(String system)
                                   throws WTException,
                                          ESINoSuchTargetException
Returns the ESI Target having the supplied system value.

Parameters:
system - - the unique id of the target ERP system/org.
Returns:
the corresponding ESITarget object
Throws:
ESINoSuchTargetException - if no corresponding target is found
WTException

getTargetsInMigration

public static QueryResult getTargetsInMigration()
                                         throws WTException
Queries those ESI Target objects that are partially migrated. (i.e., all targets for which completeMigration() has not been called.)

Returns:
a QueryResult containing ESI Target objects.
Throws:
WTException

completeMigration

public static boolean completeMigration(ESITarget target)
                                 throws WTException
Finalizes the migration activity for the supplied ESI Target.

Parameters:
target - - the target to finalize
Returns:
true if a save occurred; otherwise, false
Throws:
WTException

equals

protected static boolean equals(Object o1,
                                Object o2)
Determines if the two references are equal, taking null into account.

Parameters:
o1 - - the first object reference
o2 - - the second object reference
Returns:
true if the references match