@burgan-tech/morph-touch-runtime 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/burgan-tech-morph-touch-runtime-0.0.2.tgz +0 -0
- package/package.json +21 -0
- package/touch/Extensions/.gitkeep +0 -0
- package/touch/Functions/.gitkeep +0 -0
- package/touch/Functions/check-livekit-room-access.1.0.0.json +28 -0
- package/touch/Functions/check-livekit-room-access.http +44 -0
- package/touch/Functions/get-absence-entry.1.0.0.json +28 -0
- package/touch/Functions/get-advisor-stats.1.0.0.json +27 -0
- package/touch/Functions/get-available-slots.1.0.0.json +30 -0
- package/touch/Functions/get-available-slots.http +29 -0
- package/touch/Functions/get-chat-rooms.1.0.0.json +28 -0
- package/touch/Functions/get-chat-rooms.http +62 -0
- package/touch/Functions/get-customer-info.1.0.0.json +27 -0
- package/touch/Functions/get-matrix-sync.1.0.0.json +28 -0
- package/touch/Functions/get-rezervations.1.0.0.json +26 -0
- package/touch/Functions/get-rezervations.http +59 -0
- package/touch/Functions/get-room-messages.1.0.0.json +29 -0
- package/touch/Functions/get-room-messages.http +45 -0
- package/touch/Functions/rezervation-transfer.http +118 -0
- package/touch/Functions/send-room-message.1.0.0.json +29 -0
- package/touch/Functions/src/CheckLivekitRoomAccessMapping.csx +238 -0
- package/touch/Functions/src/GetAbsenceEntryMapping.csx +225 -0
- package/touch/Functions/src/GetAdvisorStatsMapping.csx +190 -0
- package/touch/Functions/src/GetAvailableSlotsMapping.csx +468 -0
- package/touch/Functions/src/GetChatRoomsMapping.csx +202 -0
- package/touch/Functions/src/GetCustomerInfoMapping.csx +140 -0
- package/touch/Functions/src/GetMatrixSyncMapping.csx +197 -0
- package/touch/Functions/src/GetRezervationsMapping.csx +162 -0
- package/touch/Functions/src/GetRoomMessagesMapping.csx +165 -0
- package/touch/Functions/src/SendCancelNotificationMapping.csx +63 -0
- package/touch/Functions/src/SendRoomMessageMapping.csx +131 -0
- package/touch/Schemas/.gitkeep +0 -0
- package/touch/Schemas/absence-entry.1.0.0.json +232 -0
- package/touch/Schemas/advisor-chat-rooms.1.0.0.json +62 -0
- package/touch/Schemas/chat-room.1.0.0.json +110 -0
- package/touch/Schemas/notification-sender.1.0.0.json +159 -0
- package/touch/Schemas/portfolio-manager.1.0.0.json +63 -0
- package/touch/Schemas/rezervation.1.0.0.json +102 -0
- package/touch/Tasks/.gitkeep +0 -0
- package/touch/Tasks/cancel-absence-entry-for-rezervation.1.0.0.json +21 -0
- package/touch/Tasks/check-already-completed-chat-room.1.0.0.json +24 -0
- package/touch/Tasks/check-duplicate-portfolio-manager.1.0.0.json +23 -0
- package/touch/Tasks/check-duplicate-rezervation.1.0.0.json +23 -0
- package/touch/Tasks/check-existing-permanent-chat-room.1.0.0.json +21 -0
- package/touch/Tasks/check-randevu-time.1.0.0.json +17 -0
- package/touch/Tasks/create-permanent-chat-room.1.0.0.json +28 -0
- package/touch/Tasks/determine-transfer-type.1.0.0.json +16 -0
- package/touch/Tasks/enrich-rezervations-for-transfer.1.0.0.json +23 -0
- package/touch/Tasks/execute-permanent-chatroom-update.1.0.0.json +21 -0
- package/touch/Tasks/execute-rez-chatroom-transfer.1.0.0.json +21 -0
- package/touch/Tasks/execute-rezervation-transfer.1.0.0.json +19 -0
- package/touch/Tasks/fetch-absence-entries-for-transfer.1.0.0.json +23 -0
- package/touch/Tasks/fetch-advisors-for-transfer.1.0.0.json +23 -0
- package/touch/Tasks/fetch-permanent-chatrooms-for-transfer.1.0.0.json +23 -0
- package/touch/Tasks/fetch-rez-chatrooms-for-transfer.1.0.0.json +23 -0
- package/touch/Tasks/fetch-rezervations-for-transfer.1.0.0.json +22 -0
- package/touch/Tasks/get-absence-entry-task.1.0.0.json +23 -0
- package/touch/Tasks/get-available-slots-http.1.0.0.json +27 -0
- package/touch/Tasks/get-available-slots.1.0.0.json +24 -0
- package/touch/Tasks/get-chat-room-data-for-rezervation.1.0.0.json +23 -0
- package/touch/Tasks/get-chat-token.1.0.0.json +27 -0
- package/touch/Tasks/get-matrix-room-messages.1.0.0.json +25 -0
- package/touch/Tasks/get-matrix-sync.1.0.0.json +25 -0
- package/touch/Tasks/get-rezervation-data-task.1.0.0.json +22 -0
- package/touch/Tasks/get-rezervation-state-task.1.0.0.json +22 -0
- package/touch/Tasks/get-rezervations-task.1.0.0.json +21 -0
- package/touch/Tasks/get-user-info-for-rezervation.1.0.0.json +24 -0
- package/touch/Tasks/get-video-call-url.1.0.0.json +17 -0
- package/touch/Tasks/invite-user-to-rezervation-room.1.0.0.json +27 -0
- package/touch/Tasks/join-chat-room-for-rezervation.1.0.0.json +28 -0
- package/touch/Tasks/join-matrix-room.1.0.0.json +27 -0
- package/touch/Tasks/join-user-to-room.1.0.0.json +27 -0
- package/touch/Tasks/merge-invited-user.1.0.0.json +17 -0
- package/touch/Tasks/merge-rezervation-update.1.0.0.json +16 -0
- package/touch/Tasks/merge-target-advisor-for-transfer.1.0.0.json +17 -0
- package/touch/Tasks/merge-update-body-for-randevu-update.1.0.0.json +16 -0
- package/touch/Tasks/merge-video-call-urls.1.0.0.json +17 -0
- package/touch/Tasks/query-chat-room-instances.1.0.0.json +23 -0
- package/touch/Tasks/remove-member-from-room.1.0.0.json +28 -0
- package/touch/Tasks/send-matrix-room-message.1.0.0.json +26 -0
- package/touch/Tasks/send-push-notification.1.0.0.json +26 -0
- package/touch/Tasks/send-sms-notification.1.0.0.json +26 -0
- package/touch/Tasks/set-chat-room-status-active.1.0.0.json +16 -0
- package/touch/Tasks/set-chat-room-status-deactive.1.0.0.json +16 -0
- package/touch/Tasks/set-previous-advisor.1.0.0.json +16 -0
- package/touch/Tasks/set-user-from-headers-for-rezervation.1.0.0.json +17 -0
- package/touch/Tasks/start-absence-entry-for-rezervation.1.0.0.json +21 -0
- package/touch/Tasks/start-chat-room-for-rezervation.1.0.0.json +20 -0
- package/touch/Tasks/start-notification-sender.1.0.0.json +20 -0
- package/touch/Tasks/start-permanent-chat-room.1.0.0.json +21 -0
- package/touch/Tasks/start-transfer-from-absence-entry.1.0.0.json +19 -0
- package/touch/Tasks/start-video-call.1.0.0.json +22 -0
- package/touch/Tasks/trigger-chat-room-deactivate.1.0.0.json +21 -0
- package/touch/Tasks/trigger-chat-room-transfer.1.0.0.json +21 -0
- package/touch/Tasks/trigger-chat-room-update.1.0.0.json +20 -0
- package/touch/Tasks/trigger-rezervation-add-invited-participant.1.0.0.json +20 -0
- package/touch/Tasks/trigger-rezervation-apply-update.1.0.0.json +20 -0
- package/touch/Tasks/trigger-rezervation-to-in-meet.1.0.0.json +20 -0
- package/touch/Tasks/trigger-rezervation-video-call-update.1.0.0.json +21 -0
- package/touch/Tasks/validate-date-for-rezervation.1.0.0.json +18 -0
- package/touch/Tasks/validate-slot-for-rezervation.1.0.0.json +24 -0
- package/touch/Tasks/validate-transfer-availability.1.0.0.json +23 -0
- package/touch/Views/.gitkeep +0 -0
- package/touch/Workflows/.gitkeep +0 -0
- package/touch/Workflows/absence-entry.http +458 -0
- package/touch/Workflows/absence-entry.json +179 -0
- package/touch/Workflows/add-participant-to-rezervation.http +47 -0
- package/touch/Workflows/add-participant-to-rezervation.json +340 -0
- package/touch/Workflows/chat-room.http +207 -0
- package/touch/Workflows/chat-room.json +452 -0
- package/touch/Workflows/investment-advisor.json +367 -0
- package/touch/Workflows/notification-sender.http +299 -0
- package/touch/Workflows/notification-sender.json +262 -0
- package/touch/Workflows/portfolio-manager.json +367 -0
- package/touch/Workflows/randevu-update.http +87 -0
- package/touch/Workflows/rezervation-start.json +467 -0
- package/touch/Workflows/rezervation-transfer.json +512 -0
- package/touch/Workflows/rezervation-update.http +87 -0
- package/touch/Workflows/rezervation-update.json +485 -0
- package/touch/Workflows/rezervation.http +214 -0
- package/touch/Workflows/rezervation.json +726 -0
- package/touch/Workflows/src/AllChatRoomsSuccessRule.csx +65 -0
- package/touch/Workflows/src/AlwaysTrueRule.csx +13 -0
- package/touch/Workflows/src/AnyChatRoomFailedRule.csx +64 -0
- package/touch/Workflows/src/AutoProcessRule.csx +38 -0
- package/touch/Workflows/src/BuildRezChatRoomPlanMapping.csx +160 -0
- package/touch/Workflows/src/CanStartRezervationTimerMapping.csx +48 -0
- package/touch/Workflows/src/CanStartTransferMapping.csx +14 -0
- package/touch/Workflows/src/CancelAbsenceEntryForRezervationMapping.csx +48 -0
- package/touch/Workflows/src/CancelAbsenceForRandevuUpdateMapping.csx +62 -0
- package/touch/Workflows/src/ChatRoomCreatedFailedRule.csx +54 -0
- package/touch/Workflows/src/ChatRoomCreatedSuccessRule.csx +54 -0
- package/touch/Workflows/src/ChatRoomRemoveMapping.csx +104 -0
- package/touch/Workflows/src/ChatRoomTransferInviteMapping.csx +109 -0
- package/touch/Workflows/src/ChatRoomTransferRemoveMapping.csx +71 -0
- package/touch/Workflows/src/ChatRoomUpdateMapping.csx +107 -0
- package/touch/Workflows/src/CheckAlreadyCompletedChatRoomMapping.csx +100 -0
- package/touch/Workflows/src/CheckDuplicatePortfolioManagerMapping.csx +119 -0
- package/touch/Workflows/src/CheckDuplicateRezervationMapping.csx +150 -0
- package/touch/Workflows/src/CheckExistingPermanentChatRoomMapping.csx +169 -0
- package/touch/Workflows/src/CheckRandevuTimeMapping.csx +67 -0
- package/touch/Workflows/src/CheckRezervationStateActiveOrInMeetRule.csx +14 -0
- package/touch/Workflows/src/CreateAbsenceEntryForRezervationMapping.csx +111 -0
- package/touch/Workflows/src/CreateAbsenceForRandevuUpdateMapping.csx +108 -0
- package/touch/Workflows/src/CreateChatRoomForRezervationMapping.csx +122 -0
- package/touch/Workflows/src/CreatePermanentChatRoomMapping.csx +140 -0
- package/touch/Workflows/src/CustomerControlToEndRule.csx +14 -0
- package/touch/Workflows/src/DetermineTransferTypeMapping.csx +92 -0
- package/touch/Workflows/src/EnrichRezervationsForTransferMapping.csx +495 -0
- package/touch/Workflows/src/ExecutePermanentChatRoomUpdateMapping.csx +124 -0
- package/touch/Workflows/src/ExecuteRezChatRoomTransferMapping.csx +95 -0
- package/touch/Workflows/src/ExecuteTransferMapping.csx +152 -0
- package/touch/Workflows/src/FetchAbsenceEntriesForTransferMapping.csx +116 -0
- package/touch/Workflows/src/FetchAdvisorsForTransferMapping.csx +145 -0
- package/touch/Workflows/src/FetchPermanentChatRoomsMapping.csx +128 -0
- package/touch/Workflows/src/FetchRezervationsForTransferMapping.csx +124 -0
- package/touch/Workflows/src/GetChatRoomDataForRezervationMapping.csx +100 -0
- package/touch/Workflows/src/GetChatTokenMapping.csx +85 -0
- package/touch/Workflows/src/GetRezervationDataForAddParticipantMapping.csx +105 -0
- package/touch/Workflows/src/GetRezervationDataForRandevuUpdateMapping.csx +110 -0
- package/touch/Workflows/src/GetRezervationDataMapping.csx +111 -0
- package/touch/Workflows/src/GetRezervationStateForRandevuUpdateMapping.csx +80 -0
- package/touch/Workflows/src/GetRezervationStateMapping.csx +92 -0
- package/touch/Workflows/src/GetUserInfoForRezervationMapping.csx +63 -0
- package/touch/Workflows/src/GetVideoCallUrlMapping.csx +62 -0
- package/touch/Workflows/src/HasChangedAdvisorRule.csx +28 -0
- package/touch/Workflows/src/HasChatIntegrationRule.csx +41 -0
- package/touch/Workflows/src/HasExistingPermanentRoomRule.csx +28 -0
- package/touch/Workflows/src/InviteAdvisorForRandevuUpdateMapping.csx +86 -0
- package/touch/Workflows/src/InviteNewAdvisorToRezervationRoomMapping.csx +78 -0
- package/touch/Workflows/src/InviteNewParticipantToRandevuRoomMapping.csx +88 -0
- package/touch/Workflows/src/InvitedUserMergeMapping.csx +77 -0
- package/touch/Workflows/src/InvitedUserNotAllowedRule.csx +71 -0
- package/touch/Workflows/src/InvitedUserNotInMeetRule.csx +19 -0
- package/touch/Workflows/src/IsNotfSentRule.csx +36 -0
- package/touch/Workflows/src/JoinChatRoomForAddParticipantMapping.csx +118 -0
- package/touch/Workflows/src/JoinChatRoomForRandevuStartMapping.csx +119 -0
- package/touch/Workflows/src/JoinChatRoomForRezervationMapping.csx +118 -0
- package/touch/Workflows/src/JoinMatrixRoomMapping.csx +100 -0
- package/touch/Workflows/src/JoinUserToRoomMapping.csx +118 -0
- package/touch/Workflows/src/LoginForAddParticipantChatMapping.csx +102 -0
- package/touch/Workflows/src/LoginForRandevuStartChatMapping.csx +96 -0
- package/touch/Workflows/src/MergeRezervationUpdateMapping.csx +82 -0
- package/touch/Workflows/src/MergeTargetAdvisorForTransferMapping.csx +79 -0
- package/touch/Workflows/src/MergeUpdateBodyForRandevuUpdateMapping.csx +91 -0
- package/touch/Workflows/src/NoExistingPermanentRoomRule.csx +23 -0
- package/touch/Workflows/src/NotificationCompleteAlwaysRule.csx +14 -0
- package/touch/Workflows/src/NotificationCompleteFromPendingRule.csx +41 -0
- package/touch/Workflows/src/NotificationCompleteFromSmsRule.csx +36 -0
- package/touch/Workflows/src/NotificationPushFromPendingRule.csx +42 -0
- package/touch/Workflows/src/NotificationPushFromSmsRule.csx +36 -0
- package/touch/Workflows/src/NotificationSmsPendingRule.csx +32 -0
- package/touch/Workflows/src/PermanentDoneRule.csx +44 -0
- package/touch/Workflows/src/PermanentProcessNextRule.csx +44 -0
- package/touch/Workflows/src/RezChatRoomProcessNextRule.csx +44 -0
- package/touch/Workflows/src/RezChatRoomsDoneRule.csx +44 -0
- package/touch/Workflows/src/SendPushNotificationMapping.csx +146 -0
- package/touch/Workflows/src/SendSmsNotificationMapping.csx +138 -0
- package/touch/Workflows/src/SetChatRoomStatusActiveMapping.csx +22 -0
- package/touch/Workflows/src/SetChatRoomStatusDeactiveMapping.csx +22 -0
- package/touch/Workflows/src/SetPreviousAdvisorMapping.csx +28 -0
- package/touch/Workflows/src/SetUserFromHeadersForRezervationMapping.csx +24 -0
- package/touch/Workflows/src/SlotAvailableRule.csx +33 -0
- package/touch/Workflows/src/SlotUnavailableRule.csx +33 -0
- package/touch/Workflows/src/StartChatRoomForRezervationMapping.csx +100 -0
- package/touch/Workflows/src/StartGetChatTokenForRezervationMapping.csx +71 -0
- package/touch/Workflows/src/StartNotificationForAdvisorMapping.csx +117 -0
- package/touch/Workflows/src/StartNotificationForRezervationFromUserInfoMapping.csx +128 -0
- package/touch/Workflows/src/StartNotificationForUserMapping.csx +117 -0
- package/touch/Workflows/src/StartPermanentChatRoomMapping.csx +92 -0
- package/touch/Workflows/src/StartTransferFromAbsenceEntryMapping.csx +94 -0
- package/touch/Workflows/src/StartVideoCallCustomerSubFlowMapping.csx +37 -0
- package/touch/Workflows/src/StartVideoCallForInvitedParticipantMapping.csx +54 -0
- package/touch/Workflows/src/StartVideoCallForRandevuStartMapping.csx +70 -0
- package/touch/Workflows/src/StartVideoCallStaffSubFlowMapping.csx +37 -0
- package/touch/Workflows/src/StateActiveForUpdateRule.csx +14 -0
- package/touch/Workflows/src/StateActiveRule.csx +14 -0
- package/touch/Workflows/src/StateInMeetRule.csx +14 -0
- package/touch/Workflows/src/StateNotActiveForUpdateRule.csx +14 -0
- package/touch/Workflows/src/StateNotActiveOrInMeetRule.csx +14 -0
- package/touch/Workflows/src/StatusCustomerEnterRule.csx +25 -0
- package/touch/Workflows/src/StatusStaffEnterRule.csx +25 -0
- package/touch/Workflows/src/SyncWorkingHoursRule.csx +46 -0
- package/touch/Workflows/src/TokenSuccessRule.csx +24 -0
- package/touch/Workflows/src/TransferAllDoneRule.csx +50 -0
- package/touch/Workflows/src/TransferHasInvalidRule.csx +34 -0
- package/touch/Workflows/src/TransferProcessNextRule.csx +50 -0
- package/touch/Workflows/src/TriggerChatRoomDeactivateMapping.csx +77 -0
- package/touch/Workflows/src/TriggerChatRoomTransferMapping.csx +93 -0
- package/touch/Workflows/src/TriggerChatRoomUpdateMapping.csx +99 -0
- package/touch/Workflows/src/TriggerRezervationAddInvitedParticipantMapping.csx +77 -0
- package/touch/Workflows/src/TriggerRezervationApplyUpdateMapping.csx +66 -0
- package/touch/Workflows/src/TriggerRezervationToInMeetMapping.csx +69 -0
- package/touch/Workflows/src/TriggerRezervationVideoCallUpdateMapping.csx +67 -0
- package/touch/Workflows/src/ValidateDateForRezervationMapping.csx +60 -0
- package/touch/Workflows/src/ValidateSlotForRandevuUpdateMapping.csx +211 -0
- package/touch/Workflows/src/ValidateSlotForRezervationMapping.csx +246 -0
- package/touch/Workflows/src/ValidateTransferMapping.csx +243 -0
- package/touch/Workflows/src/VideoCallUrlUpdateMergeMapping.csx +141 -0
- package/touch/Workflows/start-chat.json +217 -0
- package/touch/Workflows/start-video-call.http +93 -0
- package/touch/Workflows/start-video-call.json +206 -0
- package/vnext.config.json +58 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Threading.Tasks;
|
|
4
|
+
using BBT.Workflow.Scripting;
|
|
5
|
+
using BBT.Workflow.Definitions;
|
|
6
|
+
|
|
7
|
+
/// <summary>
|
|
8
|
+
/// Mapping for check-duplicate-rezervation (DaprServiceTask - Type 3).
|
|
9
|
+
/// Queries rezervation workflow instances to enforce two rules:
|
|
10
|
+
/// 1. A user can have at most 2 reservations in confirmed states (active, update-control, change-advisor, can-start-meeting, accept-terms).
|
|
11
|
+
/// 2. A user cannot have two reservations with overlapping time slots.
|
|
12
|
+
///
|
|
13
|
+
/// Flow:
|
|
14
|
+
/// 1. InputHandler: Builds query to find all active reservations for the same user.
|
|
15
|
+
/// 2. OutputHandler: Checks count (max 2) and time overlap; throws exception on violation.
|
|
16
|
+
/// Exception fails the transition; instance stays in its current state.
|
|
17
|
+
/// </summary>
|
|
18
|
+
public class CheckDuplicateRezervationMapping : ScriptBase, IMapping
|
|
19
|
+
{
|
|
20
|
+
public Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
|
|
21
|
+
{
|
|
22
|
+
var serviceTask = task as DaprServiceTask;
|
|
23
|
+
if (serviceTask == null)
|
|
24
|
+
throw new InvalidOperationException("Task must be a DaprServiceTask");
|
|
25
|
+
|
|
26
|
+
var appId = GetConfigValue("DAPR_APP_ID");
|
|
27
|
+
if (!string.IsNullOrEmpty(appId))
|
|
28
|
+
serviceTask.SetAppId(appId);
|
|
29
|
+
|
|
30
|
+
var data = context.Instance?.Data;
|
|
31
|
+
if (data == null || !HasProperty(data, "user") || data.user == null)
|
|
32
|
+
throw new InvalidOperationException("MAX_REZERVATION: User field is required for duplicate check");
|
|
33
|
+
|
|
34
|
+
var user = data.user.ToString();
|
|
35
|
+
var currentKey = context.Instance?.Key ?? "";
|
|
36
|
+
|
|
37
|
+
var userEscaped = user.Replace("\\", "\\\\").Replace("\"", "\\\"");
|
|
38
|
+
var keyEscaped = currentKey.Replace("\\", "\\\\").Replace("\"", "\\\"");
|
|
39
|
+
|
|
40
|
+
var queryParams = new List<string>
|
|
41
|
+
{
|
|
42
|
+
"pageSize=10",
|
|
43
|
+
"filter=" +
|
|
44
|
+
"{\"and\":[" +
|
|
45
|
+
"{\"attributes\":{\"user\":{\"eq\":\"" + userEscaped + "\"}}}," +
|
|
46
|
+
"{\"key\":{\"ne\":\"" + keyEscaped + "\"}}," +
|
|
47
|
+
"{\"currentState\":{\"eq\":\"" + "active" + "\"}}," +
|
|
48
|
+
"]}"
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
serviceTask.SetQueryString(string.Join("&", queryParams));
|
|
52
|
+
|
|
53
|
+
return Task.FromResult(new ScriptResponse());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public Task<ScriptResponse> OutputHandler(ScriptContext context)
|
|
57
|
+
{
|
|
58
|
+
var response = context.Body;
|
|
59
|
+
|
|
60
|
+
if (response?.isSuccess == false)
|
|
61
|
+
{
|
|
62
|
+
var errorMessage = response?.errorMessage?.ToString() ?? "Service call failed";
|
|
63
|
+
throw new Exception($"SERVICE_ERROR: {errorMessage}");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var responseData = response?.data;
|
|
67
|
+
var items = responseData?.items;
|
|
68
|
+
|
|
69
|
+
if (items == null || items.Count == 0)
|
|
70
|
+
return Task.FromResult(new ScriptResponse());
|
|
71
|
+
|
|
72
|
+
int count = items.Count;
|
|
73
|
+
|
|
74
|
+
if (count >= 2)
|
|
75
|
+
{
|
|
76
|
+
var user = context.Instance?.Data?.user?.ToString() ?? "unknown";
|
|
77
|
+
throw new Exception($"MAX_REZERVATION: User '{user}' already has {count} active reservations. Maximum allowed is 2.");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var instanceData = context.Instance?.Data;
|
|
81
|
+
var newStartStr = GetString(instanceData, "startDateTime");
|
|
82
|
+
var newEndStr = GetString(instanceData, "endDateTime");
|
|
83
|
+
|
|
84
|
+
if (!string.IsNullOrEmpty(newStartStr) && !string.IsNullOrEmpty(newEndStr))
|
|
85
|
+
{
|
|
86
|
+
DateTime newStart = default, newEnd = default;
|
|
87
|
+
if (DateTime.TryParse(newStartStr, out newStart) && DateTime.TryParse(newEndStr, out newEnd))
|
|
88
|
+
{
|
|
89
|
+
foreach (var item in items)
|
|
90
|
+
{
|
|
91
|
+
if (item == null) continue;
|
|
92
|
+
|
|
93
|
+
var existingStartStr = GetNestedString(item, "attributes", "startDateTime");
|
|
94
|
+
var existingEndStr = GetNestedString(item, "attributes", "endDateTime");
|
|
95
|
+
|
|
96
|
+
if (string.IsNullOrEmpty(existingStartStr) || string.IsNullOrEmpty(existingEndStr))
|
|
97
|
+
continue;
|
|
98
|
+
|
|
99
|
+
DateTime existingStart = default, existingEnd = default;
|
|
100
|
+
if (!DateTime.TryParse(existingStartStr, out existingStart) ||
|
|
101
|
+
!DateTime.TryParse(existingEndStr, out existingEnd))
|
|
102
|
+
continue;
|
|
103
|
+
|
|
104
|
+
if (existingStart < newEnd && existingEnd > newStart)
|
|
105
|
+
{
|
|
106
|
+
var existingKey = HasProperty(item, "key") ? item.key?.ToString() : "unknown";
|
|
107
|
+
throw new Exception(
|
|
108
|
+
$"TIME_OVERLAP: Requested time {newStartStr} - {newEndStr} overlaps with existing reservation '{existingKey}' ({existingStartStr} - {existingEndStr}).");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return Task.FromResult(new ScriptResponse());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private string GetString(dynamic obj, string name)
|
|
118
|
+
{
|
|
119
|
+
if (obj == null) return null;
|
|
120
|
+
try
|
|
121
|
+
{
|
|
122
|
+
if (HasProperty(obj, name))
|
|
123
|
+
{
|
|
124
|
+
var v = GetPropertyValue(obj, name);
|
|
125
|
+
return v?.ToString();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch { }
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private string GetNestedString(dynamic obj, string parent, string child)
|
|
133
|
+
{
|
|
134
|
+
if (obj == null) return null;
|
|
135
|
+
try
|
|
136
|
+
{
|
|
137
|
+
if (HasProperty(obj, parent))
|
|
138
|
+
{
|
|
139
|
+
var nested = GetPropertyValue(obj, parent);
|
|
140
|
+
if (nested != null && HasProperty(nested, child))
|
|
141
|
+
{
|
|
142
|
+
var v = GetPropertyValue(nested, child);
|
|
143
|
+
return v?.ToString();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch { }
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Threading.Tasks;
|
|
4
|
+
using BBT.Workflow.Scripting;
|
|
5
|
+
using BBT.Workflow.Definitions;
|
|
6
|
+
|
|
7
|
+
/// <summary>
|
|
8
|
+
/// Mapping for check-existing-permanent-chat-room DaprServiceTask (Type 3).
|
|
9
|
+
/// Calls get-chat-rooms flow function with user and roomType=permanent from InstanceData.
|
|
10
|
+
/// Output: hasExistingPermanentRoom (bool), existingRoomAdvisorMatches (bool), existingChatRoomInstanceKey (string).
|
|
11
|
+
/// - hasExistingPermanentRoom: true only if user has a permanent room with the same advisorType (e.g. PM request only counts PM rooms; IA request only counts IA rooms).
|
|
12
|
+
/// - existingRoomAdvisorMatches: true if that room's advisorId also matches; false otherwise.
|
|
13
|
+
/// - existingChatRoomInstanceKey: key of matching room, or first room with same advisorType when no match (for transfer).
|
|
14
|
+
/// </summary>
|
|
15
|
+
public class CheckExistingPermanentChatRoomMapping : ScriptBase, IMapping
|
|
16
|
+
{
|
|
17
|
+
public Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
|
|
18
|
+
{
|
|
19
|
+
var serviceTask = task as DaprServiceTask;
|
|
20
|
+
if (serviceTask == null)
|
|
21
|
+
throw new InvalidOperationException("Task must be a DaprServiceTask");
|
|
22
|
+
|
|
23
|
+
var appId = GetConfigValue("DAPR_APP_ID");
|
|
24
|
+
if (!string.IsNullOrEmpty(appId))
|
|
25
|
+
serviceTask.SetAppId(appId);
|
|
26
|
+
|
|
27
|
+
var data = context.Instance?.Data;
|
|
28
|
+
if (data == null)
|
|
29
|
+
throw new InvalidOperationException("Instance data is required");
|
|
30
|
+
|
|
31
|
+
var user = GetString(data, "user");
|
|
32
|
+
if (string.IsNullOrWhiteSpace(user))
|
|
33
|
+
throw new InvalidOperationException("user is required in instance data");
|
|
34
|
+
|
|
35
|
+
var queryParams = new List<string>
|
|
36
|
+
{
|
|
37
|
+
"user=" + Uri.EscapeDataString(user.Trim()),
|
|
38
|
+
"roomType=permanent",
|
|
39
|
+
"state=activated",
|
|
40
|
+
"pageSize=20"
|
|
41
|
+
};
|
|
42
|
+
serviceTask.SetQueryString(string.Join("&", queryParams));
|
|
43
|
+
|
|
44
|
+
return Task.FromResult(new ScriptResponse());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public Task<ScriptResponse> OutputHandler(ScriptContext context)
|
|
48
|
+
{
|
|
49
|
+
var response = context.Body;
|
|
50
|
+
var data = context.Instance?.Data;
|
|
51
|
+
var advisorId = GetString(data, "advisorId");
|
|
52
|
+
var advisorType = GetString(data, "advisorType");
|
|
53
|
+
|
|
54
|
+
bool hasExistingPermanentRoom = false;
|
|
55
|
+
bool existingRoomAdvisorMatches = false;
|
|
56
|
+
string existingChatRoomInstanceKey = null;
|
|
57
|
+
string firstRoomWithSameAdvisorTypeKey = null;
|
|
58
|
+
|
|
59
|
+
if (response?.isSuccess == true)
|
|
60
|
+
{
|
|
61
|
+
var responseData = response?.data ?? response?.Data ?? response;
|
|
62
|
+
var rooms = GetRoomsList(responseData);
|
|
63
|
+
if (rooms != null)
|
|
64
|
+
{
|
|
65
|
+
foreach (var room in rooms)
|
|
66
|
+
{
|
|
67
|
+
var roomAdvisorType = GetString(room, "advisorType");
|
|
68
|
+
if (!string.Equals(roomAdvisorType?.Trim(), advisorType?.Trim(), StringComparison.OrdinalIgnoreCase))
|
|
69
|
+
continue;
|
|
70
|
+
|
|
71
|
+
var roomKey = GetString(room, "instanceKey") ?? GetString(room, "key");
|
|
72
|
+
if (string.IsNullOrWhiteSpace(roomKey)) continue;
|
|
73
|
+
|
|
74
|
+
if (firstRoomWithSameAdvisorTypeKey == null)
|
|
75
|
+
firstRoomWithSameAdvisorTypeKey = roomKey;
|
|
76
|
+
|
|
77
|
+
hasExistingPermanentRoom = true;
|
|
78
|
+
|
|
79
|
+
var roomAdvisorId = GetString(room, "advisorId");
|
|
80
|
+
if (string.Equals(roomAdvisorId?.Trim(), advisorId?.Trim(), StringComparison.OrdinalIgnoreCase))
|
|
81
|
+
{
|
|
82
|
+
existingRoomAdvisorMatches = true;
|
|
83
|
+
existingChatRoomInstanceKey = roomKey;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (hasExistingPermanentRoom && existingChatRoomInstanceKey == null)
|
|
89
|
+
existingChatRoomInstanceKey = firstRoomWithSameAdvisorTypeKey;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return Task.FromResult(new ScriptResponse
|
|
94
|
+
{
|
|
95
|
+
Data = new
|
|
96
|
+
{
|
|
97
|
+
hasExistingPermanentRoom = hasExistingPermanentRoom,
|
|
98
|
+
existingRoomAdvisorMatches = existingRoomAdvisorMatches,
|
|
99
|
+
existingChatRoomInstanceKey = existingChatRoomInstanceKey
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private System.Collections.IEnumerable GetRoomsList(dynamic responseData)
|
|
105
|
+
{
|
|
106
|
+
if (responseData == null) return null;
|
|
107
|
+
try
|
|
108
|
+
{
|
|
109
|
+
// Direct rooms
|
|
110
|
+
if (HasProperty(responseData, "rooms") && responseData.rooms != null)
|
|
111
|
+
return responseData.rooms;
|
|
112
|
+
if (HasProperty(responseData, "data") && responseData.data != null && HasProperty(responseData.data, "rooms"))
|
|
113
|
+
return responseData.data.rooms;
|
|
114
|
+
if (HasProperty(responseData, "Data") && responseData.Data != null && HasProperty(responseData.Data, "rooms"))
|
|
115
|
+
return responseData.Data.rooms;
|
|
116
|
+
|
|
117
|
+
// Wrapped: checkExistingData.items[].getChatRooms.rooms (runtime task result shape)
|
|
118
|
+
var checkExisting = GetValue(responseData, "checkExistingData") ?? GetValue(responseData, "data");
|
|
119
|
+
var root = checkExisting ?? responseData;
|
|
120
|
+
if (root != null && HasProperty(root, "items") && root.items != null)
|
|
121
|
+
{
|
|
122
|
+
var items = root.items as System.Collections.IEnumerable;
|
|
123
|
+
if (items != null)
|
|
124
|
+
{
|
|
125
|
+
foreach (var item in items)
|
|
126
|
+
{
|
|
127
|
+
if (item == null) continue;
|
|
128
|
+
var getChatRooms = GetValue(item, "getChatRooms");
|
|
129
|
+
if (getChatRooms != null && HasProperty(getChatRooms, "rooms"))
|
|
130
|
+
{
|
|
131
|
+
var rooms = GetValue(getChatRooms, "rooms");
|
|
132
|
+
if (rooms is System.Collections.IEnumerable en && en != null)
|
|
133
|
+
return en;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch { }
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private object GetValue(dynamic obj, string name)
|
|
144
|
+
{
|
|
145
|
+
if (obj == null) return null;
|
|
146
|
+
try
|
|
147
|
+
{
|
|
148
|
+
if (HasProperty(obj, name))
|
|
149
|
+
return GetPropertyValue(obj, name);
|
|
150
|
+
}
|
|
151
|
+
catch { }
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private string GetString(dynamic obj, string name)
|
|
156
|
+
{
|
|
157
|
+
if (obj == null) return null;
|
|
158
|
+
try
|
|
159
|
+
{
|
|
160
|
+
if (HasProperty(obj, name))
|
|
161
|
+
{
|
|
162
|
+
var v = GetPropertyValue(obj, name);
|
|
163
|
+
return v?.ToString()?.Trim();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch { }
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Threading.Tasks;
|
|
4
|
+
using BBT.Workflow.Scripting;
|
|
5
|
+
using BBT.Workflow.Definitions;
|
|
6
|
+
|
|
7
|
+
/// <summary>
|
|
8
|
+
/// Mapping for check-randevu-time Script Task.
|
|
9
|
+
/// Validates startDateTime is within 15 minutes. Throws MEET_NOT_STARTED if >15 min until start.
|
|
10
|
+
/// </summary>
|
|
11
|
+
public class CheckRandevuTimeMapping : ScriptBase, IMapping
|
|
12
|
+
{
|
|
13
|
+
private const int MaxMinutesBeforeStart = 15;
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
public Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
|
|
20
|
+
{
|
|
21
|
+
var response = new ScriptResponse();
|
|
22
|
+
response.Data=new {};
|
|
23
|
+
return Task.FromResult(response
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public Task<ScriptResponse> OutputHandler(ScriptContext context)
|
|
28
|
+
{
|
|
29
|
+
var data = context.Instance?.Data;
|
|
30
|
+
var startDateTimeStr = GetString(data, "startDateTime");
|
|
31
|
+
if (string.IsNullOrWhiteSpace(startDateTimeStr))
|
|
32
|
+
throw new InvalidOperationException("MEET_NOT_STARTED: startDateTime is required");
|
|
33
|
+
|
|
34
|
+
DateTime startDateTime;
|
|
35
|
+
if (!DateTime.TryParse(startDateTimeStr, out startDateTime))
|
|
36
|
+
throw new InvalidOperationException("MEET_NOT_STARTED: Invalid startDateTime format");
|
|
37
|
+
|
|
38
|
+
var now = DateTime.UtcNow.AddHours(3);
|
|
39
|
+
var diff = startDateTime - now;
|
|
40
|
+
|
|
41
|
+
if (diff.TotalMinutes > MaxMinutesBeforeStart)
|
|
42
|
+
throw new InvalidOperationException("MEET_NOT_STARTED: Randevuya 15 dakikadan fazla var.");
|
|
43
|
+
LogError("Diff Minutes :"+diff.TotalMinutes+ "");
|
|
44
|
+
var result = new Dictionary<string, object>
|
|
45
|
+
{
|
|
46
|
+
{ "timeOk", true },
|
|
47
|
+
{ "minutesUntilStart", diff.TotalMinutes }
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return Task.FromResult(new ScriptResponse { Data = result });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private string GetString(dynamic obj, string name)
|
|
54
|
+
{
|
|
55
|
+
if (obj == null) return null;
|
|
56
|
+
try
|
|
57
|
+
{
|
|
58
|
+
if (HasProperty(obj, name))
|
|
59
|
+
{
|
|
60
|
+
var v = GetPropertyValue(obj, name);
|
|
61
|
+
return v?.ToString();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch { }
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
using System.Threading.Tasks;
|
|
2
|
+
using BBT.Workflow.Scripting;
|
|
3
|
+
|
|
4
|
+
/// <summary>
|
|
5
|
+
/// Condition for check-rezervation-state: state in (active, in-meet) -> check-time.
|
|
6
|
+
/// </summary>
|
|
7
|
+
public class CheckRezervationStateActiveOrInMeetRule : ScriptBase, IConditionMapping
|
|
8
|
+
{
|
|
9
|
+
public Task<bool> Handler(ScriptContext context)
|
|
10
|
+
{
|
|
11
|
+
var state = context.Instance?.Data?.state?.ToString()?.Trim();
|
|
12
|
+
return Task.FromResult(state == "active" || state == "in-meet");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Threading.Tasks;
|
|
3
|
+
using BBT.Workflow.Scripting;
|
|
4
|
+
using BBT.Workflow.Definitions;
|
|
5
|
+
|
|
6
|
+
/// <summary>
|
|
7
|
+
/// Mapping for start-absence-entry-for-rezervation StartTask (Type 11).
|
|
8
|
+
/// Creates an absence-entry rezervation instance when rezervation reaches confirmation state.
|
|
9
|
+
/// Key format: rezervation-{advisorId}-{startDateTime}-{endDateTime} (URL-safe: colons replaced with dashes).
|
|
10
|
+
/// Start goes directly to complete state (no schedule needed).
|
|
11
|
+
/// </summary>
|
|
12
|
+
public class CreateAbsenceEntryForRezervationMapping : ScriptBase, IMapping
|
|
13
|
+
{
|
|
14
|
+
public Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
|
|
15
|
+
{
|
|
16
|
+
var startTask = task as StartTask;
|
|
17
|
+
if (startTask == null)
|
|
18
|
+
throw new InvalidOperationException("Task must be a StartTask");
|
|
19
|
+
|
|
20
|
+
var data = context.Instance?.Data;
|
|
21
|
+
if (data == null || !HasProperty(data, "user") || !HasProperty(data, "advisor") ||
|
|
22
|
+
!HasProperty(data, "startDateTime") || !HasProperty(data, "endDateTime"))
|
|
23
|
+
{
|
|
24
|
+
return Task.FromResult(new ScriptResponse { Data = new { absenceEntryKey = (string)null } });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var user = data.user?.ToString()?.Trim();
|
|
28
|
+
var advisor = data.advisor?.ToString()?.Trim();
|
|
29
|
+
var startDateTime = data.startDateTime?.ToString()?.Trim();
|
|
30
|
+
var endDateTime = data.endDateTime?.ToString()?.Trim();
|
|
31
|
+
if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(advisor) ||
|
|
32
|
+
string.IsNullOrEmpty(startDateTime) || string.IsNullOrEmpty(endDateTime))
|
|
33
|
+
{
|
|
34
|
+
return Task.FromResult(new ScriptResponse { Data = new { absenceEntryKey = (string)null } });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var advisorId = NormalizeForKey(advisor);
|
|
38
|
+
var startNorm = NormalizeDateTimeForKey(startDateTime);
|
|
39
|
+
var endNorm = NormalizeDateTimeForKey(endDateTime);
|
|
40
|
+
var absenceEntryKey = $"rezervation-{advisorId}-{startNorm}-{endNorm}";
|
|
41
|
+
|
|
42
|
+
startTask.SetDomain("touch");
|
|
43
|
+
startTask.SetFlow("absence-entry");
|
|
44
|
+
startTask.SetKey(absenceEntryKey);
|
|
45
|
+
startTask.SetBody(new
|
|
46
|
+
{
|
|
47
|
+
absenceType = "rezervation",
|
|
48
|
+
advisor,
|
|
49
|
+
startDateTime,
|
|
50
|
+
endDateTime,
|
|
51
|
+
title = "Randevu"
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return Task.FromResult(new ScriptResponse
|
|
55
|
+
{
|
|
56
|
+
Data = new { absenceEntryKey }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public Task<ScriptResponse> OutputHandler(ScriptContext context)
|
|
61
|
+
{
|
|
62
|
+
var response = new ScriptResponse();
|
|
63
|
+
if (context.Body?.isSuccess == true)
|
|
64
|
+
{
|
|
65
|
+
var data = context.Instance?.Data;
|
|
66
|
+
var user = data?.user?.ToString()?.Trim();
|
|
67
|
+
var advisor = data?.advisor?.ToString()?.Trim();
|
|
68
|
+
var startDateTime = data?.startDateTime?.ToString()?.Trim();
|
|
69
|
+
var endDateTime = data?.endDateTime?.ToString()?.Trim();
|
|
70
|
+
if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(advisor) &&
|
|
71
|
+
!string.IsNullOrEmpty(startDateTime) && !string.IsNullOrEmpty(endDateTime))
|
|
72
|
+
{
|
|
73
|
+
var advisorId = NormalizeForKey(advisor);
|
|
74
|
+
var startNorm = NormalizeDateTimeForKey(startDateTime);
|
|
75
|
+
var endNorm = NormalizeDateTimeForKey(endDateTime);
|
|
76
|
+
var absenceEntryKey = $"rezervation-{advisorId}-{startNorm}-{endNorm}";
|
|
77
|
+
response.Data = new
|
|
78
|
+
{
|
|
79
|
+
absenceEntryKey,
|
|
80
|
+
absenceEntryResponse = data,
|
|
81
|
+
absenceEntryCreated = true
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
{
|
|
86
|
+
response.Data = new { absenceEntryCreated = true };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else
|
|
90
|
+
{
|
|
91
|
+
response.Data = new
|
|
92
|
+
{
|
|
93
|
+
absenceEntryCreated = false,
|
|
94
|
+
error = context.Body?.errorMessage ?? "Failed to start absence-entry"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return Task.FromResult(response);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private string NormalizeForKey(string value)
|
|
101
|
+
{
|
|
102
|
+
if (string.IsNullOrEmpty(value)) return value;
|
|
103
|
+
return value.Replace(":", "-").Replace(" ", "-");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private string NormalizeDateTimeForKey(string dateTimeStr)
|
|
107
|
+
{
|
|
108
|
+
if (string.IsNullOrEmpty(dateTimeStr)) return dateTimeStr;
|
|
109
|
+
return dateTimeStr.Replace(":", "-").Replace(" ", "-");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Threading.Tasks;
|
|
3
|
+
using BBT.Workflow.Scripting;
|
|
4
|
+
using BBT.Workflow.Definitions;
|
|
5
|
+
|
|
6
|
+
/// <summary>
|
|
7
|
+
/// Mapping for start-absence-entry-for-rezervation in randevu-update flow.
|
|
8
|
+
/// Creates absence-entry for the new advisor + start/end (from merged instance data).
|
|
9
|
+
/// </summary>
|
|
10
|
+
public class CreateAbsenceForRandevuUpdateMapping : ScriptBase, IMapping
|
|
11
|
+
{
|
|
12
|
+
public Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
|
|
13
|
+
{
|
|
14
|
+
var startTask = task as StartTask;
|
|
15
|
+
if (startTask == null)
|
|
16
|
+
throw new InvalidOperationException("Task must be a StartTask");
|
|
17
|
+
|
|
18
|
+
var data = context.Instance?.Data;
|
|
19
|
+
if (data == null)
|
|
20
|
+
return Task.FromResult(new ScriptResponse { Data = new { absenceEntryKey = (string)null } });
|
|
21
|
+
|
|
22
|
+
var advisor = GetString(data, "advisor");
|
|
23
|
+
var startDateTime = GetString(data, "startDateTime");
|
|
24
|
+
var endDateTime = GetString(data, "endDateTime");
|
|
25
|
+
|
|
26
|
+
if (string.IsNullOrEmpty(advisor) || string.IsNullOrEmpty(startDateTime) || string.IsNullOrEmpty(endDateTime))
|
|
27
|
+
return Task.FromResult(new ScriptResponse { Data = new { absenceEntryKey = (string)null } });
|
|
28
|
+
|
|
29
|
+
var advisorId = NormalizeForKey(advisor);
|
|
30
|
+
var startNorm = NormalizeDateTimeForKey(startDateTime);
|
|
31
|
+
var endNorm = NormalizeDateTimeForKey(endDateTime);
|
|
32
|
+
var absenceEntryKey = $"rezervation-{advisorId}-{startNorm}-{endNorm}";
|
|
33
|
+
|
|
34
|
+
startTask.SetDomain("touch");
|
|
35
|
+
startTask.SetFlow("absence-entry");
|
|
36
|
+
startTask.SetKey(absenceEntryKey);
|
|
37
|
+
startTask.SetBody(new
|
|
38
|
+
{
|
|
39
|
+
absenceType = "rezervation",
|
|
40
|
+
advisor = advisor.Trim(),
|
|
41
|
+
startDateTime,
|
|
42
|
+
endDateTime,
|
|
43
|
+
title = "Randevu"
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return Task.FromResult(new ScriptResponse { Data = new { absenceEntryKey } });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public Task<ScriptResponse> OutputHandler(ScriptContext context)
|
|
50
|
+
{
|
|
51
|
+
var response = new ScriptResponse();
|
|
52
|
+
if (context.Body?.isSuccess == true)
|
|
53
|
+
{
|
|
54
|
+
var data = context.Instance?.Data;
|
|
55
|
+
var advisor = GetString(data, "advisor");
|
|
56
|
+
var startDateTime = GetString(data, "startDateTime");
|
|
57
|
+
var endDateTime = GetString(data, "endDateTime");
|
|
58
|
+
if (!string.IsNullOrEmpty(advisor) && !string.IsNullOrEmpty(startDateTime) && !string.IsNullOrEmpty(endDateTime))
|
|
59
|
+
{
|
|
60
|
+
var advisorId = NormalizeForKey(advisor);
|
|
61
|
+
var startNorm = NormalizeDateTimeForKey(startDateTime);
|
|
62
|
+
var endNorm = NormalizeDateTimeForKey(endDateTime);
|
|
63
|
+
var absenceEntryKey = $"rezervation-{advisorId}-{startNorm}-{endNorm}";
|
|
64
|
+
response.Data = new { absenceEntryKey, absenceEntryCreated = true };
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
{
|
|
68
|
+
response.Data = new { absenceEntryCreated = true };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else
|
|
72
|
+
{
|
|
73
|
+
response.Data = new
|
|
74
|
+
{
|
|
75
|
+
absenceEntryCreated = false,
|
|
76
|
+
error = context.Body?.errorMessage ?? "Failed to start absence-entry"
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return Task.FromResult(response);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private string NormalizeForKey(string value)
|
|
83
|
+
{
|
|
84
|
+
if (string.IsNullOrEmpty(value)) return value;
|
|
85
|
+
return value.Replace(":", "-").Replace(" ", "-");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private string NormalizeDateTimeForKey(string dateTimeStr)
|
|
89
|
+
{
|
|
90
|
+
if (string.IsNullOrEmpty(dateTimeStr)) return dateTimeStr;
|
|
91
|
+
return dateTimeStr.Replace(":", "-").Replace(" ", "-");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private string GetString(dynamic obj, string name)
|
|
95
|
+
{
|
|
96
|
+
if (obj == null) return null;
|
|
97
|
+
try
|
|
98
|
+
{
|
|
99
|
+
if (HasProperty(obj, name))
|
|
100
|
+
{
|
|
101
|
+
var v = GetPropertyValue(obj, name);
|
|
102
|
+
return v?.ToString();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch { }
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|