Przeglądaj źródła

added extra JSON checking

Enzo 1 rok temu
rodzic
commit
dce7a62497
4 zmienionych plików z 18 dodań i 4 usunięć
  1. 14 0
      services/message-auditor.service.ts
  2. 1 1
      test/test-streamOBS.ts
  3. 2 2
      test/test5.ts
  4. 1 1
      type/datatype.ts

+ 14 - 0
services/message-auditor.service.ts

@@ -53,6 +53,7 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
     private filterData(filters: any, message: MessageLog): boolean {
         let response: boolean = true //Just using this like a statemanagement
         let payload: BaseMessage = JSON.parse(message.appData.msgPayload as string) // Extract the payload from the messageLog first
+        this.verifyIfJsonDataIsString(payload) // Convert stringified nested payload if there's any
         // Making a separate function to cater to different multi filters conditions are coded below
         if (filters) { // if filters is not null
             if (Object.keys(filters).length > 1) {
@@ -184,4 +185,17 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
         }
     }
 
+    // Addtional checking for notification messages cases
+    private verifyIfJsonDataIsString(payload: BaseMessage | any) {
+        let parsedData: any
+        if (payload.data.data.data && typeof payload.data.data.data === 'string') {
+            parsedData = JSON.parse(payload.data.data.data)
+            console.log(parsedData)
+            payload.data.data.data = parsedData
+            return payload
+        } else {
+            return payload
+        }
+    }
+
 }

+ 1 - 1
test/test-streamOBS.ts

@@ -6,7 +6,7 @@ import * as fs from "fs"
 import { BaseMessage } from "../dependencies/log/dependencies/msgutil/interface/export";
 
 export class StreamingService {
-    private messagesJSON: any = fs.readFileSync("testRequest.json")
+    private messagesJSON: any = fs.readFileSync("log.json")
     private messages = JSON.parse(this.messagesJSON)
 
     public stream(): Subject<BaseMessage> {

+ 2 - 2
test/test5.ts

@@ -69,8 +69,8 @@ let settings: MessageSynchronisationServiceSetting = {
     },
     //  Set Filters here, since it's part of the settings
     filters: {
-        'data.data.appData.msgTag[0]': 'likable',
-        'header.messageProducerInformation.origin.userApplication.userAppName': 'Client'
+        'data.data.data.personCode': 'w002',
+        'header.messageProducerInformation.origin.userApplication.userAppId': 'Content Delivery Management Server'
     }
 }
 

+ 1 - 1
type/datatype.ts

@@ -31,7 +31,7 @@ interface Filters {
 // Acknowledgement Service Class
 export interface MessageAuditorServiceInterface {
     // Set default setting
-    init(settings: MessageSynchronisationServiceSetting, filters?: any): void;
+    init(settings: MessageSynchronisationServiceSetting): void;
     // Subscribe to trigger
     subscribe(obs: Observable<ErrorTrigger>): Observable<any>;
 }