Kevin Kok Khah Whey
2023-11-07 5ae534ab606e6f2ba5ea60914224d665b0447d5a
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
Quintiq file version 2.0
#parent: #root
StaticMethod CreatePeriodTaskOperationMessage (
  MacroPlan macroplan
)
{
  Description: 'Create sanity check message for process match campaign quantity.'
  TextBody:
  [*
    // Get the limit for number of sanity check messages
    messagelimit := macroplan.GlobalParameters_MP().SanityCheckLimit();
    
    // Get PeriodTaskOperations that has sanity check violation(s)
    invalidobjects := selectsortedset( macroplan, 
                                       SanityCheckGroup.astype( SanityCheckGroupCampaign ).InvalidPeriodTaskOperation, 
                                       invalidobject,
                                       true,
                                       invalidobject.SanityCheckCampaignMostSevere() );
                                       
    objcount := 0;
    // Traverse the set of PeriodTaskOperations and create sanity check message
    // as long as the number of PeriodTaskOperations processed doesn't exceed the limit of number of messages
    traverse( invalidobjects,
              Elements,
              invalidobject,
              objcount <= messagelimit )
    {
      objcount := objcount + 1;
    
      feedbacks := construct( Strings );
      sanitycheckfeedbacks := construct( Strings );
      
      // Get sanity check violation messages and categories
      invalidobject.DoSanityCheckGroupProcessMatchCampaignQuantity( feedbacks, sanitycheckfeedbacks );
      
      i := 0;
      // Traverse each sanity check violation categories
      traverse( sanitycheckfeedbacks, 
                Elements, 
                scfb )
      {
        // Check if there're any SanityCheckMessageCampaign with the same description, if there's none, create one
        if( not exists( invalidobject, SanityCheckMessageCampaign, msg, msg.Description() = scfb ) )
        {
          //tokenize msg to retrieve category level and seperate the actual feedback
          sanitycheckmessage := SanityCheckMessageCampaign::Create( invalidobject.SanityCheckGroupCampaign(),
                                                                     feedbacks.Element( i ),
                                                                     true,
                                                                     scfb );
      
          sanitycheckmessage.PeriodTaskOperation( relset, invalidobject );
        }
        i := i + 1;
      }
      
      
    }
  *]
}