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
Quintiq file version 2.0
#parent: #root
Method SynchronizeSubscription (
  String participationID_i,
  String eventID_i,
  String calendarType_i,
  String calendarID_i,
  Boolean eventIsRecurring_i,
  Boolean eventIsAllDay_i,
  Duration eventStartTimeOfDay_i,
  Duration eventDuration_i,
  Date startDate_i,
  Boolean hasSpecificPeriod_i,
  String periodType_i,
  Date periodStartDate_i,
  Number periodNrOfOccurrences_i,
  Date periodEndDate_i
) as LibCal_Subscription
{
  Description: 'Synchronize a subscription, typically with the data of an integration object that is imported by the DIF.'
  TextBody:
  [*
    // Get the subscription that must be synchronized.
    subscription := select( this.Subscriptions(), Elements, subscr, true, subscr.ParticipationID() = participationID_i );
    
    // Get the event that is subscribed to.
    event := LibCal_Event::FindByEventID( eventID_i );
    
    if( not isnull( event ) )
    {
      useLeadingPeriod := not hasSpecificPeriod_i;  // HasSpecificPeriod is easier to understand
                                                    // in the source (e.g. Excelsheet) from which the data is imported.
      if( not isnull( subscription ) )
      {
        if( event <> subscription.Event() )
        {
          // Change the event to which is subscribed.
          // Very unlikely to happen, is not supported in the UI.
          // Can happen though if IsAlwaysAvailable is changed from FALSE to TRUE (or vice versa).
          subscription.Event().RemoveSubscriber( this );
          subscription := event.AddSubscriber( this, useLeadingPeriod );
          subscription.ParticipationID( participationID_i );
        }
      }
      else  // Subscription does not exist.
      {
        // Add the calendar as subcriber to the event from another calendar.
        subscription := event.AddSubscriber( this, useLeadingPeriod );
        subscription.ParticipationID( participationID_i );
        subscription.IsCreatedByImport( true );
      }
    
      // Synchronize the data.
      subscription.Synchronize( participationID_i,
                                calendarType_i,
                                calendarID_i,
                                eventIsRecurring_i,
                                eventIsAllDay_i,
                                eventStartTimeOfDay_i,
                                eventDuration_i,
                                startDate_i,
                                hasSpecificPeriod_i,
                                periodType_i,
                                periodStartDate_i,
                                periodNrOfOccurrences_i,
                                periodEndDate_i );
    }
    else
    {
      LibCal_Util::Warning( "LibCal_Calendar.SynchronizeSubscription() : Event with ID '" + eventID_i + "' not found for IntegrationParticipation with ID '" + participationID_i + "'." );
    }
    
    return subscription;
  *]
}