wt.admin
Class MigrateDomainAccess

java.lang.Object
  extended bywt.admin.MigrateDomainAccess
All Implemented Interfaces:
JavaMigrator

public class MigrateDomainAccess
extends Object
implements JavaMigrator

This migrator moves users into organization-specific domains, and updates their personal cabinets if necessary.


Nested Class Summary
(package private)  class MigrateDomainAccess.OrgInfo
          Utility class that collectiosn information about an organization
 
Field Summary
private static String CLASSNAME
           
private static String CONTAINER_RESOURCE
           
private  int domainNameUpperLimit
          Maximum size of AdministrativeDomain names Assigned in initProperties()
private  DirectiveServices ds
          Assigned in runMigration()
private  ObjectIdentifier exchange
          Oid of the exchange container Assigned in initContainers()
private  String[] folderedTables
          The table names for all concrete foldered objects.
private  String hostName
          Used for auto generation of inet domain names Assigned in initProperties()
private  int maxDomainCreationAttempts
          Number of times to try and find a unique org domain name Assigned in initProperties()
private  int maxInetDomainCreationAttempts
          Number of times to try and find a unique internet domain name Assigned in initProperties()
private static String ORG_RESOURCE
           
private  int orgContainerNameUpperLimit
          Maximum size of OrgContainer names Assigned in initProperties()
private  Map orgInfos
          Mapping of organization names (in upper case) to OrgInfos.
private static int PAGE_SIZE
          Number of users per page.
private  ObjectIdentifier rootDomain
          Oids of the special domains Assigned in initDomains()
private  Map servicesByName
          Mapping of service names to Repository oids Assigned in initServices()
private  Map servicesByOid
          Mapping of Repository oids to service names Assigned in initServices()
private  ObjectIdentifier systemDomain
          Oids of the special domains Assigned in initDomains()
private  ObjectIdentifier unaffiliatedDomain
          Oids of the special domains Assigned in initDomains()
private  ObjectIdentifier userDomain
          Oids of the special domains Assigned in initDomains()
private static boolean VERBOSE
           
 
Constructor Summary
MigrateDomainAccess()
           
 
Method Summary
private  ObjectIdentifier createDomain(String name, String description, ObjectIdentifier parent_domain, ObjectIdentifier parent_container)
          Creates an AdministrativeDomain named name with description description that is in domain parent_id and container container_id.
private  String generateInternetDomainName(String org_name)
          Generates a unique internet domain for the given organization name.
private  String getByInternetDomain(String internet_domain)
          Finds the dn of the organization with the givne internet domain
private  String[] getDNForOrganization(String org_name)
          Get the distinguished name of the organization
private  ObjectIdentifier getDomain(String name, long parent_id, long container_id)
          Get the AdministrativeDomain named name that is in domain parent_id and container container_id.
private  ObjectIdentifier getOrgContainer(String name)
          Get the oid of the org container with the given name.
private  MigrateDomainAccess.OrgInfo getOrgInfo(String org_name)
          Finds an org info for the given organization name.
private  ObjectIdentifier getRootDomain()
          Finds the oid of the root domain
private  String getUnusedDomainName(String name, long parent_id, long container_id)
          Generates a unique version of the given domain name within the parent domain parent_id and container container_id.
private  void initContainers()
          Finds the exchange container
private  void initDomains()
          Finds the special domains.
private  void initProperties()
          Initializes Windchill and I*E properties
private  void initServices()
          Builds a mapping of repository oids to service names
static void main(String[] args)
           
private  ObjectIdentifier migrateOrganization(String org_name)
          Ensures an organization and domain exist for the given organization name.
private  void migrateOrgDomains()
          Pages through the user table, assigning users to org domains as necessary.
private  boolean migratePersonalCabinet(long user_id, long domain_id)
          Updates the domain of the users's personal cabinet and of the cabinet's contents, if the personal cabinet is currently stored in the global user domain.
private  long migrateUser(long user_id, String dn, String service)
          Updates the domain of the user represented by the parameters.
private  void migrateWTOrganization(String org_name, long org_domain)
          Ensures that a WTOrganization with the given name exists in both LDAP and Oracle, and assigns this organization to the AdministrativeDomain with the given oid.
private  ObjectIdentifier persistWTOrganization(String org_name, String dn, long org_domain, String service)
          Persist an organization with the given name in the given domain.
 boolean runMigration(DirectiveServices directive_services)
          Implemented from the JavaMigrator interface
private static void safeClose(ResultSet rs)
          If the Statement is not null, try to close it, catching and smothering any SQLException that results.
private  void safeClose(Statement stmt)
          If the Statement is not null, try to close it, catching and smothering any SQLException that results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSNAME

private static final String CLASSNAME

ORG_RESOURCE

private static final String ORG_RESOURCE

CONTAINER_RESOURCE

private static final String CONTAINER_RESOURCE

VERBOSE

private static final boolean VERBOSE

PAGE_SIZE

private static final int PAGE_SIZE
Number of users per page. This is also used to define the size of the IN clause in migrateUsers so it shouldn't be increased.

See Also:
Constant Field Values

ds

private DirectiveServices ds
Assigned in runMigration()


domainNameUpperLimit

private int domainNameUpperLimit
Maximum size of AdministrativeDomain names Assigned in initProperties()


orgContainerNameUpperLimit

private int orgContainerNameUpperLimit
Maximum size of OrgContainer names Assigned in initProperties()


maxDomainCreationAttempts

private int maxDomainCreationAttempts
Number of times to try and find a unique org domain name Assigned in initProperties()


maxInetDomainCreationAttempts

private int maxInetDomainCreationAttempts
Number of times to try and find a unique internet domain name Assigned in initProperties()


hostName

private String hostName
Used for auto generation of inet domain names Assigned in initProperties()


folderedTables

private String[] folderedTables
The table names for all concrete foldered objects. Assigned in initProperties()


exchange

private ObjectIdentifier exchange
Oid of the exchange container Assigned in initContainers()


userDomain

private ObjectIdentifier userDomain
Oids of the special domains Assigned in initDomains()


systemDomain

private ObjectIdentifier systemDomain
Oids of the special domains Assigned in initDomains()


unaffiliatedDomain

private ObjectIdentifier unaffiliatedDomain
Oids of the special domains Assigned in initDomains()


rootDomain

private ObjectIdentifier rootDomain
Oids of the special domains Assigned in initDomains()


servicesByOid

private Map servicesByOid
Mapping of Repository oids to service names Assigned in initServices()


servicesByName

private Map servicesByName
Mapping of service names to Repository oids Assigned in initServices()


orgInfos

private Map orgInfos
Mapping of organization names (in upper case) to OrgInfos.

Constructor Detail

MigrateDomainAccess

public MigrateDomainAccess()
Method Detail

runMigration

public boolean runMigration(DirectiveServices directive_services)
                     throws Throwable
Implemented from the JavaMigrator interface

Specified by:
runMigration in interface JavaMigrator
Parameters:
directive_services - Contains migration resources
Returns:
true
Throws:
Throwable - declared so that migrators can let exceptions contibuting to failure pass out of the method. The migrator runner will handle these by logging them.

migrateOrgDomains

private void migrateOrgDomains()
                        throws Exception
Pages through the user table, assigning users to org domains as necessary.

Throws:
Exception

migrateUser

private long migrateUser(long user_id,
                         String dn,
                         String service)
                  throws Exception
Updates the domain of the user represented by the parameters. If the user has an organization name, then the user is assigned the org domain for that organization name. If there was not already an org domain, then it is created. If the user does not have an organization name, then they are assigned to the unaffiliated domain.

Parameters:
user_id - The oid of the user
dn - The DN of the user
service - The service for the user's DN
Returns:
The oid of the user's new domain
Throws:
WTException - If the user can't be found in LDAP
Exception

migratePersonalCabinet

private boolean migratePersonalCabinet(long user_id,
                                       long domain_id)
                                throws Exception
Updates the domain of the users's personal cabinet and of the cabinet's contents, if the personal cabinet is currently stored in the global user domain.

Parameters:
user_id - The oid of the user whose personal cabinet should be updated
domain_id - The oid of the domain to assign the cabinet and the cabinet's contents to.
Returns:
true if the user's personal cabinet and its contents where udpated.
Throws:
Exception

getOrgInfo

private MigrateDomainAccess.OrgInfo getOrgInfo(String org_name)
                                        throws Exception
Finds an org info for the given organization name. If there is no existing info for the name, then a new one is created, and an org domain is migrated.

Parameters:
org_name - The name of the org to find an info for
Returns:
The resulting org info
Throws:
Exception

migrateOrganization

private ObjectIdentifier migrateOrganization(String org_name)
                                      throws Exception
Ensures an organization and domain exist for the given organization name.
  1. Find the corresponding org domain for the name. If it doesn't exist, create it.
  2. Ensure a WTOrganization with the name exists in both LDAP and Oracle, and that it is assigned to the org domain.
  3. Ensure the OrgContainer with the name is assigned to the org domain.

Parameters:
org_name - The name of the organization to find or create a domain for.
Returns:
The oid of the org domain
Throws:
Exception

migrateWTOrganization

private void migrateWTOrganization(String org_name,
                                   long org_domain)
                            throws Exception
Ensures that a WTOrganization with the given name exists in both LDAP and Oracle, and assigns this organization to the AdministrativeDomain with the given oid.

Parameters:
org_domain - The oid of the domain to assign the organization to
Throws:
Exception

getDNForOrganization

private String[] getDNForOrganization(String org_name)
                               throws Exception
Get the distinguished name of the organization

Parameters:
org_name - The name of the org to look for
Returns:
A string array where the first element is the dn of the org, and the second element is the service. Or null if there is no org with the given name.
Throws:
Exception

generateInternetDomainName

private String generateInternetDomainName(String org_name)
                                   throws Exception
Generates a unique internet domain for the given organization name.

Parameters:
org_name - The name of the organization
Returns:
A unique internet domain
Throws:
Exception

getByInternetDomain

private String getByInternetDomain(String internet_domain)
                            throws Exception
Finds the dn of the organization with the givne internet domain

Parameters:
internet_domain - The internet domain to search for
Returns:
The internet domain, or null
Throws:
Exception

persistWTOrganization

private ObjectIdentifier persistWTOrganization(String org_name,
                                               String dn,
                                               long org_domain,
                                               String service)
                                        throws Exception
Persist an organization with the given name in the given domain. Also persist a UFID for the organization

Parameters:
org_name - The name of the organization
dn - The distinguished name of the organization
org_domain - The oid of the domain to persist the org in
service - The directory service the organization is in
Returns:
The oid of the new organization
Throws:
WTException - If the service can't be found
Exception

initProperties

private void initProperties()
                     throws Exception
Initializes Windchill and I*E properties

Throws:
Exception

initContainers

private void initContainers()
                     throws Exception
Finds the exchange container

Throws:
Exception

initDomains

private void initDomains()
                  throws Exception
Finds the special domains. Creates the unaffiliated domain if it doesn't already exist

Throws:
Exception

getRootDomain

private ObjectIdentifier getRootDomain()
                                throws Exception
Finds the oid of the root domain

Returns:
The ObjectIdentifier of the root domain
Throws:
WTException - If the root domain can't be found
Exception

getOrgContainer

private ObjectIdentifier getOrgContainer(String name)
                                  throws Exception
Get the oid of the org container with the given name. Assumes the name is in upper case

Parameters:
name - The name of the container, in upper case
Returns:
The ObjectIdentifier of the org container, or null if it wasn't found.
Throws:
WTException - If more than one org container is found with the given name
Exception

getDomain

private ObjectIdentifier getDomain(String name,
                                   long parent_id,
                                   long container_id)
                            throws Exception
Get the AdministrativeDomain named name that is in domain parent_id and container container_id. The search is case-insensitive

Parameters:
name - The name of the domain
parent_id - The oid of the domain's parent domain
container_id - The oid of the domain's container
Returns:
The ObjectIdentifier of the domain, or null if it wasn't found
Throws:
WTException - If more than one domain is found
Exception

getUnusedDomainName

private String getUnusedDomainName(String name,
                                   long parent_id,
                                   long container_id)
                            throws Exception
Generates a unique version of the given domain name within the parent domain parent_id and container container_id. This is adapted from getUnusedDomainName.

Parameters:
name - The name upon which the domain name should be based
parent_id - The oid of the parent domain
container_id - The oid of the container
Returns:
The unique domain name
Throws:
WTException - If no unique domain can be found after WTContainerServerHelper.MAX_DOMAIN_CREATION_ATTEMPTS
Exception

createDomain

private ObjectIdentifier createDomain(String name,
                                      String description,
                                      ObjectIdentifier parent_domain,
                                      ObjectIdentifier parent_container)
                               throws Exception
Creates an AdministrativeDomain named name with description description that is in domain parent_id and container container_id.

Parameters:
name - The name of the domain
description - The description of the domain
parent_domain - The oid of the domain's parent domain
parent_container - The oid of the domain's container
Returns:
The ObjectIdentifier of the new domain
Throws:
Exception

initServices

private void initServices()
                   throws Exception
Builds a mapping of repository oids to service names

Throws:
Exception

safeClose

private void safeClose(Statement stmt)
If the Statement is not null, try to close it, catching and smothering any SQLException that results.

Parameters:
stmt - The Statement to close

safeClose

private static void safeClose(ResultSet rs)
If the Statement is not null, try to close it, catching and smothering any SQLException that results.

Parameters:
rs - The ResultSet to close

main

public static void main(String[] args)