120 lines
3.9 KiB
Python
120 lines
3.9 KiB
Python
from databases import (
|
|
Events,
|
|
Services,
|
|
Service2Events,
|
|
Employees,
|
|
Staff,
|
|
)
|
|
from api_events.events.events.events_bind_services import (
|
|
ServiceBindEmployeeEventMethods,
|
|
)
|
|
|
|
|
|
def create_all_events_from_actions():
|
|
import api_events.events as events
|
|
|
|
active_confirmed = dict(
|
|
created_by="System",
|
|
confirmed_by="System",
|
|
is_confirmed=True,
|
|
active=True,
|
|
deleted=False,
|
|
is_notification_send=True,
|
|
)
|
|
an_empty_list, duplicate_list = [], []
|
|
|
|
for event in events.__all__:
|
|
event_selected = getattr(events, event)
|
|
for (
|
|
event_selected_key,
|
|
event_selected_one,
|
|
) in event_selected.__event_keys__.items():
|
|
an_empty_list.append(event_selected_key)
|
|
event_selected_function = getattr(event_selected, event_selected_one, None)
|
|
|
|
if endpoint_match := event_selected.action_match:
|
|
if event_selected_function:
|
|
selected_event = Events.find_one(
|
|
event_type=event_selected.event_type,
|
|
function_class=event,
|
|
function_code=event_selected_key,
|
|
endpoint_id=endpoint_match.id,
|
|
endpoint_uu_id=str(endpoint_match.uu_id),
|
|
**active_confirmed,
|
|
)
|
|
if not selected_event:
|
|
created_event = Events.create(
|
|
event_type=event_selected.event_type,
|
|
function_class=event,
|
|
function_code=event_selected_key,
|
|
endpoint_id=endpoint_match.id,
|
|
endpoint_uu_id=str(endpoint_match.uu_id),
|
|
**active_confirmed,
|
|
)
|
|
print(f"Event created: {created_event.uu_id}")
|
|
|
|
for item in an_empty_list:
|
|
if an_empty_list.count(item) > 1:
|
|
if item not in duplicate_list:
|
|
duplicate_list.append(item)
|
|
|
|
if duplicate_list:
|
|
raise Exception(
|
|
f"Duplicate events found: {duplicate_list}. Check events folder look for given uu-ids."
|
|
)
|
|
|
|
return True
|
|
|
|
|
|
def add_events_all_services_and_occupant_types():
|
|
import api_events.tasks2events as tasks2events
|
|
|
|
active_confirmed = dict(
|
|
created_by="System",
|
|
confirmed_by="System",
|
|
is_confirmed=True,
|
|
active=True,
|
|
deleted=False,
|
|
is_notification_send=True,
|
|
)
|
|
for event_block in tasks2events.__all__:
|
|
event_block_class = getattr(tasks2events, event_block)
|
|
service_selected = Services.find_one(
|
|
service_code=getattr(event_block_class, "service_code", None),
|
|
)
|
|
if not service_selected:
|
|
raise Exception(f"{event_block_class.service_code} service is not found")
|
|
|
|
service_selected.update(
|
|
related_responsibility=getattr(event_block_class, "related_code", None)
|
|
)
|
|
for block in event_block_class():
|
|
event_id, event_uu_id = block
|
|
Service2Events.find_or_create(
|
|
service_id=service_selected.id,
|
|
service_uu_id=str(service_selected.uu_id),
|
|
event_id=event_id,
|
|
event_uu_id=event_uu_id,
|
|
**active_confirmed,
|
|
)
|
|
|
|
|
|
def add_events_to_system_super_user():
|
|
|
|
add_service = Services.find_one(service_code="SRE-SUE")
|
|
if not add_service:
|
|
raise Exception("Service not found")
|
|
|
|
find_staff = Staff.find_one(staff_code="SUE")
|
|
if not find_staff:
|
|
raise Exception("Super User not found")
|
|
|
|
add_employee = Employees.find_one(staff_id=find_staff.id)
|
|
if not add_employee:
|
|
raise Exception("Super User Employee not found")
|
|
|
|
ServiceBindEmployeeEventMethods.bind_services_employee(
|
|
service_id=add_service.id,
|
|
employee_id=add_employee.id,
|
|
)
|