haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
Quintiq file version 2.0
#parent: #root
Method SynchronizeEvent (
  String eventID_i,
  String calendarType_i,
  String calendarID_i,
  String category_i,
  String subject_i,
  String description_i,
  String type_i,
  Real partialCapacity_i,
  Boolean isDefault_i,
  Boolean isRecurring_i,
  Boolean isAllDay_i,
  Duration startTimeOfDay_i,
  Duration duration_i,
  String patternType_i,
  Number recurrenceInterval_i,
  Boolean daily_IsEveryWeekday_i,
  String weekly_Weekdays_i,
  Boolean monthly_IsDay_i,
  Number monthly_Day_i,
  String monthly_WeekOfMonth_i,
  String monthly_DayOfWeek_i,
  Boolean yearly_IsDay_i,
  Number yearly_Month_i,
  Number yearly_Day_i,
  String yearly_WeekOfMonth_i,
  String yearly_DayOfWeek_i,
  String leadPartID_i,
  Date startDate_i,
  Boolean hasSpecificPeriod_i,
  String periodType_i,
  Date periodStartDate_i,
  Number periodNrOfOccurrences_i,
  Date periodEndDate_i
) as LibCal_Event
{
  Description:
  [*
    Synchronize an event, typically with the data of an integration object that is imported by the DIF.
    The LeadingParticipation of the event is also synchronized.
  *]
  TextBody:
  [*
    // Get the event that must be synchronized.
    event := select( this, Event, evnt, true, evnt.EventID() = eventID_i );
    
    // If the event does not exist for the current calendar yet a new event should be created
    // This can however only be done if the event does not already exist in another calendar. 
    if( isnull( event ) )
    {
      eventInOtherCalendar := LibCal_Event::FindByEventID( eventID_i );
      if( isnull( eventInOtherCalendar ) )
      {
        // Create a new event.
        event := LibCal_Event::CreateForImport( this, eventID_i );
      }
      else
      {
        LibCal_Util::Warning( this.DefinitionName() + ".SynchronizeEvent() : Event with ID '" + eventID_i + "' cannot be created " +
                              "for calendar " + calendarType_i + "." + calendarID_i + " because it already exists for calendar " +
                              eventInOtherCalendar.Calendar().DefinitionName() + "." + eventInOtherCalendar.Calendar().CalendarID() );
      }
    }
    
    // Synchronize the data.
    if( not isnull( event ) )
    {   
      event.Synchronize( category_i,
                         subject_i,
                         description_i,
                         type_i,
                         partialCapacity_i,
                         isDefault_i,
                         isRecurring_i,
                         isAllDay_i,
                         startTimeOfDay_i,
                         duration_i,
                         patternType_i,
                         recurrenceInterval_i,
                         daily_IsEveryWeekday_i,
                         weekly_Weekdays_i,
                         monthly_IsDay_i,
                         monthly_Day_i,
                         monthly_WeekOfMonth_i,
                         monthly_DayOfWeek_i,
                         yearly_IsDay_i,
                         yearly_Month_i,
                         yearly_Day_i,
                         yearly_WeekOfMonth_i,
                         yearly_DayOfWeek_i );
    
      // Synchronize the LeadingParticipation as part of synchronizing the Event.
      // The other participations (subscriptions) are synchronized later on.   
      if( leadPartID_i <> "" )
      {
        // If necessary, create a LeadingParticipation for the event.
        participationCreated := false;
        if( isnull( event.LeadingParticipation() ) )
        {
          LibCal_LeadingParticipation::CreateForImport( this, leadPartID_i, event );
          participationCreated := true;
        }
    
        // Synchronize the data.
        event.LeadingParticipation().Synchronize( leadPartID_i,
                                                  calendarType_i,
                                                  calendarID_i,
                                                  isRecurring_i,
                                                  isAllDay_i,
                                                  startTimeOfDay_i,
                                                  duration_i,
                                                  startDate_i,
                                                  hasSpecificPeriod_i,
                                                  periodType_i,
                                                  periodStartDate_i,
                                                  periodNrOfOccurrences_i,
                                                  periodEndDate_i );
    
        // If a new LeadingParticipation was just created, SetDuration() and SetIsAllDay() of the event must be called.
        // These methods could not be executed during the synchronization of the event, because they depend on the event's
        // LeadingParticipation, which did not exist yet at that time.
        if( participationCreated )
        {      
          event.SetDuration( duration_i );
          event.SetIsAllDay( isAllDay_i );
        }
      }
      else
      {
        LibCal_Util::Warning( this.DefinitionName() + ".SynchronizeEvent() : No LeadingParticipation found " +
                              "in the integration data for event '" + event.Subject() + "' of calendar " + calendarType_i + "." + calendarID_i );
      }
    }
    
    return event;
  *]
}