yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
Quintiq file version 2.0
#parent: #root
StaticMethod CanExecuteImportProfiles (
  output String feedback_o,
  MPSync mpsync,
  Boolean isrefreshfromsource,
  UserImportProfiles userimportprofiles
) declarative remote as Boolean
{
  Description: 'Validate whether the selected import profiles have different sources for a single object group'
  TextBody:
  [*
    // If MPSync is empty, prompt the user to refresh from data source
    if( not isrefreshfromsource 
        and guard( mpsync.IOBase( relsize ), 0 ) = 0 )
    {
      feedback_o := Translations::MPSync_ImportProfile_ValidateInput_EmptyMPSync();
    }
    // Check if there are more than one userimportprofiles
    else if( userimportprofiles.Size() > 1 )
    {
      stringbreaker := '[qQsTrBrk@]';
      
      // Get the name of expected import group name
      expectedGroups := selectuniquevalues( userimportprofiles, Elements.ImportObjectGroupInUserProfile, e, 
                                            e.IsIncludeInImportExport(), 
                                            e.ObjectGroupName() );
      // Get the unique name of the combination of user import profile, import group name, and import file location
      uniqueGroups := selectuniquevalues( userimportprofiles, Elements.BaseImportObjectGroupInProfile, e, 
                                          e.IsIncludeInImportExport(), 
                                          e.GetSourcePathObjectGroupString( stringbreaker ) );
      
      // If the number of expected groups is not the same as unique groups
      if( expectedGroups.Size() <> uniqueGroups.Size() )
      {
        // Select the set of duplicated import groups
        erroneousGroups := selectduplicates( uniqueGroups, Elements, e,
                                             true,
                                             e.RestString( e.FindString( stringbreaker, 0 ) ) );
        // Get the names of the duplicated import groups
        erroneousgroupnames := selectuniquevalues( erroneousGroups, Elements, e,
                                                   true,
                                                   e.RestString( e.FindString( stringbreaker, 0 ) ).ReplaceAll( stringbreaker, '' ) );
        erroneousgroupnames.Sort();
        erroneousgroups_feedback := construct( Strings );
        // Traverse all duplicated import groups' names to construct the feedback
        traverse( erroneousgroupnames, Elements, erroneousgroup_name )
        {
          // Get the user import profile names that has duplicating import groups that import data from different file locations
          erroneous_userimportprofilenames := selectvalues( userimportprofiles, Elements.BaseImportObjectGroupInProfile, groupinprofile,
                                                            groupinprofile.IsIncludeInImportExport()
                                                            and groupinprofile.ImportObjectGroup().GetDisplayName() = erroneousgroup_name
                                                            and erroneousGroups.Find( groupinprofile.GetSourcePathObjectGroupString( stringbreaker ) ) <> -1,
                                                            groupinprofile.BaseImportProfile().astype( UserImportProfile ).Name() );
          
          erroneous_userimportprofilenames.Sort();
          // Generate feedback text
          erroneousgroupandprofile := erroneousgroup_name
                                      + ' - '
                                      + erroneous_userimportprofilenames.ToString( ', ' );
          // Add feedback text to the set
          erroneousgroups_feedback.Add( erroneousgroupandprofile );
        }
        
        erroneousgroups_detail := erroneousgroups_feedback.ToString( String::NewLine() );
        feedback_o := Translations::MPSync_ImportProfile_ValidateInput_InvalidSources( erroneousgroups_detail );
      }
    }
    
    return feedback_o = '';
  *]
}