Browse Source

IncomingMessageService Set Up

Enzo 1 năm trước cách đây
mục cha
commit
5fa4b78123

+ 2 - 1
interface/export.ts

@@ -1,5 +1,6 @@
 
 // All service classes to be exported will be set here.
-export * from "../services/acknowledgemeent.service"
+export * from "../services/acknowledgement.service"
 export * from "../services/synchronization.service"
+export * from "../services/incomingMessage.service"
  

+ 23 - 24
services/acknowledgement.service.ts

@@ -10,18 +10,18 @@ import { Acknowledgemeent, AcknowledgementLogSetting } from "../type/acknowledge
 export class AcknowledgementService implements Acknowledgemeent {
 
     private messageUtil: FisCreateMessageUtility = new FisCreateMessageUtility("FisAppID/Name")
-    private settings1: LogSetting = {
-        storage: '',
-        setting: {
-            appId: '',
-            appName: '',
-            logLocName: '',
-            logLocId: '',
-            appLogLocId: '',
-            appLocName: '',
-            appLogId: ''
-        }
-    }
+    // private settings1: LogSetting = {
+    //     storage: '',
+    //     setting: {
+    //         appId: '',
+    //         appName: '',
+    //         logLocName: '',
+    //         logLocId: '',
+    //         appLogLocId: '',
+    //         appLocName: '',
+    //         appLogId: ''
+    //     }
+    // }
     private settings2: LogSetting = {
         storage: '',
         setting: {
@@ -36,20 +36,20 @@ export class AcknowledgementService implements Acknowledgemeent {
     }
 
     constructor(private logService1?: LoggingService, private logService2?: LoggingService) {
-        this.logService1 = new LoggingService()
+        // this.logService1 = new LoggingService()
         this.logService2 = new LoggingService()
     }
 
     // set the data. I dont know what to set yet
     public async init(settings: AcknowledgementLogSetting) {
-        let logSetting1: LogSetting = {
-            ...settings,
-            setting: {
-                ...settings.setting,
-                logLocName: "locationName1",
-                appLocName: "appLocName1"
-            }
-        }
+        // let logSetting1: LogSetting = {
+        //     ...settings,
+        //     setting: {
+        //         ...settings.setting,
+        //         logLocName: "locationName1",
+        //         appLocName: "appLocName1"
+        //     }
+        // }
         let logSetting2: LogSetting = {
             ...settings,
             setting: {
@@ -59,15 +59,14 @@ export class AcknowledgementService implements Acknowledgemeent {
             }
         }
         // console.log(settings)
-        this.settings1 = logSetting1
-        this.logService1.init(logSetting1)
+        // this.settings1 = logSetting1
+        // this.logService1.init(logSetting1)
         this.settings2 = logSetting2
         this.logService2.init(logSetting2)
     }
 
     // suppose to call logging service to give an observable type report for every message streamed
     public subscribe(obs: Observable<any>): Observable<ResponseMessage> {
-        this.logService1.subscribe(obs)
         let acknowledgementToken: Observable<ResponseMessage> = obs.pipe(
             map(
                 incoming_msg => {

+ 34 - 0
services/incomingMessage.service.ts

@@ -0,0 +1,34 @@
+import { map, Observable, of, tap } from "rxjs";
+import { BaseMessage, Command, ResponseMessage, Uuid } from "../dependencies/fisappmessagejsutilty/interface/export"
+import { LoggingService } from "../dependencies/fisloggingservice/services/logging-service";
+import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
+import { IncomingMessageServiceInterface } from "../type/datatype";
+import { AcknowledgementService } from "./acknowledgement.service";
+
+export class IncomingMessageService implements IncomingMessageServiceInterface {
+
+    constructor(private logService?: LoggingService, private acknowledgeService?: AcknowledgementService) {
+        this.logService = new LoggingService()
+        this.acknowledgeService = new AcknowledgementService()
+    }
+    init(settings: LogSetting & { incomingObservable: Observable<BaseMessage>; }): void {
+        let logSetting: LogSetting = {
+            storage: settings.storage,
+            setting: settings.setting,
+            customSetting: settings.customSetting
+        }
+        // Transform incoming observables into Observable<MessageLog> to be logged
+        let transformedOBS: Observable<any> = settings.incomingObservable.pipe(
+            map(
+                messages => (messages.data)
+            )
+        )
+        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.error(e))
+    }
+}

+ 1 - 1
services/synchronization.service.ts

@@ -1,6 +1,6 @@
 
 
-export class SyncrhonizationService {
+export class MessageSyncrhonizationService {
     public synchronize(){
         console.log('Hi. My sole existence is to SYNCHRONIZE')
     }

+ 27 - 12
test/test.ts

@@ -1,13 +1,26 @@
 import { AcknowledgementService } from "../services/acknowledgement.service";
 import { StreamingService } from "./test-streamOBS";
-import { SyncrhonizationService } from "../services/synchronization.service";
-import { LogSetting } from "../dependencies/fisloggingservice/type/datatype";
+import { MessageSyncrhonizationService } from "../services/synchronization.service";
+import { IncomingMessageService } from "../services/incomingMessage.service";
+import { map, Observable } from "rxjs";
+import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
+import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
 const acknowledge = new AcknowledgementService()
-const syncrhonize = new SyncrhonizationService()
+const incoming = new IncomingMessageService()
+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
+    }))
+);
+
 // Configure Log Setting
-const storage: LogSetting = {
+let storage: LogSetting = {
     storage: "File",
     setting: {
         appName: 'Default from client',
@@ -15,13 +28,15 @@ const storage: LogSetting = {
         logLocName: 'To be generated in client',
     }
 }
+let dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
+    storage: storage.storage,
+    setting: storage.setting,
+    customSetting: storage.customSetting,
+    incomingObservable: payload
+}
 
-// console.log(`I am Client 1`)
-// syncrhonize.synchronize()
-
-/* --------------  ACTION -------------------- */
-const payload = streamService.stream()
+incoming.init(dataSet)
 
-acknowledge.init(storage).then(() => {
-    acknowledge.subscribe(payload)
-}).catch((e) => console.error(e))
+// acknowledge.init(storage).then(() => {
+//     acknowledge.subscribe(payload)
+// }).catch((e) => console.error(e))

+ 14 - 0
type/datatype.ts

@@ -0,0 +1,14 @@
+import { Observable } from "rxjs";
+import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
+import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
+
+type IncomingMessageSetting =  LogSetting & {
+    incomingObservable:Observable<BaseMessage>
+ }
+ 
+ // Incoming message Service Class
+ export interface IncomingMessageServiceInterface  { 
+ 
+     // Set default setting
+     init(settings: IncomingMessageSetting ): void;
+ }