Prechádzať zdrojové kódy

update to support array

Enzo 1 rok pred
rodič
commit
719b959a96
3 zmenil súbory, kde vykonal 20 pridanie a 14 odobranie
  1. 17 8
      services/message-auditor.service.ts
  2. 1 2
      test/test5.ts
  3. 2 4
      type/datatype.ts

+ 17 - 8
services/message-auditor.service.ts

@@ -14,8 +14,12 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
 
     /* Set up the targets or points of synchronization. This is where it will register the 2 different location of 
     the data to be synchronized */
-    public init(settings: MessageSynchronisationServiceSetting): void {
+    public init(settings: MessageSynchronisationServiceSetting, filters?: any): void {
         this.settings = settings;
+        if (filters) {
+            console.log(`Integrating filters: ${Object.keys(this.filter)} in AuditMessage service`)
+            this.filter = filters
+        }
     }
 
     /* This is the main interface of the message sync service. The argument will take in an observable stream of 
@@ -45,11 +49,6 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
         return this.missingMessageSubject
     }
 
-    public setFilter(filters: any) {
-        this.filter = filters
-        console.log(`Integrating filters: ${Object.keys(this.filter)} in AuditMessage service`)
-    }
-
 
     /* ________________ Private Functions _________________ */
     // Filtering functions to filter out messages
@@ -59,12 +58,22 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
         // Making a separate function to cater to different multi filter conditions are coded below
         function checkValues(filter): boolean { //FYI, all parameters are string
             let key = Object.keys(filter)
-            let value = Object.values(filter)
+            console.log(Object.values(filter))
+            let value = Object.values(filter)[0]
             let res = _.get(payload, key[0])
             // Check first if the payload has the filtering properties/path
             if (_.has(payload, key[0])) {
                 // check if value is equal to fitler's
-                if (value == res) {
+                let strarray: string[]
+                // check array 
+                if (Array.isArray(value)) {
+                    strarray = value as string[]
+                }
+                else {
+                    strarray = [value as string]
+                }
+                // compare array with that string 
+                if (strarray.includes(res)) {
                     return true
                 } else {
                     return false

+ 1 - 2
test/test5.ts

@@ -83,9 +83,8 @@ async function initializeAuditService(configuration: MessageSynchronisationServi
         'data.data.appData.msgTag[0]': 'likable',
         'header.messageProducerInformation.origin.userApplication.userAppName': 'Client'
     }
-    auditService.init(configuration) // Configure two points of audit
+    auditService.init(configuration, filter) // Configure two points of audit and also adding filter
     // auditService.setFilter({ 'data.data.appData.msgTag[0]': 'oval' }) // set fitler if there's any. Please not that 
-    auditService.setFilter(filter) // set fitler if there's any. Please note that filtering doesn't work on arrays yet.
     auditService.subscribe(triggerSyncSubject).subscribe((missingElements: MessageLog) => {
         let message = JSON.parse(missingElements.appData.msgPayload as any)
         subscriber.next(message)

+ 2 - 4
type/datatype.ts

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