in ees_microsoft_outlook/microsoft_outlook_calendar.py [0:0]
def get_calendar(self, ids_list_calendars, accounts, start_time, end_time):
"""This method is used to get documents of calendar and mapped with Workplace Search fields
:param ids_list_calendars: List of ids of documents
param accounts: List of user accounts
:param start_time: Start time for fetching the calendar events
:param end_time: End time for fetching the calendar events
Returns:
documents: Documents with all calendar events
"""
documents = []
start_time = convert_datetime_to_ews_format(start_time)
end_time = convert_datetime_to_ews_format(end_time)
calendar_schema = get_schema_fields(
constant.CALENDARS_OBJECT.lower(), self.config.get_value("objects")
)
for account in accounts:
# Logic to set time zone according to user account
self.time_zone = account.default_timezone
try:
# Logic to fetch Calendar Events
for calendar in account.calendar.filter(
last_modified_time__gt=start_time,
last_modified_time__lt=end_time,
).only(
"required_attendees",
"type",
"recurrence",
"last_modified_time",
"subject",
"start",
"end",
"location",
"organizer",
"body",
"has_attachments",
"attachments",
):
# Logic to insert calendar into global_keys object
insert_document_into_doc_id_storage(
ids_list_calendars,
calendar.id,
"",
constant.CALENDARS_OBJECT.lower(),
self.config.get_value("connector_platform_type"),
)
(calendar_obj, calendar_attachment,) = self.calendar_to_docs(
ids_list_calendars,
calendar,
account.primary_smtp_address,
start_time,
end_time,
str(calendar),
)
calendar_map = {}
calendar_map["_allow_permissions"] = []
if self.config.get_value("enable_document_permission"):
calendar_map["_allow_permissions"] = [
account.primary_smtp_address
]
calendar_map["type"] = calendar_obj["type"]
for ws_field, ms_fields in calendar_schema.items():
calendar_map[ws_field] = calendar_obj[ms_fields]
documents.append(calendar_map)
if calendar_attachment:
documents.extend(calendar_attachment)
# Logic to fetch Custom Calendar Events
for child_calendar in account.calendar.children:
for calendar in child_calendar.filter(
last_modified_time__gt=start_time,
last_modified_time__lt=end_time,
).only(
"required_attendees",
"type",
"recurrence",
"last_modified_time",
"subject",
"start",
"end",
"location",
"organizer",
"body",
"has_attachments",
"attachments",
):
# Logic to insert calendar into global_keys object
insert_document_into_doc_id_storage(
ids_list_calendars,
calendar.id,
"",
constant.CALENDARS_OBJECT.lower(),
self.config.get_value("connector_platform_type"),
)
(calendar_obj, calendar_attachment,) = self.calendar_to_docs(
ids_list_calendars,
calendar,
account.primary_smtp_address,
start_time,
end_time,
str(child_calendar),
)
calendar_map = {}
calendar_map["_allow_permissions"] = []
if self.config.get_value("enable_document_permission"):
calendar_map["_allow_permissions"] = [
account.primary_smtp_address
]
calendar_map["type"] = calendar_obj["type"]
for ws_field, ms_fields in calendar_schema.items():
calendar_map[ws_field] = calendar_obj[ms_fields]
documents.append(calendar_map)
if calendar_attachment:
documents.extend(calendar_attachment)
except requests.exceptions.RequestException as request_error:
raise requests.exceptions.RequestException(
f"Error while fetching calendar data for {account.primary_smtp_address}. Error: {request_error}"
)
except Exception as exception:
self.logger.info(
f"Error while fetching calendar data for {account.primary_smtp_address}. Error: {exception}"
)
pass
return documents