@@ -40,6 +40,7 @@ public class Event extends AccountOwnedModel implements JsonObject {
4040 private List <Notification > notifications = new ArrayList <>();
4141 private List <Participant > participants = new ArrayList <>();
4242 private Map <String , String > metadata = new HashMap <>();
43+ private final Map <String , Object > modifiedFields = new HashMap <>();
4344
4445 /** for deserialization only */ public Event () {}
4546
@@ -186,62 +187,77 @@ public String toString() {
186187
187188 public void setEventCollectionId (String eventCollectionId ) {
188189 this .event_collection_id = eventCollectionId ;
190+ this .modifiedFields .put ("event_collection_id" , this .event_collection_id );
189191 }
190192
191193 public void setTitle (String title ) {
192194 this .title = title ;
195+ this .modifiedFields .put ("title" , this .title );
193196 }
194197
195198 public void setDescription (String description ) {
196199 this .description = description ;
200+ this .modifiedFields .put ("description" , this .description );
197201 }
198202
199203 public void setWhen (When when ) {
200204 this .when = when ;
205+ this .modifiedFields .put ("when" , this .when );
201206 }
202207
203208 public void setLocation (String location ) {
204209 this .location = location ;
210+ this .modifiedFields .put ("location" , this .location );
205211 }
206212
207213 public void setCustomerEventId (String customerEventId ) {
208214 this .customer_event_id = customerEventId ;
215+ this .modifiedFields .put ("customer_event_id" , this .customer_event_id );
209216 }
210217
211218 public void setCapacity (Integer capacity ) {
212219 this .capacity = capacity ;
220+ this .modifiedFields .put ("capacity" , this .capacity );
213221 }
214222
215223 public void setParticipants (List <Participant > participants ) {
216224 this .participants = participants ;
225+ this .modifiedFields .put ("participants" , this .participants );
217226 }
218227
219228 public void setBusy (Boolean busy ) {
220229 this .busy = busy ;
230+ this .modifiedFields .put ("busy" , this .busy );
221231 }
222232
223233 public void setMetadata (Map <String , String > metadata ) {
224234 this .metadata = metadata ;
235+ this .modifiedFields .put ("metadata" , this .metadata );
225236 }
226237
227238 public void setConferencing (Conferencing conferencing ) {
228239 this .conferencing = conferencing ;
240+ this .modifiedFields .put ("conferencing" , this .conferencing );
229241 }
230242
231243 public void setRoundRobinOrder (List <String > roundRobinOrder ) {
232244 this .round_robin_order = roundRobinOrder ;
245+ this .modifiedFields .put ("round_robin_order" , this .round_robin_order );
233246 }
234247
235248 public void setNotifications (List <Notification > notifications ) {
236249 this .notifications = notifications ;
250+ this .modifiedFields .put ("notifications" , this .notifications );
237251 }
238252
239253 public void setRecurrence (Recurrence recurrence ) {
240254 this .recurrence = recurrence ;
255+ this .modifiedFields .put ("recurrence" , this .recurrence );
241256 }
242257
243258 public void setReminders (Reminders reminders ) {
244259 this .reminders = reminders ;
260+ this .modifiedFields .put ("reminders" , this .reminders );
245261 }
246262
247263 /**
@@ -251,6 +267,7 @@ public void setReminders(Reminders reminders) {
251267 */
252268 public void addMetadata (String key , String value ) {
253269 this .metadata .put (key , value );
270+ this .modifiedFields .put ("metadata" , this .metadata );
254271 }
255272
256273 /**
@@ -269,6 +286,7 @@ public void addNotification(Notification... notifications) {
269286 this .notifications = new ArrayList <>();
270287 }
271288 this .notifications .addAll (Arrays .asList (notifications ));
289+ this .modifiedFields .put ("notifications" , this .notifications );
272290 }
273291
274292 /**
@@ -284,6 +302,7 @@ public void clearNotifications() {
284302 */
285303 public void addParticipants (Participant ... participants ) {
286304 this .participants .addAll (Arrays .asList (participants ));
305+ this .modifiedFields .put ("participants" , serializeParticipants ());
287306 }
288307
289308 /**
@@ -311,28 +330,24 @@ void validate() {
311330
312331 @ Override
313332 protected Map <String , Object > getWritableFields (boolean creation ) {
314- Map <String , Object > params = new HashMap <>();
315- if (creation ) {
316- Maps .putIfNotNull (params , "calendar_id" , getCalendarId ());
317- // Reminders, when creating an event, need to be included in the main object
318- if (reminders != null && reminders .reminder_minutes != null && reminders .reminder_method != null ) {
319- params .put ("reminder_minutes" , String .format ("[%d]" , reminders .reminder_minutes ));
320- params .put ("reminder_method" , reminders .reminder_method );
321- }
333+ if (!creation ) {
334+ return modifiedFields ;
322335 }
323336
324- List <Map <String , Object >> participantWritableFields = Collections .emptyList ();
325- if (participants != null && !participants .isEmpty ()) {
326- participantWritableFields = participants .stream ()
327- .map (participant -> participant .getWritableFields (creation ))
328- .collect (Collectors .toList ());
337+ Map <String , Object > params = new HashMap <>();
338+
339+ // Reminders, when creating an event, need to be included in the main object
340+ if (reminders != null && reminders .reminder_minutes != null && reminders .reminder_method != null ) {
341+ params .put ("reminder_minutes" , String .format ("[%d]" , reminders .reminder_minutes ));
342+ params .put ("reminder_method" , reminders .reminder_method );
329343 }
330344
345+ Maps .putIfNotNull (params , "calendar_id" , getCalendarId ());
331346 Maps .putIfNotNull (params , "when" , getWhen ());
332347 Maps .putIfNotNull (params , "title" , getTitle ());
333348 Maps .putIfNotNull (params , "description" , getDescription ());
334349 Maps .putIfNotNull (params , "location" , getLocation ());
335- Maps .putIfNotNull (params , "participants" , participantWritableFields );
350+ Maps .putIfNotNull (params , "participants" , serializeParticipants () );
336351 Maps .putIfNotNull (params , "busy" , getBusy ());
337352 Maps .putIfNotNull (params , "metadata" , getMetadata ());
338353 Maps .putIfNotNull (params , "conferencing" , getConferencing ());
@@ -341,6 +356,16 @@ protected Map<String, Object> getWritableFields(boolean creation) {
341356 return params ;
342357 }
343358
359+ private List <Map <String , Object >> serializeParticipants () {
360+ if (this .participants == null || this .participants .isEmpty ()) {
361+ return Collections .emptyList ();
362+ }
363+
364+ return this .participants .stream ()
365+ .map (participant -> participant .getWritableFields (false ))
366+ .collect (Collectors .toList ());
367+ }
368+
344369 public static class Recurrence {
345370 private String timezone ;
346371 private List <String > rrule ;
0 commit comments