Forráskód Böngészése

incoming && acknowledgement fix

Enzo 1 éve
szülő
commit
b8193d0961

+ 13 - 22
services/acknowledgement.service.ts

@@ -1,6 +1,6 @@
 import { AnyObject } from "mongoose";
 import { map, Observable, of, tap } from "rxjs";
-import { Command, ResponseMessage, Uuid } from "../dependencies/fisappmessagejsutilty/interface/export"
+import { BaseMessage, Command, ResponseMessage, Uuid } from "../dependencies/fisappmessagejsutilty/interface/export"
 import { FisCreateMessageUtility } from "../dependencies/fisappmessagejsutilty/interface/export";
 import { LoggingService } from "../dependencies/fisloggingservice/services/logging-service";
 import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
@@ -10,7 +10,7 @@ import { Acknowledgemeent, AcknowledgementLogSetting } from "../type/acknowledge
 export class AcknowledgementService implements Acknowledgemeent {
 
     private messageUtil: FisCreateMessageUtility = new FisCreateMessageUtility("FisAppID/Name")
-    private settings2: LogSetting = {
+    private settings: LogSetting = {
         storage: '',
         setting: {
             appId: '',
@@ -23,21 +23,14 @@ export class AcknowledgementService implements Acknowledgemeent {
         }
     }
 
-    constructor(private logService1?: LoggingService, private logService2?: LoggingService) {
+    constructor(private logService1?: LoggingService, private logService?: LoggingService) {
         // this.logService1 = new LoggingService()
-        this.logService2 = new LoggingService()
+        this.logService = new LoggingService()
     }
 
     public async init(settings: AcknowledgementLogSetting) {
-        // let logSetting1: LogSetting = {
-        //     ...settings,
-        //     setting: {
-        //         ...settings.setting,
-        //         logLocName: "locationName1",
-        //         appLocName: "appLocName1"
-        //     }
-        // }
-        let logSetting2: LogSetting = {
+
+        let logSetting: LogSetting = {
             ...settings,
             setting: {
                 ...settings.setting,
@@ -45,14 +38,12 @@ export class AcknowledgementService implements Acknowledgemeent {
                 appLocName: "appLocName2"
             }
         }
-        // console.log(settings)
-        // this.settings1 = logSetting1
-        // this.logService1.init(logSetting1)
-        this.settings2 = logSetting2
-        this.logService2.init(logSetting2)
+
+        this.settings = logSetting
+        this.logService.init(logSetting)
     }
 
-    public subscribe(obs: Observable<any>): Observable<ResponseMessage> {
+    public subscribe(obs: Observable<BaseMessage>): Observable<ResponseMessage> {
         let acknowledgementToken: Observable<ResponseMessage> = obs.pipe(
             map(
                 incoming_msg => {
@@ -68,9 +59,9 @@ export class AcknowledgementService implements Acknowledgemeent {
             map(
                 incoming_msg => {
                     let finalResponse:MessageLog = {
-                        appLogLocId: this.settings2.setting.appLogId,
+                        appLogLocId: new Uuid().generateId(),
                         appData: {
-                            msgId: new Uuid().generateId(),
+                            msgId: incoming_msg.header.messageID || new Uuid().generateId(),
                             msgLogDateTime: new Date(),
                             msgDateTime: new Date(),
                             msgTag: ['Acknowledgement'],
@@ -81,7 +72,7 @@ export class AcknowledgementService implements Acknowledgemeent {
                 }
             )
         )
-        this.logService2.subscribe(acknowledgementTokenLogging) 
+        this.logService.subscribe(acknowledgementTokenLogging) 
         return acknowledgementToken
     }
 }

+ 42 - 19
services/incomingMessage.service.ts

@@ -9,36 +9,59 @@ export class IncomingMessageService implements IncomingMessageServiceInterface {
 
     constructor(private logService?: LoggingService, private acknowledgeService?: AcknowledgementService) {
         this.logService = new LoggingService()
-        this.acknowledgeService = new AcknowledgementService()
     }
+
+    private settings: LogSetting & { incomingObservable: Observable<BaseMessage>; } = {
+        storage: '',
+        setting: {
+            appId: undefined,
+            appName: '',
+            logLocName: '',
+            logLocId: undefined,
+            appLogLocId: undefined,
+            appLocName: '',
+            appLogId: undefined
+        },
+        incomingObservable: null
+    }
+
     public init(settings: LogSetting & { incomingObservable: Observable<BaseMessage>; }): void {
-        let logSetting: LogSetting = {
-            storage: settings.storage,
-            setting: settings.setting,
-            customSetting: settings.customSetting
+
+        let newSetting: any = settings
+        newSetting.setting = {
+            ...this.settings.setting,
+            ...settings.setting,
+            customSetting:{ 
+                ...this.settings.customSetting,
+                ...settings.customSetting,
+            }
         }
 
+        this.settings = newSetting
+
         // Transform incoming observables into Observable<MessageLog> to be logged
-        let transformedOBS: Observable<any> = settings.incomingObservable.pipe(
-            map(messages => (messages.data))
+        let transformedOBS: Observable<MessageLog> = settings.incomingObservable.pipe(
+            map(message => {
+                let finalResponse: MessageLog = {
+                    appLogLocId: new Uuid().generateId(),
+                    appData: {
+                        msgId: message.header.messageID || new Uuid().generateId(),
+                        msgLogDateTime: new Date(),
+                        msgDateTime: new Date(),
+                        msgTag: ['Incoming'],
+                        msgPayload: JSON.stringify(message)
+                    }
+                }
+                return finalResponse
+            }
+            )
         )
 
         /* Trying new promise chaining structure */
-        this.logService.init(logSetting).then(() => {
+        this.logService.init(this.settings).then(() => {
             this.logService.subscribe(transformedOBS)
-        }).catch((e) => console.error(e)).then(() => {
-            this.acknowledgeService.init(logSetting)
-        }).catch((e) => console.error(e)).then(() => {
-            this.acknowledgeService.subscribe(transformedOBS)
         }).catch((e) => console.error(e))
 
-        // this.logService.init(logSetting).then(() => {
-        //     this.logService.subscribe(transformedOBS).then(() => {
-        //         this.acknowledgeService.init(logSetting).then(() => {
-        //             this.acknowledgeService.subscribe(transformedOBS)
-        //         }).catch((e) => console.error(e))
-        //     }).catch((e) => console.log(e))
-        // }).catch((e) => console.error(e))
 
     }
 }

+ 4 - 3
test/test-streamOBS.ts

@@ -1,18 +1,19 @@
 import { from, map, Observable, of } from "rxjs";
 import * as fs from "fs"
+import { BaseMessage } from "../dependencies/fisloggingservice/services/logging-service";
 
 export class StreamingService {
-    private messagesJSON: any = fs.readFileSync("dependencies/fisloggingservice/messages.json")
+    private messagesJSON: any = fs.readFileSync("testRequest.json")
     private messages = JSON.parse(this.messagesJSON)
 
-    public stream(): Observable<any> {
+    public stream(): Observable<BaseMessage> {
         return new Observable(observer => {
             let messages = this.messages
             let count = 0
             const intervalId = setInterval(() => {
                 observer.next(messages[count]);
                 count++;
-                if (count >= 7) {
+                if (count >= 4) {
                     clearInterval(intervalId);
                     observer.complete();
                 }

+ 7 - 7
test/test.ts

@@ -6,17 +6,13 @@ import { map, Observable } from "rxjs";
 import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
 import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
 const incoming = new IncomingMessageService()
+const acknowledge = new AcknowledgementService()
 const syncrhonize = new MessageSyncrhonizationService()
 const streamService = new StreamingService()
 
 /* --------------  TEST -------------------- */
 // change payload into Observable<BaseMessage>
-const payload: Observable<BaseMessage> = streamService.stream().pipe(
-    map(dataSet => ({
-        header: dataSet.appLogLocId,
-        data: dataSet
-    }))
-);
+const payload: Observable<BaseMessage> = streamService.stream();
 
 // Configure Log Setting
 let storage: LogSetting = {
@@ -34,4 +30,8 @@ let dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
     incomingObservable: payload
 }
 
-incoming.init(dataSet)
+// incoming.init(dataSet)
+
+acknowledge.init(storage).then(() => {
+    acknowledge.subscribe(dataSet.incomingObservable)
+})

+ 5 - 14
test/test2.ts

@@ -7,24 +7,12 @@ import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/d
 import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
 const incoming = new IncomingMessageService()
 const syncrhonize = new MessageSyncrhonizationService()
+const acknowledge = new AcknowledgementService()
 const streamService = new StreamingService()
 
 /* --------------  TEST -------------------- */
 // change payload into Observable<BaseMessage>
-const payload: Observable<BaseMessage> = streamService.stream().pipe(
-    map(dataSet => ({
-        header: dataSet.appLogLocId,
-        data: dataSet
-    })),
-    take(5)
-);
-
-// TESTING. Please ignore this
-// payload.pipe(take(3)).subscribe({
-//     next: data => console.log(data),
-//     error: err => console.error(err),
-//     complete: () => console.log(`Streaming Completed`)
-// })
+const payload: Observable<BaseMessage> = streamService.stream().pipe(take(3));
 
 // Configure Log Setting
 let storage: LogSetting = {
@@ -50,3 +38,6 @@ let dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
 }
 
 incoming.init(dataSet)
+// acknowledge.init(storage).then(() => {
+//     acknowledge.subscribe(dataSet.incomingObservable)
+// })

+ 202 - 0
testRequest.json

@@ -0,0 +1,202 @@
+[
+    {
+        "header": {
+            "messageType": "Command",
+            "messageID": "ab05f310-f3c5-4fd0-9af1-15cda97b6111",
+            "messageName": "Command",
+            "dateCreated": "2023-02-13T03:33:58.746Z",
+            "isAggregate": false,
+            "dataSourceTiming": "",
+            "serviceId": "",
+            "userId": "",
+            "requesterId": "Generatede203a86a-c99e-460e-95ff-f2dc7f484a7d",
+            "messageProducerInformation": {
+                "origin": {
+                    "userApplication": {
+                        "userAppId": "FisAppID/Name",
+                        "userAppName": "Client"
+                    }
+                },
+                "components": "Presentation"
+            },
+            "security": {
+                "ucpId": "GeneratedFromMessageSync"
+            },
+            "messageDataLocation": {
+                "isEmbaded": true
+            },
+            "messageDataFormat": {
+                "dataFormat": "Json"
+            },
+            "requestExecutionMode": 0,
+            "resquestTimeOut": 0,
+            "command": "New"
+        },
+        "data": {
+            "header": "fa29074d-9718-4aba-9999-0001",
+            "data": {
+                "appLogLocId": "fa29074d-9718-4aba-9999-0001",
+                "appData": {
+                    "msgId": "6c162cd3-d42d-4ab4-8882-0001",
+                    "msgLogDateTime": "2022-12-06T15:01:46.987Z",
+                    "msgDateTime": "2022-12-06T08:50:33.809Z",
+                    "msgTag": [
+                        "oval",
+                        "likable"
+                    ],
+                    "msgPayload": "Molestias facilis iusto similique iste voluptas facere. Alias est sequi. Quos consequatur temporibus blanditiis numquam vel. Eos repellat eaque. Voluptatibus optio optio magni eveniet. Quidem architecto esse aut sint neque error magnam perspiciatis."
+                }
+            }
+        }
+    },
+    {
+        "header": {
+            "messageType": "Command",
+            "messageID": "ab05f310-f3c5-4fd0-9af1-15cda97b6222",
+            "messageName": "Command",
+            "dateCreated": "2023-02-13T03:33:58.746Z",
+            "isAggregate": false,
+            "dataSourceTiming": "",
+            "serviceId": "",
+            "userId": "",
+            "requesterId": "Generatede203a86a-c99e-460e-95ff-f2dc7f484a7d",
+            "messageProducerInformation": {
+                "origin": {
+                    "userApplication": {
+                        "userAppId": "FisAppID/Name",
+                        "userAppName": "Client"
+                    }
+                },
+                "components": "Presentation"
+            },
+            "security": {
+                "ucpId": "GeneratedFromMessageSync"
+            },
+            "messageDataLocation": {
+                "isEmbaded": true
+            },
+            "messageDataFormat": {
+                "dataFormat": "Json"
+            },
+            "requestExecutionMode": 0,
+            "resquestTimeOut": 0,
+            "command": "New"
+        },
+        "data": {
+            "header": "fa29074d-9718-4aba-9999-0001",
+            "data": {
+                "appLogLocId": "fa29074d-9718-4aba-9999-0001",
+                "appData": {
+                    "msgId": "6c162cd3-d42d-4ab4-8882-0001",
+                    "msgLogDateTime": "2022-12-06T15:01:46.987Z",
+                    "msgDateTime": "2022-12-06T08:50:33.809Z",
+                    "msgTag": [
+                        "oval",
+                        "likable"
+                    ],
+                    "msgPayload": "Molestias facilis iusto similique iste voluptas facere. Alias est sequi. Quos consequatur temporibus blanditiis numquam vel. Eos repellat eaque. Voluptatibus optio optio magni eveniet. Quidem architecto esse aut sint neque error magnam perspiciatis."
+                }
+            }
+        }
+    },
+    {
+        "header": {
+            "messageType": "Command",
+            "messageID": "ab05f310-f3c5-4fd0-9af1-15cda97b6333",
+            "messageName": "Command",
+            "dateCreated": "2023-02-13T03:33:58.746Z",
+            "isAggregate": false,
+            "dataSourceTiming": "",
+            "serviceId": "",
+            "userId": "",
+            "requesterId": "Generatede203a86a-c99e-460e-95ff-f2dc7f484a7d",
+            "messageProducerInformation": {
+                "origin": {
+                    "userApplication": {
+                        "userAppId": "FisAppID/Name",
+                        "userAppName": "Client"
+                    }
+                },
+                "components": "Presentation"
+            },
+            "security": {
+                "ucpId": "GeneratedFromMessageSync"
+            },
+            "messageDataLocation": {
+                "isEmbaded": true
+            },
+            "messageDataFormat": {
+                "dataFormat": "Json"
+            },
+            "requestExecutionMode": 0,
+            "resquestTimeOut": 0,
+            "command": "New"
+        },
+        "data": {
+            "header": "fa29074d-9718-4aba-9999-0001",
+            "data": {
+                "appLogLocId": "fa29074d-9718-4aba-9999-0001",
+                "appData": {
+                    "msgId": "6c162cd3-d42d-4ab4-8882-0001",
+                    "msgLogDateTime": "2022-12-06T15:01:46.987Z",
+                    "msgDateTime": "2022-12-06T08:50:33.809Z",
+                    "msgTag": [
+                        "oval",
+                        "likable"
+                    ],
+                    "msgPayload": "Molestias facilis iusto similique iste voluptas facere. Alias est sequi. Quos consequatur temporibus blanditiis numquam vel. Eos repellat eaque. Voluptatibus optio optio magni eveniet. Quidem architecto esse aut sint neque error magnam perspiciatis."
+                }
+            }
+        }
+    },
+    {
+        "header": {
+            "messageType": "Command",
+            "messageID": "ab05f310-f3c5-4fd0-9af1-15cda97b6444",
+            "messageName": "Command",
+            "dateCreated": "2023-02-13T03:33:58.746Z",
+            "isAggregate": false,
+            "dataSourceTiming": "",
+            "serviceId": "",
+            "userId": "",
+            "requesterId": "Generatede203a86a-c99e-460e-95ff-f2dc7f484a7d",
+            "messageProducerInformation": {
+                "origin": {
+                    "userApplication": {
+                        "userAppId": "FisAppID/Name",
+                        "userAppName": "Client"
+                    }
+                },
+                "components": "Presentation"
+            },
+            "security": {
+                "ucpId": "GeneratedFromMessageSync"
+            },
+            "messageDataLocation": {
+                "isEmbaded": true
+            },
+            "messageDataFormat": {
+                "dataFormat": "Json"
+            },
+            "requestExecutionMode": 0,
+            "resquestTimeOut": 0,
+            "command": "New"
+        },
+        "data": {
+            "header": "fa29074d-9718-4aba-9999-0001",
+            "data": {
+                "appLogLocId": "fa29074d-9718-4aba-9999-0001",
+                "appData": {
+                    "msgId": "6c162cd3-d42d-4ab4-8882-0001",
+                    "msgLogDateTime": "2022-12-06T15:01:46.987Z",
+                    "msgDateTime": "2022-12-06T08:50:33.809Z",
+                    "msgTag": [
+                        "oval",
+                        "likable"
+                    ],
+                    "msgPayload": "Molestias facilis iusto similique iste voluptas facere. Alias est sequi. Quos consequatur temporibus blanditiis numquam vel. Eos repellat eaque. Voluptatibus optio optio magni eveniet. Quidem architecto esse aut sint neque error magnam perspiciatis."
+                }
+            }
+        }
+    }
+]

+ 2 - 1
type/acknowledgement.interface.ts

@@ -1,11 +1,12 @@
 import { Observable } from "rxjs";
 import { ResponseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
+import { BaseMessage } from "../dependencies/fisloggingservice/services/logging-service";
 import { LogSetting } from "../dependencies/fisloggingservice/type/datatype";
 
 export interface Acknowledgemeent {
     init(settings: LogSetting): void;
 
-    subscribe(obs: Observable<string>): Observable<ResponseMessage>
+    subscribe(obs: Observable<BaseMessage>): Observable<ResponseMessage>
 }
 
 export type AcknowledgementLogSetting = {