|
| 1 | +/* |
| 2 | + * Copyright (c) 2023. Smart Operating Block |
| 3 | + * |
| 4 | + * Use of this source code is governed by an MIT-style |
| 5 | + * license that can be found in the LICENSE file or at |
| 6 | + * https://opensource.org/licenses/MIT. |
| 7 | + */ |
| 8 | + |
| 9 | +package infrastructure.digitaltwins.parser |
| 10 | + |
| 11 | +import entities.events.EmptyEvent |
| 12 | +import entities.events.Event |
| 13 | +import entities.events.SurgeryBookingEvent |
| 14 | +import entities.surgery.SurgeryBookingData.SurgeryBooking |
| 15 | +import infrastructure.digitaltwins.events.LifecycleEvents.LifecycleEvent |
| 16 | +import infrastructure.digitaltwins.events.TwinProperties.DTEventTypes.CREATE |
| 17 | +import infrastructure.digitaltwins.events.TwinProperties.DTModelID.SURGERY_BOOKING_MODEL_ID |
| 18 | + |
| 19 | +/** |
| 20 | + * The parser of Azure Digital Twins Lifecycle Events. |
| 21 | + */ |
| 22 | +class LifecycleEventParser { |
| 23 | + |
| 24 | + /** |
| 25 | + * Manage the event of create and delete of a Digital Twin. |
| 26 | + * @param lifecycleTwinEvent the update event. |
| 27 | + * @return the specific [Event] |
| 28 | + */ |
| 29 | + fun manageEvent(lifecycleTwinEvent: LifecycleEvent): Event<Any> = |
| 30 | + when (lifecycleTwinEvent.model) { |
| 31 | + SURGERY_BOOKING_MODEL_ID.id -> manageSurgeryBookingEvents(lifecycleTwinEvent) |
| 32 | + else -> EmptyEvent() |
| 33 | + } |
| 34 | + |
| 35 | + private fun manageSurgeryBookingEvents(lifecycleTwinEvent: LifecycleEvent): Event<Any> = |
| 36 | + when (lifecycleTwinEvent.eventType) { |
| 37 | + CREATE.type -> { |
| 38 | + SurgeryBookingEvent( |
| 39 | + data = SurgeryBooking( |
| 40 | + lifecycleTwinEvent.data["booking_date_time"].toString(), |
| 41 | + lifecycleTwinEvent.data["surgery_type"].toString() |
| 42 | + ), |
| 43 | + dateTime = lifecycleTwinEvent.eventDateTime |
| 44 | + ) |
| 45 | + } |
| 46 | + else -> EmptyEvent() |
| 47 | + } |
| 48 | +} |
0 commit comments