lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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();
    }
  *]
}