admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Quintiq file version 2.0
#parent: #root
Method CreateDemoScenariosAndImport (
  String democategory,
  String demoscenario,
  MPSync mpsync,
  MPDomainHandler mpdomainhandler,
  SWF_WorkflowDataset workflow,
  String snopusername
) as ScenarioMP
{
  TextBody:
  [*
    // Load Sales demo workflow data from binary string
    this.SynchronizeDemoWorkflowDataset( democategory, workflow );  
    
    // Retrive DemoScenario kt
    table := DemoScenarioTable::Table();
    scenarios := construct( Strings );
    scenarioMP := null( ScenarioMP );
    datapath := GlobalParameters_MP::GetDefinitonsDir() + "/" + GlobalParameters_MP::GetSalesDemoPath() + "/" + democategory;
    i := 0;
    
    
    scenarios := selectvalues( table, Rows, r, r.Demo() = democategory and ( demoscenario = Translations::Scenario_DemoScenario_All() or r.Scenario() = demoscenario ), r.Scenario() );
    
    // To make sure Transaction in domainhandler is completed
    Transaction::Transaction().Propagate();
    
    // Go through every row in DemoScenario and create scenario and import data respectively
    traverse( scenarios, Elements, e , e <> Translations::Scenario_DemoScenario_All() )
    {  
      base := null( ScenarioMP );
      
      foldername :=  ifexpr( e = '-', democategory, democategory + '/' + e );
      datasetname := ScenarioManager::GetUniqueCompanyDatasetName( ScenarioManager::ScenarioMP() );
    
      rootfolder := select( this, RootScenarioFolder, root, true, true );
      folder := select( rootfolder, Children, child, child.Name() = democategory );
      
      if( isnull( folder ) )
      {
        folder := this.CreateFolder( rootfolder, democategory, democategory, snopusername );
      }
      
      // We do not use the CreateScenarioMP because we need specific dataset name.
      base := ScenarioMP::Create( this,
                                  folder,
                                  datasetname,
                                  ifexpr( e = '-', foldername, e ),
                                  '',
                                  GlobalParameters_MP::GetStorageState(),
                                  '',
                                  snopusername );
    
      // We will return the first created demo dataset to be selected in App.
      // All strategies, account and bookmarks for a Demo type is the same, we only need to import it once
     if( i = 0 ) 
      {    
        scenarioMP := base; // We will return the first created demo dataset to be selected in App.
           
        accounts := ScenarioManager::ReadAccountFile( datapath );
        this.SynchronizeAccounts( accounts );
       
        strategies := ScenarioManager::ReadStrategiesFile( datapath );
        this.ImportStrategies( strategies );
    
        bookmarks := ScenarioManager::ReadBookmarksFile( datapath );  
        this.ImportBookmarks( bookmarks ); 
        
        kpisettings := ScenarioManager::ReadKPISettingsFile( datapath );
        this.ImportKPISettings( kpisettings );
        
        importprofiles := MPSync::ReadImportProfilesFile( datapath );
        mpsync.ImportUserGroupProfiles( importprofiles ); 
        mpsync.SynchronizeDemoImportProfiles( datapath );
      }
     
      i := i + 1; 
       
      // Add authorization to all user groups to scenario
      base.AuthorizeAll();
    
      kb := select( this.MDSScenarioManager(), MDSKBs, kb, kb.Name().ToUpper() = this.CompanyKBName().ToUpper() );
      this.UpdateScenarioKBInfo( base, kb.Name(), kb.Branch(), kb.ChangeNr(), base.State(), kb.Description() );
    
      mdsid := MDSID::Create( base.DatasetMDSID() );
      row := select( table, Rows, r, r.Demo() = democategory and r.Scenario() = base.Name() );    
      
      strategy := ifexpr( row.StrategyIsWildcard(), Strategy::DefaultStrategyName(), row.Strategy() )
        
      MacroPlan::JobSynchronizeDemoDataAndRunOptimizer( mdsid, base, foldername, democategory, strategy );
    }
    
    return scenarioMP;
  *]
}