Quintiq file version 2.0 
 | 
#parent: #root 
 | 
MethodOverride SynchronizeHierarchies 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    // 1. First all the Hierarchies IsSoftDeleted attribute are set to true 
 | 
    traverse( this, Hierarchy, hierarchy ) 
 | 
    { 
 | 
      hierarchy.IsSoftDeleted( true ); 
 | 
    } 
 | 
     
 | 
    // 2. Create a Hierarchy object for each SetType of unique Group if it does not exist 
 | 
    // Retrieve all distinct unique group names of set type 
 | 
    uniqueGroupNames := selectuniquevalues( this, 
 | 
                                            SystemOnChannel.SetType, 
 | 
                                            setType, 
 | 
                                            true, 
 | 
                                            setType.Group() 
 | 
                                           ); 
 | 
     
 | 
    traverse( uniqueGroupNames, Elements, uniqueGroupName ) 
 | 
    { 
 | 
      // Check if there is a Hierarchy with the group name exist 
 | 
      hierarchy := select( this, Hierarchy, hierarchy, true, hierarchy.Name() = uniqueGroupName ); 
 | 
     
 | 
      if( isnull( hierarchy ) ) 
 | 
      { 
 | 
        hierarchy := LibDMF_Hierarchy::Create( this, 
 | 
                                               uniqueGroupName ); 
 | 
      } 
 | 
     
 | 
      // Mark the Hierarchy to not be removed 
 | 
      hierarchy.IsSoftDeleted( false ); 
 | 
     
 | 
      // Update the timestamp for the Hierarchy 
 | 
      hierarchy.UpdateTimeStampLastUpdated(); 
 | 
    } 
 | 
     
 | 
    // 3. Remove all the Hierarchies for which there are no more set types "linked" to 
 | 
    traverse( this, Hierarchy, hierarchy, hierarchy.IsSoftDeleted() ) 
 | 
    { 
 | 
      hierarchy.Delete(); 
 | 
    } 
 | 
  *] 
 | 
} 
 |