Browse Source

temp solution

Enzo 1 năm trước cách đây
mục cha
commit
74bd35a397
6 tập tin đã thay đổi với 238 bổ sung95 xóa
  1. 2 1
      .gitignore
  2. 1 0
      package.json
  3. 0 1
      services/incomingMessage.service.ts
  4. 6 2
      services/synchronization.service.ts
  5. 185 0
      test/temptest.ts
  6. 44 91
      test/test3a.ts

+ 2 - 1
.gitignore

@@ -5,4 +5,5 @@ appLocation.json
 appLogLoc.json
 appProfile.json
 log.json
-loglocation.json
+loglocation.json
+stupid.ts

+ 1 - 0
package.json

@@ -5,6 +5,7 @@
   "main": "index.js",
   "scripts": {
     "build": "tsc -p tsconfig.json",
+    "temp": "node test/temptest.js",
     "start": "node test/test1a.js",
     "start1a": "node test/test1a.js",
     "start1b": "node test/test1b.js",

+ 0 - 1
services/incomingMessage.service.ts

@@ -57,7 +57,6 @@ export class IncomingMessageService implements IncomingMessageServiceInterface {
             )
         )
 
-        /* Trying new promise chaining structure */
         this.logService.init(this.settings).then(() => {
             this.logService.subscribe(transformedOBS)
         }).catch((e) => console.error(e))

+ 6 - 2
services/synchronization.service.ts

@@ -35,7 +35,11 @@ export class MessageSyncrhonizationService implements MessageSynchronisationServ
     // Incoming obstriger serves as a trigger point to perform another synchronization
     public subscribe(obsTrigger: Observable<string>): Observable<any> {
         let subjectOutput = this.syncrhonize()
-
+        this.targetSrc.subscribe(subjectOutput)
+        subjectOutput.subscribe({
+            next: missingMsg => console.log(`Synchronizing ${missingMsg.appData.msgId}`)
+        })
+        
         // obs.subscribe({
         //     next: element => {
         //         subjectOutput = this.syncrhonize()
@@ -86,7 +90,7 @@ export class MessageSyncrhonizationService implements MessageSynchronisationServ
         })
         return promiseQuery
     }
-    // compare results and return differences
+    // compare results and return differences`
     private async checkArrayDifferences(args: { arr1?: any[], arr2?: any[] }): Promise<any[]> {
         return new Promise((resolve, reject) => {
             let missingMsg: MessageLog[] = []

+ 185 - 0
test/temptest.ts

@@ -0,0 +1,185 @@
+import { resolve } from "path";
+import { Observable, map, Subject, takeUntil, take } from "rxjs";
+import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
+import { LogSetting } from "../dependencies/fisloggingservice/type/datatype";
+import { AcknowledgementService } from "../services/acknowledgement.service";
+import { IncomingMessageService } from "../services/incomingMessage.service";
+import { MessageSyncrhonizationService } from "../services/synchronization.service";
+import { MessageSynchronisationServiceSetting } from "../type/datatype";
+import { StreamingService } from "./test-streamOBS";
+
+
+/* Pre - Defined Data && Settings */
+const stream = new StreamingService()
+// Declare source Services && Observables (Using File Storage) Simulating Full Logs
+const source_synchronize = new MessageSyncrhonizationService()
+const source_payload: Observable<BaseMessage> = stream.stream()
+const source_incoming = new IncomingMessageService()
+const source_payload_subject : Subject<BaseMessage> = new Subject()
+source_payload.subscribe(
+    {
+        next: (data) => {
+            source_payload_subject.next(data)
+            // console.log(data)
+        }
+    }
+)
+const source_acknowledge = new AcknowledgementService()
+const source_payload_string = source_payload.pipe(
+    map((data) => {
+        return JSON.stringify(data);
+    })
+)
+
+// Declare target Services && Observables (Using MongoDB Storage) Simulating Partial Logs
+const target_payload: Observable<BaseMessage> = stream.stream().pipe(take(2))
+const target_payload_subject: Subject<BaseMessage> = new Subject()
+target_payload.subscribe(
+    {
+        next: (data) => {
+            target_payload_subject.next(data)
+            // console.log(data)
+        }
+    }
+)
+const target_incoming = new IncomingMessageService()
+const target_syncrhonize = new MessageSyncrhonizationService()
+const target_acknowledge = new AcknowledgementService()
+const target_payload_string = target_payload.pipe(
+    map((data) => {
+        return JSON.stringify(data);
+    }),
+)
+
+// Decalre Source Storage
+let source_storage: LogSetting = {
+    storage: "File",
+    setting: {
+        appName: 'Default from client',
+        appLocName: 'To be generated in client',
+        logLocName: 'To be generated in client',
+    }
+}
+
+let source_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
+    storage: source_storage.storage,
+    setting: source_storage.setting,
+    customSetting: source_storage.customSetting,
+    incomingObservable: source_payload_subject
+}
+
+//Declare Target Storage
+let target_storage: LogSetting = {
+    storage: "MongoDB",
+    setting: {
+        appName: 'Default from client',
+        appLocName: 'To be generated in client',
+        logLocName: 'To be generated in client',
+    },
+    customSetting: {
+        srv: true,
+        user: "testDB",
+        password: "h1nt1OyXw6QeUnzS",
+        server: "cluster0.29sklte.mongodb.net",
+        collection: "log",
+    }
+}
+let target_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
+    storage: target_storage.storage,
+    setting: target_storage.setting,
+    customSetting: target_storage.customSetting,
+    incomingObservable: target_payload_subject
+}
+
+// Combine source and target storage to form MessageSynchronisationServiceSetting
+let settings: MessageSynchronisationServiceSetting = {
+    incomingSource: {
+        //all of the settings to be combined here
+        ...source_storage,
+        tags: ['Incoming']
+    }, //LogSetting & {tags:string[] },   
+    target: {
+        ...target_storage,
+        tags: ['Incoming']
+    }  //LogSetting & {tags:string[] }  
+}
+
+
+/* ------------- CODING TEST --------------- */
+const new_subject: Subject<BaseMessage> = new Subject();
+const subjectObs = { // Observer but a subject looking to subscribe
+    next: (data) => {
+        console.log(data)
+    }
+}
+new_subject.subscribe(subjectObs) // Observerble(Subject) subcribed and stream data for observer(subject) "subjectObs"
+
+source_incoming.init(
+    {
+        storage: source_storage.storage,
+        setting: source_storage.setting,
+        customSetting: source_storage.customSetting,
+        incomingObservable: new_subject.asObservable()
+    }
+)
+target_incoming.init(
+    {
+        storage: target_storage.storage,
+        setting: target_storage.setting,
+        customSetting: target_storage.customSetting,
+        incomingObservable: new_subject.asObservable()
+    }
+)
+setTimeout(() => {
+    new_subject.next(<BaseMessage>{
+        "header": {
+            "messageType": "Command",
+            "messageID": "ab05f310-f3c5-4fd0-9af1-15cda97b4444",
+            "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."
+                }
+            }
+        }
+    }
+    )
+}, 1000)

+ 44 - 91
test/test3a.ts

@@ -1,7 +1,7 @@
 import { resolve } from "path";
 import { Observable, map, Subject, takeUntil, take } from "rxjs";
 import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
-import { LogSetting } from "../dependencies/fisloggingservice/type/datatype";
+import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
 import { AcknowledgementService } from "../services/acknowledgement.service";
 import { IncomingMessageService } from "../services/incomingMessage.service";
 import { MessageSyncrhonizationService } from "../services/synchronization.service";
@@ -11,11 +11,18 @@ import { StreamingService } from "./test-streamOBS";
 
 /* Pre - Defined Data && Settings */
 const stream = new StreamingService()
+
 // Declare source Services && Observables (Using File Storage) Simulating Full Logs
 const source_synchronize = new MessageSyncrhonizationService()
-const source_payload: Observable<BaseMessage> = stream.stream()
+const source_payload: Observable<BaseMessage> = stream.stream().pipe()
 const source_incoming = new IncomingMessageService()
-const source_acknowledge = new AcknowledgementService()
+const source_payload_subject: Subject<BaseMessage> = new Subject()
+source_payload.subscribe({
+    next: (data) => {
+        source_payload_subject.next(data)
+        // console.log(data)
+    }
+})
 const source_payload_string = source_payload.pipe(
     map((data) => {
         return JSON.stringify(data);
@@ -23,25 +30,29 @@ const source_payload_string = source_payload.pipe(
 )
 
 // Declare target Services && Observables (Using MongoDB Storage) Simulating Partial Logs
+const target_syncrhonize = new MessageSyncrhonizationService()
 const target_payload: Observable<BaseMessage> = stream.stream().pipe(take(2))
 const target_payload_subject: Subject<BaseMessage> = new Subject()
-target_payload.subscribe(
-    {
-        next: (data) => {
-            target_payload_subject.next(data)
-        }
-    }
-)
 const target_incoming = new IncomingMessageService()
-const target_syncrhonize = new MessageSyncrhonizationService()
-const target_acknowledge = new AcknowledgementService()
+target_payload.subscribe({
+    next: (data) => {
+        target_payload_subject.next(<BaseMessage>data)
+    }
+})
 const target_payload_string = target_payload.pipe(
     map((data) => {
         return JSON.stringify(data);
     }),
 )
+// testing to see if data is sent in
+target_payload_subject.subscribe({
+    next: element => {
+        // console.log(element) 
+        // Missing MessageLog Data is sent in
+    }
+})
 
-// Decalre Source Storage
+// Declare Source Storage
 let source_storage: LogSetting = {
     storage: "File",
     setting: {
@@ -55,7 +66,7 @@ let source_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> }
     storage: source_storage.storage,
     setting: source_storage.setting,
     customSetting: source_storage.customSetting,
-    incomingObservable: source_payload
+    incomingObservable: source_payload_subject
 }
 
 //Declare Target Storage
@@ -74,11 +85,12 @@ let target_storage: LogSetting = {
         collection: "log",
     }
 }
+
 let target_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
     storage: target_storage.storage,
     setting: target_storage.setting,
     customSetting: target_storage.customSetting,
-    incomingObservable: target_payload
+    incomingObservable: target_payload_subject
 }
 
 // Combine source and target storage to form MessageSynchronisationServiceSetting
@@ -94,94 +106,35 @@ let settings: MessageSynchronisationServiceSetting = {
     }  //LogSetting & {tags:string[] }  
 }
 
-setTimeout(()=>{
-    target_payload_subject.next(
-        <BaseMessage>{
-            "header": {
-                "messageType": "Command",
-                "messageID": "ab05f310-f3c5-4fd0-9af1-15cda97b4444",
-                "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."
-                    }
-                }
-            }
-        }
-    )
-},2000)
 
 /* -------- SYNCHRONIZATION --------- */
-async function initializeData(): Promise<void> {
+function initializeData() {
     source_incoming.init(source_dataSet)
     target_incoming.init(target_dataSet)
-    return 
 }
 
-/*  Run this code to pluck some data into the database. 4 in File storage and 2 in Mongo */
+/*  Run this code to put some data into the database. 4 in File storage and 2 in Mongo */
 // initializeData()
 
-
-/* Testing to wrap everything into a promise */
-// initializeData().then(() => {
-//     source_synchronize.init(settings).then(() => {
-//         source_synchronize.subscribe(source_payload_string).subscribe({
-//             next: msgToBeSynchronized => {
-//                 target_payload_subject.next(msgToBeSynchronized)
-//                 console.log(msgToBeSynchronized) // It does log missing items
-//             }
-//         })
-//     })
-// })
-
 /*  Type 1 synchronization */
 /* Please note that this operation assumes that there's already existing data in the designated storage place. It still cannot perform real-time live streaming dynamically
 when there is a streaming occuring.  */
+// source_synchronize.init(settings).then(() => {
+//     source_synchronize.subscribe(source_payload_string).subscribe({
+//         next: (msgToBeSynchronized) => {
+//             target_payload_subject.next(msgToBeSynchronized)
+//             // console.log(msgToBeSynchronized) // It does log missing items
+//         }
+//     })
+// })
+
 source_synchronize.init(settings).then(() => {
-    source_synchronize.subscribe(source_payload_string).subscribe({
-        next: msgToBeSynchronized => {
-            target_payload_subject.next(msgToBeSynchronized)
-            // console.log(msgToBeSynchronized) // It does log missing items
+    let stream = source_synchronize.subscribe(source_payload_string) // this returns an observable declared with stream
+    stream.subscribe({
+        next: (messageToBeSync) => {
+            target_payload_subject.next(messageToBeSync)
+            // console.log(messageToBeSync)
         }
     })
 })
- 
-// Doesnt seem like they do anything
+