Skip to content
Merged

1531 #1775

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions docs/src/content/docs/reference/components/google-calendar.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,56 @@ Type: ARRAY



### Update Event
Updates event in Google Calendar.

#### Properties

| Name | Type | Control Type | Description |
|:--------------:|:------------:|:--------------------:|:-------------------:|
| Calendar Identifier | STRING | SELECT | |
| Event | STRING | SELECT | Event to update. |
| Title | STRING | TEXT | New title of the event. |
| All Day Event? | BOOLEAN | SELECT | |
| Start Date | DATE | DATE | New start date of the event. |
| End Date | DATE | DATE | New end date of the event. |
| Start Date Time | DATE_TIME | DATE_TIME | New (inclusive) start time of the event. For a recurring event, this is the start time of the first instance. |
| End Date Time | DATE_TIME | DATE_TIME | New (exclusive) end time of the event. For a recurring event, this is the end time of the first instance. |
| Description | STRING | TEXT | New description of the event. Can contain HTML. |
| Attendees | [STRING\($email)] | ARRAY_BUILDER | New attendees of the event. |


### Output



Type: OBJECT


#### Properties

| Type | Control Type |
|:------------:|:--------------------:|
| STRING | TEXT |
| STRING | TEXT |
| STRING | TEXT |
| DATE_TIME | DATE_TIME |
| DATE_TIME | DATE_TIME |
| STRING | TEXT |
| STRING | TEXT |
| STRING | TEXT |
| STRING | TEXT |
| STRING | TEXT |
| STRING | TEXT |
| [{INTEGER\(additionalGuests), STRING\(comment), STRING\(displayName), STRING\(email), STRING\(id), BOOLEAN\(optional), BOOLEAN\(organizer), BOOLEAN\(resource), STRING\(responseStatus), BOOLEAN\(self)}] | ARRAY_BUILDER |
| [{STRING\(fileId), STRING\(fileUrl), STRING\(iconLink), STRING\(mimeType), STRING\(title)}] | ARRAY_BUILDER |
| {[{STRING\(method), INTEGER\(minutes)}]\(overrides), BOOLEAN\(useDefault)} | OBJECT_BUILDER |






<hr />

# Additional instructions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.bytechef.component.google.calendar.action.GoogleCalendarDeleteEventAction;
import com.bytechef.component.google.calendar.action.GoogleCalendarGetEventsAction;
import com.bytechef.component.google.calendar.action.GoogleCalendarGetFreeTimeSlotsAction;
import com.bytechef.component.google.calendar.action.GoogleCalendarUpdateEventAction;
import com.bytechef.component.google.calendar.trigger.GoogleCalendarEventTrigger;
import com.google.auto.service.AutoService;

Expand All @@ -52,7 +53,8 @@ public class GoogleCalendarComponentHandler implements ComponentHandler {
GoogleCalendarCreateQuickEventAction.ACTION_DEFINITION,
GoogleCalendarDeleteEventAction.ACTION_DEFINITION,
GoogleCalendarGetEventsAction.ACTION_DEFINITION,
GoogleCalendarGetFreeTimeSlotsAction.ACTION_DEFINITION)
GoogleCalendarGetFreeTimeSlotsAction.ACTION_DEFINITION,
GoogleCalendarUpdateEventAction.ACTION_DEFINITION)
.triggers(GoogleCalendarEventTrigger.TRIGGER_DEFINITION);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EVENT_ID;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EVENT_OUTPUT_PROPERTY;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.createCustomEvent;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.getEvent;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.updateEvent;

import com.bytechef.component.definition.ActionContext;
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.google.calendar.util.GoogleCalendarUtils;
import com.bytechef.component.google.calendar.util.GoogleCalendarUtils.CustomEvent;
import com.bytechef.google.commons.GoogleServices;
import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.Event;
import com.google.api.services.calendar.model.EventAttendee;
import java.io.IOException;
Expand Down Expand Up @@ -74,40 +74,24 @@ private GoogleCalendarAddAttendeesToEventAction() {
public static CustomEvent perform(
Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) throws IOException {

Calendar calendar = GoogleServices.getCalendar(connectionParameters);

String calendarId = inputParameters.getRequiredString(CALENDAR_ID);
String eventId = inputParameters.getRequiredString(EVENT_ID);

Event event = calendar
.events()
.get(calendarId, eventId)
.execute();
Event event = getEvent(inputParameters, connectionParameters);

List<String> newAttendees = inputParameters.getList(ATTENDEES, String.class, List.of());

List<EventAttendee> newEventAttendees = newAttendees
.stream()
.map(attendee -> new EventAttendee().setEmail(attendee))
.toList();

List<EventAttendee> attendees = event.getAttendees();

if (attendees == null) {
event.setAttendees(
newAttendees
.stream()
.map(attendee -> new EventAttendee().setEmail(attendee))
.toList());
event.setAttendees(newEventAttendees);
} else {
event.getAttendees()
.addAll(
newAttendees
.stream()
.map(attendee -> new EventAttendee().setEmail(attendee))
.toList());
.addAll(newEventAttendees);
}

Event updatedEvent = calendar
.events()
.update(calendarId, eventId, event)
.execute();

return createCustomEvent(updatedEvent);
return createCustomEvent(updateEvent(inputParameters, connectionParameters, event));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* Copyright 2023-present ByteChef Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.google.calendar.action;

import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.definition.ComponentDsl.array;
import static com.bytechef.component.definition.ComponentDsl.bool;
import static com.bytechef.component.definition.ComponentDsl.date;
import static com.bytechef.component.definition.ComponentDsl.dateTime;
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
import static com.bytechef.component.definition.ComponentDsl.string;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.ALL_DAY;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.ATTENDEES;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.CALENDAR_ID;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.CALENDAR_ID_PROPERTY;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.DESCRIPTION;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EMAIL;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.END;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EVENT_ID;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EVENT_OUTPUT_PROPERTY;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.START;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.SUMMARY;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.createCustomEvent;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.createEventDateTime;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.getEvent;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.updateEvent;

import com.bytechef.component.definition.ActionContext;
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.google.calendar.util.GoogleCalendarUtils;
import com.bytechef.component.google.calendar.util.GoogleCalendarUtils.CustomEvent;
import com.google.api.services.calendar.model.Event;
import com.google.api.services.calendar.model.EventAttendee;
import java.io.IOException;
import java.util.List;

/**
* @author Monika Kušter
*/
public class GoogleCalendarUpdateEventAction {

public static final ModifiableActionDefinition ACTION_DEFINITION = action("updateEvent")
.title("Update Event")
.description("Updates event in Google Calendar.")
.properties(
CALENDAR_ID_PROPERTY,
string(EVENT_ID)
.label("Event")
.description("Event to update.")
.options((ActionOptionsFunction<String>) GoogleCalendarUtils::getEventIdOptions)
.optionsLookupDependsOn(CALENDAR_ID)
.required(true),
string(SUMMARY)
.label("Title")
.description("New title of the event.")
.required(false),
bool(ALL_DAY)
.label("All Day Event?")
.required(false),
date(START)
.label("Start Date")
.description("New start date of the event.")
.displayCondition("%s == true".formatted(ALL_DAY))
.required(true),
date(END)
.label("End Date")
.description("New end date of the event.")
.displayCondition("%s == true".formatted(ALL_DAY))
.required(true),
dateTime(START)
.label("Start Date Time")
.description(
"New (inclusive) start time of the event. For a recurring event, this is the start time of the " +
"first instance.")
.displayCondition("%s == false".formatted(ALL_DAY))
.required(true),
dateTime(END)
.label("End Date Time")
.description(
"New (exclusive) end time of the event. For a recurring event, this is the end time of the " +
"first instance.")
.displayCondition("%s == false".formatted(ALL_DAY))
.required(true),
string(DESCRIPTION)
.label("Description")
.description("New description of the event. Can contain HTML.")
.required(false),
array(ATTENDEES)
.label("Attendees")
.description("New attendees of the event.")
.items(
string(EMAIL)
.label("Email")
.description("The attendee's email address."))
.required(false))
.output(outputSchema(EVENT_OUTPUT_PROPERTY))
.perform(GoogleCalendarUpdateEventAction::perform);

private GoogleCalendarUpdateEventAction() {
}

public static CustomEvent perform(
Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) throws IOException {

Event event = getEvent(inputParameters, connectionParameters);

List<String> attendees = inputParameters.getList(ATTENDEES, String.class, List.of());

if (!attendees.isEmpty()) {
List<EventAttendee> eventAttendees = attendees
.stream()
.map(attendee -> new EventAttendee().setEmail(attendee))
.toList();

List<EventAttendee> existingAttendees = event.getAttendees();
if (existingAttendees == null || existingAttendees.isEmpty()) {
event.setAttendees(eventAttendees);
} else {
event.getAttendees()
.addAll(eventAttendees);
}
}

String description = inputParameters.getString(DESCRIPTION);

if (description != null) {
event.setDescription(description);
}

String summary = inputParameters.getString(SUMMARY);

if (summary != null) {
event.setSummary(summary);
}

if (inputParameters.getBoolean(ALL_DAY) != null) {
event
.setEnd(createEventDateTime(inputParameters, END))
.setStart(createEventDateTime(inputParameters, START));
}

return createCustomEvent(updateEvent(inputParameters, connectionParameters, event));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.ALL_DAY;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.CALENDAR_ID;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.DATE_RANGE;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EVENT_ID;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EVENT_TYPE;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.FROM;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.LOCAL_TIME_MAX;
Expand Down Expand Up @@ -209,6 +210,15 @@ private static List<CustomEvent> convertToCustomEvents(List<Event> eventList) {
.toList();
}

public static Event getEvent(Parameters inputParameters, Parameters connectionParameters) throws IOException {
Calendar calendar = GoogleServices.getCalendar(connectionParameters);

return calendar
.events()
.get(inputParameters.getRequiredString(CALENDAR_ID), inputParameters.getRequiredString(EVENT_ID))
.execute();
}

public static List<Option<String>> getEventIdOptions(
Parameters inputParameters, Parameters connectionParameters, Map<String, String> dependencyPaths,
String searchText, Context context) throws IOException {
Expand All @@ -233,6 +243,16 @@ public static List<Option<String>> getEventIdOptions(
return options;
}

public static Event updateEvent(Parameters inputParameters, Parameters connectionParameters, Event event)
throws IOException {
Calendar calendar = GoogleServices.getCalendar(connectionParameters);

return calendar
.events()
.update(inputParameters.getRequiredString(CALENDAR_ID), inputParameters.getRequiredString(EVENT_ID), event)
.execute();
}

@SuppressFBWarnings("EI")
public record CustomEvent(
String iCalUID, String id, String summary, String description, Temporal startTime, Temporal endTime,
Expand Down
Loading
Loading